ethereum.paris.vmethereum.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__
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 |
---|
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 :
Key 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.
51 | @dataclass |
---|
class BlockOutput:
block_gas_used
73 | block_gas_used: Uint = Uint(0) |
---|
transactions_trie
74 | transactions_trie: Trie[ |
---|---|
75 | Bytes, Optional[Union[Bytes, LegacyTransaction]] |
76 | ] = field(default_factory=lambda: Trie(secured=False, default=None)) |
receipts_trie
77 | receipts_trie: Trie[Bytes, Optional[Union[Bytes, Receipt]]] = field( |
---|---|
78 | default_factory=lambda: Trie(secured=False, default=None) |
79 | ) |
receipt_keys
80 | receipt_keys: Tuple[Bytes, ...] = field(default_factory=tuple) |
---|
block_logs
81 | block_logs: Tuple[Log, ...] = field(default_factory=tuple) |
---|
withdrawals_trie
82 | withdrawals_trie: Trie[Bytes, Optional[Union[Bytes, Withdrawal]]] = field( |
---|---|
83 | default_factory=lambda: Trie(secured=False, default=None) |
84 | ) |
TransactionEnvironment
Items that are used by contract creation or message call.
87 | @dataclass |
---|
class TransactionEnvironment:
origin
93 | origin: Address |
---|
gas_price
94 | gas_price: Uint |
---|
gas
95 | gas: Uint |
---|
access_list_addresses
96 | access_list_addresses: Set[Address] |
---|
access_list_storage_keys
97 | access_list_storage_keys: Set[Tuple[Address, Bytes32]] |
---|
index_in_block
98 | index_in_block: Optional[Uint] |
---|
tx_hash
99 | tx_hash: Optional[Hash32] |
---|
traces
100 | traces: List[dict] |
---|
Message
Items that are used by contract creation or message call.
103 | @dataclass |
---|
class Message:
block_env
109 | block_env: BlockEnvironment |
---|
tx_env
110 | tx_env: TransactionEnvironment |
---|
caller
111 | caller: Address |
---|
target
112 | target: Union[Bytes0, Address] |
---|
current_target
113 | current_target: Address |
---|
gas
114 | gas: Uint |
---|
value
115 | value: U256 |
---|
data
116 | data: Bytes |
---|
code_address
117 | code_address: Optional[Address] |
---|
code
118 | code: Bytes |
---|
depth
119 | depth: Uint |
---|
should_transfer_value
120 | should_transfer_value: bool |
---|
is_static
121 | is_static: bool |
---|
accessed_addresses
122 | accessed_addresses: Set[Address] |
---|
accessed_storage_keys
123 | accessed_storage_keys: Set[Tuple[Address, Bytes32]] |
---|
parent_evm
124 | parent_evm: Optional["Evm"] |
---|
Evm
The internal state of the virtual machine.
127 | @dataclass |
---|
class Evm:
pc
131 | pc: Uint |
---|
stack
132 | stack: List[U256] |
---|
memory
133 | memory: bytearray |
---|
code
134 | code: Bytes |
---|
gas_left
135 | gas_left: Uint |
---|
valid_jump_destinations
136 | valid_jump_destinations: Set[Uint] |
---|
logs
137 | logs: Tuple[Log, ...] |
---|
refund_counter
138 | refund_counter: int |
---|
running
139 | running: bool |
---|
message
140 | message: Message |
---|
output
141 | output: Bytes |
---|
accounts_to_delete
142 | accounts_to_delete: Set[Address] |
---|
return_data
143 | return_data: Bytes |
---|
error
144 | error: Optional[EthereumException] |
---|
accessed_addresses
145 | accessed_addresses: Set[Address] |
---|
accessed_storage_keys
146 | 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:
150 | """ |
---|---|
151 | Incorporate the state of a successful `child_evm` into the parent `evm`. |
152 |
|
153 | Parameters |
154 | ---------- |
155 | evm : |
156 | The parent `EVM`. |
157 | child_evm : |
158 | The child evm to incorporate. |
159 | """ |
160 | evm.gas_left += child_evm.gas_left |
161 | evm.logs += child_evm.logs |
162 | evm.refund_counter += child_evm.refund_counter |
163 | evm.accounts_to_delete.update(child_evm.accounts_to_delete) |
164 | evm.accessed_addresses.update(child_evm.accessed_addresses) |
165 | 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:
169 | """ |
---|---|
170 | Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. |
171 |
|
172 | Parameters |
173 | ---------- |
174 | evm : |
175 | The parent `EVM`. |
176 | child_evm : |
177 | The child evm to incorporate. |
178 | """ |
179 | evm.gas_left += child_evm.gas_left |