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

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

gas_limit

43
    gas_limit: Uint

gas_price

44
    gas_price: Uint

time

45
    time: U256

difficulty

46
    difficulty: Uint

state

47
    state: State

chain_id

48
    chain_id: U64

traces

49
    traces: List[dict]

Message

Items that are used by contract creation or message call.

52
@dataclass
class Message:

caller

58
    caller: Address

target

59
    target: Union[Bytes0, Address]

current_target

60
    current_target: Address

gas

61
    gas: Uint

value

62
    value: U256

data

63
    data: Bytes

code_address

64
    code_address: Optional[Address]

code

65
    code: Bytes

depth

66
    depth: Uint

should_transfer_value

67
    should_transfer_value: bool

is_static

68
    is_static: bool

accessed_addresses

69
    accessed_addresses: Set[Address]

accessed_storage_keys

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

parent_evm

71
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

74
@dataclass
class Evm:

pc

78
    pc: Uint

stack

79
    stack: List[U256]

memory

80
    memory: bytearray

code

81
    code: Bytes

gas_left

82
    gas_left: Uint

env

83
    env: Environment

valid_jump_destinations

84
    valid_jump_destinations: Set[Uint]

logs

85
    logs: Tuple[Log, ...]

refund_counter

86
    refund_counter: int

running

87
    running: bool

message

88
    message: Message

output

89
    output: Bytes

accounts_to_delete

90
    accounts_to_delete: Set[Address]

touched_accounts

91
    touched_accounts: Set[Address]

return_data

92
    return_data: Bytes

error

93
    error: Optional[Exception]

accessed_addresses

94
    accessed_addresses: Set[Address]

accessed_storage_keys

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