ethereum.frontier.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
.
1""" 2Ethereum Virtual Machine (EVM) 3^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 4 5.. contents:: Table of Contents 6 :backlinks: none 7 :local: 8 9Introduction 10------------ 11 12The abstract computer which runs the code stored in an 13`.fork_types.Account`. 14""" 15 16from dataclasses import dataclass 17from typing import List, Optional, Set, Tuple, Union 18 19from ethereum.base_types import U256, Bytes, Bytes0, Uint 20from ethereum.crypto.hash import Hash32 21 22from ..fork_types import Address, Log 23from ..state import State 24 25__all__ = ("Environment", "Evm", "Message") 26 27 28@dataclass 29class Environment: 30 """ 31 Items external to the virtual machine itself, provided by the environment. 32 """ 33 34 caller: Address 35 block_hashes: List[Hash32] 36 origin: Address 37 coinbase: Address 38 number: Uint 39 gas_limit: Uint 40 gas_price: Uint 41 time: U256 42 difficulty: Uint 43 state: State 44 traces: List[dict] 45 46 47@dataclass 48class Message: 49 """ 50 Items that are used by contract creation or message call. 51 """ 52 53 caller: Address 54 target: Union[Bytes0, Address] 55 current_target: Address 56 gas: Uint 57 value: U256 58 data: Bytes 59 code_address: Optional[Address] 60 code: Bytes 61 depth: Uint 62 parent_evm: Optional["Evm"] 63 64 65@dataclass 66class Evm: 67 """The internal state of the virtual machine.""" 68 69 pc: Uint 70 stack: List[U256] 71 memory: bytearray 72 code: Bytes 73 gas_left: Uint 74 env: Environment 75 valid_jump_destinations: Set[Uint] 76 logs: Tuple[Log, ...] 77 refund_counter: U256 78 running: bool 79 message: Message 80 output: Bytes 81 accounts_to_delete: Set[Address] 82 error: Optional[Exception] 83 84 85def incorporate_child_on_success(evm: Evm, child_evm: Evm) -> None: 86 """ 87 Incorporate the state of a successful `child_evm` into the parent `evm`. 88 89 Parameters 90 ---------- 91 evm : 92 The parent `EVM`. 93 child_evm : 94 The child evm to incorporate. 95 """ 96 evm.gas_left += child_evm.gas_left 97 evm.logs += child_evm.logs 98 evm.refund_counter += child_evm.refund_counter 99 evm.accounts_to_delete.update(child_evm.accounts_to_delete) 100 101 102def incorporate_child_on_error(evm: Evm, child_evm: Evm) -> None: 103 """ 104 Incorporate the state of an unsuccessful `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
@dataclass
class
Environment:
29@dataclass 30class Environment: 31 """ 32 Items external to the virtual machine itself, provided by the environment. 33 """ 34 35 caller: Address 36 block_hashes: List[Hash32] 37 origin: Address 38 coinbase: Address 39 number: Uint 40 gas_limit: Uint 41 gas_price: Uint 42 time: U256 43 difficulty: Uint 44 state: State 45 traces: List[dict]
Items external to the virtual machine itself, provided by the environment.
@dataclass
class
Evm:
66@dataclass 67class Evm: 68 """The internal state of the virtual machine.""" 69 70 pc: Uint 71 stack: List[U256] 72 memory: bytearray 73 code: Bytes 74 gas_left: Uint 75 env: Environment 76 valid_jump_destinations: Set[Uint] 77 logs: Tuple[Log, ...] 78 refund_counter: U256 79 running: bool 80 message: Message 81 output: Bytes 82 accounts_to_delete: Set[Address] 83 error: Optional[Exception]
The internal state of the virtual machine.
@dataclass
class
Message:
48@dataclass 49class Message: 50 """ 51 Items that are used by contract creation or message call. 52 """ 53 54 caller: Address 55 target: Union[Bytes0, Address] 56 current_target: Address 57 gas: Uint 58 value: U256 59 data: Bytes 60 code_address: Optional[Address] 61 code: Bytes 62 depth: Uint 63 parent_evm: Optional["Evm"]
Items that are used by contract creation or message call.