ethereum.forks.paris.vmethereum.forks.shanghai.vm
Ethereum Virtual Machine (EVM).
.. contents:: Table of Contents :backlinks: none :local:
Introduction
The abstract computer which runs the code stored in an
.fork_types.Account.
__all__¶
| 30 | __all__ = ("Environment", "Evm", "Message") |
|---|
BlockEnvironment ¶
Items external to the virtual machine itself, provided by the environment.
| 33 | @dataclass |
|---|
class BlockEnvironment:
chain_id¶
| 39 | chain_id: U64 |
|---|
state¶
| 40 | state: State |
|---|
block_gas_limit¶
| 41 | block_gas_limit: Uint |
|---|
block_hashes¶
| 42 | block_hashes: List[Hash32] |
|---|
coinbase¶
| 43 | coinbase: Address |
|---|
number¶
| 44 | number: Uint |
|---|
base_fee_per_gas¶
| 45 | base_fee_per_gas: Uint |
|---|
time¶
| 46 | time: U256 |
|---|
prev_randao¶
| 47 | prev_randao: Bytes32 |
|---|
BlockOutput ¶
Output from applying the block body to the present state.
Contains the following:
block_gas_used : ethereum.base_types.Uint
Gas used for executing all transactions.
transactions_trie : ethereum.fork_types.Root
Trie of all the transactions in the block.
receipts_trie : ethereum.fork_types.Root
Trie root of all the receipts in the block.
receipt_keys :
Keys of all the receipts in the block.
block_logs : Bloom
Logs bloom of all the logs included in all the transactions of the
block.
withdrawals_trie : ethereum.fork_types.Root
Trie root of all the withdrawals in the block.
| 50 | @dataclass |
|---|
class BlockOutput:
block_gas_used¶
| 72 | block_gas_used: Uint = Uint(0) |
|---|
transactions_trie¶
| 73 | transactions_trie: Trie[Bytes, Optional[Bytes | LegacyTransaction]] = ( |
|---|---|
| 74 | field(default_factory=lambda: Trie(secured=False, default=None)) |
| 75 | ) |
receipts_trie¶
| 76 | receipts_trie: Trie[Bytes, Optional[Bytes | Receipt]] = field( |
|---|---|
| 77 | default_factory=lambda: Trie(secured=False, default=None) |
| 78 | ) |
receipt_keys¶
| 79 | receipt_keys: Tuple[Bytes, ...] = field(default_factory=tuple) |
|---|
block_logs¶
| 80 | block_logs: Tuple[Log, ...] = field(default_factory=tuple) |
|---|
withdrawals_trie¶
| 81 | withdrawals_trie: Trie[Bytes, Optional[Bytes | Withdrawal]] = field( |
|---|---|
| 82 | default_factory=lambda: Trie(secured=False, default=None) |
| 83 | ) |
TransactionEnvironment ¶
Items that are used by contract creation or message call.
| 86 | @dataclass |
|---|
class TransactionEnvironment:
origin¶
| 92 | origin: Address |
|---|
gas_price¶
| 93 | gas_price: Uint |
|---|
gas¶
| 94 | gas: Uint |
|---|
access_list_addresses¶
| 95 | access_list_addresses: Set[Address] |
|---|
access_list_storage_keys¶
| 96 | access_list_storage_keys: Set[Tuple[Address, Bytes32]] |
|---|
index_in_block¶
| 97 | index_in_block: Optional[Uint] |
|---|
tx_hash¶
| 98 | tx_hash: Optional[Hash32] |
|---|
Message ¶
Items that are used by contract creation or message call.
| 101 | @dataclass |
|---|
class Message:
block_env¶
| 107 | block_env: BlockEnvironment |
|---|
tx_env¶
| 108 | tx_env: TransactionEnvironment |
|---|
caller¶
| 109 | caller: Address |
|---|
target¶
| 110 | target: Bytes0 | Address |
|---|
current_target¶
| 111 | current_target: Address |
|---|
gas¶
| 112 | gas: Uint |
|---|
value¶
| 113 | value: U256 |
|---|
data¶
| 114 | data: Bytes |
|---|
code_address¶
| 115 | code_address: Optional[Address] |
|---|
code¶
| 116 | code: Bytes |
|---|
depth¶
| 117 | depth: Uint |
|---|
should_transfer_value¶
| 118 | should_transfer_value: bool |
|---|
is_static¶
| 119 | is_static: bool |
|---|
accessed_addresses¶
| 120 | accessed_addresses: Set[Address] |
|---|
accessed_storage_keys¶
| 121 | accessed_storage_keys: Set[Tuple[Address, Bytes32]] |
|---|
parent_evm¶
| 122 | parent_evm: Optional["Evm"] |
|---|
Evm ¶
The internal state of the virtual machine.
| 125 | @dataclass |
|---|
class Evm:
pc¶
| 129 | pc: Uint |
|---|
stack¶
| 130 | stack: List[U256] |
|---|
memory¶
| 131 | memory: bytearray |
|---|
code¶
| 132 | code: Bytes |
|---|
gas_left¶
| 133 | gas_left: Uint |
|---|
valid_jump_destinations¶
| 134 | valid_jump_destinations: Set[Uint] |
|---|
logs¶
| 135 | logs: Tuple[Log, ...] |
|---|
refund_counter¶
| 136 | refund_counter: int |
|---|
running¶
| 137 | running: bool |
|---|
message¶
| 138 | message: Message |
|---|
output¶
| 139 | output: Bytes |
|---|
accounts_to_delete¶
| 140 | accounts_to_delete: Set[Address] |
|---|
return_data¶
| 141 | return_data: Bytes |
|---|
error¶
| 142 | error: Optional[EthereumException] |
|---|
accessed_addresses¶
| 143 | accessed_addresses: Set[Address] |
|---|
accessed_storage_keys¶
| 144 | accessed_storage_keys: Set[Tuple[Address, Bytes32]] |
|---|
incorporate_child_on_success ¶
Incorporate the state of a successful child_evm into the parent evm.
Parameters
evm :
The parent EVM.
child_evm :
The child evm to incorporate.
def incorporate_child_on_success(evm: Evm, child_evm: Evm) -> None:
| 148 | """ |
|---|---|
| 149 | Incorporate the state of a successful `child_evm` into the parent `evm`. |
| 150 | |
| 151 | Parameters |
| 152 | ---------- |
| 153 | evm : |
| 154 | The parent `EVM`. |
| 155 | child_evm : |
| 156 | The child evm to incorporate. |
| 157 | |
| 158 | """ |
| 159 | evm.gas_left += child_evm.gas_left |
| 160 | evm.logs += child_evm.logs |
| 161 | evm.refund_counter += child_evm.refund_counter |
| 162 | evm.accounts_to_delete.update(child_evm.accounts_to_delete) |
| 163 | evm.accessed_addresses.update(child_evm.accessed_addresses) |
| 164 | evm.accessed_storage_keys.update(child_evm.accessed_storage_keys) |
incorporate_child_on_error ¶
Incorporate the state of an unsuccessful child_evm into the parent evm.
Parameters
evm :
The parent EVM.
child_evm :
The child evm to incorporate.
def incorporate_child_on_error(evm: Evm, child_evm: Evm) -> None:
| 168 | """ |
|---|---|
| 169 | Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. |
| 170 | |
| 171 | Parameters |
| 172 | ---------- |
| 173 | evm : |
| 174 | The parent `EVM`. |
| 175 | child_evm : |
| 176 | The child evm to incorporate. |
| 177 | |
| 178 | """ |
| 179 | evm.gas_left += child_evm.gas_left |