|
1 | 1 | //! Support for "cheat codes" / bypass functions
|
2 | 2 |
|
| 3 | +use alloy_eips::eip7702::SignedAuthorization; |
3 | 4 | use alloy_evm::precompiles::{Precompile, PrecompileInput};
|
4 | 5 | use alloy_primitives::{
|
5 |
| - Address, Bytes, |
| 6 | + Address, Bytes, U256, |
6 | 7 | map::{AddressHashSet, foldhash::HashMap},
|
7 | 8 | };
|
| 9 | +use alloy_rpc_types::Authorization; |
8 | 10 | use parking_lot::RwLock;
|
9 | 11 | use revm::precompile::{
|
10 | 12 | PrecompileError, PrecompileOutput, PrecompileResult, secp256k1::ec_recover_run,
|
@@ -84,6 +86,38 @@ impl CheatsManager {
|
84 | 86 | pub fn has_recover_overrides(&self) -> bool {
|
85 | 87 | !self.state.read().signature_overrides.is_empty()
|
86 | 88 | }
|
| 89 | + |
| 90 | + /// Creates authorization entries for impersonated accounts with signature overrides. |
| 91 | + /// This allows impersonated accounts to be used in EIP-7702 transactions. |
| 92 | + pub fn create_impersonated_authorizations( |
| 93 | + &self, |
| 94 | + authorizations: &[SignedAuthorization], |
| 95 | + chain_id: u64, |
| 96 | + ) -> Vec<SignedAuthorization> { |
| 97 | + let mut authorization_list = authorizations.to_vec(); |
| 98 | + for addr in self.impersonated_accounts() { |
| 99 | + let auth = Authorization { chain_id: U256::from(chain_id), address: addr, nonce: 0 }; |
| 100 | + |
| 101 | + let signed_auth = SignedAuthorization::new_unchecked( |
| 102 | + auth, |
| 103 | + 0, // y_parity |
| 104 | + U256::from(1), // r |
| 105 | + U256::from(1), // s |
| 106 | + ); |
| 107 | + |
| 108 | + let mut sig_bytes = [0u8; 65]; |
| 109 | + let r_bytes = signed_auth.r().to_be_bytes::<32>(); |
| 110 | + let s_bytes = signed_auth.s().to_be_bytes::<32>(); |
| 111 | + sig_bytes[..32].copy_from_slice(&r_bytes); |
| 112 | + sig_bytes[32..64].copy_from_slice(&s_bytes); |
| 113 | + sig_bytes[64] = signed_auth.y_parity(); |
| 114 | + let sig = Bytes::copy_from_slice(&sig_bytes); |
| 115 | + |
| 116 | + self.add_recover_override(sig, addr); |
| 117 | + authorization_list.push(signed_auth); |
| 118 | + } |
| 119 | + authorization_list |
| 120 | + } |
87 | 121 | }
|
88 | 122 |
|
89 | 123 | /// Container type for all the state variables
|
|
0 commit comments