Struct revm_interpreter::Interpreter
source · pub struct Interpreter {
pub contract: Box<Contract>,
pub instruction_pointer: *const u8,
pub instruction_result: InstructionResult,
pub gas: Gas,
pub shared_memory: SharedMemory,
pub stack: Stack,
pub return_data_buffer: Bytes,
pub is_static: bool,
pub next_action: InterpreterAction,
}Fields§
§contract: Box<Contract>Contract information and invoking data
instruction_pointer: *const u8The current instruction pointer.
instruction_result: InstructionResultThe execution control flag. If this is not set to Continue, the interpreter will stop
execution.
gas: GasThe gas state.
Shared memory.
Note: This field is only set while running the interpreter loop. Otherwise it is taken and replaced with empty shared memory.
stack: StackStack.
return_data_buffer: BytesThe return data buffer for internal calls. It has multi usage:
- It contains the output bytes of call sub call.
- When this interpreter finishes execution it contains the output bytes of this contract.
is_static: boolWhether the interpreter is in “staticcall” mode, meaning no state changes can happen.
next_action: InterpreterActionActions that the EVM should do.
Set inside CALL or CREATE instructions and RETURN or REVERT instructions. Additionally those instructions will set InstructionResult to CallOrCreate/Return/Revert so we know the reason.
Implementations§
source§impl Interpreter
impl Interpreter
sourcepub fn new(contract: Box<Contract>, gas_limit: u64, is_static: bool) -> Self
pub fn new(contract: Box<Contract>, gas_limit: u64, is_static: bool) -> Self
Create new interpreter
sourcepub fn insert_create_outcome(&mut self, create_outcome: CreateOutcome)
pub fn insert_create_outcome(&mut self, create_outcome: CreateOutcome)
Inserts the output of a create call into the interpreter.
This function is used after a create call has been executed. It processes the outcome
of that call and updates the state of the interpreter accordingly.
§Arguments
create_outcome- ACreateOutcomestruct containing the results of thecreatecall.
§Behavior
The function updates the return_data_buffer with the data from create_outcome.
Depending on the InstructionResult indicated by create_outcome, it performs one of the following:
Ok: Pushes the address fromcreate_outcometo the stack, updates gas costs, and records any gas refunds.Revert: PushesU256::ZEROto the stack and updates gas costs.FatalExternalError: Sets theinstruction_resulttoInstructionResult::FatalExternalError.Default: PushesU256::ZEROto the stack.
§Side Effects
- Updates
return_data_bufferwith the data fromcreate_outcome. - Modifies the stack by pushing values depending on the
InstructionResult. - Updates gas costs and records refunds in the interpreter’s
gasfield. - May alter
instruction_resultin case of external errors.
sourcepub fn insert_call_outcome(
&mut self,
shared_memory: &mut SharedMemory,
call_outcome: CallOutcome
)
pub fn insert_call_outcome( &mut self, shared_memory: &mut SharedMemory, call_outcome: CallOutcome )
Inserts the outcome of a call into the virtual machine’s state.
This function takes the result of a call, represented by CallOutcome,
and updates the virtual machine’s state accordingly. It involves updating
the return data buffer, handling gas accounting, and setting the memory
in shared storage based on the outcome of the call.
§Arguments
shared_memory- A mutable reference to the shared memory used by the virtual machine.call_outcome- The outcome of the call to be processed, containing details such as instruction result, gas information, and output data.
§Behavior
The function first copies the output data from the call outcome to the virtual machine’s return data buffer. It then checks the instruction result from the call outcome:
return_ok!(): Processes successful execution, refunds gas, and updates shared memory.return_revert!(): Handles a revert by only updating the gas usage and shared memory.InstructionResult::FatalExternalError: Sets the instruction result to a fatal external error.- Any other result: No specific action is taken.
sourcepub fn current_opcode(&self) -> u8
pub fn current_opcode(&self) -> u8
Returns the opcode at the current instruction pointer.
sourcepub fn program_counter(&self) -> usize
pub fn program_counter(&self) -> usize
Returns the current program counter.
sourcepub fn take_memory(&mut self) -> SharedMemory
pub fn take_memory(&mut self) -> SharedMemory
Take memory and replace it with empty memory.
sourcepub fn run<FN, H: Host>(
&mut self,
shared_memory: SharedMemory,
instruction_table: &[FN; 256],
host: &mut H
) -> InterpreterAction
pub fn run<FN, H: Host>( &mut self, shared_memory: SharedMemory, instruction_table: &[FN; 256], host: &mut H ) -> InterpreterAction
Executes the interpreter until it returns or stops.
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for Interpreter
impl !Send for Interpreter
impl !Sync for Interpreter
impl Unpin for Interpreter
impl UnwindSafe for Interpreter
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.