EIP-4788/parentBeaconBlockRoot fixes (#5318)
This commit is contained in:
parent
6162e735dd
commit
6fd4983f6b
|
@ -509,9 +509,11 @@ proc storeBlock(
|
|||
when typeof(signedBlock).toFork() >= ConsensusFork.Bellatrix:
|
||||
template payload(): auto = signedBlock.message.body.execution_payload
|
||||
if signedBlock.message.is_execution_block and
|
||||
payload.block_hash != payload.compute_execution_block_hash():
|
||||
payload.block_hash !=
|
||||
signedBlock.message.compute_execution_block_hash():
|
||||
debug "Execution block hash validation failed",
|
||||
execution_payload = shortLog(payload)
|
||||
self[].dumpInvalidBlock(signedBlock)
|
||||
doAssert strictVerification notin dag.updateFlags
|
||||
self.consensusManager.quarantine[].addUnviable(signedBlock.root)
|
||||
return err((VerifierError.Invalid, ProcessingStatus.completed))
|
||||
|
|
|
@ -1219,7 +1219,7 @@ proc ETHExecutionBlockHeaderCreateFromJson(
|
|||
return nil
|
||||
|
||||
# Check fork consistency
|
||||
static: doAssert totalSerializedFields(BlockObject) == 25,
|
||||
static: doAssert totalSerializedFields(BlockObject) == 26,
|
||||
"Only update this number once code is adjusted to check new fields!"
|
||||
if bdata.baseFeePerGas.isNone and (
|
||||
bdata.withdrawals.isSome or bdata.withdrawalsRoot.isSome or
|
||||
|
@ -1232,6 +1232,8 @@ proc ETHExecutionBlockHeaderCreateFromJson(
|
|||
return nil
|
||||
if bdata.blobGasUsed.isSome != bdata.excessBlobGas.isSome:
|
||||
return nil
|
||||
if bdata.parentBeaconBlockRoot.isSome != bdata.parentBeaconBlockRoot.isSome:
|
||||
return nil
|
||||
|
||||
# Construct block header
|
||||
static: # `GasInt` is signed. We only use it for hashing.
|
||||
|
@ -1272,7 +1274,12 @@ proc ETHExecutionBlockHeaderCreateFromJson(
|
|||
if bdata.excessBlobGas.isSome:
|
||||
some distinctBase(bdata.excessBlobGas.get)
|
||||
else:
|
||||
none(uint64))
|
||||
none(uint64),
|
||||
parentBeaconBlockRoot:
|
||||
if bdata.parentBeaconBlockRoot.isSome:
|
||||
some distinctBase(bdata.parentBeaconBlockRoot.get.asEth2Digest)
|
||||
else:
|
||||
none(ExecutionHash256))
|
||||
if rlpHash(blockHeader) != executionHash[]:
|
||||
return nil
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ import
|
|||
eth/common/[eth_types, eth_types_rlp],
|
||||
eth/rlp, eth/trie/[db, hexary],
|
||||
# Internal
|
||||
./datatypes/[phase0, altair, bellatrix, capella, deneb],
|
||||
"."/[eth2_merkleization, forks, ssz_codec]
|
||||
|
||||
# TODO although eth2_merkleization already exports ssz_codec, *sometimes* code
|
||||
|
@ -419,8 +418,9 @@ proc computeWithdrawalsTrieRoot*(
|
|||
doAssert false, "HexaryTrie.put failed: " & $exc.msg
|
||||
tr.rootHash()
|
||||
|
||||
proc payloadToBlockHeader*(
|
||||
payload: ForkyExecutionPayload): ExecutionBlockHeader =
|
||||
proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader =
|
||||
template payload: auto = blck.body.execution_payload
|
||||
|
||||
static: # `GasInt` is signed. We only use it for hashing.
|
||||
doAssert sizeof(GasInt) == sizeof(payload.gas_limit)
|
||||
doAssert sizeof(GasInt) == sizeof(payload.gas_used)
|
||||
|
@ -442,28 +442,33 @@ proc payloadToBlockHeader*(
|
|||
some payload.excess_blob_gas
|
||||
else:
|
||||
none(uint64)
|
||||
parentBeaconBlockRoot =
|
||||
when typeof(payload).toFork >= ConsensusFork.Deneb:
|
||||
some ExecutionHash256(data: blck.parent_root.data)
|
||||
else:
|
||||
none(ExecutionHash256)
|
||||
|
||||
ExecutionBlockHeader(
|
||||
parentHash : payload.parent_hash,
|
||||
ommersHash : EMPTY_UNCLE_HASH,
|
||||
coinbase : EthAddress payload.fee_recipient.data,
|
||||
stateRoot : payload.state_root,
|
||||
txRoot : txRoot,
|
||||
receiptRoot : payload.receipts_root,
|
||||
bloom : payload.logs_bloom.data,
|
||||
difficulty : default(DifficultyInt),
|
||||
blockNumber : payload.block_number.u256,
|
||||
gasLimit : cast[GasInt](payload.gas_limit),
|
||||
gasUsed : cast[GasInt](payload.gas_used),
|
||||
timestamp : fromUnix(int64.saturate payload.timestamp),
|
||||
extraData : payload.extra_data.asSeq,
|
||||
mixDigest : payload.prev_randao, # EIP-4399 `mixDigest` -> `prevRandao`
|
||||
nonce : default(BlockNonce),
|
||||
fee : some payload.base_fee_per_gas,
|
||||
withdrawalsRoot: withdrawalsRoot,
|
||||
blobGasUsed : blobGasUsed, # EIP-4844
|
||||
excessBlobGas : excessBlobGas) # EIP-4844
|
||||
parentHash : payload.parent_hash,
|
||||
ommersHash : EMPTY_UNCLE_HASH,
|
||||
coinbase : EthAddress payload.fee_recipient.data,
|
||||
stateRoot : payload.state_root,
|
||||
txRoot : txRoot,
|
||||
receiptRoot : payload.receipts_root,
|
||||
bloom : payload.logs_bloom.data,
|
||||
difficulty : default(DifficultyInt),
|
||||
blockNumber : payload.block_number.u256,
|
||||
gasLimit : cast[GasInt](payload.gas_limit),
|
||||
gasUsed : cast[GasInt](payload.gas_used),
|
||||
timestamp : fromUnix(int64.saturate payload.timestamp),
|
||||
extraData : payload.extra_data.asSeq,
|
||||
mixDigest : payload.prev_randao, # EIP-4399 `mixDigest` -> `prevRandao`
|
||||
nonce : default(BlockNonce),
|
||||
fee : some payload.base_fee_per_gas,
|
||||
withdrawalsRoot : withdrawalsRoot,
|
||||
blobGasUsed : blobGasUsed, # EIP-4844
|
||||
excessBlobGas : excessBlobGas, # EIP-4844
|
||||
parentBeaconBlockRoot : parentBeaconBlockRoot) # EIP-4788
|
||||
|
||||
proc compute_execution_block_hash*(
|
||||
payload: ForkyExecutionPayload): Eth2Digest =
|
||||
rlpHash payloadToBlockHeader(payload)
|
||||
proc compute_execution_block_hash*(blck: ForkyBeaconBlock): Eth2Digest =
|
||||
rlpHash blockToBlockHeader(blck)
|
||||
|
|
|
@ -12,7 +12,7 @@ import
|
|||
std/sequtils,
|
||||
unittest2,
|
||||
taskpools,
|
||||
../beacon_chain/[conf, beacon_clock],
|
||||
../beacon_chain/conf,
|
||||
../beacon_chain/spec/[beaconstate, forks, helpers, state_transition],
|
||||
../beacon_chain/spec/datatypes/deneb,
|
||||
../beacon_chain/gossip_processing/block_processor,
|
||||
|
|
|
@ -110,7 +110,8 @@ proc build_empty_merge_execution_payload(state: bellatrix.BeaconState):
|
|||
timestamp: timestamp,
|
||||
base_fee_per_gas: EIP1559_INITIAL_BASE_FEE)
|
||||
|
||||
payload.block_hash = rlpHash payloadToBlockHeader(payload)
|
||||
payload.block_hash = rlpHash blockToBlockHeader(bellatrix.BeaconBlock(body:
|
||||
bellatrix.BeaconBlockBody(execution_payload: payload)))
|
||||
|
||||
bellatrix.ExecutionPayloadForSigning(executionPayload: payload,
|
||||
blockValue: Wei.zero)
|
||||
|
@ -145,7 +146,8 @@ proc build_empty_execution_payload(
|
|||
blockValue: Wei.zero)
|
||||
|
||||
payload.executionPayload.block_hash =
|
||||
payload.executionPayload.compute_execution_block_hash()
|
||||
bellatrix.BeaconBlock(body: bellatrix.BeaconBlockBody(execution_payload:
|
||||
payload.executionPayload)).compute_execution_block_hash()
|
||||
|
||||
payload
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit d217d309eb12e39d2a642feae1d9d27157b88352
|
||||
Subproject commit 074edff1b4cdbc9989e2ee9f996437a28a3ba182
|
|
@ -1 +1 @@
|
|||
Subproject commit 04f56c593a035af1b7bebdc726543a2a73826412
|
||||
Subproject commit 759c31439c5e01655bf0a8e8a47f6db010c7a5b8
|
Loading…
Reference in New Issue