Skip to content
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

feat: add blob sidecar index check #7313

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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) {
Copy link
Member

Choose a reason for hiding this comment

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

just noticed the check is incorrect, this should be

blobSidecar.index >= chain.config.MAX_BLOBS_PER_BLOCK

Copy link
Contributor Author

@ensi321 ensi321 Dec 19, 2024

Choose a reason for hiding this comment

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

Oops gonna open another PR

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
Loading