ethereum.state
Shared state types and the PreState protocol used by the state transition
function.
The PreState protocol specifies the operations that any pre-execution state
provider must support, allowing multiple backing implementations (in-memory
dict, on-disk database, witness, etc.).
Address¶
| 20 | Address = Bytes20 |
|---|
Root¶
| 21 | Root = Hash32 |
|---|
EMPTY_CODE_HASH¶
| 23 | EMPTY_CODE_HASH = keccak256(b"") |
|---|
Account ¶
State associated with an address.
| 26 | @slotted_freezable |
|---|
| 27 | @dataclass |
|---|
class Account:
nonce¶
| 33 | nonce: Uint |
|---|
balance¶
| 34 | balance: U256 |
|---|
code_hash¶
| 35 | code_hash: Hash32 |
|---|
EMPTY_ACCOUNT¶
| 38 | EMPTY_ACCOUNT = Account( |
|---|---|
| 39 | nonce=Uint(0), |
| 40 | balance=U256(0), |
| 41 | code_hash=EMPTY_CODE_HASH, |
| 42 | ) |
LeafNode ¶
Leaf node in the Merkle Trie.
| 45 | @slotted_freezable |
|---|
| 46 | @dataclass |
|---|
class LeafNode:
rest_of_key¶
| 50 | rest_of_key: Bytes |
|---|
value¶
| 51 | value: Extended |
|---|
ExtensionNode ¶
Extension node in the Merkle Trie.
| 54 | @slotted_freezable |
|---|
| 55 | @dataclass |
|---|
class ExtensionNode:
key_segment¶
| 59 | key_segment: Bytes |
|---|
subnode¶
| 60 | subnode: Extended |
|---|
BranchSubnodes¶
| 63 | BranchSubnodes = Tuple[ |
|---|---|
| 64 | Extended, |
| 65 | Extended, |
| 66 | Extended, |
| 67 | Extended, |
| 68 | Extended, |
| 69 | Extended, |
| 70 | Extended, |
| 71 | Extended, |
| 72 | Extended, |
| 73 | Extended, |
| 74 | Extended, |
| 75 | Extended, |
| 76 | Extended, |
| 77 | Extended, |
| 78 | Extended, |
| 79 | Extended, |
| 80 | ] |
BranchNode ¶
Branch node in the Merkle Trie.
| 83 | @slotted_freezable |
|---|
| 84 | @dataclass |
|---|
class BranchNode:
subnodes¶
| 88 | subnodes: BranchSubnodes |
|---|
value¶
| 89 | value: Extended |
|---|
InternalNode¶
| 92 | InternalNode = LeafNode | ExtensionNode | BranchNode |
|---|
BlockDiff ¶
State changes produced by executing a block.
| 95 | @dataclass |
|---|
class BlockDiff:
account_changes¶
Per-address account diffs produced by execution.
| 101 | account_changes: Dict[Address, Optional[Account]] |
|---|
storage_changes¶
Per-address storage diffs produced by execution.
| 104 | storage_changes: Dict[Address, Dict[Bytes32, U256]] |
|---|
code_changes¶
New bytecodes (keyed by code hash) introduced by execution.
| 107 | code_changes: Dict[Hash32, Bytes] |
|---|
PreState ¶
Protocol for providing pre-execution state.
Specify the operations that any pre-state provider (dict, database, witness, etc.) must support for the EELS state transition.
class PreState:
get_account_optional ¶
Get the account at an address.
Return None if there is no account at the address.
get_storage ¶
Get a storage value.
Return U256(0) if the key has not been set.
def get_storage(self, address: Address, key: Bytes32) -> U256:
| 128 | """ |
|---|---|
| 129 | Get a storage value. |
| 130 | |
| 131 | Return ``U256(0)`` if the key has not been set. |
| 132 | """ |
| 133 | ... |
get_code ¶
Get the bytecode for a given code hash.
Return b"" for EMPTY_CODE_HASH.
def get_code(self, code_hash: Hash32) -> Bytes:
| 136 | """ |
|---|---|
| 137 | Get the bytecode for a given code hash. |
| 138 | |
| 139 | Return ``b""`` for ``EMPTY_CODE_HASH``. |
| 140 | """ |
| 141 | ... |
account_has_storage ¶
Check whether an account has any storage.
Only needed for EIP-7610.
def account_has_storage(self, address: Address) -> bool:
| 144 | """ |
|---|---|
| 145 | Check whether an account has any storage. |
| 146 | |
| 147 | Only needed for EIP-7610. |
| 148 | """ |
| 149 | ... |
compute_state_root_and_trie_changes ¶
Compute the state root after applying changes to the pre-state.
Return the new state root together with the internal trie nodes that were created or modified.
def compute_state_root_and_trie_changes(self, account_changes: Dict[Address, Optional[Account]], storage_changes: Dict[Address, Dict[Bytes32, U256]]) -> Tuple[Root, List[InternalNode]]:
| 156 | """ |
|---|---|
| 157 | Compute the state root after applying changes to the pre-state. |
| 158 | |
| 159 | Return the new state root together with the internal trie nodes |
| 160 | that were created or modified. |
| 161 | """ |
| 162 | ... |