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

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

BlockEnvironment

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

33
@dataclass
class BlockEnvironment:

chain_id

39
    chain_id: U64

state

40
    state: State

block_gas_limit

41
    block_gas_limit: Uint

block_hashes

42
    block_hashes: List[Hash32]

coinbase

43
    coinbase: Address

number

44
    number: Uint

base_fee_per_gas

45
    base_fee_per_gas: Uint

time

46
    time: U256

difficulty

48
    difficulty: Uint

prev_randao

47
    prev_randao: Bytes32

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[Bytes | LegacyTransaction]] = (
72
        field(default_factory=lambda: Trie(secured=False, default=None))
73
    )

receipts_trie

74
    receipts_trie: Trie[Bytes, Optional[Bytes | 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

access_list_addresses

90
    access_list_addresses: Set[Address]

access_list_storage_keys

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

index_in_block

92
    index_in_block: Optional[Uint]

tx_hash

93
    tx_hash: Optional[Hash32]

Message

Items that are used by contract creation or message call.

96
@dataclass
class Message:

block_env

102
    block_env: BlockEnvironment

tx_env

103
    tx_env: TransactionEnvironment

caller

104
    caller: Address

target

105
    target: Bytes0 | Address

current_target

106
    current_target: Address

gas

107
    gas: Uint

value

108
    value: U256

data

109
    data: Bytes

code_address

110
    code_address: Optional[Address]

code

111
    code: Bytes

depth

112
    depth: Uint

should_transfer_value

113
    should_transfer_value: bool

is_static

114
    is_static: bool

accessed_addresses

115
    accessed_addresses: Set[Address]

accessed_storage_keys

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

parent_evm

117
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

120
@dataclass
class Evm:

pc

124
    pc: Uint

stack

125
    stack: List[U256]

memory

126
    memory: bytearray

code

127
    code: Bytes

gas_left

128
    gas_left: Uint

valid_jump_destinations

129
    valid_jump_destinations: Set[Uint]

logs

130
    logs: Tuple[Log, ...]

refund_counter

131
    refund_counter: int

running

132
    running: bool

message

133
    message: Message

output

134
    output: Bytes

accounts_to_delete

135
    accounts_to_delete: Set[Address]

touched_accounts

137
    touched_accounts: Set[Address]

return_data

136
    return_data: Bytes

error

137
    error: Optional[EthereumException]

accessed_addresses

138
    accessed_addresses: Set[Address]

accessed_storage_keys

139
    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:
143
    """
144
    Incorporate the state of a successful `child_evm` into the parent `evm`.
145
146
    Parameters
147
    ----------
148
    evm :
149
        The parent `EVM`.
150
    child_evm :
151
        The child evm to incorporate.
152
153
    """
154
    evm.gas_left += child_evm.gas_left
155
    evm.logs += child_evm.logs
156
    evm.refund_counter += child_evm.refund_counter
157
    evm.accounts_to_delete.update(child_evm.accounts_to_delete)
160
    evm.touched_accounts.update(child_evm.touched_accounts)
161
    if account_exists_and_is_empty(
162
        evm.message.block_env.state, child_evm.message.current_target
163
    ):
164
        evm.touched_accounts.add(child_evm.message.current_target)
158
    evm.accessed_addresses.update(child_evm.accessed_addresses)
159
    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:
163
    """
164
    Incorporate the state of an unsuccessful `child_evm` into the parent `evm`.
165
166
    Parameters
167
    ----------
168
    evm :
169
        The parent `EVM`.
170
    child_evm :
171
        The child evm to incorporate.
172
173
    """
181
    # In block 2675119, the empty account at 0x3 (the RIPEMD160 precompile) was
182
    # cleared despite running out of gas. This is an obscure edge case that can
183
    # only happen to a precompile.
184
    # According to the general rules governing clearing of empty accounts, the
185
    # touch should have been reverted. Due to client bugs, this event went
186
    # unnoticed and 0x3 has been exempted from the rule that touches are
187
    # reverted in order to preserve this historical behaviour.
188
    if RIPEMD160_ADDRESS in child_evm.touched_accounts:
189
        evm.touched_accounts.add(RIPEMD160_ADDRESS)
190
    if child_evm.message.current_target == RIPEMD160_ADDRESS:
191
        if account_exists_and_is_empty(
192
            evm.message.block_env.state, child_evm.message.current_target
193
        ):
194
            evm.touched_accounts.add(RIPEMD160_ADDRESS)
174
    evm.gas_left += child_evm.gas_left