diff --git a/crates/context/Cargo.toml b/crates/context/Cargo.toml index d116dd039f..37abdd68ec 100644 --- a/crates/context/Cargo.toml +++ b/crates/context/Cargo.toml @@ -65,6 +65,7 @@ dev = [ "optional_block_gas_limit", "optional_eip3541", "optional_eip3607", + "optional_eip7623", "optional_no_base_fee", "optional_priority_fee_check", "optional_fee_charge", @@ -74,6 +75,7 @@ optional_balance_check = [] optional_block_gas_limit = [] optional_eip3541 = [] optional_eip3607 = [] +optional_eip7623 = [] optional_no_base_fee = [] optional_priority_fee_check = [] optional_fee_charge = [] diff --git a/crates/context/interface/src/cfg.rs b/crates/context/interface/src/cfg.rs index 6454557e92..71755e5a64 100644 --- a/crates/context/interface/src/cfg.rs +++ b/crates/context/interface/src/cfg.rs @@ -44,6 +44,9 @@ pub trait Cfg { /// Returns whether the EIP-3541 (disallowing new contracts with 0xEF prefix) is disabled. fn is_eip3541_disabled(&self) -> bool; + /// Returns whether the EIP-7623 (increased calldata cost) is disabled. + fn is_eip7623_disabled(&self) -> bool; + /// Returns whether the balance check is disabled. fn is_balance_check_disabled(&self) -> bool; diff --git a/crates/context/src/cfg.rs b/crates/context/src/cfg.rs index db2194506a..b463592827 100644 --- a/crates/context/src/cfg.rs +++ b/crates/context/src/cfg.rs @@ -92,6 +92,14 @@ pub struct CfgEnv { /// By default, it is set to `false`. #[cfg(feature = "optional_eip3607")] pub disable_eip3607: bool, + /// EIP-7623 increases calldata cost. + /// + /// This EIP can be considered irrelevant in the context of an EVM-compatible L2 rollup, + /// if it does not make use of blobs. + /// + /// By default, it is set to `false`. + #[cfg(feature = "optional_eip7623")] + pub disable_eip7623: bool, /// Disables base fee checks for EIP-1559 transactions /// /// This is useful for testing method calls with zero gas price. @@ -161,6 +169,8 @@ impl CfgEnv { disable_eip3541: false, #[cfg(feature = "optional_eip3607")] disable_eip3607: false, + #[cfg(feature = "optional_eip7623")] + disable_eip7623: false, #[cfg(feature = "optional_no_base_fee")] disable_base_fee: false, #[cfg(feature = "optional_priority_fee_check")] @@ -210,6 +220,8 @@ impl CfgEnv { disable_eip3541: self.disable_eip3541, #[cfg(feature = "optional_eip3607")] disable_eip3607: self.disable_eip3607, + #[cfg(feature = "optional_eip7623")] + disable_eip7623: self.disable_eip7623, #[cfg(feature = "optional_no_base_fee")] disable_base_fee: self.disable_base_fee, #[cfg(feature = "optional_priority_fee_check")] @@ -248,6 +260,13 @@ impl CfgEnv { self.disable_fee_charge = disable; self } + + /// Sets the disable eip7623 flag. + #[cfg(feature = "optional_eip7623")] + pub fn with_disable_eip7623(mut self, disable: bool) -> Self { + self.disable_eip7623 = disable; + self + } } impl + Copy> Cfg for CfgEnv { @@ -317,6 +336,16 @@ impl + Copy> Cfg for CfgEnv { } } + fn is_eip7623_disabled(&self) -> bool { + cfg_if::cfg_if! { + if #[cfg(feature = "optional_eip7623")] { + self.disable_eip7623 + } else { + false + } + } + } + fn is_balance_check_disabled(&self) -> bool { cfg_if::cfg_if! { if #[cfg(feature = "optional_balance_check")] { diff --git a/crates/handler/src/handler.rs b/crates/handler/src/handler.rs index d8eea22245..e79141524a 100644 --- a/crates/handler/src/handler.rs +++ b/crates/handler/src/handler.rs @@ -224,6 +224,7 @@ pub trait Handler { // Calculate final refund and add EIP-7702 refund to gas. self.refund(evm, exec_result, eip7702_gas_refund); // Ensure gas floor is met and minimum floor gas is spent. + // if `cfg.is_eip7623_disabled` is true, floor gas will be set to zero self.eip7623_check_gas_floor(evm, exec_result, init_and_floor_gas); // Return unused gas to caller self.reimburse_caller(evm, exec_result)?; @@ -251,7 +252,12 @@ pub trait Handler { #[inline] fn validate_initial_tx_gas(&self, evm: &Self::Evm) -> Result { let ctx = evm.ctx_ref(); - validation::validate_initial_tx_gas(ctx.tx(), ctx.cfg().spec().into()).map_err(From::from) + validation::validate_initial_tx_gas( + ctx.tx(), + ctx.cfg().spec().into(), + ctx.cfg().is_eip7623_disabled(), + ) + .map_err(From::from) } /* PRE EXECUTION */ diff --git a/crates/handler/src/validation.rs b/crates/handler/src/validation.rs index 92a8b9f873..737f3111b0 100644 --- a/crates/handler/src/validation.rs +++ b/crates/handler/src/validation.rs @@ -224,8 +224,13 @@ pub fn validate_tx_env( pub fn validate_initial_tx_gas( tx: impl Transaction, spec: SpecId, + is_eip7623_disabled: bool, ) -> Result { - let gas = gas::calculate_initial_tx_gas_for_tx(&tx, spec); + let mut gas = gas::calculate_initial_tx_gas_for_tx(&tx, spec); + + if is_eip7623_disabled { + gas.floor_gas = 0 + } // Additional check to see if limit is big enough to cover initial gas. if gas.initial_gas > tx.gas_limit() { diff --git a/crates/revm/Cargo.toml b/crates/revm/Cargo.toml index 1b5ad65728..dd2aa5f077 100644 --- a/crates/revm/Cargo.toml +++ b/crates/revm/Cargo.toml @@ -84,6 +84,7 @@ dev = [ "optional_block_gas_limit", "optional_eip3541", "optional_eip3607", + "optional_eip7623", "optional_no_base_fee", ] memory_limit = ["context/memory_limit", "interpreter/memory_limit"] @@ -91,6 +92,7 @@ optional_balance_check = ["context/optional_balance_check"] optional_block_gas_limit = ["context/optional_block_gas_limit"] optional_eip3541 = ["context/optional_eip3541"] optional_eip3607 = ["context/optional_eip3607"] +optional_eip7623 = ["context/optional_eip7623"] optional_no_base_fee = ["context/optional_no_base_fee"] # Precompiles features: Please look at the comments in `precompile` crate for more information.