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

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

BlockEnvironment

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

38
@final
39
@dataclass
class BlockEnvironment:

chain_id

45
    chain_id: U64

state

46
    state: BlockState

block_gas_limit

47
    block_gas_limit: Uint

block_hashes

48
    block_hashes: List[Hash32]

coinbase

49
    coinbase: Address

number

50
    number: Uint

time

51
    time: U256

difficulty

52
    difficulty: Uint

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.

55
@final
56
@dataclass
class BlockOutput:

block_gas_used

76
    block_gas_used: Uint = Uint(0)

transactions_trie

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

receipts_trie

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

receipt_keys

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

block_logs

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

TransactionEnvironment

Items that are used while processing a transaction.

87
@final
88
@dataclass
class TransactionEnvironment:

origin

94
    origin: Address

gas_price

95
    gas_price: Uint

gas

96
    gas: Uint

access_list_addresses

97
    access_list_addresses: Set[Address]

access_list_storage_keys

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

state

99
    state: TransactionState

index_in_block

98
    index_in_block: Uint
100
    index_in_block: Optional[Uint]

tx_hash

101
    tx_hash: Optional[Hash32]

Message

Items that are used by contract creation or message call.

104
@final
105
@dataclass
class Message:

block_env

111
    block_env: BlockEnvironment

tx_env

112
    tx_env: TransactionEnvironment

caller

113
    caller: Address

target

114
    target: Bytes0 | Address

current_target

115
    current_target: Address

gas

116
    gas: Uint

value

117
    value: U256

data

118
    data: Bytes

code_address

119
    code_address: Optional[Address]

code

120
    code: Bytes

depth

121
    depth: Uint

should_transfer_value

122
    should_transfer_value: bool

is_static

123
    is_static: bool

accessed_addresses

124
    accessed_addresses: Set[Address]

accessed_storage_keys

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

parent_evm

126
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

129
@final
130
@dataclass
class Evm:

pc

134
    pc: Uint

stack

135
    stack: List[U256]

memory

136
    memory: bytearray

code

137
    code: Bytes

gas_left

138
    gas_left: Uint

valid_jump_destinations

139
    valid_jump_destinations: Set[Uint]

logs

140
    logs: Tuple[Log, ...]

refund_counter

141
    refund_counter: int

running

142
    running: bool

message

143
    message: Message

output

144
    output: Bytes

accounts_to_delete

145
    accounts_to_delete: Set[Address]

touched_accounts

146
    touched_accounts: Set[Address]

return_data

147
    return_data: Bytes

error

148
    error: Optional[EthereumException]

accessed_addresses

149
    accessed_addresses: Set[Address]

accessed_storage_keys

150
    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:
154
    <snip>
165
    evm.gas_left += child_evm.gas_left
166
    evm.logs += child_evm.logs
167
    evm.refund_counter += child_evm.refund_counter
168
    evm.accounts_to_delete.update(child_evm.accounts_to_delete)
169
    evm.touched_accounts.update(child_evm.touched_accounts)
170
    if account_exists_and_is_empty(
171
        evm.message.tx_env.state, child_evm.message.current_target
172
    ):
167
        evm.touched_accounts.add(child_evm.message.current_target)
173
        evm.touched_accounts.add(child_evm.message.current_target)
174
    evm.accessed_addresses.update(child_evm.accessed_addresses)
175
    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:
179
    <snip>
190
    # In block 2675119, the empty account at 0x3 (the RIPEMD160 precompile) was
191
    # cleared despite running out of gas. This is an obscure edge case that can
192
    # only happen to a precompile.
193
    # According to the general rules governing clearing of empty accounts, the
194
    # touch should have been reverted. Due to client bugs, this event went
195
    # unnoticed and 0x3 has been exempted from the rule that touches are
196
    # reverted in order to preserve this historical behaviour.
197
    if RIPEMD160_ADDRESS in child_evm.touched_accounts:
198
        evm.touched_accounts.add(RIPEMD160_ADDRESS)
199
    if child_evm.message.current_target == RIPEMD160_ADDRESS:
200
        if account_exists_and_is_empty(
201
            evm.message.tx_env.state, child_evm.message.current_target
202
        ):
203
            evm.touched_accounts.add(RIPEMD160_ADDRESS)
204
    evm.gas_left += child_evm.gas_left