diff --git a/crates/handler/src/frame.rs b/crates/handler/src/frame.rs index 823ec568df..e29ca23efb 100644 --- a/crates/handler/src/frame.rs +++ b/crates/handler/src/frame.rs @@ -193,16 +193,7 @@ impl EthFrame { let is_static = inputs.is_static; let gas_limit = inputs.gas_limit; - if let Some(result) = precompiles - .run( - ctx, - &inputs.bytecode_address, - &interpreter_input, - is_static, - gas_limit, - ) - .map_err(ERROR::from_string)? - { + if let Some(result) = precompiles.run(ctx, &inputs).map_err(ERROR::from_string)? { if result.result.is_ok() { ctx.journal_mut().checkpoint_commit(); } else { diff --git a/crates/handler/src/precompile_provider.rs b/crates/handler/src/precompile_provider.rs index eb75bf6135..a89e8be52c 100644 --- a/crates/handler/src/precompile_provider.rs +++ b/crates/handler/src/precompile_provider.rs @@ -1,7 +1,7 @@ use auto_impl::auto_impl; use context::{Cfg, LocalContextTr}; use context_interface::ContextTr; -use interpreter::{CallInput, Gas, InputsImpl, InstructionResult, InterpreterResult}; +use interpreter::{CallInput, CallInputs, Gas, InstructionResult, InterpreterResult}; use precompile::PrecompileError; use precompile::{PrecompileSpecId, Precompiles}; use primitives::{hardfork::SpecId, Address, Bytes}; @@ -23,10 +23,7 @@ pub trait PrecompileProvider { fn run( &mut self, context: &mut CTX, - address: &Address, - inputs: &InputsImpl, - is_static: bool, - gas_limit: u64, + inputs: &CallInputs, ) -> Result, String>; /// Get the warm addresses. @@ -93,18 +90,15 @@ impl PrecompileProvider for EthPrecompiles { fn run( &mut self, context: &mut CTX, - address: &Address, - inputs: &InputsImpl, - _is_static: bool, - gas_limit: u64, + inputs: &CallInputs, ) -> Result, String> { - let Some(precompile) = self.precompiles.get(address) else { + let Some(precompile) = self.precompiles.get(&inputs.bytecode_address) else { return Ok(None); }; let mut result = InterpreterResult { result: InstructionResult::Return, - gas: Gas::new(gas_limit), + gas: Gas::new(inputs.gas_limit), output: Bytes::new(), }; @@ -121,7 +115,7 @@ impl PrecompileProvider for EthPrecompiles { CallInput::Bytes(bytes) => bytes.0.iter().as_slice(), }; - match precompile.execute(input_bytes, gas_limit) { + match precompile.execute(input_bytes, inputs.gas_limit) { Ok(output) => { let underflow = result.gas.record_cost(output.gas_used); assert!(underflow, "Gas underflow is not possible"); diff --git a/crates/op-revm/src/precompiles.rs b/crates/op-revm/src/precompiles.rs index 579ceb30c8..033b2f3a00 100644 --- a/crates/op-revm/src/precompiles.rs +++ b/crates/op-revm/src/precompiles.rs @@ -4,7 +4,7 @@ use revm::{ context::Cfg, context_interface::ContextTr, handler::{EthPrecompiles, PrecompileProvider}, - interpreter::{InputsImpl, InterpreterResult}, + interpreter::{CallInputs, InterpreterResult}, precompile::{ self, bn254, secp256r1, Precompile, PrecompileError, PrecompileId, PrecompileResult, Precompiles, @@ -111,13 +111,9 @@ where fn run( &mut self, context: &mut CTX, - address: &Address, - inputs: &InputsImpl, - is_static: bool, - gas_limit: u64, + inputs: &CallInputs, ) -> Result, String> { - self.inner - .run(context, address, inputs, is_static, gas_limit) + self.inner.run(context, inputs) } #[inline] diff --git a/examples/custom_precompile_journal/src/precompile_provider.rs b/examples/custom_precompile_journal/src/precompile_provider.rs index caab5682fd..9ebdb26d76 100644 --- a/examples/custom_precompile_journal/src/precompile_provider.rs +++ b/examples/custom_precompile_journal/src/precompile_provider.rs @@ -4,7 +4,7 @@ use revm::{ context::Cfg, context_interface::{ContextTr, JournalTr, LocalContextTr, Transaction}, handler::{EthPrecompiles, PrecompileProvider}, - interpreter::{Gas, InputsImpl, InstructionResult, InterpreterResult}, + interpreter::{CallInputs, Gas, InstructionResult, InterpreterResult}, precompile::{PrecompileError, PrecompileOutput, PrecompileResult}, primitives::{address, hardfork::SpecId, Address, Bytes, U256}, }; @@ -52,21 +52,15 @@ where fn run( &mut self, context: &mut CTX, - address: &Address, - inputs: &InputsImpl, - is_static: bool, - gas_limit: u64, + inputs: &CallInputs, ) -> Result, String> { // Check if this is our custom precompile - if *address == CUSTOM_PRECOMPILE_ADDRESS { - return Ok(Some(run_custom_precompile( - context, inputs, is_static, gas_limit, - )?)); + if inputs.bytecode_address == CUSTOM_PRECOMPILE_ADDRESS { + return Ok(Some(run_custom_precompile(context, inputs)?)); } // Otherwise, delegate to standard Ethereum precompiles - self.inner - .run(context, address, inputs, is_static, gas_limit) + self.inner.run(context, inputs) } fn warm_addresses(&self) -> Box> { @@ -84,9 +78,7 @@ where /// Runs our custom precompile fn run_custom_precompile( context: &mut CTX, - inputs: &InputsImpl, - is_static: bool, - gas_limit: u64, + inputs: &CallInputs, ) -> Result { let input_bytes = match &inputs.input { revm::interpreter::CallInput::SharedBuffer(range) => { @@ -105,13 +97,13 @@ fn run_custom_precompile( let result = if input_bytes.is_empty() { // Read storage operation - handle_read_storage(context, gas_limit) + handle_read_storage(context, inputs.gas_limit) } else if input_bytes.len() == 32 { - if is_static { + if inputs.is_static { return Err("Cannot modify state in static context".to_string()); } // Write storage operation - handle_write_storage(context, &input_bytes, gas_limit) + handle_write_storage(context, &input_bytes, inputs.gas_limit) } else { Err(PrecompileError::Other("Invalid input length".to_string())) }; @@ -124,7 +116,7 @@ fn run_custom_precompile( } else { InstructionResult::Return }, - gas: Gas::new(gas_limit), + gas: Gas::new(inputs.gas_limit), output: output.bytes, }; let underflow = interpreter_result.gas.record_cost(output.gas_used); @@ -139,7 +131,7 @@ fn run_custom_precompile( } else { InstructionResult::PrecompileError }, - gas: Gas::new(gas_limit), + gas: Gas::new(inputs.gas_limit), output: Bytes::new(), }), }