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

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

Environment

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

32
@dataclass
class Environment:

caller

38
    caller: Address

block_hashes

39
    block_hashes: List[Hash32]

origin

40
    origin: Address

coinbase

41
    coinbase: Address

number

42
    number: Uint

base_fee_per_gas

43
    base_fee_per_gas: Uint

gas_limit

44
    gas_limit: Uint

gas_price

45
    gas_price: Uint

time

46
    time: U256

prev_randao

47
    prev_randao: Bytes32

state

48
    state: State

chain_id

49
    chain_id: U64

traces

50
    traces: List[dict]

excess_blob_gas

51
    excess_blob_gas: U64

blob_versioned_hashes

52
    blob_versioned_hashes: Tuple[VersionedHash, ...]

transient_storage

53
    transient_storage: TransientStorage

Message

Items that are used by contract creation or message call.

56
@dataclass
class Message:

caller

62
    caller: Address

target

63
    target: Union[Bytes0, Address]

current_target

64
    current_target: Address

gas

65
    gas: Uint

value

66
    value: U256

data

67
    data: Bytes

code_address

68
    code_address: Optional[Address]

code

69
    code: Bytes

depth

70
    depth: Uint

should_transfer_value

71
    should_transfer_value: bool

is_static

72
    is_static: bool

accessed_addresses

73
    accessed_addresses: Set[Address]

accessed_storage_keys

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

parent_evm

75
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

78
@dataclass
class Evm:

pc

82
    pc: Uint

stack

83
    stack: List[U256]

memory

84
    memory: bytearray

code

85
    code: Bytes

gas_left

86
    gas_left: Uint

env

87
    env: Environment

valid_jump_destinations

88
    valid_jump_destinations: Set[Uint]

logs

89
    logs: Tuple[Log, ...]

refund_counter

90
    refund_counter: int

running

91
    running: bool

message

92
    message: Message

output

93
    output: Bytes

accounts_to_delete

94
    accounts_to_delete: Set[Address]

touched_accounts

95
    touched_accounts: Set[Address]

return_data

96
    return_data: Bytes

error

97
    error: Optional[Exception]

accessed_addresses

98
    accessed_addresses: Set[Address]

accessed_storage_keys

99
    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:
103
    """
104
    Incorporate the state of a successful `child_evm` into the parent `evm`.
105
106
    Parameters
107
    ----------
108
    evm :
109
        The parent `EVM`.
110
    child_evm :
111
        The child evm to incorporate.
112
    """
113
    evm.gas_left += child_evm.gas_left
114
    evm.logs += child_evm.logs
115
    evm.refund_counter += child_evm.refund_counter
116
    evm.accounts_to_delete.update(child_evm.accounts_to_delete)
117
    evm.touched_accounts.update(child_evm.touched_accounts)
118
    if account_exists_and_is_empty(
119
        evm.env.state, child_evm.message.current_target
120
    ):
121
        evm.touched_accounts.add(child_evm.message.current_target)
122
    evm.accessed_addresses.update(child_evm.accessed_addresses)
123
    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:
127
    """
128
    Incorporate the state of an unsuccessful `child_evm` into the parent `evm`.
129
130
    Parameters
131
    ----------
132
    evm :
133
        The parent `EVM`.
134
    child_evm :
135
        The child evm to incorporate.
136
    """
137
    # In block 2675119, the empty account at 0x3 (the RIPEMD160 precompile) was
138
    # cleared despite running out of gas. This is an obscure edge case that can
139
    # only happen to a precompile.
140
    # According to the general rules governing clearing of empty accounts, the
141
    # touch should have been reverted. Due to client bugs, this event went
142
    # unnoticed and 0x3 has been exempted from the rule that touches are
143
    # reverted in order to preserve this historical behaviour.
144
    if RIPEMD160_ADDRESS in child_evm.touched_accounts:
145
        evm.touched_accounts.add(RIPEMD160_ADDRESS)
146
    if child_evm.message.current_target == RIPEMD160_ADDRESS:
147
        if account_exists_and_is_empty(
148
            evm.env.state, child_evm.message.current_target
149
        ):
150
            evm.touched_accounts.add(RIPEMD160_ADDRESS)
151
    evm.gas_left += child_evm.gas_left