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

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

Environment

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

30
@dataclass
class Environment:

caller

36
    caller: Address

block_hashes

37
    block_hashes: List[Hash32]

origin

38
    origin: Address

coinbase

39
    coinbase: Address

number

40
    number: Uint

base_fee_per_gas

41
    base_fee_per_gas: Uint

gas_limit

42
    gas_limit: Uint

gas_price

43
    gas_price: Uint

time

44
    time: U256

difficulty

45
    difficulty: Uint

state

46
    state: State

chain_id

47
    chain_id: U64

traces

48
    traces: List[dict]

Message

Items that are used by contract creation or message call.

51
@dataclass
class Message:

caller

57
    caller: Address

target

58
    target: Union[Bytes0, Address]

current_target

59
    current_target: Address

gas

60
    gas: Uint

value

61
    value: U256

data

62
    data: Bytes

code_address

63
    code_address: Optional[Address]

code

64
    code: Bytes

depth

65
    depth: Uint

should_transfer_value

66
    should_transfer_value: bool

is_static

67
    is_static: bool

accessed_addresses

68
    accessed_addresses: Set[Address]

accessed_storage_keys

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

parent_evm

70
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

73
@dataclass
class Evm:

pc

77
    pc: Uint

stack

78
    stack: List[U256]

memory

79
    memory: bytearray

code

80
    code: Bytes

gas_left

81
    gas_left: Uint

env

82
    env: Environment

valid_jump_destinations

83
    valid_jump_destinations: Set[Uint]

logs

84
    logs: Tuple[Log, ...]

refund_counter

85
    refund_counter: int

running

86
    running: bool

message

87
    message: Message

output

88
    output: Bytes

accounts_to_delete

89
    accounts_to_delete: Set[Address]

touched_accounts

90
    touched_accounts: Set[Address]

return_data

91
    return_data: Bytes

error

92
    error: Optional[Exception]

accessed_addresses

93
    accessed_addresses: Set[Address]

accessed_storage_keys

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