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

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

difficulty

47
    difficulty: Uint

state

48
    state: State

chain_id

49
    chain_id: U64

traces

50
    traces: List[dict]

Message

Items that are used by contract creation or message call.

53
@dataclass
class Message:

caller

59
    caller: Address

target

60
    target: Union[Bytes0, Address]

current_target

61
    current_target: Address

gas

62
    gas: Uint

value

63
    value: U256

data

64
    data: Bytes

code_address

65
    code_address: Optional[Address]

code

66
    code: Bytes

depth

67
    depth: Uint

should_transfer_value

68
    should_transfer_value: bool

is_static

69
    is_static: bool

accessed_addresses

70
    accessed_addresses: Set[Address]

accessed_storage_keys

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

parent_evm

72
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

75
@dataclass
class Evm:

pc

79
    pc: Uint

stack

80
    stack: List[U256]

memory

81
    memory: bytearray

code

82
    code: Bytes

gas_left

83
    gas_left: Uint

env

84
    env: Environment

valid_jump_destinations

85
    valid_jump_destinations: Set[Uint]

logs

86
    logs: Tuple[Log, ...]

refund_counter

87
    refund_counter: int

running

88
    running: bool

message

89
    message: Message

output

90
    output: Bytes

accounts_to_delete

91
    accounts_to_delete: Set[Address]

touched_accounts

92
    touched_accounts: Set[Address]

return_data

93
    return_data: Bytes

error

94
    error: Optional[Exception]

accessed_addresses

95
    accessed_addresses: Set[Address]

accessed_storage_keys

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