From 1d02110a68d5a8dfe1c3463228ee9ab06b3ec133 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 23 May 2024 15:30:49 -0500 Subject: [PATCH 1/6] Update compute_el_header_block_hash for EIP-7685 --- .../test/helpers/execution_payload.py | 35 +++++++++---------- .../pyspec/eth2spec/test/helpers/genesis.py | 9 ++--- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index ef6e2f6442..33d7acce59 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -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) diff --git a/tests/core/pyspec/eth2spec/test/helpers/genesis.py b/tests/core/pyspec/eth2spec/test/helpers/genesis.py index 3896b41731..4919509eb2 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/genesis.py +++ b/tests/core/pyspec/eth2spec/test/helpers/genesis.py @@ -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 From d46e4aa36b64c47e4c510e52a43ff25363fbef9f Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 23 May 2024 15:55:16 -0500 Subject: [PATCH 2/6] Split long line into two --- tests/core/pyspec/eth2spec/test/helpers/execution_payload.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 33d7acce59..3b5ec5c0da 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -105,7 +105,8 @@ def compute_el_header_block_hash(spec, # 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"))) + empty_root = bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000") + execution_payload_header_rlp.append((Binary(32, 32), empty_root)) if is_post_electra(spec): # requests_root execution_payload_header_rlp.append((Binary(32, 32), requests_trie_root)) From 12cab5a864f296566066c1e07f18c17f70bd605e Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Thu, 23 May 2024 16:17:29 -0500 Subject: [PATCH 3/6] Make request type a bytes type --- tests/core/pyspec/eth2spec/test/helpers/execution_payload.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 3b5ec5c0da..d9177dd9af 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -147,7 +147,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 "\x01" + encode(values, sedes) + return b"\x01" + encode(values, sedes) def get_deposit_receipt_rlp(spec, deposit_receipt): @@ -166,7 +166,7 @@ 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 "\x00" + encode(values, sedes) + return b"\x00" + encode(values, sedes) def compute_el_block_hash(spec, payload): From 9b15abc7983cfd87b8debb749cbd73b3754218fa Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Fri, 31 May 2024 08:53:18 -0500 Subject: [PATCH 4/6] Append "_bytes" to modified RLP functions --- .../pyspec/eth2spec/test/helpers/execution_payload.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index d9177dd9af..9b963e6034 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -137,7 +137,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), @@ -150,7 +150,7 @@ def get_withdrawal_request_rlp(withdrawal_request): return b"\x01" + encode(values, sedes) -def get_deposit_receipt_rlp(spec, deposit_receipt): +def get_deposit_receipt_rlp_bytes(deposit_receipt): deposit_receipt_rlp = [ # pubkey (Binary(48, 48), deposit_receipt.pubkey), @@ -180,8 +180,8 @@ def compute_el_block_hash(spec, payload): withdrawals_trie_root = compute_trie_root_from_indexed_data(withdrawals_encoded) if is_post_electra(spec): 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_encoded += [get_deposit_receipt_rlp_bytes(receipt) for receipt in payload.deposit_receipts] + requests_encoded += [get_withdrawal_request_rlp_bytes(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) From 0298370af2e0876abe563691c59bb9924bbb16f2 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 10 Jun 2024 11:28:18 -0500 Subject: [PATCH 5/6] Fix rlp_bytes methods --- .../test/helpers/execution_payload.py | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 5047f0d2ea..73dfe99fd4 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -137,6 +137,25 @@ def get_withdrawal_rlp(withdrawal): return encode(values, sedes) +def get_deposit_request_rlp_bytes(deposit_request): + deposit_request_rlp = [ + # pubkey + (Binary(48, 48), deposit_request.pubkey), + # withdrawal_credentials + (Binary(32, 32), deposit_request.withdrawal_credentials), + # amount + (big_endian_int, deposit_request.amount), + # pubkey + (Binary(96, 96), deposit_request.signature), + # index + (big_endian_int, deposit_request.index), + ] + + sedes = List([schema for schema, _ in deposit_request_rlp]) + values = [value for _, value in deposit_request_rlp] + return b"\x00" + encode(values, sedes) + + # https://eips.ethereum.org/EIPS/eip-7002 def get_withdrawal_request_rlp_bytes(withdrawal_request): withdrawal_request_rlp = [ @@ -164,26 +183,7 @@ def get_consolidation_request_rlp_bytes(consolidation_request): 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), - # withdrawal_credentials - (Binary(32, 32), deposit_request.withdrawal_credentials), - # amount - (big_endian_int, deposit_request.amount), - # pubkey - (Binary(96, 96), deposit_request.signature), - # index - (big_endian_int, deposit_request.index), - ] - - sedes = List([schema for schema, _ in deposit_request_rlp]) - values = [value for _, value in deposit_request_rlp] - return encode(values, sedes) + return b"\x02" + encode(values, sedes) def compute_el_block_hash(spec, payload): From 83cb494e31829ea42523fda7e025e9b954c30570 Mon Sep 17 00:00:00 2001 From: Justin Traglia Date: Mon, 10 Jun 2024 11:28:54 -0500 Subject: [PATCH 6/6] Rename receipt to request --- tests/core/pyspec/eth2spec/test/helpers/execution_payload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 73dfe99fd4..dbfd29e671 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -197,7 +197,7 @@ def compute_el_block_hash(spec, payload): withdrawals_trie_root = compute_trie_root_from_indexed_data(withdrawals_encoded) if is_post_electra(spec): requests_encoded = [] - requests_encoded += [get_deposit_request_rlp_bytes(receipt) for receipt in payload.deposit_requests] + requests_encoded += [get_deposit_request_rlp_bytes(request) for request 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]