ethereum.frontier.vmethereum.homestead.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 |
---|
time
46 | time: U256 |
---|
difficulty
47 | difficulty: Uint |
---|
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.
50 | @dataclass |
---|
class BlockOutput:
block_gas_used
70 | block_gas_used: Uint = Uint(0) |
---|
transactions_trie
71 | transactions_trie: Trie[Bytes, Optional[Transaction]] = field( |
---|---|
72 | default_factory=lambda: Trie(secured=False, default=None) |
73 | ) |
receipts_trie
74 | receipts_trie: Trie[Bytes, Optional[Receipt]] = field( |
---|---|
75 | default_factory=lambda: Trie(secured=False, default=None) |
76 | ) |
receipt_keys
77 | receipt_keys: Tuple[Bytes, ...] = field(default_factory=tuple) |
---|
block_logs
78 | block_logs: Tuple[Log, ...] = field(default_factory=tuple) |
---|
TransactionEnvironment
Items that are used by contract creation or message call.
81 | @dataclass |
---|
class TransactionEnvironment:
origin
87 | origin: Address |
---|
gas_price
88 | gas_price: Uint |
---|
gas
89 | gas: Uint |
---|
index_in_block
90 | index_in_block: Uint |
---|
tx_hash
91 | tx_hash: Optional[Hash32] |
---|
traces
92 | traces: List[dict] |
---|
Message
Items that are used by contract creation or message call.
95 | @dataclass |
---|
class Message:
block_env
101 | block_env: BlockEnvironment |
---|
tx_env
102 | tx_env: TransactionEnvironment |
---|
caller
103 | caller: Address |
---|
target
104 | target: Union[Bytes0, Address] |
---|
current_target
105 | current_target: Address |
---|
gas
106 | gas: Uint |
---|
value
107 | value: U256 |
---|
data
108 | data: Bytes |
---|
code_address
109 | code_address: Optional[Address] |
---|
code
110 | code: Bytes |
---|
depth
111 | depth: Uint |
---|
should_transfer_value
112 | should_transfer_value: bool |
---|
parent_evm
113 | parent_evm: Optional["Evm"] |
---|
Evm
The internal state of the virtual machine.
116 | @dataclass |
---|
class Evm:
pc
120 | pc: Uint |
---|
stack
121 | stack: List[U256] |
---|
memory
122 | memory: bytearray |
---|
code
123 | code: Bytes |
---|
gas_left
124 | gas_left: Uint |
---|
valid_jump_destinations
125 | valid_jump_destinations: Set[Uint] |
---|
logs
126 | logs: Tuple[Log, ...] |
---|
refund_counter
127 | refund_counter: int |
---|
running
128 | running: bool |
---|
message
129 | message: Message |
---|
output
130 | output: Bytes |
---|
accounts_to_delete
131 | accounts_to_delete: Set[Address] |
---|
error
132 | 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:
136 | """ |
---|---|
137 | Incorporate the state of a successful `child_evm` into the parent `evm`. |
138 |
|
139 | Parameters |
140 | ---------- |
141 | evm : |
142 | The parent `EVM`. |
143 | child_evm : |
144 | The child evm to incorporate. |
145 | """ |
146 | evm.gas_left += child_evm.gas_left |
147 | evm.logs += child_evm.logs |
148 | evm.refund_counter += child_evm.refund_counter |
149 | evm.accounts_to_delete.update(child_evm.accounts_to_delete) |
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:
153 | """ |
---|---|
154 | Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. |
155 |
|
156 | Parameters |
157 | ---------- |
158 | evm : |
159 | The parent `EVM`. |
160 | child_evm : |
161 | The child evm to incorporate. |
162 | """ |
163 | evm.gas_left += child_evm.gas_left |