From bfe54d25def3e72705c6fa027549878d7e69f996 Mon Sep 17 00:00:00 2001 From: NC <17676176+ensi321@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:45:51 -0800 Subject: [PATCH] feat: add blob sidecar index check (#7313) Validate blobSidecar index --- .../beacon-node/src/chain/errors/blobSidecarError.ts | 2 ++ packages/beacon-node/src/chain/validation/blobSidecar.ts | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/packages/beacon-node/src/chain/errors/blobSidecarError.ts b/packages/beacon-node/src/chain/errors/blobSidecarError.ts index 71118d8b8f9..216ad9206db 100644 --- a/packages/beacon-node/src/chain/errors/blobSidecarError.ts +++ b/packages/beacon-node/src/chain/errors/blobSidecarError.ts @@ -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", @@ -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} diff --git a/packages/beacon-node/src/chain/validation/blobSidecar.ts b/packages/beacon-node/src/chain/validation/blobSidecar.ts index e2f4ed267d0..4aeff0f23ff 100644 --- a/packages/beacon-node/src/chain/validation/blobSidecar.ts +++ b/packages/beacon-node/src/chain/validation/blobSidecar.ts @@ -18,6 +18,15 @@ export async function validateGossipBlobSidecar( ): Promise { 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, {