Computation
BaseComputation
- class eth.vm.computation.BaseComputation(state: StateAPI, message: MessageAPI, transaction_context: TransactionContextAPI)
The base class for all execution computations.
Note
Each
BaseComputation
class must be configured with:opcodes
: A mapping from the opcode integer value to the logicfunction for the opcode.
_precompiles
: A mapping of contract address to the precompile functionfor execution of precompiled contracts.
- add_child_computation(child_computation: ComputationAPI) None
Add the given
child_computation
.
- apply_child_computation(child_msg: MessageAPI) ComputationAPI
Apply the vm message
child_msg
as a child computation.
- classmethod apply_computation(state: StateAPI, message: MessageAPI, transaction_context: TransactionContextAPI, parent_computation: ComputationAPI | None = None) ComputationAPI
Execute the logic within the message: Either run the precompile, or step through each opcode. Generally, the only VM-specific logic is for each opcode as it executes.
This should rarely be called directly, because it will skip over other important VM-specific logic that happens before or after the execution.
Instead, prefer
apply_message()
orapply_create_message()
.
- classmethod apply_create_message(state: StateAPI, message: MessageAPI, transaction_context: TransactionContextAPI, parent_computation: ComputationAPI | None = None) ComputationAPI
Execute a VM message to create a new contract. This is where the VM-specific create logic exists.
- classmethod apply_message(state: StateAPI, message: MessageAPI, transaction_context: TransactionContextAPI, parent_computation: ComputationAPI | None = None) ComputationAPI
Execute a VM message. This is where the VM-specific call logic exists.
- consume_gas(amount: int, reason: str) None
Consume
amount
of gas from the remaining gas. Raise eth.exceptions.OutOfGas if there is not enough gas remaining.
- classmethod consume_initcode_gas_cost(computation: ComputationAPI) None
Before starting the computation, consume initcode gas cost.
- extend_memory(start_position: int, size: int) None
Extend the size of the memory to be at minimum
start_position + size
bytes in length. Raise eth.exceptions.OutOfGas if there is not enough gas to pay for extending the memory.
- generate_child_computation(child_msg: MessageAPI) ComputationAPI
Generate a child computation from the given
child_msg
.
- get_accounts_for_deletion() List[Address]
Return a tuple of addresses that are registered for deletion.
- get_gas_meter() GasMeterAPI
Return the gas meter for the computation.
- get_log_entries() Tuple[Tuple[bytes, Tuple[int, ...], bytes], ...]
Return the log entries for this computation and its children.
They are sorted in the same order they were emitted during the transaction processing, and include the sequential counter as the first element of the tuple representing every entry.
- classmethod get_precompiles() Dict[Address, Callable[[ComputationAPI], Any]]
Return a dictionary where the keys are the addresses of precompiles and the values are the precompile functions.
- get_raw_log_entries() Tuple[Tuple[int, bytes, Tuple[int, ...], bytes], ...]
Return a tuple of raw log entries.
- get_self_destruct_beneficiaries() List[Address]
Return a list of addresses that were beneficiaries of the self-destruct opcode - whether or not the contract was self-destructed, post-Cancun.
- memory_copy(destination: int, source: int, length: int) None
Copy bytes of memory with size
length
fromsource
todestination
- memory_read_bytes(start_position: int, size: int) bytes
Read and return
size
bytes from memory starting atstart_position
.
- memory_write(start_position: int, size: int, value: bytes) None
Write
value
to memory atstart_position
. Require thatlen(value) == size
.
- prepare_child_message(gas: int, to: Address, value: int, data: bytes | memoryview, code: bytes, **kwargs: Any) MessageAPI
Helper method for creating a child computation.
- raise_if_error() None
If there was an error during computation, raise it as an exception immediately.
- Raises:
VMError –
- register_account_for_deletion(beneficiary: Address) None
Register the address of
beneficiary
for deletion.
- children: List[ComputationAPI] = None
- code: CodeStreamAPI = None
- property error: VMError
Return the
VMError
of the computation. RaiseAttributeError
if no error exists.
- property is_origin_computation: bool
Return
True
if this computation is the outermost computation atdepth == 0
.
- logger: ExtendedDebugLogger = <ExtendedDebugLogger eth.vm.computation.BaseComputation (WARNING)>
- msg: MessageAPI = None
- property precompiles: Dict[Address, Callable[[ComputationAPI], Any]]
Return a dictionary where the keys are the addresses of precompiles and the values are the precompile functions.
- property should_erase_return_data: bool
Return
True
if the return data should be zerod out due to an error.
- stack_pop1_any
- stack_pop1_bytes
- stack_pop1_int
- stack_pop_any
- stack_pop_bytes
- stack_pop_ints
- stack_push_bytes
- stack_push_int
- transaction_context: TransactionContextAPI = None