ethereum.paris.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] |
---|
Message
Items that are used by contract creation or message call.
54 | @dataclass |
---|
class Message:
caller
60 | caller: Address |
---|
target
61 | target: Union[Bytes0, Address] |
---|
current_target
62 | current_target: Address |
---|
gas
63 | gas: Uint |
---|
value
64 | value: U256 |
---|
data
65 | data: Bytes |
---|
code_address
66 | code_address: Optional[Address] |
---|
code
67 | code: Bytes |
---|
depth
68 | depth: Uint |
---|
should_transfer_value
69 | should_transfer_value: bool |
---|
is_static
70 | is_static: bool |
---|
accessed_addresses
71 | accessed_addresses: Set[Address] |
---|
accessed_storage_keys
72 | accessed_storage_keys: Set[Tuple[Address, Bytes32]] |
---|
parent_evm
73 | parent_evm: Optional["Evm"] |
---|
Evm
The internal state of the virtual machine.
76 | @dataclass |
---|
class Evm:
pc
80 | pc: Uint |
---|
stack
81 | stack: List[U256] |
---|
memory
82 | memory: bytearray |
---|
code
83 | code: Bytes |
---|
gas_left
84 | gas_left: Uint |
---|
env
85 | env: Environment |
---|
valid_jump_destinations
86 | valid_jump_destinations: Set[Uint] |
---|
logs
87 | logs: Tuple[Log, ...] |
---|
refund_counter
88 | refund_counter: int |
---|
running
89 | running: bool |
---|
message
90 | message: Message |
---|
output
91 | output: Bytes |
---|
accounts_to_delete
92 | accounts_to_delete: Set[Address] |
---|
touched_accounts
93 | touched_accounts: Set[Address] |
---|
return_data
94 | return_data: Bytes |
---|
error
95 | error: Optional[EthereumException] |
---|
accessed_addresses
96 | accessed_addresses: Set[Address] |
---|
accessed_storage_keys
97 | 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:
101 | """ |
---|---|
102 | Incorporate the state of a successful `child_evm` into the parent `evm`. |
103 |
|
104 | Parameters |
105 | ---------- |
106 | evm : |
107 | The parent `EVM`. |
108 | child_evm : |
109 | The child evm to incorporate. |
110 | """ |
111 | evm.gas_left += child_evm.gas_left |
112 | evm.logs += child_evm.logs |
113 | evm.refund_counter += child_evm.refund_counter |
114 | evm.accounts_to_delete.update(child_evm.accounts_to_delete) |
115 | evm.touched_accounts.update(child_evm.touched_accounts) |
116 | if account_exists_and_is_empty( |
117 | evm.env.state, child_evm.message.current_target |
118 | ): |
119 | evm.touched_accounts.add(child_evm.message.current_target) |
120 | evm.accessed_addresses.update(child_evm.accessed_addresses) |
121 | 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:
125 | """ |
---|---|
126 | Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. |
127 |
|
128 | Parameters |
129 | ---------- |
130 | evm : |
131 | The parent `EVM`. |
132 | child_evm : |
133 | The child evm to incorporate. |
134 | """ |
135 | # In block 2675119, the empty account at 0x3 (the RIPEMD160 precompile) was |
136 | # cleared despite running out of gas. This is an obscure edge case that can |
137 | # only happen to a precompile. |
138 | # According to the general rules governing clearing of empty accounts, the |
139 | # touch should have been reverted. Due to client bugs, this event went |
140 | # unnoticed and 0x3 has been exempted from the rule that touches are |
141 | # reverted in order to preserve this historical behaviour. |
142 | if RIPEMD160_ADDRESS in child_evm.touched_accounts: |
143 | evm.touched_accounts.add(RIPEMD160_ADDRESS) |
144 | if child_evm.message.current_target == RIPEMD160_ADDRESS: |
145 | if account_exists_and_is_empty( |
146 | evm.env.state, child_evm.message.current_target |
147 | ): |
148 | evm.touched_accounts.add(RIPEMD160_ADDRESS) |
149 | evm.gas_left += child_evm.gas_left |