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

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

parent_evm

69
    parent_evm: Optional["Evm"]

Evm

The internal state of the virtual machine.

72
@dataclass
class Evm:

pc

76
    pc: Uint

stack

77
    stack: List[U256]

memory

78
    memory: bytearray

code

79
    code: Bytes

gas_left

80
    gas_left: Uint

env

81
    env: Environment

valid_jump_destinations

82
    valid_jump_destinations: Set[Uint]

logs

83
    logs: Tuple[Log, ...]

refund_counter

84
    refund_counter: int

running

85
    running: bool

message

86
    message: Message

output

87
    output: Bytes

accounts_to_delete

88
    accounts_to_delete: Set[Address]

touched_accounts

89
    touched_accounts: Set[Address]

return_data

90
    return_data: Bytes

error

91
    error: Optional[Exception]

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