mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-18 10:31:04 +00:00
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:
|
when typeof(signedBlock).toFork() >= ConsensusFork.Bellatrix:
|
||||||
template payload(): auto = signedBlock.message.body.execution_payload
|
template payload(): auto = signedBlock.message.body.execution_payload
|
||||||
if signedBlock.message.is_execution_block and
|
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",
|
debug "Execution block hash validation failed",
|
||||||
execution_payload = shortLog(payload)
|
execution_payload = shortLog(payload)
|
||||||
|
self[].dumpInvalidBlock(signedBlock)
|
||||||
doAssert strictVerification notin dag.updateFlags
|
doAssert strictVerification notin dag.updateFlags
|
||||||
self.consensusManager.quarantine[].addUnviable(signedBlock.root)
|
self.consensusManager.quarantine[].addUnviable(signedBlock.root)
|
||||||
return err((VerifierError.Invalid, ProcessingStatus.completed))
|
return err((VerifierError.Invalid, ProcessingStatus.completed))
|
||||||
|
@ -1219,7 +1219,7 @@ proc ETHExecutionBlockHeaderCreateFromJson(
|
|||||||
return nil
|
return nil
|
||||||
|
|
||||||
# Check fork consistency
|
# 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!"
|
"Only update this number once code is adjusted to check new fields!"
|
||||||
if bdata.baseFeePerGas.isNone and (
|
if bdata.baseFeePerGas.isNone and (
|
||||||
bdata.withdrawals.isSome or bdata.withdrawalsRoot.isSome or
|
bdata.withdrawals.isSome or bdata.withdrawalsRoot.isSome or
|
||||||
@ -1232,6 +1232,8 @@ proc ETHExecutionBlockHeaderCreateFromJson(
|
|||||||
return nil
|
return nil
|
||||||
if bdata.blobGasUsed.isSome != bdata.excessBlobGas.isSome:
|
if bdata.blobGasUsed.isSome != bdata.excessBlobGas.isSome:
|
||||||
return nil
|
return nil
|
||||||
|
if bdata.parentBeaconBlockRoot.isSome != bdata.parentBeaconBlockRoot.isSome:
|
||||||
|
return nil
|
||||||
|
|
||||||
# Construct block header
|
# Construct block header
|
||||||
static: # `GasInt` is signed. We only use it for hashing.
|
static: # `GasInt` is signed. We only use it for hashing.
|
||||||
@ -1272,7 +1274,12 @@ proc ETHExecutionBlockHeaderCreateFromJson(
|
|||||||
if bdata.excessBlobGas.isSome:
|
if bdata.excessBlobGas.isSome:
|
||||||
some distinctBase(bdata.excessBlobGas.get)
|
some distinctBase(bdata.excessBlobGas.get)
|
||||||
else:
|
else:
|
||||||
none(uint64))
|
none(uint64),
|
||||||
|
parentBeaconBlockRoot:
|
||||||
|
if bdata.parentBeaconBlockRoot.isSome:
|
||||||
|
some distinctBase(bdata.parentBeaconBlockRoot.get.asEth2Digest)
|
||||||
|
else:
|
||||||
|
none(ExecutionHash256))
|
||||||
if rlpHash(blockHeader) != executionHash[]:
|
if rlpHash(blockHeader) != executionHash[]:
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import
|
|||||||
eth/common/[eth_types, eth_types_rlp],
|
eth/common/[eth_types, eth_types_rlp],
|
||||||
eth/rlp, eth/trie/[db, hexary],
|
eth/rlp, eth/trie/[db, hexary],
|
||||||
# Internal
|
# Internal
|
||||||
./datatypes/[phase0, altair, bellatrix, capella, deneb],
|
|
||||||
"."/[eth2_merkleization, forks, ssz_codec]
|
"."/[eth2_merkleization, forks, ssz_codec]
|
||||||
|
|
||||||
# TODO although eth2_merkleization already exports ssz_codec, *sometimes* code
|
# TODO although eth2_merkleization already exports ssz_codec, *sometimes* code
|
||||||
@ -419,8 +418,9 @@ proc computeWithdrawalsTrieRoot*(
|
|||||||
doAssert false, "HexaryTrie.put failed: " & $exc.msg
|
doAssert false, "HexaryTrie.put failed: " & $exc.msg
|
||||||
tr.rootHash()
|
tr.rootHash()
|
||||||
|
|
||||||
proc payloadToBlockHeader*(
|
proc blockToBlockHeader*(blck: ForkyBeaconBlock): ExecutionBlockHeader =
|
||||||
payload: ForkyExecutionPayload): ExecutionBlockHeader =
|
template payload: auto = blck.body.execution_payload
|
||||||
|
|
||||||
static: # `GasInt` is signed. We only use it for hashing.
|
static: # `GasInt` is signed. We only use it for hashing.
|
||||||
doAssert sizeof(GasInt) == sizeof(payload.gas_limit)
|
doAssert sizeof(GasInt) == sizeof(payload.gas_limit)
|
||||||
doAssert sizeof(GasInt) == sizeof(payload.gas_used)
|
doAssert sizeof(GasInt) == sizeof(payload.gas_used)
|
||||||
@ -442,6 +442,11 @@ proc payloadToBlockHeader*(
|
|||||||
some payload.excess_blob_gas
|
some payload.excess_blob_gas
|
||||||
else:
|
else:
|
||||||
none(uint64)
|
none(uint64)
|
||||||
|
parentBeaconBlockRoot =
|
||||||
|
when typeof(payload).toFork >= ConsensusFork.Deneb:
|
||||||
|
some ExecutionHash256(data: blck.parent_root.data)
|
||||||
|
else:
|
||||||
|
none(ExecutionHash256)
|
||||||
|
|
||||||
ExecutionBlockHeader(
|
ExecutionBlockHeader(
|
||||||
parentHash : payload.parent_hash,
|
parentHash : payload.parent_hash,
|
||||||
@ -462,8 +467,8 @@ proc payloadToBlockHeader*(
|
|||||||
fee : some payload.base_fee_per_gas,
|
fee : some payload.base_fee_per_gas,
|
||||||
withdrawalsRoot : withdrawalsRoot,
|
withdrawalsRoot : withdrawalsRoot,
|
||||||
blobGasUsed : blobGasUsed, # EIP-4844
|
blobGasUsed : blobGasUsed, # EIP-4844
|
||||||
excessBlobGas : excessBlobGas) # EIP-4844
|
excessBlobGas : excessBlobGas, # EIP-4844
|
||||||
|
parentBeaconBlockRoot : parentBeaconBlockRoot) # EIP-4788
|
||||||
|
|
||||||
proc compute_execution_block_hash*(
|
proc compute_execution_block_hash*(blck: ForkyBeaconBlock): Eth2Digest =
|
||||||
payload: ForkyExecutionPayload): Eth2Digest =
|
rlpHash blockToBlockHeader(blck)
|
||||||
rlpHash payloadToBlockHeader(payload)
|
|
||||||
|
@ -12,7 +12,7 @@ import
|
|||||||
std/sequtils,
|
std/sequtils,
|
||||||
unittest2,
|
unittest2,
|
||||||
taskpools,
|
taskpools,
|
||||||
../beacon_chain/[conf, beacon_clock],
|
../beacon_chain/conf,
|
||||||
../beacon_chain/spec/[beaconstate, forks, helpers, state_transition],
|
../beacon_chain/spec/[beaconstate, forks, helpers, state_transition],
|
||||||
../beacon_chain/spec/datatypes/deneb,
|
../beacon_chain/spec/datatypes/deneb,
|
||||||
../beacon_chain/gossip_processing/block_processor,
|
../beacon_chain/gossip_processing/block_processor,
|
||||||
|
@ -110,7 +110,8 @@ proc build_empty_merge_execution_payload(state: bellatrix.BeaconState):
|
|||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
base_fee_per_gas: EIP1559_INITIAL_BASE_FEE)
|
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,
|
bellatrix.ExecutionPayloadForSigning(executionPayload: payload,
|
||||||
blockValue: Wei.zero)
|
blockValue: Wei.zero)
|
||||||
@ -145,7 +146,8 @@ proc build_empty_execution_payload(
|
|||||||
blockValue: Wei.zero)
|
blockValue: Wei.zero)
|
||||||
|
|
||||||
payload.executionPayload.block_hash =
|
payload.executionPayload.block_hash =
|
||||||
payload.executionPayload.compute_execution_block_hash()
|
bellatrix.BeaconBlock(body: bellatrix.BeaconBlockBody(execution_payload:
|
||||||
|
payload.executionPayload)).compute_execution_block_hash()
|
||||||
|
|
||||||
payload
|
payload
|
||||||
|
|
||||||
|
2
vendor/nim-eth
vendored
2
vendor/nim-eth
vendored
@ -1 +1 @@
|
|||||||
Subproject commit d217d309eb12e39d2a642feae1d9d27157b88352
|
Subproject commit 074edff1b4cdbc9989e2ee9f996437a28a3ba182
|
2
vendor/nim-web3
vendored
2
vendor/nim-web3
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 04f56c593a035af1b7bebdc726543a2a73826412
|
Subproject commit 759c31439c5e01655bf0a8e8a47f6db010c7a5b8
|
Loading…
x
Reference in New Issue
Block a user