ethereum.forks.shanghai.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: BlockState

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

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

50
@dataclass
class BlockOutput:

block_gas_used

72
    block_gas_used: Uint = Uint(0)

transactions_trie

73
    transactions_trie: Trie[Bytes, Optional[Bytes | LegacyTransaction]] = (
74
        field(default_factory=lambda: Trie(secured=False, default=None))
75
    )

receipts_trie

76
    receipts_trie: Trie[Bytes, Optional[Bytes | Receipt]] = field(
77
        default_factory=lambda: Trie(secured=False, default=None)
78
    )

receipt_keys

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

block_logs

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

withdrawals_trie

81
    withdrawals_trie: Trie[Bytes, Optional[Bytes | Withdrawal]] = field(
82
        default_factory=lambda: Trie(secured=False, default=None)
83
    )

TransactionEnvironment

Items that are used by contract creation or message call.

86
@dataclass
class TransactionEnvironment:

origin

92
    origin: Address

gas_price

93
    gas_price: Uint

gas

94
    gas: Uint

access_list_addresses

95
    access_list_addresses: Set[Address]

access_list_storage_keys

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

state

97
    state: TransactionState

index_in_block

98
    index_in_block: Optional[Uint]

tx_hash

99
    tx_hash: Optional[Hash32]

Message

Items that are used by contract creation or message call.

102
@dataclass
class Message:

block_env

108
    block_env: BlockEnvironment

tx_env

109
    tx_env: TransactionEnvironment

caller

110
    caller: Address

target

111
    target: Bytes0 | Address

current_target

112
    current_target: Address

gas

113
    gas: Uint

value

114
    value: U256

data

115
    data: Bytes

code_address

116
    code_address: Optional[Address]

code

117
    code: Bytes

depth

118
    depth: Uint

should_transfer_value

119
    should_transfer_value: bool

is_static

120
    is_static: bool

accessed_addresses

121
    accessed_addresses: Set[Address]

accessed_storage_keys

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

parent_evm

123
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

126
@dataclass
class Evm:

pc

130
    pc: Uint

stack

131
    stack: List[U256]

memory

132
    memory: bytearray

code

133
    code: Bytes

gas_left

134
    gas_left: Uint

valid_jump_destinations

135
    valid_jump_destinations: Set[Uint]

logs

136
    logs: Tuple[Log, ...]

refund_counter

137
    refund_counter: int

running

138
    running: bool

message

139
    message: Message

output

140
    output: Bytes

accounts_to_delete

141
    accounts_to_delete: Set[Address]

return_data

142
    return_data: Bytes

error

143
    error: Optional[EthereumException]

accessed_addresses

144
    accessed_addresses: Set[Address]

accessed_storage_keys

145
    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:
149
    """
150
    Incorporate the state of a successful `child_evm` into the parent `evm`.
151
152
    Parameters
153
    ----------
154
    evm :
155
        The parent `EVM`.
156
    child_evm :
157
        The child evm to incorporate.
158
159
    """
160
    evm.gas_left += child_evm.gas_left
161
    evm.logs += child_evm.logs
162
    evm.refund_counter += child_evm.refund_counter
163
    evm.accounts_to_delete.update(child_evm.accounts_to_delete)
164
    evm.accessed_addresses.update(child_evm.accessed_addresses)
165
    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:
169
    """
170
    Incorporate the state of an unsuccessful `child_evm` into the parent `evm`.
171
172
    Parameters
173
    ----------
174
    evm :
175
        The parent `EVM`.
176
    child_evm :
177
        The child evm to incorporate.
178
179
    """
180
    evm.gas_left += child_evm.gas_left