Skip to content

Commit

Permalink
feat: add blob sidecar index check (#7313)
Browse files Browse the repository at this point in the history
Validate blobSidecar index
  • Loading branch information
ensi321 authored Dec 19, 2024
1 parent 7cd296b commit bfe54d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/beacon-node/src/chain/errors/blobSidecarError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {RootHex, Slot, ValidatorIndex} from "@lodestar/types";
import {GossipActionError} from "./gossipValidation.js";

export enum BlobSidecarErrorCode {
INDEX_TOO_LARGE = "BLOB_SIDECAR_ERROR_INDEX_TOO_LARGE",
INVALID_INDEX = "BLOB_SIDECAR_ERROR_INVALID_INDEX",
/** !bls.KeyValidate(block.body.blob_kzg_commitments[i]) */
INVALID_KZG = "BLOB_SIDECAR_ERROR_INVALID_KZG",
Expand All @@ -26,6 +27,7 @@ export enum BlobSidecarErrorCode {
}

export type BlobSidecarErrorType =
| {code: BlobSidecarErrorCode.INDEX_TOO_LARGE; blobIdx: number; maxBlobsPerBlock: number}
| {code: BlobSidecarErrorCode.INVALID_INDEX; blobIdx: number; subnet: number}
| {code: BlobSidecarErrorCode.INVALID_KZG; blobIdx: number}
| {code: BlobSidecarErrorCode.INVALID_KZG_TXS}
Expand Down
9 changes: 9 additions & 0 deletions packages/beacon-node/src/chain/validation/blobSidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export async function validateGossipBlobSidecar(
): Promise<void> {
const blobSlot = blobSidecar.signedBlockHeader.message.slot;

// [REJECT] The sidecar's index is consistent with `MAX_BLOBS_PER_BLOCK` -- i.e. `blob_sidecar.index < MAX_BLOBS_PER_BLOCK`.
if (blobSidecar.index < chain.config.MAX_BLOBS_PER_BLOCK) {
throw new BlobSidecarGossipError(GossipAction.REJECT, {
code: BlobSidecarErrorCode.INDEX_TOO_LARGE,
blobIdx: blobSidecar.index,
maxBlobsPerBlock: chain.config.MAX_BLOBS_PER_BLOCK,
});
}

// [REJECT] The sidecar is for the correct subnet -- i.e. `compute_subnet_for_blob_sidecar(sidecar.index) == subnet_id`.
if (computeSubnetForBlobSidecar(blobSidecar.index, chain.config) !== subnet) {
throw new BlobSidecarGossipError(GossipAction.REJECT, {
Expand Down

0 comments on commit bfe54d2

Please sign in to comment.