ethereum.forks.bpo1.vmethereum.forks.bpo2.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__¶
| 31 | __all__ = ("Environment", "Evm", "Message") |
|---|
BlockEnvironment ¶
Items external to the virtual machine itself, provided by the environment.
| 34 | @dataclass |
|---|
class BlockEnvironment:
chain_id¶
| 40 | chain_id: U64 |
|---|
state¶
| 41 | state: State |
|---|
block_gas_limit¶
| 42 | block_gas_limit: Uint |
|---|
block_hashes¶
| 43 | block_hashes: List[Hash32] |
|---|
coinbase¶
| 44 | coinbase: Address |
|---|
number¶
| 45 | number: Uint |
|---|
base_fee_per_gas¶
| 46 | base_fee_per_gas: Uint |
|---|
time¶
| 47 | time: U256 |
|---|
prev_randao¶
| 48 | prev_randao: Bytes32 |
|---|
excess_blob_gas¶
| 49 | excess_blob_gas: U64 |
|---|
parent_beacon_block_root¶
| 50 | parent_beacon_block_root: Hash32 |
|---|
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.
blob_gas_used : ethereum.base_types.U64
Total blob gas used in the block.
requests : Bytes
Hash of all the requests in the block.
| 53 | @dataclass |
|---|
class BlockOutput:
block_gas_used¶
| 79 | block_gas_used: Uint = Uint(0) |
|---|
transactions_trie¶
| 80 | transactions_trie: Trie[Bytes, Optional[Bytes | LegacyTransaction]] = ( |
|---|---|
| 81 | field(default_factory=lambda: Trie(secured=False, default=None)) |
| 82 | ) |
receipts_trie¶
| 83 | receipts_trie: Trie[Bytes, Optional[Bytes | Receipt]] = field( |
|---|---|
| 84 | default_factory=lambda: Trie(secured=False, default=None) |
| 85 | ) |
receipt_keys¶
| 86 | receipt_keys: Tuple[Bytes, ...] = field(default_factory=tuple) |
|---|
block_logs¶
| 87 | block_logs: Tuple[Log, ...] = field(default_factory=tuple) |
|---|
withdrawals_trie¶
| 88 | withdrawals_trie: Trie[Bytes, Optional[Bytes | Withdrawal]] = field( |
|---|---|
| 89 | default_factory=lambda: Trie(secured=False, default=None) |
| 90 | ) |
blob_gas_used¶
| 91 | blob_gas_used: U64 = U64(0) |
|---|
requests¶
| 92 | requests: List[Bytes] = field(default_factory=list) |
|---|
TransactionEnvironment ¶
Items that are used by contract creation or message call.
| 95 | @dataclass |
|---|
class TransactionEnvironment:
origin¶
| 101 | origin: Address |
|---|
gas_price¶
| 102 | gas_price: Uint |
|---|
gas¶
| 103 | gas: Uint |
|---|
access_list_addresses¶
| 104 | access_list_addresses: Set[Address] |
|---|
access_list_storage_keys¶
| 105 | access_list_storage_keys: Set[Tuple[Address, Bytes32]] |
|---|
transient_storage¶
| 106 | transient_storage: TransientStorage |
|---|
blob_versioned_hashes¶
| 107 | blob_versioned_hashes: Tuple[VersionedHash, ...] |
|---|
index_in_block¶
| 109 | index_in_block: Optional[Uint] |
|---|
tx_hash¶
| 110 | tx_hash: Optional[Hash32] |
|---|
Message ¶
Items that are used by contract creation or message call.
| 113 | @dataclass |
|---|
class Message:
block_env¶
| 119 | block_env: BlockEnvironment |
|---|
tx_env¶
| 120 | tx_env: TransactionEnvironment |
|---|
caller¶
| 121 | caller: Address |
|---|
target¶
| 122 | target: Bytes0 | Address |
|---|
current_target¶
| 123 | current_target: Address |
|---|
gas¶
| 124 | gas: Uint |
|---|
value¶
| 125 | value: U256 |
|---|
data¶
| 126 | data: Bytes |
|---|
code_address¶
| 127 | code_address: Optional[Address] |
|---|
code¶
| 128 | code: Bytes |
|---|
depth¶
| 129 | depth: Uint |
|---|
should_transfer_value¶
| 130 | should_transfer_value: bool |
|---|
is_static¶
| 131 | is_static: bool |
|---|
accessed_addresses¶
| 132 | accessed_addresses: Set[Address] |
|---|
accessed_storage_keys¶
| 133 | accessed_storage_keys: Set[Tuple[Address, Bytes32]] |
|---|
disable_precompiles¶
| 134 | disable_precompiles: bool |
|---|
parent_evm¶
| 135 | parent_evm: Optional["Evm"] |
|---|
Evm ¶
The internal state of the virtual machine.
| 138 | @dataclass |
|---|
class Evm:
pc¶
| 142 | pc: Uint |
|---|
stack¶
| 143 | stack: List[U256] |
|---|
memory¶
| 144 | memory: bytearray |
|---|
code¶
| 145 | code: Bytes |
|---|
gas_left¶
| 146 | gas_left: Uint |
|---|
valid_jump_destinations¶
| 147 | valid_jump_destinations: Set[Uint] |
|---|
logs¶
| 148 | logs: Tuple[Log, ...] |
|---|
refund_counter¶
| 149 | refund_counter: int |
|---|
running¶
| 150 | running: bool |
|---|
message¶
| 151 | message: Message |
|---|
output¶
| 152 | output: Bytes |
|---|
accounts_to_delete¶
| 153 | accounts_to_delete: Set[Address] |
|---|
return_data¶
| 154 | return_data: Bytes |
|---|
error¶
| 155 | error: Optional[EthereumException] |
|---|
accessed_addresses¶
| 156 | accessed_addresses: Set[Address] |
|---|
accessed_storage_keys¶
| 157 | 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:
| 161 | """ |
|---|---|
| 162 | Incorporate the state of a successful `child_evm` into the parent `evm`. |
| 163 | |
| 164 | Parameters |
| 165 | ---------- |
| 166 | evm : |
| 167 | The parent `EVM`. |
| 168 | child_evm : |
| 169 | The child evm to incorporate. |
| 170 | |
| 171 | """ |
| 172 | evm.gas_left += child_evm.gas_left |
| 173 | evm.logs += child_evm.logs |
| 174 | evm.refund_counter += child_evm.refund_counter |
| 175 | evm.accounts_to_delete.update(child_evm.accounts_to_delete) |
| 176 | evm.accessed_addresses.update(child_evm.accessed_addresses) |
| 177 | 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:
| 181 | """ |
|---|---|
| 182 | Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. |
| 183 | |
| 184 | Parameters |
| 185 | ---------- |
| 186 | evm : |
| 187 | The parent `EVM`. |
| 188 | child_evm : |
| 189 | The child evm to incorporate. |
| 190 | |
| 191 | """ |
| 192 | evm.gas_left += child_evm.gas_left |