Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export enum DataColumnSidecarErrorCode {
INCLUSION_PROOF_INVALID = "DATA_COLUMN_SIDECAR_ERROR_INCLUSION_PROOF_INVALID",
INCORRECT_PROPOSER = "DATA_COLUMN_SIDECAR_ERROR_INCORRECT_PROPOSER",
PAYLOAD_ENVELOPE_INPUT_MISSING = "DATA_COLUMN_SIDECAR_ERROR_PAYLOAD_ENVELOPE_INPUT_MISSING",
FINALIZED_NOT_ANCESTOR = "DATA_COLUMN_SIDECAR_ERROR_FINALIZED_NOT_ANCESTOR",
ALREADY_SEEN_TUPLE = "DATA_COLUMN_SIDECAR_ERROR_ALREADY_SEEN_TUPLE",
}

export type DataColumnSidecarErrorType =
Expand Down Expand Up @@ -128,7 +130,9 @@ export type DataColumnSidecarErrorType =
}
| {code: DataColumnSidecarErrorCode.INVALID_KZG_PROOF_BATCH; slot: number; reason: string}
| {code: DataColumnSidecarErrorCode.INCORRECT_PROPOSER; actualProposerIndex: number; expectedProposerIndex: number}
| {code: DataColumnSidecarErrorCode.PAYLOAD_ENVELOPE_INPUT_MISSING; slot: Slot; blockRoot: RootHex};
| {code: DataColumnSidecarErrorCode.PAYLOAD_ENVELOPE_INPUT_MISSING; slot: Slot; blockRoot: RootHex}
| {code: DataColumnSidecarErrorCode.FINALIZED_NOT_ANCESTOR; parentRoot: RootHex; finalizedRoot: RootHex}
| {code: DataColumnSidecarErrorCode.ALREADY_SEEN_TUPLE; slot: Slot; proposerIndex: number; columnIndex: number};

export class DataColumnSidecarGossipError extends GossipActionError<DataColumnSidecarErrorType> {}
export class DataColumnSidecarValidationError extends LodestarError<DataColumnSidecarErrorType> {}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ export class SeenBlockInput {
// gossip validation. Spec requires `[IGNORE]` for a subsequent sidecar matching the
// same tuple.
private blobSidecarTuples = new Map<Slot, Set<string>>();
// Tracks data column sidecar tuples `(slot, proposer_index, column_index)` already
// seen via gossip validation. Spec requires `[IGNORE]` for a subsequent sidecar
// matching the same tuple.
private dataColumnSidecarTuples = new Map<Slot, Set<string>>();

constructor({
config,
Expand Down Expand Up @@ -432,6 +436,23 @@ export class SeenBlockInput {
seenSet.add(`${proposerIndex}:${blobIndex}`);
}

/**
* Same proposer signing two different blocks at the same slot (equivocation)
* yields the same tuple, and only the first valid sidecar should propagate.
*/
isSeenDataColumnSidecar(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: number): boolean {
return this.dataColumnSidecarTuples.get(slot)?.has(`${proposerIndex}:${columnIndex}`) ?? false;
}

markSeenDataColumnSidecar(slot: Slot, proposerIndex: ValidatorIndex, columnIndex: number): void {
let seenSet = this.dataColumnSidecarTuples.get(slot);
if (!seenSet) {
seenSet = new Set<string>();
this.dataColumnSidecarTuples.set(slot, seenSet);
}
seenSet.add(`${proposerIndex}:${columnIndex}`);
}

private buildCommonProps(slot: Slot): {
daOutOfRange: boolean;
forkName: ForkName;
Expand Down Expand Up @@ -460,6 +481,7 @@ export class SeenBlockInput {
}
pruneSetToMax(this.verifiedProposerSignatures, MAX_BLOCK_INPUT_CACHE_SIZE);
pruneSetToMax(this.blobSidecarTuples, MAX_BLOCK_INPUT_CACHE_SIZE);
pruneSetToMax(this.dataColumnSidecarTuples, MAX_BLOCK_INPUT_CACHE_SIZE);
}

private evictBlockInput(blockInput: IBlockInput): void {
Expand Down
50 changes: 38 additions & 12 deletions packages/beacon-node/src/chain/validation/dataColumnSidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getBlockHeaderProposerSignatureSetByHeaderSlot,
getBlockHeaderProposerSignatureSetByParentStateSlot,
} from "@lodestar/state-transition";
import {DataColumnSidecar, Root, Slot, SubnetID, fulu, gloas, ssz} from "@lodestar/types";
import {DataColumnSidecar, Root, RootHex, Slot, SubnetID, fulu, gloas, ssz} from "@lodestar/types";
import {byteArrayEquals, toRootHex, verifyMerkleBranch} from "@lodestar/utils";
import {BeaconMetrics} from "../../metrics/metrics/beacon.js";
import {Metrics} from "../../metrics/metrics.js";
Expand All @@ -35,6 +35,24 @@ export async function validateGossipFuluDataColumnSidecar(
metrics: Metrics | null
): Promise<void> {
const blockHeader = dataColumnSidecar.signedBlockHeader.message;

// [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index,
// sidecar.index). Spec orders this check first, before any expensive verification.
if (
chain.seenBlockInputCache.isSeenDataColumnSidecar(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this, doesn't the BlockInput handle seen columns already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two checks have different keys and the spec mandates the tuple check.

  • BlockInput.hasColumn (gossipHandlers.ts:354-366) is keyed by (blockRoot, columnIndex) — it short-circuits re-gossip of the same column for the same block (or columns we already fetched via reqresp / getBlobsV2).
  • seenBlockInputCache.isSeenDataColumnSidecar is keyed by (slot, proposerIndex, columnIndex) and is the spec's first check. It catches equivocation: a proposer signing two different blocks at the same slot produces sidecars with the same (slot, proposer, index) but different blockRoot, so the BlockInput-keyed check would miss the second one and we'd re-run KZG + propagate. The class comment at seenGossipBlockInput.ts:440-442 calls this out.

Same shape as the blob path (isSeenBlobSidecar, blobSidecar.ts:182).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lodekeeper are you sure about this, if that's the case this seems like a bug in our current implementation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — my "spec orders this first" framing was wrong. Re-reading the Deneb spec and Fulu spec, the IGNORE tuple check is listed after KZG and qualified by "with valid header signature, sidecar inclusion proof, and kzg proof" — i.e. "first validated tuple", not "first tuple seen".

So neither file has a literal spec-correctness bug:

  • Mark side (writes to cache) is what the "with valid…" qualifier constrains — and in both files markSeen* runs only after all checks pass (data column line 231, blob line 209). Good.
  • Read side placement is up to the client. Lighthouse uses a two-phase pattern: an early read-only check (verify_is_unknown_sidecar) for perf, then the late write under the spec-listed position. See consensus-specs#3261 for the related blob-spam discussion.

This PR places the data column read check early; blobSidecar.ts (on this branch) places it after KZG. Both are correctness-equivalent given the post-validation mark; the early position saves a BLS sig + inclusion proof + KZG verify on duplicate gossip.

The two-key argument still holds: BlockInput.hasColumn catches re-gossip of (blockRoot, columnIndex), seen-tuple catches equivocations on (slot, proposerIndex, columnIndex). So we still need the seen-tuple check somewhere. Happy to align both files to the early position in a follow-up if you prefer the perf path.

blockHeader.slot,
blockHeader.proposerIndex,
dataColumnSidecar.index
)
) {
throw new DataColumnSidecarGossipError(GossipAction.IGNORE, {
code: DataColumnSidecarErrorCode.ALREADY_SEEN_TUPLE,
slot: blockHeader.slot,
proposerIndex: blockHeader.proposerIndex,
columnIndex: dataColumnSidecar.index,
});
}

const blockRootHex = toRootHex(ssz.phase0.BeaconBlockHeader.hashTreeRoot(blockHeader));

// 1) [REJECT] The sidecar is valid as verified by verify_data_column_sidecar
Expand Down Expand Up @@ -104,9 +122,24 @@ export async function validateGossipFuluDataColumnSidecar(
});
}

// getBlockSlotState also checks for whether the current finalized checkpoint is an ancestor of the block.
// As a result, we throw an IGNORE (whereas the spec says we should REJECT for this scenario).
// this is something we should change this in the future to make the code airtight to the spec.
// 9) [REJECT] The current finalized_checkpoint is an ancestor of the sidecar's block
// -- i.e. get_checkpoint_block(store, block_header.parent_root, store.finalized_checkpoint.epoch)
// == store.finalized_checkpoint.root
const finalizedAncestorSlot = computeStartSlotAtEpoch(finalizedCheckpoint.epoch);
let ancestorRoot: RootHex | undefined;
try {
ancestorRoot = chain.forkChoice.getAncestor(parentRoot, finalizedAncestorSlot).blockRoot;
} catch {
// parent not in fork-choice or finalized slot before parent's chain start
}
Comment on lines +130 to +135

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If parentBlock.slot is less than or equal to finalizedAncestorSlot (which can happen when there are skipped slots or when the parent block is before the finalized slot), calling chain.forkChoice.getAncestor with a slot higher than the block's slot will throw an error. This causes ancestorRoot to remain undefined, leading to an incorrect FINALIZED_NOT_ANCESTOR rejection for a valid sidecar.

According to the consensus spec's get_ancestor logic, if the block's slot is less than or equal to the requested ancestor slot, the ancestor is the block itself (parentRoot). We should handle this case explicitly to avoid throwing an error and incorrectly rejecting valid gossip messages.

  let ancestorRoot: RootHex | undefined;
  if (parentBlock.slot <= finalizedAncestorSlot) {
    ancestorRoot = parentRoot;
  } else {
    try {
      ancestorRoot = chain.forkChoice.getAncestor(parentRoot, finalizedAncestorSlot).blockRoot;
    } catch {
      // parent not in fork-choice or finalized slot before parent's chain start
    }
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the careful read, but I think the premise here is incorrect.

getAncestor in packages/fork-choice/src/protoArray/protoArray.ts:1523-1541 follows the consensus-specs get_ancestor algorithm:

if (block.slot <= ancestorSlot) {
  return block;
}

It only throws in two cases:

  1. MISSING_PROTO_ARRAY_BLOCK if blockRoot isn't in the proto-array. We already confirmed parentBlock exists via chain.forkChoice.getBlockHexDefaultStatus(parentRoot) just above (line 79-96), so this can't fire.
  2. UNKNOWN_ANCESTOR if walking up hits a missing parent — but that requires block.slot > ancestorSlot, i.e. it's not the boundary case being described.

For parentBlock.slot <= finalizedAncestorSlot, getAncestor returns parentBlock directly, so ancestorRoot = parentRoot. The subsequent ancestorRoot !== finalizedCheckpoint.rootHex check then resolves correctly:

  • Skipped slots at the checkpoint boundary (finalized root anchored at slot < finalizedAncestorSlot, parentRoot equals that root): ancestorRoot = parentRoot = finalizedRoot → PASS ✅
  • Parent on a different fork at/before the finalized slot: ancestorRoot = parentRoot ≠ finalizedRoot → REJECT ✅ (correct rejection — that parent isn't on the finalized fork)

This pattern directly mirrors blobSidecar.ts:144-159, which has been live for some time without producing false rejections. The proposed fix is functionally equivalent (it just inlines the early-return that getAncestor already does internally).

Spec reference: https://github.com/ethereum/consensus-specs/blob/dev/specs/phase0/fork-choice.md#get_ancestor

No change needed here.

if (ancestorRoot !== finalizedCheckpoint.rootHex) {
throw new DataColumnSidecarGossipError(GossipAction.REJECT, {
code: DataColumnSidecarErrorCode.FINALIZED_NOT_ANCESTOR,
parentRoot,
finalizedRoot: finalizedCheckpoint.rootHex,
});
}

// 7) [REJECT] The sidecar's block's parent passes validation.
const blockState = await chain.regen
.getBlockSlotState(parentBlock, blockHeader.slot, {dontTransferCache: true}, RegenCaller.validateGossipDataColumn)
Expand Down Expand Up @@ -160,11 +193,6 @@ export async function validateGossipFuluDataColumnSidecar(
chain.seenBlockInputCache.markVerifiedProposerSignature(blockHeader.slot, blockRootHex, signature);
}

// 9) [REJECT] The current finalized_checkpoint is an ancestor of the sidecar's block
// -- i.e. get_checkpoint_block(store, block_header.parent_root, store.finalized_checkpoint.epoch)
// == store.finalized_checkpoint.root
// Handled by 7)

// 10) [REJECT] The sidecar's kzg_commitments field inclusion proof is valid as verified by
// verify_data_column_sidecar_inclusion_proof
// TODO: Can cache result on (commitments, proof, header) in the future
Expand Down Expand Up @@ -200,9 +228,7 @@ export async function validateGossipFuluDataColumnSidecar(
kzgProofTimer?.();
}

// 12) [IGNORE] The sidecar is the first sidecar for the tuple (block_header.slot, block_header.proposer_index,
// sidecar.index) with valid header signature, sidecar inclusion proof, and kzg proof
// -- Handled in seenGossipBlockInput
chain.seenBlockInputCache.markSeenDataColumnSidecar(blockHeader.slot, proposerIndex, dataColumnSidecar.index);
}

// SPEC FUNCTION
Expand Down
14 changes: 10 additions & 4 deletions packages/beacon-node/test/spec/presets/networking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {bigIntToBytes, loadYaml} from "@lodestar/utils";
import {computeColumnsForCustodyGroup, getCustodyGroups} from "../../../src/util/dataColumns.js";
import {ethereumConsensusSpecsTests} from "../specTestVersioning.js";
import {isGossipValidationHandler, runGossipValidationTest} from "../utils/gossipValidation.js";
import {readdirSyncSpec, specTestIterator} from "../utils/specTestIterator.js";
import {defaultSkipOpts, readdirSyncSpec, specTestIterator} from "../utils/specTestIterator.js";
import {RunnerType, TestRunnerCustom} from "../utils/types.js";

type ComputeColumnForCustodyGroupInput = {
Expand Down Expand Up @@ -74,6 +74,12 @@ const networking: TestRunnerCustom = (fork, testHandler, testSuite, testSuiteDir
}
};

specTestIterator(path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET), {
networking: {type: RunnerType.custom, fn: networking},
});
specTestIterator(
path.join(ethereumConsensusSpecsTests.outputDir, "tests", ACTIVE_PRESET),
{networking: {type: RunnerType.custom, fn: networking}},
{
...defaultSkipOpts,
// gossip_partial_data_column_sidecar requires cell-level DAS support not yet in Lodestar
skippedHandlers: ["gossip_partial_data_column_sidecar"],
}
);
14 changes: 14 additions & 0 deletions packages/beacon-node/test/spec/utils/gossipValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {validateGossipAttesterSlashing} from "../../../src/chain/validation/atte
import {validateGossipBlobSidecar} from "../../../src/chain/validation/blobSidecar.js";
import {validateGossipBlock} from "../../../src/chain/validation/block.js";
import {validateGossipBlsToExecutionChange} from "../../../src/chain/validation/blsToExecutionChange.js";
import {validateGossipFuluDataColumnSidecar} from "../../../src/chain/validation/dataColumnSidecar.js";
import {validateGossipProposerSlashing} from "../../../src/chain/validation/proposerSlashing.js";
import {validateGossipSyncCommittee} from "../../../src/chain/validation/syncCommittee.js";
import {validateSyncCommitteeGossipContributionAndProof} from "../../../src/chain/validation/syncCommitteeContributionAndProof.js";
Expand Down Expand Up @@ -162,6 +163,7 @@ const gossipTopicByHandler = {
gossip_sync_committee_contribution_and_proof: GossipType.sync_committee_contribution_and_proof,
gossip_bls_to_execution_change: GossipType.bls_to_execution_change,
gossip_blob_sidecar: GossipType.blob_sidecar,
gossip_data_column_sidecar: GossipType.data_column_sidecar,
} as const satisfies Record<string, GossipType>;

export function isGossipValidationHandler(topicHandler: string): topicHandler is keyof typeof gossipTopicByHandler {
Expand Down Expand Up @@ -741,6 +743,18 @@ async function validateMessageForTopic(
break;
}

case GossipType.data_column_sidecar: {
const dataColumnSidecar = rejectOnInvalidSerializedBytes(() => ssz.fulu.DataColumnSidecar.deserialize(bytes));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the fork SSZ type for data-column gossip tests

When these networking tests run for gloas/gossip_data_column_sidecar, this always deserializes the message as the Fulu container, which still expects signedBlockHeader, kzgCommitments, and an inclusion proof. Gloas data-column sidecars instead contain slot and beaconBlockRoot, so valid Gloas fixtures will be mapped to SPEC_INVALID_SERIALIZED_BYTES and rejected before the Gloas validation path can be exercised; the harness should deserialize with sszTypesFor(fork).DataColumnSidecar and dispatch to the appropriate validator.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that the Gloas DataColumnSidecar differs from Fulu — packages/types/src/gloas/sszTypes.ts:301-313 drops signedBlockHeader / kzgCommitments / kzgCommitmentsInclusionProof and adds slot + beaconBlockRoot. Deserializing Gloas bytes through the Fulu container would indeed reject as SPEC_INVALID_SERIALIZED_BYTES.

Scope-deferring this for two reasons:

  1. No Gloas DCS gossip fixtures yet. Both consensus-specs PRs (Track sync committee metrics #5146, Add LC header validations #5246) and the current test corpus only include gossip_data_column_sidecar under Fulu:

    packages/beacon-node/spec-tests/tests/{minimal,mainnet}/fulu/networking/gossip_data_column_sidecar
    

    The Gloas networking/ folder only has slashings, BLS-to-execution, sync committee — no DCS fixtures. Adding the dispatch now would be untested code that the runner never reaches.

  2. Different validator signature. validateGossipGloasDataColumnSidecar(chain, payloadInput, sidecar, …) takes a PayloadEnvelopeInput, which isn't present in the standalone-DCS gossip fixture format. Once upstream defines the Gloas DCS fixture layout (likely coupled with the gossip_execution_payload_envelope flow), the harness can construct the right input shape and dispatch via sszTypesFor(fork).DataColumnSidecar.

Tracking as a follow-up — I'll wire the per-fork dispatch when Gloas DCS gossip fixtures land in consensus-specs.

const parentRootHex = toRootHex(dataColumnSidecar.signedBlockHeader.message.parentRoot);

if (rejectedFailedBlockRoots.has(parentRootHex)) {
throw new GossipActionError(GossipAction.REJECT, {code: "SPEC_PARENT_BLOCK_FAILED"});
}

await validateGossipFuluDataColumnSidecar(chain, dataColumnSidecar, Number(message.subnet_id ?? 0), null);
break;
}

default:
throw new Error(`Unknown gossip topic: ${topic}`);
}
Expand Down