ethereum.shanghai.vmethereum.cancun.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

base_fee_per_gas

46
    base_fee_per_gas: Uint

time

47
    time: U256

prev_randao

48
    prev_randao: Bytes32

excess_blob_gas

49
    excess_blob_gas: U64

parent_beacon_block_root

50
    parent_beacon_block_root: Hash32

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

53
@dataclass
class BlockOutput:

block_gas_used

77
    block_gas_used: Uint = Uint(0)

transactions_trie

78
    transactions_trie: Trie[
79
        Bytes, Optional[Union[Bytes, LegacyTransaction]]
80
    ] = field(default_factory=lambda: Trie(secured=False, default=None))

receipts_trie

81
    receipts_trie: Trie[Bytes, Optional[Union[Bytes, Receipt]]] = field(
82
        default_factory=lambda: Trie(secured=False, default=None)
83
    )

receipt_keys

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

block_logs

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

withdrawals_trie

86
    withdrawals_trie: Trie[Bytes, Optional[Union[Bytes, Withdrawal]]] = field(
87
        default_factory=lambda: Trie(secured=False, default=None)
88
    )

blob_gas_used

89
    blob_gas_used: U64 = U64(0)

TransactionEnvironment

Items that are used by contract creation or message call.

92
@dataclass
class TransactionEnvironment:

origin

98
    origin: Address

gas_price

99
    gas_price: Uint

gas

100
    gas: Uint

access_list_addresses

101
    access_list_addresses: Set[Address]

access_list_storage_keys

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

transient_storage

103
    transient_storage: TransientStorage

blob_versioned_hashes

104
    blob_versioned_hashes: Tuple[VersionedHash, ...]

index_in_block

105
    index_in_block: Optional[Uint]

tx_hash

106
    tx_hash: Optional[Hash32]

traces

107
    traces: List[dict]

Message

Items that are used by contract creation or message call.

110
@dataclass
class Message:

block_env

116
    block_env: BlockEnvironment

tx_env

117
    tx_env: TransactionEnvironment

caller

118
    caller: Address

target

119
    target: Union[Bytes0, Address]

current_target

120
    current_target: Address

gas

121
    gas: Uint

value

122
    value: U256

data

123
    data: Bytes

code_address

124
    code_address: Optional[Address]

code

125
    code: Bytes

depth

126
    depth: Uint

should_transfer_value

127
    should_transfer_value: bool

is_static

128
    is_static: bool

accessed_addresses

129
    accessed_addresses: Set[Address]

accessed_storage_keys

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

parent_evm

131
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

134
@dataclass
class Evm:

pc

138
    pc: Uint

stack

139
    stack: List[U256]

memory

140
    memory: bytearray

code

141
    code: Bytes

gas_left

142
    gas_left: Uint

valid_jump_destinations

143
    valid_jump_destinations: Set[Uint]

logs

144
    logs: Tuple[Log, ...]

refund_counter

145
    refund_counter: int

running

146
    running: bool

message

147
    message: Message

output

148
    output: Bytes

accounts_to_delete

149
    accounts_to_delete: Set[Address]

return_data

150
    return_data: Bytes

error

151
    error: Optional[EthereumException]

accessed_addresses

152
    accessed_addresses: Set[Address]

accessed_storage_keys

153
    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:
157
    """
158
    Incorporate the state of a successful `child_evm` into the parent `evm`.
159
160
    Parameters
161
    ----------
162
    evm :
163
        The parent `EVM`.
164
    child_evm :
165
        The child evm to incorporate.
166
    """
167
    evm.gas_left += child_evm.gas_left
168
    evm.logs += child_evm.logs
169
    evm.refund_counter += child_evm.refund_counter
170
    evm.accounts_to_delete.update(child_evm.accounts_to_delete)
171
    evm.accessed_addresses.update(child_evm.accessed_addresses)
172
    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:
176
    """
177
    Incorporate the state of an unsuccessful `child_evm` into the parent `evm`.
178
179
    Parameters
180
    ----------
181
    evm :
182
        The parent `EVM`.
183
    child_evm :
184
        The child evm to incorporate.
185
    """
186
    evm.gas_left += child_evm.gas_left