diff --git a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py index 94aa4b1099..dbfd29e671 100644 --- a/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py +++ b/tests/core/pyspec/eth2spec/test/helpers/execution_payload.py @@ -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`. """ @@ -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] @@ -138,21 +137,7 @@ def get_withdrawal_rlp(withdrawal): return encode(values, sedes) -# https://eips.ethereum.org/EIPS/eip-7002 -def get_withdrawal_request_rlp(withdrawal_request): - withdrawal_request_rlp = [ - # source_address - (Binary(20, 20), withdrawal_request.source_address), - # validator_pubkey - (Binary(48, 48), withdrawal_request.validator_pubkey), - ] - - sedes = List([schema for schema, _ in withdrawal_request_rlp]) - values = [value for _, value in withdrawal_request_rlp] - return encode(values, sedes) - - -def get_deposit_request_rlp(spec, deposit_request): +def get_deposit_request_rlp_bytes(deposit_request): deposit_request_rlp = [ # pubkey (Binary(48, 48), deposit_request.pubkey), @@ -168,24 +153,55 @@ def get_deposit_request_rlp(spec, deposit_request): sedes = List([schema for schema, _ in deposit_request_rlp]) values = [value for _, value in deposit_request_rlp] - return encode(values, sedes) + return b"\x00" + encode(values, sedes) + + +# https://eips.ethereum.org/EIPS/eip-7002 +def get_withdrawal_request_rlp_bytes(withdrawal_request): + withdrawal_request_rlp = [ + # source_address + (Binary(20, 20), withdrawal_request.source_address), + # validator_pubkey + (Binary(48, 48), withdrawal_request.validator_pubkey), + ] + + sedes = List([schema for schema, _ in withdrawal_request_rlp]) + values = [value for _, value in withdrawal_request_rlp] + return b"\x01" + encode(values, sedes) + + +# 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"\x02" + 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_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(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] + + requests_trie_root = compute_trie_root_from_indexed_data(requests_encoded) payload_header = get_execution_payload_header(spec, payload) @@ -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, ) @@ -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) diff --git a/tests/core/pyspec/eth2spec/test/helpers/genesis.py b/tests/core/pyspec/eth2spec/test/helpers/genesis.py index 34ddd88ca2..307491ac76 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_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