Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update compute_el_header_block_hash for EIP-7685 #3778

Merged
merged 7 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions tests/core/pyspec/eth2spec/test/helpers/execution_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def compute_el_header_block_hash(spec,
payload_header,
transactions_trie_root,
withdrawals_trie_root=None,
deposit_requests_trie_root=None,
withdrawal_requests_root=None,
consolidation_requests_root=None):
requests_trie_root=None):
"""
Computes the RLP execution block hash described by an `ExecutionPayloadHeader`.
"""
Expand Down Expand Up @@ -103,15 +101,16 @@ 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
empty_root = bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000")
execution_payload_header_rlp.append((Binary(32, 32), empty_root))
if is_post_electra(spec):
# deposit_requests_root
assert deposit_requests_trie_root is not None
execution_payload_header_rlp.append((Binary(32, 32), deposit_requests_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]
Expand Down Expand Up @@ -139,7 +138,7 @@ def get_withdrawal_rlp(withdrawal):


# https://eips.ethereum.org/EIPS/eip-7002
def get_withdrawal_request_rlp(withdrawal_request):
def get_withdrawal_request_rlp_bytes(withdrawal_request):
withdrawal_request_rlp = [
# source_address
(Binary(20, 20), withdrawal_request.source_address),
Expand All @@ -149,10 +148,26 @@ 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 b"\x01" + encode(values, sedes)


def get_deposit_request_rlp(spec, deposit_request):
# https://eips.ethereum.org/EIPS/eip-7251
def get_consolidation_request_rlp_bytes(consolidation_request):
consolidation_request_rlp = [
# source_address
(Binary(20, 20), consolidation_request.source_address),
# source_pubkey
(Binary(48, 48), consolidation_request.source_pubkey),
# target_pubkey
(Binary(48, 48), consolidation_request.target_pubkey),
]

sedes = List([schema for schema, _ in consolidation_request_rlp])
values = [value for _, value in consolidation_request_rlp]
return b"\x01" + encode(values, sedes)


def get_deposit_request_rlp_bytes(spec, deposit_request):
deposit_request_rlp = [
# pubkey
(Binary(48, 48), deposit_request.pubkey),
Expand All @@ -175,17 +190,18 @@ def compute_el_block_hash(spec, payload):
transactions_trie_root = compute_trie_root_from_indexed_data(payload.transactions)

withdrawals_trie_root = None
deposit_requests_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_requests_encoded = [get_deposit_request_rlp(spec, receipt) for receipt in payload.deposit_requests]
deposit_requests_trie_root = compute_trie_root_from_indexed_data(deposit_requests_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_request_rlp_bytes(receipt) for receipt in payload.deposit_requests]
requests_encoded += [get_withdrawal_request_rlp_bytes(request) for request in payload.withdrawal_requests]
requests_encoded += [get_consolidation_request_rlp_bytes(request) for request in payload.consolidation_requests]

requests_trie_root = compute_trie_root_from_indexed_data(requests_encoded)

payload_header = get_execution_payload_header(spec, payload)

Expand All @@ -194,8 +210,7 @@ def compute_el_block_hash(spec, payload):
payload_header,
transactions_trie_root,
withdrawals_trie_root,
deposit_requests_trie_root,
withdrawal_requests_root,
requests_trie_root,
)


Expand Down Expand Up @@ -231,8 +246,9 @@ 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_requests = []
payload.withdrawal_requests = []
payload.consolidation_requests = []

payload.block_hash = compute_el_block_hash(spec, payload)

Expand Down
9 changes: 3 additions & 6 deletions tests/core/pyspec/eth2spec/test/helpers/genesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,19 @@ def get_sample_genesis_execution_payload_header(spec,

transactions_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
withdrawals_trie_root = None
deposit_requests_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_requests_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_requests_trie_root,
exits_trie_root,
requests_trie_root,
)
return payload_header

Expand Down
Loading