Update compute_el_header_block_hash for EIP-7685

This commit is contained in:
Justin Traglia 2024-05-23 15:30:49 -05:00
parent 836bc43a06
commit 1d02110a68
2 changed files with 19 additions and 25 deletions

View File

@ -58,8 +58,7 @@ def compute_el_header_block_hash(spec,
payload_header,
transactions_trie_root,
withdrawals_trie_root=None,
deposit_receipts_trie_root=None,
withdrawal_requests_root=None):
requests_trie_root=None):
"""
Computes the RLP execution block hash described by an `ExecutionPayloadHeader`.
"""
@ -101,15 +100,15 @@ def compute_el_header_block_hash(spec,
# withdrawals_root
execution_payload_header_rlp.append((Binary(32, 32), withdrawals_trie_root))
if is_post_deneb(spec):
# excess_blob_gas
# blob_gas_used
execution_payload_header_rlp.append((big_endian_int, payload_header.blob_gas_used))
# excess_blob_gas
execution_payload_header_rlp.append((big_endian_int, payload_header.excess_blob_gas))
# parent_beacon_root
execution_payload_header_rlp.append((Binary(32, 32), bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000")))
if is_post_electra(spec):
# deposit_receipts_root
assert deposit_receipts_trie_root is not None
execution_payload_header_rlp.append((Binary(32, 32), deposit_receipts_trie_root))
# withdrawal requests root
execution_payload_header_rlp.append((Binary(32, 32), withdrawal_requests_root))
# requests_root
execution_payload_header_rlp.append((Binary(32, 32), requests_trie_root))
sedes = List([schema for schema, _ in execution_payload_header_rlp])
values = [value for _, value in execution_payload_header_rlp]
@ -147,7 +146,7 @@ def get_withdrawal_request_rlp(withdrawal_request):
sedes = List([schema for schema, _ in withdrawal_request_rlp])
values = [value for _, value in withdrawal_request_rlp]
return encode(values, sedes)
return "\x01" + encode(values, sedes)
def get_deposit_receipt_rlp(spec, deposit_receipt):
@ -166,24 +165,23 @@ def get_deposit_receipt_rlp(spec, deposit_receipt):
sedes = List([schema for schema, _ in deposit_receipt_rlp])
values = [value for _, value in deposit_receipt_rlp]
return encode(values, sedes)
return "\x00" + encode(values, sedes)
def compute_el_block_hash(spec, payload):
transactions_trie_root = compute_trie_root_from_indexed_data(payload.transactions)
withdrawals_trie_root = None
deposit_receipts_trie_root = None
withdrawal_requests_root = None
requests_trie_root = None
if is_post_capella(spec):
withdrawals_encoded = [get_withdrawal_rlp(withdrawal) for withdrawal in payload.withdrawals]
withdrawals_trie_root = compute_trie_root_from_indexed_data(withdrawals_encoded)
if is_post_electra(spec):
deposit_receipts_encoded = [get_deposit_receipt_rlp(spec, receipt) for receipt in payload.deposit_receipts]
deposit_receipts_trie_root = compute_trie_root_from_indexed_data(deposit_receipts_encoded)
withdrawal_requests_encoded = [get_withdrawal_request_rlp(request) for request in payload.withdrawal_requests]
withdrawal_requests_root = compute_trie_root_from_indexed_data(withdrawal_requests_encoded)
requests_encoded = []
requests_encoded += [get_deposit_receipt_rlp(spec, receipt) for receipt in payload.deposit_receipts]
requests_encoded += [get_withdrawal_request_rlp(request) for request in payload.withdrawal_requests]
requests_trie_root = compute_trie_root_from_indexed_data(requests_encoded)
payload_header = get_execution_payload_header(spec, payload)
@ -192,8 +190,7 @@ def compute_el_block_hash(spec, payload):
payload_header,
transactions_trie_root,
withdrawals_trie_root,
deposit_receipts_trie_root,
withdrawal_requests_root,
requests_trie_root,
)
@ -229,8 +226,8 @@ def build_empty_execution_payload(spec, state, randao_mix=None):
payload.blob_gas_used = 0
payload.excess_blob_gas = 0
if is_post_electra(spec):
# just to be clear
payload.deposit_receipts = []
payload.withdrawal_requests = []
payload.block_hash = compute_el_block_hash(spec, payload)

View File

@ -50,22 +50,19 @@ def get_sample_genesis_execution_payload_header(spec,
transactions_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
withdrawals_trie_root = None
deposit_receipts_trie_root = None
exits_trie_root = None
requests_trie_root = None
if is_post_capella(spec):
withdrawals_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
if is_post_electra(spec):
deposit_receipts_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
exits_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
requests_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
payload_header.block_hash = compute_el_header_block_hash(
spec,
payload_header,
transactions_trie_root,
withdrawals_trie_root,
deposit_receipts_trie_root,
exits_trie_root,
requests_trie_root,
)
return payload_header