diff --git a/crates/anvil/src/cmd.rs b/crates/anvil/src/cmd.rs index 508c3dc8e1f1..2c5e08ba1f57 100644 --- a/crates/anvil/src/cmd.rs +++ b/crates/anvil/src/cmd.rs @@ -171,6 +171,9 @@ pub struct NodeArgs { #[command(flatten)] pub server_config: ServerConfig, + /// The memory limit per EVM execution in bytes. + #[arg(long)] + pub memory_limit: Option, } #[cfg(windows)] @@ -235,6 +238,7 @@ impl NodeArgs { .with_optimism(self.evm_opts.optimism) .with_disable_default_create2_deployer(self.evm_opts.disable_default_create2_deployer) .with_slots_in_an_epoch(self.slots_in_an_epoch) + .with_memory_limit(self.memory_limit) } fn account_generator(&self) -> AccountGenerator { diff --git a/crates/anvil/src/config.rs b/crates/anvil/src/config.rs index 354bf2c589d9..039d7779b440 100644 --- a/crates/anvil/src/config.rs +++ b/crates/anvil/src/config.rs @@ -172,6 +172,8 @@ pub struct NodeConfig { pub enable_optimism: bool, /// Slots in an epoch pub slots_in_an_epoch: u64, + /// Memory configuration layer + pub memory_limit: Option, } impl NodeConfig { @@ -407,11 +409,18 @@ impl Default for NodeConfig { disable_default_create2_deployer: false, enable_optimism: false, slots_in_an_epoch: 32, + memory_limit: None, } } } impl NodeConfig { + /// Returns the memory limit of the node + #[must_use] + pub fn with_memory_limit(mut self, mems_value: Option) -> Self { + self.memory_limit = mems_value; + self + } /// Returns the base fee to use pub fn get_base_fee(&self) -> U256 { self.base_fee @@ -831,6 +840,10 @@ impl NodeConfig { cfg.disable_block_gas_limit = self.disable_block_gas_limit; cfg.handler_cfg.is_optimism = self.enable_optimism; + if let Some(value) = self.memory_limit { + cfg.memory_limit = value; + } + let env = revm::primitives::Env { cfg: cfg.cfg_env, block: BlockEnv {