Skip to content

Commit a24837b

Browse files
authored
Merge pull request #3778 from jtraglia/electra-block-hash
Update compute_el_header_block_hash for EIP-7685
2 parents d4b6c0c + 83cb494 commit a24837b

File tree

2 files changed

+53
-40
lines changed

2 files changed

+53
-40
lines changed

tests/core/pyspec/eth2spec/test/helpers/execution_payload.py

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ def compute_el_header_block_hash(spec,
5959
payload_header,
6060
transactions_trie_root,
6161
withdrawals_trie_root=None,
62-
deposit_requests_trie_root=None,
63-
withdrawal_requests_root=None,
64-
consolidation_requests_root=None):
62+
requests_trie_root=None):
6563
"""
6664
Computes the RLP execution block hash described by an `ExecutionPayloadHeader`.
6765
"""
@@ -103,15 +101,16 @@ def compute_el_header_block_hash(spec,
103101
# withdrawals_root
104102
execution_payload_header_rlp.append((Binary(32, 32), withdrawals_trie_root))
105103
if is_post_deneb(spec):
106-
# excess_blob_gas
104+
# blob_gas_used
107105
execution_payload_header_rlp.append((big_endian_int, payload_header.blob_gas_used))
106+
# excess_blob_gas
108107
execution_payload_header_rlp.append((big_endian_int, payload_header.excess_blob_gas))
108+
# parent_beacon_root
109+
empty_root = bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000")
110+
execution_payload_header_rlp.append((Binary(32, 32), empty_root))
109111
if is_post_electra(spec):
110-
# deposit_requests_root
111-
assert deposit_requests_trie_root is not None
112-
execution_payload_header_rlp.append((Binary(32, 32), deposit_requests_trie_root))
113-
# withdrawal requests root
114-
execution_payload_header_rlp.append((Binary(32, 32), withdrawal_requests_root))
112+
# requests_root
113+
execution_payload_header_rlp.append((Binary(32, 32), requests_trie_root))
115114

116115
sedes = List([schema for schema, _ in execution_payload_header_rlp])
117116
values = [value for _, value in execution_payload_header_rlp]
@@ -138,21 +137,7 @@ def get_withdrawal_rlp(withdrawal):
138137
return encode(values, sedes)
139138

140139

141-
# https://eips.ethereum.org/EIPS/eip-7002
142-
def get_withdrawal_request_rlp(withdrawal_request):
143-
withdrawal_request_rlp = [
144-
# source_address
145-
(Binary(20, 20), withdrawal_request.source_address),
146-
# validator_pubkey
147-
(Binary(48, 48), withdrawal_request.validator_pubkey),
148-
]
149-
150-
sedes = List([schema for schema, _ in withdrawal_request_rlp])
151-
values = [value for _, value in withdrawal_request_rlp]
152-
return encode(values, sedes)
153-
154-
155-
def get_deposit_request_rlp(spec, deposit_request):
140+
def get_deposit_request_rlp_bytes(deposit_request):
156141
deposit_request_rlp = [
157142
# pubkey
158143
(Binary(48, 48), deposit_request.pubkey),
@@ -168,24 +153,55 @@ def get_deposit_request_rlp(spec, deposit_request):
168153

169154
sedes = List([schema for schema, _ in deposit_request_rlp])
170155
values = [value for _, value in deposit_request_rlp]
171-
return encode(values, sedes)
156+
return b"\x00" + encode(values, sedes)
157+
158+
159+
# https://eips.ethereum.org/EIPS/eip-7002
160+
def get_withdrawal_request_rlp_bytes(withdrawal_request):
161+
withdrawal_request_rlp = [
162+
# source_address
163+
(Binary(20, 20), withdrawal_request.source_address),
164+
# validator_pubkey
165+
(Binary(48, 48), withdrawal_request.validator_pubkey),
166+
]
167+
168+
sedes = List([schema for schema, _ in withdrawal_request_rlp])
169+
values = [value for _, value in withdrawal_request_rlp]
170+
return b"\x01" + encode(values, sedes)
171+
172+
173+
# https://eips.ethereum.org/EIPS/eip-7251
174+
def get_consolidation_request_rlp_bytes(consolidation_request):
175+
consolidation_request_rlp = [
176+
# source_address
177+
(Binary(20, 20), consolidation_request.source_address),
178+
# source_pubkey
179+
(Binary(48, 48), consolidation_request.source_pubkey),
180+
# target_pubkey
181+
(Binary(48, 48), consolidation_request.target_pubkey),
182+
]
183+
184+
sedes = List([schema for schema, _ in consolidation_request_rlp])
185+
values = [value for _, value in consolidation_request_rlp]
186+
return b"\x02" + encode(values, sedes)
172187

173188

174189
def compute_el_block_hash(spec, payload):
175190
transactions_trie_root = compute_trie_root_from_indexed_data(payload.transactions)
176191

177192
withdrawals_trie_root = None
178-
deposit_requests_trie_root = None
179-
withdrawal_requests_root = None
193+
requests_trie_root = None
180194

181195
if is_post_capella(spec):
182196
withdrawals_encoded = [get_withdrawal_rlp(withdrawal) for withdrawal in payload.withdrawals]
183197
withdrawals_trie_root = compute_trie_root_from_indexed_data(withdrawals_encoded)
184198
if is_post_electra(spec):
185-
deposit_requests_encoded = [get_deposit_request_rlp(spec, receipt) for receipt in payload.deposit_requests]
186-
deposit_requests_trie_root = compute_trie_root_from_indexed_data(deposit_requests_encoded)
187-
withdrawal_requests_encoded = [get_withdrawal_request_rlp(request) for request in payload.withdrawal_requests]
188-
withdrawal_requests_root = compute_trie_root_from_indexed_data(withdrawal_requests_encoded)
199+
requests_encoded = []
200+
requests_encoded += [get_deposit_request_rlp_bytes(request) for request in payload.deposit_requests]
201+
requests_encoded += [get_withdrawal_request_rlp_bytes(request) for request in payload.withdrawal_requests]
202+
requests_encoded += [get_consolidation_request_rlp_bytes(request) for request in payload.consolidation_requests]
203+
204+
requests_trie_root = compute_trie_root_from_indexed_data(requests_encoded)
189205

190206
payload_header = get_execution_payload_header(spec, payload)
191207

@@ -194,8 +210,7 @@ def compute_el_block_hash(spec, payload):
194210
payload_header,
195211
transactions_trie_root,
196212
withdrawals_trie_root,
197-
deposit_requests_trie_root,
198-
withdrawal_requests_root,
213+
requests_trie_root,
199214
)
200215

201216

@@ -231,8 +246,9 @@ def build_empty_execution_payload(spec, state, randao_mix=None):
231246
payload.blob_gas_used = 0
232247
payload.excess_blob_gas = 0
233248
if is_post_electra(spec):
234-
# just to be clear
235249
payload.deposit_requests = []
250+
payload.withdrawal_requests = []
251+
payload.consolidation_requests = []
236252

237253
payload.block_hash = compute_el_block_hash(spec, payload)
238254

tests/core/pyspec/eth2spec/test/helpers/genesis.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,19 @@ def get_sample_genesis_execution_payload_header(spec,
5050

5151
transactions_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
5252
withdrawals_trie_root = None
53-
deposit_requests_trie_root = None
54-
exits_trie_root = None
53+
requests_trie_root = None
5554

5655
if is_post_capella(spec):
5756
withdrawals_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
5857
if is_post_electra(spec):
59-
deposit_requests_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
60-
exits_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
58+
requests_trie_root = bytes.fromhex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
6159

6260
payload_header.block_hash = compute_el_header_block_hash(
6361
spec,
6462
payload_header,
6563
transactions_trie_root,
6664
withdrawals_trie_root,
67-
deposit_requests_trie_root,
68-
exits_trie_root,
65+
requests_trie_root,
6966
)
7067
return payload_header
7168

0 commit comments

Comments
 (0)