ethereum.tangerine_whistle.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 should_transfer_value: bool 63 parent_evm: Optional["Evm"] 64 65 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] 84 85 86def incorporate_child_on_success(evm: Evm, child_evm: Evm) -> None: 87 """ 88 Incorporate the state of a successful `child_evm` into the parent `evm`. 89 90 Parameters 91 ---------- 92 evm : 93 The parent `EVM`. 94 child_evm : 95 The child evm to incorporate. 96 """ 97 evm.gas_left += child_evm.gas_left 98 evm.logs += child_evm.logs 99 evm.refund_counter += child_evm.refund_counter 100 evm.accounts_to_delete.update(child_evm.accounts_to_delete) 101 102 103def incorporate_child_on_error(evm: Evm, child_evm: Evm) -> None: 104 """ 105 Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. 106 107 Parameters 108 ---------- 109 evm : 110 The parent `EVM`. 111 child_evm : 112 The child evm to incorporate. 113 """ 114 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:
67@dataclass 68class Evm: 69 """The internal state of the virtual machine.""" 70 71 pc: Uint 72 stack: List[U256] 73 memory: bytearray 74 code: Bytes 75 gas_left: Uint 76 env: Environment 77 valid_jump_destinations: Set[Uint] 78 logs: Tuple[Log, ...] 79 refund_counter: U256 80 running: bool 81 message: Message 82 output: Bytes 83 accounts_to_delete: Set[Address] 84 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 should_transfer_value: bool 64 parent_evm: Optional["Evm"]
Items that are used by contract creation or message call.