diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index a062613e75..c325ff8b58 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -413,7 +413,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB, let journaled_state = JournaledState::new(precompiles.len(), GSPEC::SPEC_ID); #[cfg(feature = "optimism")] - let handler = if env.cfg.optimism { + let handler: Handler = if env.cfg.optimism { Handler::optimism::() } else { Handler::mainnet::() diff --git a/crates/revm/src/handler.rs b/crates/revm/src/handler.rs index ba347f852f..10b3c5dc9c 100644 --- a/crates/revm/src/handler.rs +++ b/crates/revm/src/handler.rs @@ -50,8 +50,8 @@ impl Handler { pub fn taiko() -> Self { use crate::taiko::handler; Self { - call_return: handler::handle_call_return::, - calculate_gas_refund: handler::calculate_gas_refund::, + call_return: mainnet::handle_call_return::, + calculate_gas_refund: mainnet::calculate_gas_refund::, reimburse_caller: handler::handle_reimburse_caller::, reward_beneficiary: handler::reward_beneficiary::, } diff --git a/crates/revm/src/taiko/handler.rs b/crates/revm/src/taiko/handler.rs index 9bc0988e74..97218e50f2 100644 --- a/crates/revm/src/taiko/handler.rs +++ b/crates/revm/src/taiko/handler.rs @@ -7,33 +7,6 @@ use crate::{ EVMData, }; -/// Handle output of the transaction -pub fn handle_call_return( - env: &Env, - call_result: InstructionResult, - returned_gas: Gas, -) -> Gas { - let tx_gas_limit = env.tx.gas_limit; - // Spend the gas limit. Gas is reimbursed when the tx returns successfully. - let mut gas = Gas::new(tx_gas_limit); - if env.tx.taiko.is_anchor { - return gas; - } - gas.record_cost(tx_gas_limit); - - match call_result { - return_ok!() => { - gas.erase_cost(returned_gas.remaining()); - gas.record_refund(returned_gas.refunded()); - } - return_revert!() => { - gas.erase_cost(returned_gas.remaining()); - } - _ => {} - } - gas -} - #[inline] pub fn handle_reimburse_caller( data: &mut EVMData<'_, DB>, @@ -108,69 +81,3 @@ pub fn reward_beneficiary( .saturating_add(basefee * U256::from(gas.spend() - gas_refund)); Ok(()) } - -/// Calculate gas refund for transaction. -/// -/// If config is set to disable gas refund, it will return 0. -/// -/// If spec is set to london, it will decrease the maximum refund amount to 5th part of -/// gas spend. (Before london it was 2th part of gas spend) -#[inline] -pub fn calculate_gas_refund(env: &Env, gas: &Gas) -> u64 { - // no refund for anchor tx and gas refund disabled. - if env.tx.taiko.is_anchor || env.cfg.is_gas_refund_disabled() { - 0 - } else { - // EIP-3529: Reduction in refunds - let max_refund_quotient = if SPEC::enabled(LONDON) { 5 } else { 2 }; - (gas.refunded() as u64).min(gas.spend() / max_refund_quotient) - } -} - -#[cfg(test)] -mod tests { - use revm_interpreter::primitives::CancunSpec; - - use super::*; - - #[test] - fn test_consume_gas() { - let mut env = Env::default(); - env.tx.gas_limit = 100; - - let gas = handle_call_return::(&env, InstructionResult::Stop, Gas::new(90)); - assert_eq!(gas.remaining(), 90); - assert_eq!(gas.spend(), 10); - assert_eq!(gas.refunded(), 0); - } - - #[test] - fn test_consume_gas_with_refund() { - let mut env = Env::default(); - env.tx.gas_limit = 100; - - let mut return_gas = Gas::new(90); - return_gas.record_refund(30); - - let gas = handle_call_return::(&env, InstructionResult::Stop, return_gas); - assert_eq!(gas.remaining(), 90); - assert_eq!(gas.spend(), 10); - assert_eq!(gas.refunded(), 30); - - let gas = handle_call_return::(&env, InstructionResult::Revert, return_gas); - assert_eq!(gas.remaining(), 90); - assert_eq!(gas.spend(), 10); - assert_eq!(gas.refunded(), 0); - } - - #[test] - fn test_revert_gas() { - let mut env = Env::default(); - env.tx.gas_limit = 100; - - let gas = handle_call_return::(&env, InstructionResult::Revert, Gas::new(90)); - assert_eq!(gas.remaining(), 90); - assert_eq!(gas.spend(), 10); - assert_eq!(gas.refunded(), 0); - } -}