diff --git a/crates/anvil/src/config.rs b/crates/anvil/src/config.rs index f32aaf1ad8a8..f262cfb0c559 100644 --- a/crates/anvil/src/config.rs +++ b/crates/anvil/src/config.rs @@ -32,7 +32,10 @@ use foundry_common::{ }; use foundry_config::Config; use foundry_evm::{ - executor::fork::{BlockchainDb, BlockchainDbMeta, SharedBackend}, + executor::{ + fork::{BlockchainDb, BlockchainDbMeta, SharedBackend}, + inspector::DEFAULT_CREATE2_DEPLOYER, + }, revm, revm::primitives::{BlockEnv, CfgEnv, SpecId, TxEnv, U256 as rU256}, utils::{apply_chain_and_block_specific_env_changes, h256_to_b256, u256_to_ru256}, @@ -163,6 +166,8 @@ pub struct NodeConfig { pub init_state: Option, /// max number of blocks with transactions in memory pub transaction_block_keeper: Option, + /// Disable the default CREATE2 deployer + pub disable_default_create2_deployer: bool, } impl NodeConfig { @@ -398,6 +403,7 @@ impl Default for NodeConfig { prune_history: Default::default(), init_state: None, transaction_block_keeper: None, + disable_default_create2_deployer: false, } } } @@ -1005,6 +1011,15 @@ latest block number: {latest_block}" ) .await; + // Writes the default create2 deployer to the backend, + // if the option is not disabled and we are not forking. + if !self.disable_default_create2_deployer && self.eth_rpc_url.is_none() { + backend + .set_create2_deployer(DEFAULT_CREATE2_DEPLOYER) + .await + .expect("Failed to create default create2 deployer"); + } + if let Some(ref state) = self.init_state { backend .get_db() diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index 98ba22c2eba2..c0d9b0bc3a05 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -60,6 +60,7 @@ use foundry_evm::{ executor::{ backend::{DatabaseError, DatabaseResult}, inspector::AccessListTracer, + DEFAULT_CREATE2_DEPLOYER_RUNTIME_CODE, }, revm::{ self, @@ -235,6 +236,13 @@ impl Backend { backend } + /// Writes the CREATE2 deployer code directly to the database at the address provided. + pub async fn set_create2_deployer(&self, address: Address) -> DatabaseResult<()> { + self.set_code(address, Bytes::from_static(DEFAULT_CREATE2_DEPLOYER_RUNTIME_CODE)).await?; + + Ok(()) + } + /// Updates memory limits that should be more strict when auto-mine is enabled pub(crate) fn update_interval_mine_block_time(&self, block_time: Duration) { self.states.write().update_interval_mine_block_time(block_time) diff --git a/crates/evm/src/executor/mod.rs b/crates/evm/src/executor/mod.rs index 3de78fbc868a..aa32860c60e4 100644 --- a/crates/evm/src/executor/mod.rs +++ b/crates/evm/src/executor/mod.rs @@ -64,7 +64,10 @@ pub use builder::ExecutorBuilder; /// A mapping of addresses to their changed state. pub type StateChangeset = HashMap; +/// The initcode of the default create2 deployer. pub const DEFAULT_CREATE2_DEPLOYER_CODE: &[u8] = &hex!("604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3"); +/// The runtime code of the default create2 deployer. +pub const DEFAULT_CREATE2_DEPLOYER_RUNTIME_CODE: &[u8] = &hex!("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3"); /// A type that can execute calls ///