Crate interpreter
Expand description
§revm-interpreter
Interpreter is part of the project that executes EVM instructions.
Modules§
- gas
- Gas calculation utilities and constants. EVM gas calculation utilities.
- host
- Host interface for external blockchain state access.
- instruction_
context - Context passed to instruction implementations.
- instructions
- EVM instruction implementations organized by category. EVM opcode implementations.
- interpreter
- Core interpreter implementation for EVM bytecode execution. Core interpreter implementation and components.
- interpreter_
action - Types for interpreter actions like calls and contract creation.
- interpreter_
types - Type traits and definitions for interpreter customization.
Macros§
- as_
isize_ saturated - Converts a
U256
value to aisize
, saturating toisize::MAX
if the value is too large. - as_
u64_ saturated - Converts a
U256
value to au64
, saturating toMAX
if the value is too large. - as_
usize_ or_ fail - Converts a
U256
value to ausize
, failing the instruction if the value is too large. - as_
usize_ or_ fail_ ret - Converts a
U256
value to ausize
and returnsret
, failing the instruction if the value is too large. - as_
usize_ saturated - Converts a
U256
value to ausize
, saturating toMAX
if the value is too large. - assume
- Macro for asserting assumptions in debug builds. In debug builds, this will trigger unreachable code if the assumption is false. In release builds, this serves as an optimization hint.
- check
- Check if the
SPEC
is enabled, and fail the instruction if it is not. - debug_
unreachable - Macro that triggers
unreachable!
in debug builds but uses unchecked unreachable in release builds. This provides better error messages during development while optimizing for performance in release. - gas
- Records a
gas
cost and fails the instruction if it would exceed the available gas. - gas_
or_ fail - Same as
gas!
, but withgas
as an option. - otry
- Macro for optional try - returns early if the expression evaluates to None.
Similar to the
?
operator but for use in instruction implementations. - popn
- Pops n values from the stack. Fails the instruction if n values can’t be popped.
- popn_
top - Pops n values from the stack and returns the top value. Fails the instruction if n values can’t be popped.
- push
- Pushes a
B256
value onto the stack. Fails the instruction if the stack is full. - require_
eof - Error if the current call is executing EOF.
- require_
non_ staticcall - Fails the instruction if the current call is static.
- resize_
memory - Resizes the interpreterreter memory if necessary. Fails the instruction if the memory or gas limit is exceeded.
- return_
error - Macro that matches all error instruction results. Used in pattern matching to handle all error outcomes.
- return_
ok - Macro that matches all successful instruction results. Used in pattern matching to handle all successful execution outcomes.
- return_
revert - Macro that matches all revert instruction results. Used in pattern matching to handle all revert outcomes.
- tri
const
Option?
.
Structs§
- Call
Inputs - Inputs for a call.
- Call
Outcome - Represents the outcome of a call operation in a virtual machine.
- Create
Inputs - Inputs for a create call
- Create
Outcome - Represents the outcome of a create operation in an interpreter.
- Gas
- Represents the state of gas during execution.
- Initial
AndFloor Gas - Init and floor gas from transaction
- Inputs
Impl - Inputs for the interpreter that are used for execution of the call.
- Instruction
Context - Context passed to instruction implementations containing the host and interpreter. This struct provides access to both the host interface for external state operations and the interpreter state for stack, memory, and gas operations.
- Interpreter
- Main interpreter structure that contains all components defined in
InterpreterTypes
. - Interpreter
Result - The result of an interpreter operation.
- SStore
Result - Represents the result of an
sstore
operation. - Self
Destruct Result - Result of a selfdestruct action
- Shared
Memory - A sequential memory shared between calls, which uses
a
Vec
for internal representation. A SharedMemory instance should always be obtained using thenew
static method to ensure memory safety. - Stack
- EVM stack with STACK_LIMIT capacity of words.
- State
Load - State load information that contains the data and if the account or storage is cold loaded
Enums§
- Call
Input - Input enum for a call.
- Call
Scheme - Call scheme.
- Call
Value - Call value.
- Create
Scheme - Create scheme
- Frame
Input - Input data for creating a new execution frame.
- Instruction
Result - Result of executing an EVM instruction. This enum represents all possible outcomes when executing an instruction, including successful execution, reverts, and various error conditions.
- Internal
Result - Internal results that are not exposed externally
- Interpreter
Action - Actions that the interpreter can request from the host environment.
- Success
OrHalt - Represents the outcome of instruction execution, distinguishing between success, revert, halt (error), fatal external errors, and internal results.
Constants§
- MAX_
CODE_ SIZE - By default the limit is
0xC000
(49_152 bytes). - MAX_
INITCODE_ SIZE - By default the limit is
0x12000
(73_728 bytes). - STACK_
LIMIT - EVM interpreter stack limit.
Traits§
- Host
- Host trait with all methods that are needed by the Interpreter.
- Interpreter
Types - Trait defining the component types used by an interpreter implementation.
Functions§
- instruction_
table - Returns the instruction table for the given spec.
- num_
words - Returns number of words what would fit to provided number of bytes, i.e. it rounds up the number bytes to number of words.
Type Aliases§
- Instruction
- EVM opcode function signature.
- Instruction
Table - Instruction table is list of instruction function pointers mapped to 256 EVM opcodes.