ethereum.forks.amsterdam.block_access_lists.rlp_utils
Utilities for working with Block Access Lists using RLP encoding, as specified in EIP-7928.
This module provides:
RLP encoding functions for all Block Access List types
Hash computation using
keccak256Validation logic to ensure structural correctness
The encoding follows the RLP specification used throughout Ethereum.
compute_block_access_list_hash
Compute the hash of a Block Access List.
The Block Access List is RLP-encoded and then hashed with keccak256.
Parameters
block_access_list : The Block Access List to hash.
Returns
hash : The keccak256 hash of the RLP-encoded Block Access List.
def compute_block_access_list_hash(block_access_list: BlockAccessList) -> Hash32:
| 30 | """ |
|---|---|
| 31 | Compute the hash of a Block Access List. |
| 32 | |
| 33 | The Block Access List is RLP-encoded and then hashed with keccak256. |
| 34 | |
| 35 | Parameters |
| 36 | ---------- |
| 37 | block_access_list : |
| 38 | The Block Access List to hash. |
| 39 | |
| 40 | Returns |
| 41 | ------- |
| 42 | hash : |
| 43 | The keccak256 hash of the RLP-encoded Block Access List. |
| 44 | |
| 45 | """ |
| 46 | block_access_list_bytes = rlp_encode_block_access_list(block_access_list) |
| 47 | return keccak256(block_access_list_bytes) |
rlp_encode_block_access_list
Encode a [BlockAccessList] to RLP bytes.
This is the top-level encoding function that produces the final RLP representation of a block's access list, following the updated EIP-7928 specification.
Parameters
block_access_list : The block access list to encode.
Returns
encoded : The complete RLP-encoded block access list.
[BlockAccessList]: ref:ethereum.forks.amsterdam.block_access_lists.rlp_types.BlockAccessList # noqa: E501
def rlp_encode_block_access_list(block_access_list: BlockAccessList) -> Bytes:
| 51 | """ |
|---|---|
| 52 | Encode a [`BlockAccessList`] to RLP bytes. |
| 53 | |
| 54 | This is the top-level encoding function that produces the final RLP |
| 55 | representation of a block's access list, following the updated EIP-7928 |
| 56 | specification. |
| 57 | |
| 58 | Parameters |
| 59 | ---------- |
| 60 | block_access_list : |
| 61 | The block access list to encode. |
| 62 | |
| 63 | Returns |
| 64 | ------- |
| 65 | encoded : |
| 66 | The complete RLP-encoded block access list. |
| 67 | |
| 68 | [`BlockAccessList`]: ref:ethereum.forks.amsterdam.block_access_lists.rlp_types.BlockAccessList # noqa: E501 |
| 69 | |
| 70 | """ |
| 71 | # Encode as a list of AccountChanges directly (not wrapped) |
| 72 | account_changes_list = [] |
| 73 | for account in block_access_list: |
| 74 | # Each account is encoded as: |
| 75 | # [address, storage_changes, storage_reads, |
| 76 | # balance_changes, nonce_changes, code_changes] |
| 77 | storage_changes_list = [ |
| 78 | [ |
| 79 | slot_changes.slot, |
| 80 | [ |
| 81 | [Uint(c.block_access_index), c.new_value] |
| 82 | for c in slot_changes.changes |
| 83 | ], |
| 84 | ] |
| 85 | for slot_changes in account.storage_changes |
| 86 | ] |
| 87 | |
| 88 | storage_reads_list = list(account.storage_reads) |
| 89 | |
| 90 | balance_changes_list = [ |
| 91 | [Uint(bc.block_access_index), Uint(bc.post_balance)] |
| 92 | for bc in account.balance_changes |
| 93 | ] |
| 94 | |
| 95 | nonce_changes_list = [ |
| 96 | [Uint(nc.block_access_index), Uint(nc.new_nonce)] |
| 97 | for nc in account.nonce_changes |
| 98 | ] |
| 99 | |
| 100 | code_changes_list = [ |
| 101 | [Uint(cc.block_access_index), cc.new_code] |
| 102 | for cc in account.code_changes |
| 103 | ] |
| 104 | |
| 105 | account_changes_list.append( |
| 106 | [ |
| 107 | account.address, |
| 108 | storage_changes_list, |
| 109 | storage_reads_list, |
| 110 | balance_changes_list, |
| 111 | nonce_changes_list, |
| 112 | code_changes_list, |
| 113 | ] |
| 114 | ) |
| 115 | |
| 116 | encoded = rlp.encode(cast(Extended, account_changes_list)) |
| 117 | return Bytes(encoded) |