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

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

BlockEnvironment

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

35
@dataclass
class BlockEnvironment:

chain_id

41
    chain_id: U64

state

41
    state: State
42
    state: BlockState

block_gas_limit

43
    block_gas_limit: Uint

block_hashes

44
    block_hashes: List[Hash32]

coinbase

45
    coinbase: Address

number

46
    number: Uint

base_fee_per_gas

47
    base_fee_per_gas: Uint

time

48
    time: U256

prev_randao

49
    prev_randao: Bytes32

excess_blob_gas

50
    excess_blob_gas: U64

parent_beacon_block_root

51
    parent_beacon_block_root: Hash32

block_access_list_builder

52
    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.

55
@dataclass
class BlockOutput:

block_gas_used

83
    block_gas_used: Uint = Uint(0)

transactions_trie

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

receipts_trie

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

receipt_keys

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

block_logs

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

withdrawals_trie

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

blob_gas_used

95
    blob_gas_used: U64 = U64(0)

requests

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

block_access_list

97
    block_access_list: BlockAccessList = field(default_factory=list)

TransactionEnvironment

Items that are used by contract creation or message call.

100
@dataclass
class TransactionEnvironment:

origin

106
    origin: Address

gas_price

107
    gas_price: Uint

gas

108
    gas: Uint

access_list_addresses

109
    access_list_addresses: Set[Address]

access_list_storage_keys

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

transient_storage

106
    transient_storage: TransientStorage

state

111
    state: TransactionState

blob_versioned_hashes

112
    blob_versioned_hashes: Tuple[VersionedHash, ...]

authorizations

113
    authorizations: Tuple[Authorization, ...]

index_in_block

114
    index_in_block: Optional[Uint]

tx_hash

115
    tx_hash: Optional[Hash32]

Message

Items that are used by contract creation or message call.

118
@dataclass
class Message:

block_env

124
    block_env: BlockEnvironment

tx_env

125
    tx_env: TransactionEnvironment

caller

126
    caller: Address

target

127
    target: Bytes0 | Address

current_target

128
    current_target: Address

gas

129
    gas: Uint

value

130
    value: U256

data

131
    data: Bytes

code_address

132
    code_address: Optional[Address]

code

133
    code: Bytes

depth

134
    depth: Uint

should_transfer_value

135
    should_transfer_value: bool

is_static

136
    is_static: bool

accessed_addresses

137
    accessed_addresses: Set[Address]

accessed_storage_keys

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

disable_precompiles

139
    disable_precompiles: bool

parent_evm

140
    parent_evm: Optional["Evm"]

is_create

141
    is_create: bool

Evm

The internal state of the virtual machine.

144
@dataclass
class Evm:

pc

148
    pc: Uint

stack

149
    stack: List[U256]

memory

150
    memory: bytearray

code

151
    code: Bytes

gas_left

152
    gas_left: Uint

valid_jump_destinations

153
    valid_jump_destinations: Set[Uint]

logs

154
    logs: Tuple[Log, ...]

refund_counter

155
    refund_counter: int

running

156
    running: bool

message

157
    message: Message

output

158
    output: Bytes

accounts_to_delete

159
    accounts_to_delete: Set[Address]

return_data

160
    return_data: Bytes

error

161
    error: Optional[EthereumException]

accessed_addresses

162
    accessed_addresses: Set[Address]

accessed_storage_keys

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