Skip to content

Commit 48e7508

Browse files
authored
Gloas beacon block validation update (#7657)
* feat: add validation for gloas * fix: spec update and remove gloasComment * fix: gloas block validation * fix: state field * fix: template var and return * feat: update helper for Gloas * fix: update validations * chore: cleanup * chore: update spec url
1 parent 02b18e4 commit 48e7508

File tree

3 files changed

+63
-19
lines changed

3 files changed

+63
-19
lines changed

beacon_chain/consensus_object_pools/blockchain_dag.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,9 +2283,8 @@ proc loadExecutionBlockHash*(dag: ChainDAGRef, bid: BlockId): Opt[Eth2Digest] =
22832283
return Opt.none(Eth2Digest)
22842284

22852285
withBlck(blockData):
2286-
debugGloasComment " "
2287-
when consensusFork == ConsensusFork.Gloas:
2288-
Opt.some ZERO_HASH
2286+
when consensusFork >= ConsensusFork.Gloas:
2287+
Opt.some forkyBlck.message.body.signed_execution_payload_bid.message.block_hash
22892288
elif consensusFork >= ConsensusFork.Bellatrix:
22902289
Opt.some forkyBlck.message.body.execution_payload.block_hash
22912290
else:

beacon_chain/gossip_processing/gossip_validation.nim

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ func getMaxBlobsPerBlock(cfg: RuntimeConfig, slot: Slot): uint64 =
340340
else:
341341
cfg.MAX_BLOBS_PER_BLOCK
342342

343-
debugGloasComment ""
344-
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-beta.0/specs/gloas/p2p-interface.md#beacon_block
343+
# https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/gloas/p2p-interface.md#beacon_block
345344
template validateBeaconBlockBellatrix(
346345
_: phase0.SignedBeaconBlock | altair.SignedBeaconBlock | gloas.SignedBeaconBlock,
347346
_: BlockRef): untyped =
@@ -401,8 +400,7 @@ template validateBeaconBlockBellatrix(
401400
# cannot occur here, because Nimbus's optimistic sync waits for either
402401
# `ACCEPTED` or `SYNCING` from the EL to get this far.
403402

404-
debugGloasComment ""
405-
# https://github.com/ethereum/consensus-specs/blob/v1.6.0-beta.0/specs/gloas/p2p-interface.md#beacon_block
403+
# https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/gloas/p2p-interface.md#beacon_block
406404
template validateBeaconBlockDeneb(
407405
_: ChainDAGRef,
408406
_:
@@ -428,6 +426,49 @@ template validateBeaconBlockDeneb(
428426
blob_params.MAX_BLOBS_PER_BLOCK):
429427
return dag.checkedReject("validateBeaconBlockDeneb: too many blob commitments")
430428

429+
template validateBeaconBlockGloas(
430+
_: ChainDAGRef,
431+
_:
432+
phase0.SignedBeaconBlock | altair.SignedBeaconBlock |
433+
bellatrix.SignedBeaconBlock | capella.SignedBeaconBlock |
434+
deneb.SignedBeaconBlock | electra.SignedBeaconBlock |
435+
fulu.SignedBeaconBlock): untyped =
436+
discard
437+
438+
# https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/gloas/p2p-interface.md#beacon_block
439+
template validateBeaconBlockGloas(
440+
dag: ChainDAGRef,
441+
signed_beacon_block: gloas.SignedBeaconBlock): untyped =
442+
template blck: untyped = signed_beacon_block.message
443+
template bid: untyped = blck.body.signed_execution_payload_bid.message
444+
445+
# If execution_payload verification of block's execution payload parent by an
446+
# execution node is complete:
447+
#
448+
# - [REJECT] The block's execution payload parent (defined by
449+
# bid.parent_block_hash) passes all validation.
450+
let
451+
parentRef = dag.getBlockRef(bid.parent_block_root)
452+
parentBlock =
453+
if parentRef.isSome():
454+
dag.getForkedBlock(parentRef.get().bid)
455+
else:
456+
Opt.none(ForkedTrustedSignedBeaconBlock)
457+
if parentBlock.isSome():
458+
withBlck(parentBlock.get()):
459+
if forkyBlck.message.is_execution_block:
460+
let parentHash = dag.loadExecutionBlockHash(parentRef.get()).valueOr:
461+
return dag.checkedReject(
462+
"validateBeaconBlockGloas: invalid execution parent")
463+
if not (bid.parent_block_hash == parentHash):
464+
return dag.checkedReject(
465+
"validateBeaconBlockGloas: invalid execution parent")
466+
467+
# [REJECT] The bid's parent (defined by `bid.parent_block_root`) equals the
468+
# block's parent (defined by `block.parent_root`).
469+
if not (bid.parent_block_root == blck.parent_root):
470+
return dag.checkedReject("validateBeaconBlockGloas: parent block mismatch")
471+
431472
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.4/specs/deneb/p2p-interface.md#blob_sidecar_subnet_id
432473
proc validateBlobSidecar*(
433474
dag: ChainDAGRef, quarantine: ref Quarantine,
@@ -806,8 +847,9 @@ proc validateDataColumnSidecar*(
806847

807848
ok()
808849

809-
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/phase0/p2p-interface.md#beacon_block
810-
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/p2p-interface.md#beacon_block
850+
# https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/phase0/p2p-interface.md#beacon_block
851+
# https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/bellatrix/p2p-interface.md#beacon_block
852+
# https://github.com/ethereum/consensus-specs/blob/v1.6.1/specs/gloas/p2p-interface.md#beacon_block
811853
proc validateBeaconBlock*(
812854
dag: ChainDAGRef, quarantine: ref Quarantine,
813855
signed_beacon_block: ForkySignedBeaconBlock,
@@ -888,9 +930,10 @@ proc validateBeaconBlock*(
888930
quarantine[].addOrphan(dag.finalizedHead.slot, signed_beacon_block).isOkOr:
889931
# Queueing failed because the parent was unviable - this means this block
890932
# is unviable as well, for the same reason
891-
return
892-
case error
893-
of UnviableKind.Invalid:
933+
case error
934+
of UnviableKind.Invalid:
935+
when typeof(signed_beacon_block).kind <= ConsensusFork.Fulu:
936+
# These checks are removed in Gloas.
894937
if signed_beacon_block.message.is_execution_block:
895938
# https://github.com/ethereum/consensus-specs/blob/v1.3.0/specs/bellatrix/p2p-interface.md#beacon_block
896939
#
@@ -917,11 +960,11 @@ proc validateBeaconBlock*(
917960
# whether it was marked unviable due to consensus (REJECT) or
918961
# execution (IGNORE) verification failure. We err on the IGNORE side.
919962
# TODO track this as a separate UnviableKind
920-
errIgnore("BeaconBlock: parent invalid")
963+
return errIgnore("BeaconBlock: parent invalid")
921964
else:
922-
errReject("BeaconBlock: parent invalid")
923-
of UnviableKind.UnviableFork:
924-
errIgnore("BeaconBlock: parent from unviable fork")
965+
return errReject("BeaconBlock: parent invalid")
966+
of UnviableKind.UnviableFork:
967+
return errIgnore("BeaconBlock: parent from unviable fork")
925968

926969
debug "Block quarantined",
927970
blockRoot = shortLog(signed_beacon_block.root),
@@ -937,6 +980,8 @@ proc validateBeaconBlock*(
937980

938981
dag.validateBeaconBlockDeneb(signed_beacon_block, wallTime)
939982

983+
dag.validateBeaconBlockGloas(signed_beacon_block)
984+
940985
# [REJECT] The block is from a higher slot than its parent.
941986
if not (signed_beacon_block.message.slot > parent.bid.slot):
942987
return dag.checkedReject(

beacon_chain/spec/helpers.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ func is_merge_transition_complete*(state: gloas.BeaconState): bool =
400400

401401
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.9/sync/optimistic.md#helpers
402402
func is_execution_block*(body: SomeForkyBeaconBlockBody): bool =
403-
when typeof(body).kind == ConsensusFork.Gloas:
404-
debugGloasComment ""
405-
false
403+
when typeof(body).kind >= ConsensusFork.Gloas:
404+
# Execution payload should always be enabled since Gloas.
405+
true
406406
elif typeof(body).kind >= ConsensusFork.Bellatrix:
407407
const defaultExecutionPayload = default(typeof(body.execution_payload))
408408
body.execution_payload != defaultExecutionPayload

0 commit comments

Comments
 (0)