Implement latest EIP-7685 `requestsHash` method (#6667)
It's now this weird one-off hashing method so that EL can partially forget in some modules what the data schema is.
This commit is contained in:
parent
7e5338deb3
commit
6f6de8d9dc
|
@ -533,9 +533,7 @@ proc storeBlock(
|
|||
# required checks on the CL instead and proceed as if the EL was syncing
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.8/specs/bellatrix/beacon-chain.md#verify_and_notify_new_payload
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.8/specs/deneb/beacon-chain.md#modified-verify_and_notify_new_payload
|
||||
debugComment "electra block hash has new/changed format"
|
||||
when typeof(signedBlock).kind >= ConsensusFork.Bellatrix and
|
||||
typeof(signedBlock).kind != ConsensusFork.Electra:
|
||||
when typeof(signedBlock).kind >= ConsensusFork.Bellatrix:
|
||||
if signedBlock.message.is_execution_block:
|
||||
template payload(): auto = signedBlock.message.body.execution_payload
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
import
|
||||
# Status libraries
|
||||
stew/[byteutils, endians2, objects],
|
||||
nimcrypto/sha2,
|
||||
chronicles,
|
||||
eth/common/[eth_types, eth_types_rlp],
|
||||
eth/rlp, eth/trie/ordered_trie,
|
||||
|
@ -466,24 +467,26 @@ func append*(w: var RlpWriter, request: electra.ConsolidationRequest) =
|
|||
targetPubkey: Bytes48 request.target_pubkey.blob)
|
||||
|
||||
# https://eips.ethereum.org/EIPS/eip-7685
|
||||
proc computeRequestsTrieRoot(
|
||||
func computeRequestsHash(
|
||||
requests: electra.ExecutionRequests): EthHash32 =
|
||||
let n =
|
||||
requests.deposits.len +
|
||||
requests.withdrawals.len +
|
||||
requests.consolidations.len
|
||||
let requestsHash = computeDigest:
|
||||
template mixInRequests(requestType, requestList): untyped =
|
||||
block:
|
||||
let hash = computeDigest:
|
||||
bind h
|
||||
h.update([requestType.byte])
|
||||
for request in requestList:
|
||||
h.update SSZ.encode(request)
|
||||
h.update(hash.data)
|
||||
|
||||
var b = OrderedTrieRootBuilder.init(n)
|
||||
static:
|
||||
doAssert DEPOSIT_REQUEST_TYPE < WITHDRAWAL_REQUEST_TYPE
|
||||
doAssert WITHDRAWAL_REQUEST_TYPE < CONSOLIDATION_REQUEST_TYPE
|
||||
mixInRequests(DEPOSIT_REQUEST_TYPE, requests.deposits)
|
||||
mixInRequests(WITHDRAWAL_REQUEST_TYPE, requests.withdrawals)
|
||||
mixInRequests(CONSOLIDATION_REQUEST_TYPE, requests.consolidations)
|
||||
|
||||
static:
|
||||
doAssert DEPOSIT_REQUEST_TYPE < WITHDRAWAL_REQUEST_TYPE
|
||||
doAssert WITHDRAWAL_REQUEST_TYPE < CONSOLIDATION_REQUEST_TYPE
|
||||
|
||||
b.add(requests.deposits.asSeq) # EIP-6110
|
||||
b.add(requests.withdrawals.asSeq) # EIP-7002
|
||||
b.add(requests.consolidations.asSeq) # EIP-7251
|
||||
|
||||
b.rootHash()
|
||||
requestsHash.to(EthHash32)
|
||||
|
||||
proc blockToBlockHeader*(blck: ForkyBeaconBlock): EthHeader =
|
||||
template payload: auto = blck.body.execution_payload
|
||||
|
@ -516,7 +519,7 @@ proc blockToBlockHeader*(blck: ForkyBeaconBlock): EthHeader =
|
|||
Opt.none(EthHash32)
|
||||
requestsHash =
|
||||
when typeof(payload).kind >= ConsensusFork.Electra:
|
||||
Opt.some blck.body.execution_requests.computeRequestsTrieRoot()
|
||||
Opt.some blck.body.execution_requests.computeRequestsHash()
|
||||
else:
|
||||
Opt.none(EthHash32)
|
||||
|
||||
|
|
Loading…
Reference in New Issue