ethereum.cancun.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") |
---|
Environment
Items external to the virtual machine itself, provided by the environment.
33 | @dataclass |
---|
class Environment:
caller
39 | caller: Address |
---|
block_hashes
40 | block_hashes: List[Hash32] |
---|
origin
41 | origin: Address |
---|
coinbase
42 | coinbase: Address |
---|
number
43 | number: Uint |
---|
base_fee_per_gas
44 | base_fee_per_gas: Uint |
---|
gas_limit
45 | gas_limit: Uint |
---|
gas_price
46 | gas_price: Uint |
---|
time
47 | time: U256 |
---|
prev_randao
48 | prev_randao: Bytes32 |
---|
state
49 | state: State |
---|
chain_id
50 | chain_id: U64 |
---|
traces
51 | traces: List[dict] |
---|
excess_blob_gas
52 | excess_blob_gas: U64 |
---|
blob_versioned_hashes
53 | blob_versioned_hashes: Tuple[VersionedHash, ...] |
---|
transient_storage
54 | transient_storage: TransientStorage |
---|
Message
Items that are used by contract creation or message call.
57 | @dataclass |
---|
class Message:
caller
63 | caller: Address |
---|
target
64 | target: Union[Bytes0, Address] |
---|
current_target
65 | current_target: Address |
---|
gas
66 | gas: Uint |
---|
value
67 | value: U256 |
---|
data
68 | data: Bytes |
---|
code_address
69 | code_address: Optional[Address] |
---|
code
70 | code: Bytes |
---|
depth
71 | depth: Uint |
---|
should_transfer_value
72 | should_transfer_value: bool |
---|
is_static
73 | is_static: bool |
---|
accessed_addresses
74 | accessed_addresses: Set[Address] |
---|
accessed_storage_keys
75 | accessed_storage_keys: Set[Tuple[Address, Bytes32]] |
---|
parent_evm
76 | parent_evm: Optional["Evm"] |
---|
Evm
The internal state of the virtual machine.
79 | @dataclass |
---|
class Evm:
pc
83 | pc: Uint |
---|
stack
84 | stack: List[U256] |
---|
memory
85 | memory: bytearray |
---|
code
86 | code: Bytes |
---|
gas_left
87 | gas_left: Uint |
---|
env
88 | env: Environment |
---|
valid_jump_destinations
89 | valid_jump_destinations: Set[Uint] |
---|
logs
90 | logs: Tuple[Log, ...] |
---|
refund_counter
91 | refund_counter: int |
---|
running
92 | running: bool |
---|
message
93 | message: Message |
---|
output
94 | output: Bytes |
---|
accounts_to_delete
95 | accounts_to_delete: Set[Address] |
---|
touched_accounts
96 | touched_accounts: Set[Address] |
---|
return_data
97 | return_data: Bytes |
---|
error
98 | error: Optional[EthereumException] |
---|
accessed_addresses
99 | accessed_addresses: Set[Address] |
---|
accessed_storage_keys
100 | 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:
104 | """ |
---|---|
105 | Incorporate the state of a successful `child_evm` into the parent `evm`. |
106 |
|
107 | Parameters |
108 | ---------- |
109 | evm : |
110 | The parent `EVM`. |
111 | child_evm : |
112 | The child evm to incorporate. |
113 | """ |
114 | evm.gas_left += child_evm.gas_left |
115 | evm.logs += child_evm.logs |
116 | evm.refund_counter += child_evm.refund_counter |
117 | evm.accounts_to_delete.update(child_evm.accounts_to_delete) |
118 | evm.touched_accounts.update(child_evm.touched_accounts) |
119 | if account_exists_and_is_empty( |
120 | evm.env.state, child_evm.message.current_target |
121 | ): |
122 | evm.touched_accounts.add(child_evm.message.current_target) |
123 | evm.accessed_addresses.update(child_evm.accessed_addresses) |
124 | 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:
128 | """ |
---|---|
129 | Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. |
130 |
|
131 | Parameters |
132 | ---------- |
133 | evm : |
134 | The parent `EVM`. |
135 | child_evm : |
136 | The child evm to incorporate. |
137 | """ |
138 | # In block 2675119, the empty account at 0x3 (the RIPEMD160 precompile) was |
139 | # cleared despite running out of gas. This is an obscure edge case that can |
140 | # only happen to a precompile. |
141 | # According to the general rules governing clearing of empty accounts, the |
142 | # touch should have been reverted. Due to client bugs, this event went |
143 | # unnoticed and 0x3 has been exempted from the rule that touches are |
144 | # reverted in order to preserve this historical behaviour. |
145 | if RIPEMD160_ADDRESS in child_evm.touched_accounts: |
146 | evm.touched_accounts.add(RIPEMD160_ADDRESS) |
147 | if child_evm.message.current_target == RIPEMD160_ADDRESS: |
148 | if account_exists_and_is_empty( |
149 | evm.env.state, child_evm.message.current_target |
150 | ): |
151 | evm.touched_accounts.add(RIPEMD160_ADDRESS) |
152 | evm.gas_left += child_evm.gas_left |