ethereum.forks.spurious_dragon.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
@dataclass
class BlockEnvironment:

chain_id

44
    chain_id: U64

state

45
    state: BlockState

block_gas_limit

46
    block_gas_limit: Uint

block_hashes

47
    block_hashes: List[Hash32]

coinbase

48
    coinbase: Address

number

49
    number: Uint

time

50
    time: U256

difficulty

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

54
@dataclass
class BlockOutput:

block_gas_used

74
    block_gas_used: Uint = Uint(0)

transactions_trie

75
    transactions_trie: Trie[Bytes, Optional[Transaction]] = field(
76
        default_factory=lambda: Trie(secured=False, default=None)
77
    )

receipts_trie

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

receipt_keys

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

block_logs

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

TransactionEnvironment

Items that are used by contract creation or message call.

85
@dataclass
class TransactionEnvironment:

origin

91
    origin: Address

gas_price

92
    gas_price: Uint

gas

93
    gas: Uint

state

94
    state: TransactionState

index_in_block

95
    index_in_block: Uint

tx_hash

96
    tx_hash: Optional[Hash32]

Message

Items that are used by contract creation or message call.

99
@dataclass
class Message:

block_env

105
    block_env: BlockEnvironment

tx_env

106
    tx_env: TransactionEnvironment

caller

107
    caller: Address

target

108
    target: Bytes0 | Address

current_target

109
    current_target: Address

gas

110
    gas: Uint

value

111
    value: U256

data

112
    data: Bytes

code_address

113
    code_address: Optional[Address]

code

114
    code: Bytes

depth

115
    depth: Uint

should_transfer_value

116
    should_transfer_value: bool

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

136
    touched_accounts: Set[Address]

error

137
    error: Optional[EthereumException]

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:
141
    """
142
    Incorporate the state of a successful `child_evm` into the parent `evm`.
143
144
    Parameters
145
    ----------
146
    evm :
147
        The parent `EVM`.
148
    child_evm :
149
        The child evm to incorporate.
150
151
    """
152
    evm.gas_left += child_evm.gas_left
153
    evm.logs += child_evm.logs
154
    evm.refund_counter += child_evm.refund_counter
155
    evm.accounts_to_delete.update(child_evm.accounts_to_delete)
156
    evm.touched_accounts.update(child_evm.touched_accounts)
157
    if account_exists_and_is_empty(
158
        evm.message.tx_env.state, child_evm.message.current_target
159
    ):
160
        evm.touched_accounts.add(child_evm.message.current_target)

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:
164
    """
165
    Incorporate the state of an unsuccessful `child_evm` into the parent `evm`.
166
167
    Parameters
168
    ----------
169
    evm :
170
        The parent `EVM`.
171
    child_evm :
172
        The child evm to incorporate.
173
174
    """
175
    # In block 2675119, the empty account at 0x3 (the RIPEMD160 precompile) was
176
    # cleared despite running out of gas. This is an obscure edge case that can
177
    # only happen to a precompile.
178
    # According to the general rules governing clearing of empty accounts, the
179
    # touch should have been reverted. Due to client bugs, this event went
180
    # unnoticed and 0x3 has been exempted from the rule that touches are
181
    # reverted in order to preserve this historical behaviour.
182
    if RIPEMD160_ADDRESS in child_evm.touched_accounts:
183
        evm.touched_accounts.add(RIPEMD160_ADDRESS)
184
    if child_evm.message.current_target == RIPEMD160_ADDRESS:
185
        if account_exists_and_is_empty(
186
            evm.message.tx_env.state, child_evm.message.current_target
187
        ):
188
            evm.touched_accounts.add(RIPEMD160_ADDRESS)
189
    evm.gas_left += child_evm.gas_left