diff --git a/crates/interpreter/src/inner_models.rs b/crates/interpreter/src/inner_models.rs index 0c29f72778..754450ba59 100644 --- a/crates/interpreter/src/inner_models.rs +++ b/crates/interpreter/src/inner_models.rs @@ -1,7 +1,7 @@ +pub use crate::primitives::CreateScheme; use crate::primitives::{Address, Bytes, TransactTo, TxEnv, U256}; use alloc::boxed::Box; - -pub use crate::primitives::CreateScheme; +use core::ops::Range; /// Inputs for a call. #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -19,6 +19,8 @@ pub struct CallInputs { pub context: CallContext, /// Whether this is a static call. pub is_static: bool, + /// The return memory offset where the output of the call is written. + pub return_memory_offset: Range, } /// Inputs for a create call. @@ -61,6 +63,7 @@ impl CallInputs { scheme: CallScheme::Call, }, is_static: false, + return_memory_offset: 0..0, }) } @@ -106,7 +109,7 @@ impl CreateInputs { #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum CallScheme { - /// `CALL` + /// `CALL`. Call, /// `CALLCODE` CallCode, diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index 58ae99932e..4919b644a6 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -364,8 +364,8 @@ pub fn call(interpreter: &mut Interpreter, host: &mut H) { scheme: CallScheme::Call, }, is_static: interpreter.is_static, + return_memory_offset, }), - return_memory_offset, }; interpreter.instruction_result = InstructionResult::CallOrCreate; } @@ -419,8 +419,8 @@ pub fn call_code(interpreter: &mut Interpreter, host: &mut scheme: CallScheme::CallCode, }, is_static: interpreter.is_static, + return_memory_offset, }), - return_memory_offset, }; interpreter.instruction_result = InstructionResult::CallOrCreate; } @@ -465,8 +465,8 @@ pub fn delegate_call(interpreter: &mut Interpreter, host: & scheme: CallScheme::DelegateCall, }, is_static: interpreter.is_static, + return_memory_offset, }), - return_memory_offset, }; interpreter.instruction_result = InstructionResult::CallOrCreate; } @@ -511,8 +511,8 @@ pub fn static_call(interpreter: &mut Interpreter, host: &mu scheme: CallScheme::StaticCall, }, is_static: true, + return_memory_offset, }), - return_memory_offset, }; interpreter.instruction_result = InstructionResult::CallOrCreate; } diff --git a/crates/interpreter/src/interpreter.rs b/crates/interpreter/src/interpreter.rs index a33efbd886..4cddf3ca6d 100644 --- a/crates/interpreter/src/interpreter.rs +++ b/crates/interpreter/src/interpreter.rs @@ -15,7 +15,6 @@ use crate::{ }; use alloc::boxed::Box; use core::cmp::min; -use core::ops::Range; use revm_primitives::U256; pub use self::shared_memory::EMPTY_SHARED_MEMORY; @@ -70,10 +69,6 @@ pub enum InterpreterAction { Call { /// Call inputs inputs: Box, - /// The offset into `self.memory` of the return data. - /// - /// This value must be ignored if `self.return_len` is 0. - return_memory_offset: Range, }, /// CREATE or CREATE2 instruction called. Create { inputs: Box }, diff --git a/crates/revm/src/context.rs b/crates/revm/src/context.rs index b53e73ac49..0fe1161175 100644 --- a/crates/revm/src/context.rs +++ b/crates/revm/src/context.rs @@ -13,7 +13,6 @@ use crate::{ FrameOrResult, JournalCheckpoint, CALL_STACK_LIMIT, }; use alloc::boxed::Box; -use core::ops::Range; /// Main Context structure that contains both EvmContext and External context. pub struct Context { @@ -358,11 +357,7 @@ impl EvmContext { } /// Make call frame - pub fn make_call_frame( - &mut self, - inputs: &CallInputs, - return_memory_range: Range, - ) -> FrameOrResult { + pub fn make_call_frame(&mut self, inputs: &CallInputs) -> FrameOrResult { let gas = Gas::new(inputs.gas_limit); let return_result = |instruction_result: InstructionResult| { @@ -372,7 +367,7 @@ impl EvmContext { gas, output: Bytes::new(), }, - return_memory_range.clone(), + inputs.return_memory_offset.clone(), ) }; @@ -421,7 +416,7 @@ impl EvmContext { } else { self.journaled_state.checkpoint_revert(checkpoint); } - FrameOrResult::new_call_result(result, return_memory_range) + FrameOrResult::new_call_result(result, inputs.return_memory_offset.clone()) } else if !bytecode.is_empty() { let contract = Box::new(Contract::new_with_context( inputs.input.clone(), @@ -431,7 +426,7 @@ impl EvmContext { )); // Create interpreter and executes call and push new CallStackFrame. FrameOrResult::new_call_frame( - return_memory_range, + inputs.return_memory_offset.clone(), checkpoint, Interpreter::new(contract, gas.limit(), inputs.is_static), ) @@ -601,6 +596,7 @@ pub(crate) mod test_utils { scheme: revm_interpreter::CallScheme::Call, }, is_static: false, + return_memory_offset: 0..0, } } @@ -672,7 +668,7 @@ mod tests { evm_context.journaled_state.depth = CALL_STACK_LIMIT as usize + 1; let contract = address!("dead10000000000000000000000000000001dead"); let call_inputs = test_utils::create_mock_call_inputs(contract); - let res = evm_context.make_call_frame(&call_inputs, 0..0); + let res = evm_context.make_call_frame(&call_inputs); let FrameOrResult::Result(err) = res else { panic!("Expected FrameOrResult::Result"); }; @@ -693,7 +689,7 @@ mod tests { let contract = address!("dead10000000000000000000000000000001dead"); let mut call_inputs = test_utils::create_mock_call_inputs(contract); call_inputs.transfer.value = U256::from(1); - let res = evm_context.make_call_frame(&call_inputs, 0..0); + let res = evm_context.make_call_frame(&call_inputs); let FrameOrResult::Result(result) = res else { panic!("Expected FrameOrResult::Result"); }; @@ -714,7 +710,7 @@ mod tests { let mut evm_context = create_cache_db_evm_context_with_balance(Box::new(env), cdb, bal); let contract = address!("dead10000000000000000000000000000001dead"); let call_inputs = test_utils::create_mock_call_inputs(contract); - let res = evm_context.make_call_frame(&call_inputs, 0..0); + let res = evm_context.make_call_frame(&call_inputs); let FrameOrResult::Result(result) = res else { panic!("Expected FrameOrResult::Result"); }; @@ -739,7 +735,7 @@ mod tests { ); let mut evm_context = create_cache_db_evm_context_with_balance(Box::new(env), cdb, bal); let call_inputs = test_utils::create_mock_call_inputs(contract); - let res = evm_context.make_call_frame(&call_inputs, 0..0); + let res = evm_context.make_call_frame(&call_inputs); let FrameOrResult::Frame(Frame::Call(call_frame)) = res else { panic!("Expected FrameOrResult::Frame(Frame::Call(..))"); }; diff --git a/crates/revm/src/evm.rs b/crates/revm/src/evm.rs index ff9d574bb7..9db4c50854 100644 --- a/crates/revm/src/evm.rs +++ b/crates/revm/src/evm.rs @@ -253,10 +253,7 @@ impl Evm<'_, EXT, DB> { let exec = &mut self.handler.execution; let frame_or_result = match next_action { - InterpreterAction::Call { - inputs, - return_memory_offset, - } => exec.call(&mut self.context, inputs, return_memory_offset), + InterpreterAction::Call { inputs } => exec.call(&mut self.context, inputs), InterpreterAction::Create { inputs } => exec.create(&mut self.context, inputs), InterpreterAction::Return { result } => { // free memory context. @@ -335,7 +332,6 @@ impl Evm<'_, EXT, DB> { TransactTo::Call(_) => exec.call( ctx, CallInputs::new_boxed(&ctx.evm.env.tx, gas_limit).unwrap(), - 0..0, ), TransactTo::Create(_) => exec.create( ctx, diff --git a/crates/revm/src/handler/handle_types/execution.rs b/crates/revm/src/handler/handle_types/execution.rs index b25536935b..7ed7aa5e8c 100644 --- a/crates/revm/src/handler/handle_types/execution.rs +++ b/crates/revm/src/handler/handle_types/execution.rs @@ -5,7 +5,7 @@ use crate::{ CallFrame, Context, CreateFrame, Frame, FrameOrResult, FrameResult, }; use alloc::{boxed::Box, sync::Arc}; -use core::ops::Range; + use revm_interpreter::{CallOutcome, CreateOutcome, InterpreterResult}; /// Handles first frame return handle. @@ -14,7 +14,7 @@ pub type LastFrameReturnHandle<'a, EXT, DB> = /// Handle sub call. pub type FrameCallHandle<'a, EXT, DB> = - Arc, Box, Range) -> FrameOrResult + 'a>; + Arc, Box) -> FrameOrResult + 'a>; /// Handle call return pub type FrameCallReturnHandle<'a, EXT, DB> = @@ -83,13 +83,8 @@ impl<'a, EXT, DB: Database> ExecutionHandler<'a, EXT, DB> { /// Call frame call handler. #[inline] - pub fn call( - &self, - context: &mut Context, - inputs: Box, - return_memory_offset: Range, - ) -> FrameOrResult { - (self.call)(context, inputs, return_memory_offset) + pub fn call(&self, context: &mut Context, inputs: Box) -> FrameOrResult { + (self.call)(context, inputs.clone()) } /// Call registered handler for call return. diff --git a/crates/revm/src/handler/mainnet/execution.rs b/crates/revm/src/handler/mainnet/execution.rs index b5a47a9f7f..d56d94e99a 100644 --- a/crates/revm/src/handler/mainnet/execution.rs +++ b/crates/revm/src/handler/mainnet/execution.rs @@ -8,7 +8,7 @@ use crate::{ CallFrame, Context, CreateFrame, Frame, FrameOrResult, FrameResult, }; use alloc::boxed::Box; -use core::ops::Range; + use revm_interpreter::{CallOutcome, InterpreterResult}; /// Helper function called inside [`last_frame_return`] @@ -61,11 +61,8 @@ pub fn last_frame_return( pub fn call( context: &mut Context, inputs: Box, - return_memory_offset: Range, ) -> FrameOrResult { - context - .evm - .make_call_frame(&inputs, return_memory_offset.clone()) + context.evm.make_call_frame(&inputs) } #[inline] diff --git a/crates/revm/src/inspector.rs b/crates/revm/src/inspector.rs index 16fa68b174..9379f8864a 100644 --- a/crates/revm/src/inspector.rs +++ b/crates/revm/src/inspector.rs @@ -1,5 +1,3 @@ -use core::ops::Range; - use crate::{ interpreter::{CallInputs, CreateInputs, Interpreter}, primitives::{db::Database, Address, Log, U256}, @@ -82,11 +80,9 @@ pub trait Inspector { &mut self, context: &mut EvmContext, inputs: &mut CallInputs, - return_memory_offset: Range, ) -> Option { let _ = context; let _ = inputs; - let _ = return_memory_offset; None } diff --git a/crates/revm/src/inspector/customprinter.rs b/crates/revm/src/inspector/customprinter.rs index fc3af4085b..5e8c948b2e 100644 --- a/crates/revm/src/inspector/customprinter.rs +++ b/crates/revm/src/inspector/customprinter.rs @@ -1,8 +1,6 @@ //! Custom print inspector, it has step level information of execution. //! It is a great tool if some debugging is needed. -use core::ops::Range; - use revm_interpreter::CallOutcome; use revm_interpreter::CreateOutcome; @@ -79,7 +77,6 @@ impl Inspector for CustomPrintTracer { &mut self, _context: &mut EvmContext, inputs: &mut CallInputs, - _return_memory_offset: Range, ) -> Option { println!( "SM CALL: {:?}, context:{:?}, is_static:{:?}, transfer:{:?}, input_size:{:?}", diff --git a/crates/revm/src/inspector/eip3155.rs b/crates/revm/src/inspector/eip3155.rs index 44c779d33d..0f08edc275 100644 --- a/crates/revm/src/inspector/eip3155.rs +++ b/crates/revm/src/inspector/eip3155.rs @@ -5,7 +5,6 @@ use crate::{ EvmContext, Inspector, }; -use core::ops::Range; use revm_interpreter::CallOutcome; use revm_interpreter::CreateOutcome; use serde_json::json; @@ -86,7 +85,6 @@ impl Inspector for TracerEip3155 { &mut self, _context: &mut EvmContext, _inputs: &mut CallInputs, - _return_memory_offset: Range, ) -> Option { None } diff --git a/crates/revm/src/inspector/gas.rs b/crates/revm/src/inspector/gas.rs index 61beeb0068..67e67ef8eb 100644 --- a/crates/revm/src/inspector/gas.rs +++ b/crates/revm/src/inspector/gas.rs @@ -72,7 +72,6 @@ impl Inspector for GasInspector { #[cfg(test)] mod tests { - use core::ops::Range; use revm_interpreter::CallOutcome; use revm_interpreter::CreateOutcome; @@ -115,9 +114,8 @@ mod tests { &mut self, context: &mut EvmContext, call: &mut CallInputs, - return_memory_offset: Range, ) -> Option { - self.gas_inspector.call(context, call, return_memory_offset) + self.gas_inspector.call(context, call) } fn call_end( diff --git a/crates/revm/src/inspector/handler_register.rs b/crates/revm/src/inspector/handler_register.rs index 5dce6243b0..a3b6d8fcd2 100644 --- a/crates/revm/src/inspector/handler_register.rs +++ b/crates/revm/src/inspector/handler_register.rs @@ -8,6 +8,7 @@ use crate::{ }; use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; +/// Provides access to an `Inspector` instance. pub trait GetInspector { fn get_inspector(&mut self) -> &mut dyn Inspector; } @@ -154,16 +155,17 @@ pub fn inspector_handle_register<'a, DB: Database, EXT: GetInspector>( // Call handler let call_input_stack_inner = call_input_stack.clone(); let old_handle = handler.execution.call.clone(); - handler.execution.call = Arc::new(move |ctx, mut inputs, range| -> FrameOrResult { + handler.execution.call = Arc::new(move |ctx, mut inputs| -> FrameOrResult { let inspector = ctx.external.get_inspector(); + let _mems = inputs.return_memory_offset.clone(); // call inspector callto change input or return outcome. - if let Some(outcome) = inspector.call(&mut ctx.evm, &mut inputs, range.clone()) { + if let Some(outcome) = inspector.call(&mut ctx.evm, &mut inputs) { call_input_stack_inner.borrow_mut().push(inputs.clone()); return FrameOrResult::Result(FrameResult::Call(outcome)); } call_input_stack_inner.borrow_mut().push(inputs.clone()); - let mut frame_or_result = old_handle(ctx, inputs, range); + let mut frame_or_result = old_handle(ctx, inputs); let inspector = ctx.external.get_inspector(); if let FrameOrResult::Frame(frame) = &mut frame_or_result { @@ -251,7 +253,6 @@ pub fn inspector_instruction< #[cfg(test)] mod tests { - use core::ops::Range; use super::*; use crate::{ @@ -305,7 +306,6 @@ mod tests { &mut self, context: &mut EvmContext, _call: &mut CallInputs, - _return_memory_offset: Range, ) -> Option { if self.call { unreachable!("call should not be called twice")