Repository navigation
fix: resolve PTC committee against the referenced block state #9426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import {RootHex, gloas, ssz} from "@lodestar/types"; | |
| import {toRootHex} from "@lodestar/utils"; | ||
| import {GossipAction, PayloadAttestationError, PayloadAttestationErrorCode} from "../errors/index.js"; | ||
| import {IBeaconChain} from "../index.js"; | ||
| import {RegenCaller} from "../regen/index.js"; | ||
|
|
||
| export type PayloadAttestationValidationResult = { | ||
| attDataRootHex: RootHex; | ||
|
|
@@ -61,25 +62,33 @@ async function validatePayloadAttestationMessage( | |
| // [IGNORE] The message's block `data.beacon_block_root` has been seen (via | ||
| // gossip or non-gossip sources) (a client MAY queue attestation for processing | ||
| // once the block is retrieved. Note a client might want to request payload after). | ||
| if (!chain.forkChoice.hasBlock(data.beaconBlockRoot)) { | ||
| const block = chain.forkChoice.getBlockHexDefaultStatus(toRootHex(data.beaconBlockRoot)); | ||
| if (block === null) { | ||
| throw new PayloadAttestationError(GossipAction.IGNORE, { | ||
| code: PayloadAttestationErrorCode.UNKNOWN_BLOCK_ROOT, | ||
| blockRoot: toRootHex(data.beaconBlockRoot), | ||
| }); | ||
| } | ||
|
|
||
| const state = chain.getHeadState(); | ||
| if (!isStatePostGloas(state)) { | ||
| throw new Error(`Expected gloas+ state for payload attestation validation, got fork=${state.forkName}`); | ||
| } | ||
|
|
||
| // [REJECT] The message's block `data.beacon_block_root` passes validation. | ||
| // TODO GLOAS: implement this. Technically if we cannot get proto block from fork choice, | ||
| // it is possible that the block didn't pass the validation | ||
|
|
||
| // Use the referenced block's branch state for the PTC committee check | ||
| const state = await chain.regen | ||
| .getBlockSlotState(block, data.slot, {dontTransferCache: true}, RegenCaller.validateGossipPayloadAttestationMessage) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| .catch(() => { | ||
| throw new PayloadAttestationError(GossipAction.IGNORE, { | ||
| code: PayloadAttestationErrorCode.UNKNOWN_BLOCK_ROOT, | ||
| blockRoot: toRootHex(data.beaconBlockRoot), | ||
| }); | ||
| }); | ||
| if (!isStatePostGloas(state)) { | ||
| throw new Error(`Expected gloas+ state for payload attestation validation, got fork=${state.forkName}`); | ||
| } | ||
|
|
||
| // [REJECT] The message's validator index is within the payload committee in | ||
| // `get_ptc(state, data.slot)`. The `state` is the head state corresponding to | ||
| // processing the block up to the current slot as determined by the fork choice. | ||
| // `get_ptc(state, data.slot)`. | ||
| // The validator may occupy multiple PTC positions because `compute_ptc` samples | ||
| // by effective balance — collect all of them so duplicate votes are counted. | ||
| const validatorCommitteeIndices = state.getIndicesInPayloadTimelinessCommittee(validatorIndex, data.slot); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the payload attestation's slot (
data.slot) is strictly less than the referenced block's slot (block.slot), it represents a static protocol violation (an attestation cannot target a block from a future slot relative to itself). Currently, this case will causegetBlockSlotStateto throw aSLOT_BEFORE_BLOCK_SLOTerror, which is caught and mapped toUNKNOWN_BLOCK_ROOTwithGossipAction.IGNORE.To prevent peers from spamming these invalid attestations without being penalized, and to avoid the overhead of calling
getBlockSlotStatefor an obviously invalid attestation, we should explicitly check this condition andREJECTthe message.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.