ethereum.forks.homestead.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__
| 30 | __all__ = ("Environment", "Evm", "Message") | 
|---|
BlockEnvironment
Items external to the virtual machine itself, provided by the environment.
| 33 | @dataclass | 
|---|
class BlockEnvironment:
chain_id
| 39 |     chain_id: U64 | 
|---|
state
| 40 |     state: State | 
|---|
block_gas_limit
| 41 |     block_gas_limit: Uint | 
|---|
block_hashes
| 42 |     block_hashes: List[Hash32] | 
|---|
coinbase
| 43 |     coinbase: Address | 
|---|
number
| 44 |     number: Uint | 
|---|
time
| 45 |     time: U256 | 
|---|
difficulty
| 46 |     difficulty: Uint | 
|---|
BlockOutput
Output from applying the block body to the present state.
Contains the following:
block_gas_used : ethereum.base_types.Uint
Gas used for executing all transactions.
transactions_trie : ethereum.fork_types.Root
Trie of all the transactions in the block.
receipts_trie : ethereum.fork_types.Root
Trie root of all the receipts in the block.
receipt_keys :
Key of all the receipts in the block.
block_logs : Bloom
Logs bloom of all the logs included in all the transactions of the
block.
| 49 | @dataclass | 
|---|
class BlockOutput:
block_gas_used
| 69 |     block_gas_used: Uint = Uint(0) | 
|---|
transactions_trie
| 70 |     transactions_trie: Trie[Bytes, Optional[Transaction]] = field( | 
|---|---|
| 71 |         default_factory=lambda: Trie(secured=False, default=None) | 
| 72 |     ) | 
receipts_trie
| 73 |     receipts_trie: Trie[Bytes, Optional[Receipt]] = field( | 
|---|---|
| 74 |         default_factory=lambda: Trie(secured=False, default=None) | 
| 75 |     ) | 
receipt_keys
| 76 |     receipt_keys: Tuple[Bytes, ...] = field(default_factory=tuple) | 
|---|
block_logs
| 77 |     block_logs: Tuple[Log, ...] = field(default_factory=tuple) | 
|---|
TransactionEnvironment
Items that are used by contract creation or message call.
| 80 | @dataclass | 
|---|
class TransactionEnvironment:
origin
| 86 |     origin: Address | 
|---|
gas_price
| 87 |     gas_price: Uint | 
|---|
gas
| 88 |     gas: Uint | 
|---|
index_in_block
| 89 |     index_in_block: Uint | 
|---|
tx_hash
| 90 |     tx_hash: Optional[Hash32] | 
|---|
Message
Items that are used by contract creation or message call.
| 93 | @dataclass | 
|---|
class Message:
block_env
| 99 |     block_env: BlockEnvironment | 
|---|
tx_env
| 100 |     tx_env: TransactionEnvironment | 
|---|
caller
| 101 |     caller: Address | 
|---|
target
| 102 |     target: Bytes0 | Address | 
|---|
current_target
| 103 |     current_target: Address | 
|---|
gas
| 104 |     gas: Uint | 
|---|
value
| 105 |     value: U256 | 
|---|
data
| 106 |     data: Bytes | 
|---|
code_address
| 107 |     code_address: Optional[Address] | 
|---|
code
| 108 |     code: Bytes | 
|---|
depth
| 109 |     depth: Uint | 
|---|
should_transfer_value
| 110 |     should_transfer_value: bool | 
|---|
parent_evm
| 111 |     parent_evm: Optional["Evm"] | 
|---|
Evm
The internal state of the virtual machine.
| 114 | @dataclass | 
|---|
class Evm:
pc
| 118 |     pc: Uint | 
|---|
stack
| 119 |     stack: List[U256] | 
|---|
memory
| 120 |     memory: bytearray | 
|---|
code
| 121 |     code: Bytes | 
|---|
gas_left
| 122 |     gas_left: Uint | 
|---|
valid_jump_destinations
| 123 |     valid_jump_destinations: Set[Uint] | 
|---|
logs
| 124 |     logs: Tuple[Log, ...] | 
|---|
refund_counter
| 125 |     refund_counter: int | 
|---|
running
| 126 |     running: bool | 
|---|
message
| 127 |     message: Message | 
|---|
output
| 128 |     output: Bytes | 
|---|
accounts_to_delete
| 129 |     accounts_to_delete: Set[Address] | 
|---|
error
| 130 |     error: Optional[EthereumException] | 
|---|
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:
            
| 134 |     """ | 
|---|---|
| 135 |     Incorporate the state of a successful `child_evm` into the parent `evm`. | 
| 136 |  | 
| 137 |     Parameters | 
| 138 |     ---------- | 
| 139 |     evm : | 
| 140 |         The parent `EVM`. | 
| 141 |     child_evm : | 
| 142 |         The child evm to incorporate. | 
| 143 |  | 
| 144 |     """ | 
| 145 |     evm.gas_left += child_evm.gas_left | 
| 146 |     evm.logs += child_evm.logs | 
| 147 |     evm.refund_counter += child_evm.refund_counter | 
| 148 |     evm.accounts_to_delete.update(child_evm.accounts_to_delete) | 
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:
            
| 152 |     """ | 
|---|---|
| 153 |     Incorporate the state of an unsuccessful `child_evm` into the parent `evm`. | 
| 154 |  | 
| 155 |     Parameters | 
| 156 |     ---------- | 
| 157 |     evm : | 
| 158 |         The parent `EVM`. | 
| 159 |     child_evm : | 
| 160 |         The child evm to incorporate. | 
| 161 |  | 
| 162 |     """ | 
| 163 |     evm.gas_left += child_evm.gas_left |