ethereum.spurious_dragon.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__
27 | __all__ = ("Environment", "Evm", "Message") |
---|
Environment
Items external to the virtual machine itself, provided by the environment.
30 | @dataclass |
---|
class Environment:
caller
36 | caller: Address |
---|
block_hashes
37 | block_hashes: List[Hash32] |
---|
origin
38 | origin: Address |
---|
coinbase
39 | coinbase: Address |
---|
number
40 | number: Uint |
---|
gas_limit
41 | gas_limit: Uint |
---|
gas_price
42 | gas_price: Uint |
---|
time
43 | time: U256 |
---|
difficulty
44 | difficulty: Uint |
---|
state
45 | state: State |
---|
traces
46 | traces: List[dict] |
---|
Message
Items that are used by contract creation or message call.
49 | @dataclass |
---|
class Message:
caller
55 | caller: Address |
---|
target
56 | target: Union[Bytes0, Address] |
---|
current_target
57 | current_target: Address |
---|
gas
58 | gas: Uint |
---|
value
59 | value: U256 |
---|
data
60 | data: Bytes |
---|
code_address
61 | code_address: Optional[Address] |
---|
code
62 | code: Bytes |
---|
depth
63 | depth: Uint |
---|
should_transfer_value
64 | should_transfer_value: bool |
---|
parent_evm
65 | parent_evm: Optional["Evm"] |
---|
Evm
The internal state of the virtual machine.
68 | @dataclass |
---|
class Evm:
pc
72 | pc: Uint |
---|
stack
73 | stack: List[U256] |
---|
memory
74 | memory: bytearray |
---|
code
75 | code: Bytes |
---|
gas_left
76 | gas_left: Uint |
---|
env
77 | env: Environment |
---|
valid_jump_destinations
78 | valid_jump_destinations: Set[Uint] |
---|
logs
79 | logs: Tuple[Log, ...] |
---|
refund_counter
80 | refund_counter: int |
---|
running
81 | running: bool |
---|
message
82 | message: Message |
---|
output
83 | output: Bytes |
---|
accounts_to_delete
84 | accounts_to_delete: Set[Address] |
---|
touched_accounts
85 | touched_accounts: Set[Address] |
---|
error
86 | error: Optional[Exception] |
---|
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:
90 | """ |
---|---|
91 | Incorporate the state of a successful `child_evm` into the parent `evm`. |
92 |
|
93 | Parameters |
94 | ---------- |
95 | evm : |
96 | The parent `EVM`. |
97 | child_evm : |
98 | The child evm to incorporate. |
99 | """ |
100 | evm.gas_left += child_evm.gas_left |
101 | evm.logs += child_evm.logs |
102 | evm.refund_counter += child_evm.refund_counter |
103 | evm.accounts_to_delete.update(child_evm.accounts_to_delete) |
104 | evm.touched_accounts.update(child_evm.touched_accounts) |
105 | if account_exists_and_is_empty( |
106 | evm.env.state, child_evm.message.current_target |
107 | ): |
108 | 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:
112 | """ |
---|---|
113 | Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. |
114 |
|
115 | Parameters |
116 | ---------- |
117 | evm : |
118 | The parent `EVM`. |
119 | child_evm : |
120 | The child evm to incorporate. |
121 | """ |
122 | # In block 2675119, the empty account at 0x3 (the RIPEMD160 precompile) was |
123 | # cleared despite running out of gas. This is an obscure edge case that can |
124 | # only happen to a precompile. |
125 | # According to the general rules governing clearing of empty accounts, the |
126 | # touch should have been reverted. Due to client bugs, this event went |
127 | # unnoticed and 0x3 has been exempted from the rule that touches are |
128 | # reverted in order to preserve this historical behaviour. |
129 | if RIPEMD160_ADDRESS in child_evm.touched_accounts: |
130 | evm.touched_accounts.add(RIPEMD160_ADDRESS) |
131 | if child_evm.message.current_target == RIPEMD160_ADDRESS: |
132 | if account_exists_and_is_empty( |
133 | evm.env.state, child_evm.message.current_target |
134 | ): |
135 | evm.touched_accounts.add(RIPEMD160_ADDRESS) |
136 | evm.gas_left += child_evm.gas_left |