ethereum.forks.amsterdam.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__

33
__all__ = ("Environment", "Evm", "Message")

BlockEnvironment

Items external to the virtual machine itself, provided by the environment.

36
@dataclass
class BlockEnvironment:

chain_id

42
    chain_id: U64

state

43
    state: BlockState

block_gas_limit

44
    block_gas_limit: Uint

block_hashes

45
    block_hashes: List[Hash32]

coinbase

46
    coinbase: Address

number

47
    number: Uint

base_fee_per_gas

48
    base_fee_per_gas: Uint

time

49
    time: U256

prev_randao

50
    prev_randao: Bytes32

excess_blob_gas

51
    excess_blob_gas: U64

parent_beacon_block_root

52
    parent_beacon_block_root: Hash32

block_access_list_builder

53
    block_access_list_builder: BlockAccessListBuilder

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 : Keys of all the receipts in the block. block_logs : Bloom Logs bloom of all the logs included in all the transactions of the block. withdrawals_trie : ethereum.fork_types.Root Trie root of all the withdrawals in the block. blob_gas_used : ethereum.base_types.U64 Total blob gas used in the block. requests : Bytes Hash of all the requests in the block. block_access_list: BlockAccessList The block access list for the block.

56
@dataclass
class BlockOutput:

block_gas_used

84
    block_gas_used: Uint = Uint(0)

transactions_trie

85
    transactions_trie: Trie[Bytes, Optional[Bytes | LegacyTransaction]] = (
86
        field(default_factory=lambda: Trie(secured=False, default=None))
87
    )

receipts_trie

88
    receipts_trie: Trie[Bytes, Optional[Bytes | Receipt]] = field(
89
        default_factory=lambda: Trie(secured=False, default=None)
90
    )

receipt_keys

91
    receipt_keys: Tuple[Bytes, ...] = field(default_factory=tuple)

block_logs

92
    block_logs: Tuple[Log, ...] = field(default_factory=tuple)

withdrawals_trie

93
    withdrawals_trie: Trie[Bytes, Optional[Bytes | Withdrawal]] = field(
94
        default_factory=lambda: Trie(secured=False, default=None)
95
    )

blob_gas_used

96
    blob_gas_used: U64 = U64(0)

requests

97
    requests: List[Bytes] = field(default_factory=list)

block_access_list

98
    block_access_list: BlockAccessList = field(default_factory=list)

TransactionEnvironment

Items that are used by contract creation or message call.

101
@dataclass
class TransactionEnvironment:

origin

107
    origin: Address

gas_price

108
    gas_price: Uint

gas

109
    gas: Uint

access_list_addresses

110
    access_list_addresses: Set[Address]

access_list_storage_keys

111
    access_list_storage_keys: Set[Tuple[Address, Bytes32]]

state

112
    state: TransactionState

blob_versioned_hashes

113
    blob_versioned_hashes: Tuple[VersionedHash, ...]

authorizations

114
    authorizations: Tuple[Authorization, ...]

index_in_block

115
    index_in_block: Optional[Uint]

tx_hash

116
    tx_hash: Optional[Hash32]

Message

Items that are used by contract creation or message call.

119
@dataclass
class Message:

block_env

125
    block_env: BlockEnvironment

tx_env

126
    tx_env: TransactionEnvironment

caller

127
    caller: Address

target

128
    target: Bytes0 | Address

current_target

129
    current_target: Address

gas

130
    gas: Uint

value

131
    value: U256

data

132
    data: Bytes

code_address

133
    code_address: Optional[Address]

code

134
    code: Bytes

depth

135
    depth: Uint

should_transfer_value

136
    should_transfer_value: bool

is_static

137
    is_static: bool

accessed_addresses

138
    accessed_addresses: Set[Address]

accessed_storage_keys

139
    accessed_storage_keys: Set[Tuple[Address, Bytes32]]

disable_precompiles

140
    disable_precompiles: bool

parent_evm

141
    parent_evm: Optional["Evm"]

is_create

142
    is_create: bool

Evm

The internal state of the virtual machine.

145
@dataclass
class Evm:

pc

149
    pc: Uint

stack

150
    stack: List[U256]

memory

151
    memory: bytearray

code

152
    code: Bytes

gas_left

153
    gas_left: Uint

valid_jump_destinations

154
    valid_jump_destinations: Set[Uint]

logs

155
    logs: Tuple[Log, ...]

refund_counter

156
    refund_counter: int

running

157
    running: bool

message

158
    message: Message

output

159
    output: Bytes

accounts_to_delete

160
    accounts_to_delete: Set[Address]

return_data

161
    return_data: Bytes

error

162
    error: Optional[EthereumException]

accessed_addresses

163
    accessed_addresses: Set[Address]

accessed_storage_keys

164
    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:
168
    """
169
    Incorporate the state of a successful `child_evm` into the parent `evm`.
170
171
    Parameters
172
    ----------
173
    evm :
174
        The parent `EVM`.
175
    child_evm :
176
        The child evm to incorporate.
177
178
    """
179
    evm.gas_left += child_evm.gas_left
180
    evm.logs += child_evm.logs
181
    evm.refund_counter += child_evm.refund_counter
182
    evm.accounts_to_delete.update(child_evm.accounts_to_delete)
183
    evm.accessed_addresses.update(child_evm.accessed_addresses)
184
    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:
188
    """
189
    Incorporate the state of an unsuccessful `child_evm` into the parent `evm`.
190
191
    Parameters
192
    ----------
193
    evm :
194
        The parent `EVM`.
195
    child_evm :
196
        The child evm to incorporate.
197
198
    """
199
    evm.gas_left += child_evm.gas_left