From 96dda385ae09963f883ab5506bdfb6f28b7d6df7 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Wed, 3 Apr 2024 21:51:29 +0200 Subject: [PATCH] feat(interpreter): remove SPEC generic from gas calculation functions (#1243) * feat(interpreter): remove SPEC generic from gas calculation functions * feat(interpreter): make most gas cost calculation functions `const` * set_final_refund * unused * fix: optimism * chore: use `is_london: bool` instead of `SpecId` in `Gas::set_final_refund` --- crates/interpreter/src/gas.rs | 5 +- crates/interpreter/src/gas/calc.rs | 209 +++++++++++------- .../src/instructions/arithmetic.rs | 2 +- crates/interpreter/src/instructions/host.rs | 17 +- .../src/instructions/host/call_helpers.rs | 3 +- crates/interpreter/src/interpreter.rs | 2 +- crates/primitives/src/specification.rs | 8 +- crates/revm/src/handler/mainnet/execution.rs | 12 +- crates/revm/src/handler/mainnet/validation.rs | 3 +- crates/revm/src/optimism/handler_register.rs | 2 +- 10 files changed, 153 insertions(+), 110 deletions(-) diff --git a/crates/interpreter/src/gas.rs b/crates/interpreter/src/gas.rs index 01598cc159..51739b1057 100644 --- a/crates/interpreter/src/gas.rs +++ b/crates/interpreter/src/gas.rs @@ -5,7 +5,6 @@ mod constants; pub use calc::*; pub use constants::*; -use revm_primitives::{Spec, SpecId::LONDON}; /// Represents the state of gas during execution. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] @@ -94,8 +93,8 @@ impl Gas { /// /// Related to EIP-3529: Reduction in refunds #[inline] - pub fn set_final_refund(&mut self) { - let max_refund_quotient = if SPEC::enabled(LONDON) { 5 } else { 2 }; + pub fn set_final_refund(&mut self, is_london: bool) { + let max_refund_quotient = if is_london { 5 } else { 2 }; self.refunded = (self.refunded() as u64).min(self.spent() / max_refund_quotient) as i64; } diff --git a/crates/interpreter/src/gas/calc.rs b/crates/interpreter/src/gas/calc.rs index b7f91b1814..dcc949c008 100644 --- a/crates/interpreter/src/gas/calc.rs +++ b/crates/interpreter/src/gas/calc.rs @@ -1,13 +1,34 @@ use super::constants::*; use crate::inner_models::SelfDestructResult; -use crate::primitives::{Address, Spec, SpecId::*, U256}; +use crate::primitives::{Address, SpecId, U256}; use std::vec::Vec; +/// `const` Option `?`. +macro_rules! tri { + ($e:expr) => { + match $e { + Some(v) => v, + None => return None, + } + }; +} + +/// `const` unwrap. +macro_rules! opt_unwrap { + ($e:expr) => { + match $e { + Some(v) => v, + None => panic!("unwrap failed"), + } + }; +} + +/// `SSTORE` opcode refund calculation. #[allow(clippy::collapsible_else_if)] -pub fn sstore_refund(original: U256, current: U256, new: U256) -> i64 { - if SPEC::enabled(ISTANBUL) { +pub fn sstore_refund(spec_id: SpecId, original: U256, current: U256, new: U256) -> i64 { + if spec_id.is_enabled_in(SpecId::ISTANBUL) { // EIP-3529: Reduction in refunds - let sstore_clears_schedule = if SPEC::enabled(LONDON) { + let sstore_clears_schedule = if spec_id.is_enabled_in(SpecId::LONDON) { (SSTORE_RESET - COLD_SLOAD_COST + ACCESS_LIST_STORAGE_KEY) as i64 } else { REFUND_SSTORE_CLEARS @@ -29,10 +50,10 @@ pub fn sstore_refund(original: U256, current: U256, new: U256) -> i6 } if original == new { - let (gas_sstore_reset, gas_sload) = if SPEC::enabled(BERLIN) { + let (gas_sstore_reset, gas_sload) = if spec_id.is_enabled_in(SpecId::BERLIN) { (SSTORE_RESET - COLD_SLOAD_COST, WARM_STORAGE_READ_COST) } else { - (SSTORE_RESET, sload_cost::(false)) + (SSTORE_RESET, sload_cost(spec_id, false)) }; if original == U256::ZERO { refund += (SSTORE_SET - gas_sload) as i64; @@ -53,16 +74,12 @@ pub fn sstore_refund(original: U256, current: U256, new: U256) -> i6 } } +/// `CREATE2` opcode cost calculation. #[inline] -pub fn create2_cost(len: usize) -> Option { - let base = CREATE; - // ceil(len / 32.0) - let len = len as u64; - let sha_addup_base = (len / 32) + u64::from((len % 32) != 0); - let sha_addup = KECCAK256WORD.checked_mul(sha_addup_base)?; - let gas = base.checked_add(sha_addup)?; - - Some(gas) +pub const fn create2_cost(len: u64) -> Option { + let sha_addup_base = len.div_ceil(32); + let sha_addup = tri!(KECCAK256WORD.checked_mul(sha_addup_base)); + CREATE.checked_add(sha_addup) } #[inline] @@ -85,13 +102,14 @@ fn log2floor(value: U256) -> u64 { l } +/// `EXP` opcode cost calculation. #[inline] -pub fn exp_cost(power: U256) -> Option { +pub fn exp_cost(spec_id: SpecId, power: U256) -> Option { if power == U256::ZERO { Some(EXP) } else { // EIP-160: EXP cost increase - let gas_byte = U256::from(if SPEC::enabled(SPURIOUS_DRAGON) { + let gas_byte = U256::from(if spec_id.is_enabled_in(SpecId::SPURIOUS_DRAGON) { 50 } else { 10 @@ -103,55 +121,61 @@ pub fn exp_cost(power: U256) -> Option { } } +/// `*COPY` opcodes cost calculation. #[inline] -pub fn verylowcopy_cost(len: u64) -> Option { - let wordd = len / 32; - let wordr = len % 32; - VERYLOW.checked_add(COPY.checked_mul(if wordr == 0 { wordd } else { wordd + 1 })?) +pub const fn verylowcopy_cost(len: u64) -> Option { + VERYLOW.checked_add(tri!(cost_per_word(len, COPY))) } +/// `EXTCODECOPY` opcode cost calculation. #[inline] -pub fn extcodecopy_cost(len: u64, is_cold: bool) -> Option { - let wordd = len / 32; - let wordr = len % 32; - - let base_gas: u64 = if SPEC::enabled(BERLIN) { +pub const fn extcodecopy_cost(spec_id: SpecId, len: u64, is_cold: bool) -> Option { + let base_gas = if spec_id.is_enabled_in(SpecId::BERLIN) { if is_cold { COLD_ACCOUNT_ACCESS_COST } else { WARM_STORAGE_READ_COST } - } else if SPEC::enabled(TANGERINE) { + } else if spec_id.is_enabled_in(SpecId::TANGERINE) { 700 } else { 20 }; - base_gas.checked_add(COPY.checked_mul(if wordr == 0 { wordd } else { wordd + 1 })?) + base_gas.checked_add(tri!(cost_per_word(len, COPY))) } -pub fn account_access_gas(is_cold: bool) -> u64 { - if SPEC::enabled(BERLIN) { +/// `BALANCE` opcode cost calculation. +#[inline] +pub const fn account_access_gas(spec_id: SpecId, is_cold: bool) -> u64 { + if spec_id.is_enabled_in(SpecId::BERLIN) { if is_cold { COLD_ACCOUNT_ACCESS_COST } else { WARM_STORAGE_READ_COST } - } else if SPEC::enabled(ISTANBUL) { + } else if spec_id.is_enabled_in(SpecId::ISTANBUL) { 700 } else { 20 } } -pub fn log_cost(n: u8, len: u64) -> Option { - LOG.checked_add(LOGDATA.checked_mul(len)?)? - .checked_add(LOGTOPIC * n as u64) +/// `LOG` opcode cost calculation. +#[inline] +pub const fn log_cost(n: u8, len: u64) -> Option { + tri!(LOG.checked_add(tri!(LOGDATA.checked_mul(len)))).checked_add(LOGTOPIC * n as u64) } -pub fn keccak256_cost(len: u64) -> Option { - let wordd = len / 32; - let wordr = len % 32; - KECCAK256.checked_add(KECCAK256WORD.checked_mul(if wordr == 0 { wordd } else { wordd + 1 })?) +/// `KECCAK256` opcode cost calculation. +#[inline] +pub const fn keccak256_cost(len: u64) -> Option { + KECCAK256.checked_add(tri!(cost_per_word(len, KECCAK256WORD))) +} + +/// Cost for memory length. `ceil(len / 32) * multiple`. +#[inline] +pub const fn cost_per_word(len: u64, multiple: u64) -> Option { + len.div_ceil(32).checked_mul(multiple) } /// EIP-3860: Limit and meter initcode @@ -160,24 +184,23 @@ pub fn keccak256_cost(len: u64) -> Option { /// /// This cannot overflow as the initcode length is assumed to be checked. #[inline] -pub fn initcode_cost(len: u64) -> u64 { - let wordd = len / 32; - let wordr = len % 32; - INITCODE_WORD_COST * if wordr == 0 { wordd } else { wordd + 1 } +pub const fn initcode_cost(len: u64) -> u64 { + opt_unwrap!(cost_per_word(len, INITCODE_WORD_COST)) } +/// `SLOAD` opcode cost calculation. #[inline] -pub fn sload_cost(is_cold: bool) -> u64 { - if SPEC::enabled(BERLIN) { +pub const fn sload_cost(spec_id: SpecId, is_cold: bool) -> u64 { + if spec_id.is_enabled_in(SpecId::BERLIN) { if is_cold { COLD_SLOAD_COST } else { WARM_STORAGE_READ_COST } - } else if SPEC::enabled(ISTANBUL) { + } else if spec_id.is_enabled_in(SpecId::ISTANBUL) { // EIP-1884: Repricing for trie-size-dependent opcodes INSTANBUL_SLOAD_GAS - } else if SPEC::enabled(TANGERINE) { + } else if spec_id.is_enabled_in(SpecId::TANGERINE) { // EIP-150: Gas cost changes for IO-heavy operations 200 } else { @@ -185,8 +208,10 @@ pub fn sload_cost(is_cold: bool) -> u64 { } } -#[allow(clippy::collapsible_else_if)] -pub fn sstore_cost( +/// `SSTORE` opcode cost calculation. +#[inline] +pub fn sstore_cost( + spec_id: SpecId, original: U256, current: U256, new: U256, @@ -194,11 +219,11 @@ pub fn sstore_cost( is_cold: bool, ) -> Option { // EIP-1706 Disable SSTORE with gasleft lower than call stipend - if SPEC::enabled(ISTANBUL) && gas <= CALL_STIPEND { + if spec_id.is_enabled_in(SpecId::ISTANBUL) && gas <= CALL_STIPEND { return None; } - if SPEC::enabled(BERLIN) { + if spec_id.is_enabled_in(SpecId::BERLIN) { // Berlin specification logic let mut gas_cost = istanbul_sstore_cost::( original, current, new, @@ -208,7 +233,7 @@ pub fn sstore_cost( gas_cost += COLD_SLOAD_COST; } Some(gas_cost) - } else if SPEC::enabled(ISTANBUL) { + } else if spec_id.is_enabled_in(SpecId::ISTANBUL) { // Istanbul logic Some(istanbul_sstore_cost::( original, current, new, @@ -220,7 +245,7 @@ pub fn sstore_cost( } /// EIP-2200: Structured Definitions for Net Gas Metering -#[inline(always)] +#[inline] fn istanbul_sstore_cost( original: U256, current: U256, @@ -237,7 +262,8 @@ fn istanbul_sstore_cost( } } -/// Frontier sstore cost just had two cases set and reset values +/// Frontier sstore cost just had two cases set and reset values. +#[inline] fn frontier_sstore_cost(current: U256, new: U256) -> u64 { if current == U256::ZERO && new != U256::ZERO { SSTORE_SET @@ -246,39 +272,48 @@ fn frontier_sstore_cost(current: U256, new: U256) -> u64 { } } -pub fn selfdestruct_cost(res: SelfDestructResult) -> u64 { +/// `SELFDESTRUCT` opcode cost calculation. +#[inline] +pub const fn selfdestruct_cost(spec_id: SpecId, res: SelfDestructResult) -> u64 { // EIP-161: State trie clearing (invariant-preserving alternative) - let should_charge_topup = if SPEC::enabled(SPURIOUS_DRAGON) { + let should_charge_topup = if spec_id.is_enabled_in(SpecId::SPURIOUS_DRAGON) { res.had_value && !res.target_exists } else { !res.target_exists }; // EIP-150: Gas cost changes for IO-heavy operations - let selfdestruct_gas_topup = if SPEC::enabled(TANGERINE) && should_charge_topup { + let selfdestruct_gas_topup = if spec_id.is_enabled_in(SpecId::TANGERINE) && should_charge_topup + { 25000 } else { 0 }; // EIP-150: Gas cost changes for IO-heavy operations - let selfdestruct_gas = if SPEC::enabled(TANGERINE) { 5000 } else { 0 }; + let selfdestruct_gas = if spec_id.is_enabled_in(SpecId::TANGERINE) { + 5000 + } else { + 0 + }; let mut gas = selfdestruct_gas + selfdestruct_gas_topup; - if SPEC::enabled(BERLIN) && res.is_cold { + if spec_id.is_enabled_in(SpecId::BERLIN) && res.is_cold { gas += COLD_ACCOUNT_ACCESS_COST } gas } -pub fn call_gas(is_cold: bool) -> u64 { - if SPEC::enabled(BERLIN) { +/// Basic `CALL` opcode cost calculation, see [`call_cost`]. +#[inline] +pub const fn call_gas(spec_id: SpecId, is_cold: bool) -> u64 { + if spec_id.is_enabled_in(SpecId::BERLIN) { if is_cold { COLD_ACCOUNT_ACCESS_COST } else { WARM_STORAGE_READ_COST } - } else if SPEC::enabled(TANGERINE) { + } else if spec_id.is_enabled_in(SpecId::TANGERINE) { // EIP-150: Gas cost changes for IO-heavy operations 700 } else { @@ -286,33 +321,23 @@ pub fn call_gas(is_cold: bool) -> u64 { } } -pub fn call_cost( +/// `CALL` opcode cost calculation. +#[inline] +pub const fn call_cost( + spec_id: SpecId, transfers_value: bool, is_new: bool, is_cold: bool, is_call_or_callcode: bool, is_call_or_staticcall: bool, ) -> u64 { - call_gas::(is_cold) + call_gas(spec_id, is_cold) + xfer_cost(is_call_or_callcode, transfers_value) - + new_cost::(is_call_or_staticcall, is_new, transfers_value) -} - -#[inline] -pub fn warm_cold_cost(is_cold: bool, regular_value: u64) -> u64 { - if SPEC::enabled(BERLIN) { - if is_cold { - COLD_ACCOUNT_ACCESS_COST - } else { - WARM_STORAGE_READ_COST - } - } else { - regular_value - } + + new_cost(spec_id, is_call_or_staticcall, is_new, transfers_value) } #[inline] -fn xfer_cost(is_call_or_callcode: bool, transfers_value: bool) -> u64 { +const fn xfer_cost(is_call_or_callcode: bool, transfers_value: bool) -> u64 { if is_call_or_callcode && transfers_value { CALLVALUE } else { @@ -321,21 +346,27 @@ fn xfer_cost(is_call_or_callcode: bool, transfers_value: bool) -> u64 { } #[inline] -fn new_cost(is_call_or_staticcall: bool, is_new: bool, transfers_value: bool) -> u64 { +const fn new_cost( + spec_id: SpecId, + is_call_or_staticcall: bool, + is_new: bool, + transfers_value: bool, +) -> u64 { if !is_call_or_staticcall || !is_new { return 0; } // EIP-161: State trie clearing (invariant-preserving alternative) - if SPEC::enabled(SPURIOUS_DRAGON) && !transfers_value { + if spec_id.is_enabled_in(SpecId::SPURIOUS_DRAGON) && !transfers_value { return 0; } NEWACCOUNT } +/// Memory expansion cost calculation. #[inline] -pub fn memory_gas(a: usize) -> u64 { +pub const fn memory_gas(a: usize) -> u64 { let a = a as u64; MEMORY .saturating_mul(a) @@ -344,7 +375,8 @@ pub fn memory_gas(a: usize) -> u64 { /// Initial gas that is deducted for transaction to be included. /// Initial gas contains initial stipend gas, gas for access list and input data. -pub fn validate_initial_tx_gas( +pub fn validate_initial_tx_gas( + spec_id: SpecId, input: &[u8], is_create: bool, access_list: &[(Address, Vec)], @@ -356,10 +388,15 @@ pub fn validate_initial_tx_gas( // initdate stipend initial_gas += zero_data_len * TRANSACTION_ZERO_DATA; // EIP-2028: Transaction data gas cost reduction - initial_gas += non_zero_data_len * if SPEC::enabled(ISTANBUL) { 16 } else { 68 }; + initial_gas += non_zero_data_len + * if spec_id.is_enabled_in(SpecId::ISTANBUL) { + 16 + } else { + 68 + }; // get number of access list account and storages. - if SPEC::enabled(BERLIN) { + if spec_id.is_enabled_in(SpecId::BERLIN) { let accessed_slots = access_list .iter() .fold(0, |slot_count, (_, slots)| slot_count + slots.len() as u64); @@ -369,7 +406,7 @@ pub fn validate_initial_tx_gas( // base stipend initial_gas += if is_create { - if SPEC::enabled(HOMESTEAD) { + if spec_id.is_enabled_in(SpecId::HOMESTEAD) { // EIP-2: Homestead Hard-fork Changes 53000 } else { @@ -381,7 +418,7 @@ pub fn validate_initial_tx_gas( // EIP-3860: Limit and meter initcode // Initcode stipend for bytecode analysis - if SPEC::enabled(SHANGHAI) && is_create { + if spec_id.is_enabled_in(SpecId::SHANGHAI) && is_create { initial_gas += initcode_cost(input.len() as u64) } diff --git a/crates/interpreter/src/instructions/arithmetic.rs b/crates/interpreter/src/instructions/arithmetic.rs index 2d76727951..8d1e512773 100644 --- a/crates/interpreter/src/instructions/arithmetic.rs +++ b/crates/interpreter/src/instructions/arithmetic.rs @@ -65,7 +65,7 @@ pub fn mulmod(interpreter: &mut Interpreter, _host: &mut H) { pub fn exp(interpreter: &mut Interpreter, _host: &mut H) { pop_top!(interpreter, op1, op2); - gas_or_fail!(interpreter, gas::exp_cost::(*op2)); + gas_or_fail!(interpreter, gas::exp_cost(SPEC::SPEC_ID, *op2)); *op2 = op1.pow(*op2); } diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index b19d0dfc01..cd5d735ef7 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -23,7 +23,7 @@ pub fn balance(interpreter: &mut Interpreter, host interpreter, if SPEC::enabled(ISTANBUL) { // EIP-1884: Repricing for trie-size-dependent opcodes - gas::account_access_gas::(is_cold) + gas::account_access_gas(SPEC::SPEC_ID, is_cold) } else if SPEC::enabled(TANGERINE) { 400 } else { @@ -105,7 +105,7 @@ pub fn extcodecopy(interpreter: &mut Interpreter, let len = as_usize_or_fail!(interpreter, len_u256); gas_or_fail!( interpreter, - gas::extcodecopy_cost::(len as u64, is_cold) + gas::extcodecopy_cost(SPEC::SPEC_ID, len as u64, is_cold) ); if len == 0 { return; @@ -146,7 +146,7 @@ pub fn sload(interpreter: &mut Interpreter, host: interpreter.instruction_result = InstructionResult::FatalExternalError; return; }; - gas!(interpreter, gas::sload_cost::(is_cold)); + gas!(interpreter, gas::sload_cost(SPEC::SPEC_ID, is_cold)); push!(interpreter, value); } @@ -166,9 +166,12 @@ pub fn sstore(interpreter: &mut Interpreter, host: }; gas_or_fail!(interpreter, { let remaining_gas = interpreter.gas.remaining(); - gas::sstore_cost::(original, old, new, remaining_gas, is_cold) + gas::sstore_cost(SPEC::SPEC_ID, original, old, new, remaining_gas, is_cold) }); - refund!(interpreter, gas::sstore_refund::(original, old, new)); + refund!( + interpreter, + gas::sstore_refund(SPEC::SPEC_ID, original, old, new) + ); } /// EIP-1153: Transient storage opcodes @@ -240,7 +243,7 @@ pub fn selfdestruct(interpreter: &mut Interpreter, if !SPEC::enabled(LONDON) && !res.previously_destroyed { refund!(interpreter, gas::SELFDESTRUCT) } - gas!(interpreter, gas::selfdestruct_cost::(res)); + gas!(interpreter, gas::selfdestruct_cost(SPEC::SPEC_ID, res)); interpreter.instruction_result = InstructionResult::SelfDestruct; } @@ -285,7 +288,7 @@ pub fn create( // EIP-1014: Skinny CREATE2 let scheme = if IS_CREATE2 { pop!(interpreter, salt); - gas_or_fail!(interpreter, gas::create2_cost(len)); + gas_or_fail!(interpreter, gas::create2_cost(len as u64)); CreateScheme::Create2 { salt } } else { gas!(interpreter, gas::CREATE); diff --git a/crates/interpreter/src/instructions/host/call_helpers.rs b/crates/interpreter/src/instructions/host/call_helpers.rs index 05a7a20334..803d0e6235 100644 --- a/crates/interpreter/src/instructions/host/call_helpers.rs +++ b/crates/interpreter/src/instructions/host/call_helpers.rs @@ -49,7 +49,8 @@ pub fn calc_call_gas( }; let is_new = !exist; - let call_cost = gas::call_cost::( + let call_cost = gas::call_cost( + SPEC::SPEC_ID, has_transfer, is_new, is_cold, diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index 4ee51db756..cc9184ef47 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -217,7 +217,7 @@ impl Interpreter { let out_offset = call_outcome.memory_start(); let out_len = call_outcome.memory_length(); - self.return_data_buffer = call_outcome.output().to_owned(); + self.return_data_buffer.clone_from(call_outcome.output()); let target_len = min(out_len, self.return_data_buffer.len()); match call_outcome.instruction_result() { diff --git a/crates/primitives/src/specification.rs b/crates/primitives/src/specification.rs index 6d75e25c44..c976702839 100644 --- a/crates/primitives/src/specification.rs +++ b/crates/primitives/src/specification.rs @@ -67,15 +67,19 @@ pub enum SpecId { } impl SpecId { + /// Returns the `SpecId` for the given `u8`. #[inline] pub fn try_from_u8(spec_id: u8) -> Option { Self::n(spec_id) } - pub fn is_enabled_in(&self, other: Self) -> bool { - Self::enabled(*self, other) + /// Returns `true` if the given specification ID is enabled in this spec. + #[inline] + pub const fn is_enabled_in(self, other: Self) -> bool { + Self::enabled(self, other) } + /// Returns `true` if the given specification ID is enabled in this spec. #[inline] pub const fn enabled(our: SpecId, other: SpecId) -> bool { our as u8 >= other as u8 diff --git a/crates/revm/src/handler/mainnet/execution.rs b/crates/revm/src/handler/mainnet/execution.rs index dc1514ea8b..ba79aabe4b 100644 --- a/crates/revm/src/handler/mainnet/execution.rs +++ b/crates/revm/src/handler/mainnet/execution.rs @@ -4,12 +4,11 @@ use crate::{ return_ok, return_revert, CallInputs, CreateInputs, CreateOutcome, Gas, InstructionResult, SharedMemory, }, - primitives::{EVMError, Env, Spec}, + primitives::{EVMError, Env, Spec, SpecId}, CallFrame, Context, CreateFrame, Frame, FrameOrResult, FrameResult, }; -use std::boxed::Box; - use revm_interpreter::{CallOutcome, InterpreterResult}; +use std::boxed::Box; /// Helper function called inside [`last_frame_return`] #[inline] @@ -44,7 +43,7 @@ pub fn frame_return_with_refund_flag( // gas spend. (Before london it was 2th part of gas spend) if refund_enabled { // EIP-3529: Reduction in refunds - gas.set_final_refund::(); + gas.set_final_refund(SPEC::SPEC_ID.is_enabled_in(SpecId::LONDON)); } } @@ -139,10 +138,9 @@ pub fn insert_create_outcome( #[cfg(test)] mod tests { - use revm_interpreter::{primitives::CancunSpec, InterpreterResult}; - use revm_precompile::Bytes; - use super::*; + use revm_interpreter::primitives::CancunSpec; + use revm_precompile::Bytes; /// Creates frame result. fn call_last_frame_return(instruction_result: InstructionResult, gas: Gas) -> Gas { diff --git a/crates/revm/src/handler/mainnet/validation.rs b/crates/revm/src/handler/mainnet/validation.rs index 29c441f135..176e0e8282 100644 --- a/crates/revm/src/handler/mainnet/validation.rs +++ b/crates/revm/src/handler/mainnet/validation.rs @@ -43,7 +43,8 @@ pub fn validate_initial_tx_gas( let is_create = env.tx.transact_to.is_create(); let access_list = &env.tx.access_list; - let initial_gas_spend = gas::validate_initial_tx_gas::(input, is_create, access_list); + let initial_gas_spend = + gas::validate_initial_tx_gas(SPEC::SPEC_ID, input, is_create, access_list); // Additional check to see if limit is big enough to cover initial gas. if initial_gas_spend > env.tx.gas_limit { diff --git a/crates/revm/src/optimism/handler_register.rs b/crates/revm/src/optimism/handler_register.rs index fe6ee94cbb..600d6709d0 100644 --- a/crates/revm/src/optimism/handler_register.rs +++ b/crates/revm/src/optimism/handler_register.rs @@ -133,7 +133,7 @@ pub fn last_frame_return( // Prior to Regolith, deposit transactions did not receive gas refunds. let is_gas_refund_disabled = env.cfg.is_gas_refund_disabled() || (is_deposit && !is_regolith); if !is_gas_refund_disabled { - gas.set_final_refund::(); + gas.set_final_refund(SPEC::SPEC_ID.is_enabled_in(SpecId::LONDON)); } Ok(()) }