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