Skip to content

Commit

Permalink
Merge branch 'unstable' into devnet-5
Browse files Browse the repository at this point in the history
  • Loading branch information
nflaig committed Dec 19, 2024
2 parents cd7b1b4 + 8c7eaf8 commit 06ec5f6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {ZERO_HASH, ZERO_HASH_HEX} from "../../constants/index.js";
import {IEth1ForBlockProduction} from "../../eth1/index.js";
import {numToQuantity} from "../../eth1/provider/utils.js";
import {IExecutionBuilder, IExecutionEngine, PayloadAttributes, PayloadId} from "../../execution/index.js";
import {fromGraffitiBuffer} from "../../util/graffiti.js";
import type {BeaconChain} from "../chain.js";
import {CommonBlockBody} from "../interface.js";
import {validateBlobsAndKzgCommitments} from "./validateBlobsAndKzgCommitments.js";
Expand Down Expand Up @@ -154,7 +155,7 @@ export async function produceBlockBody<T extends BlockType>(
} = blockBody;

Object.assign(logMeta, {
graffiti,
graffiti: fromGraffitiBuffer(graffiti),
attestations: attestations.length,
deposits: deposits.length,
voluntaryExits: voluntaryExits.length,
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
7 changes: 7 additions & 0 deletions packages/beacon-node/src/util/graffiti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export function toGraffitiBuffer(graffiti: string): Buffer {
return Buffer.concat([Buffer.from(graffiti, "utf8"), Buffer.alloc(GRAFFITI_SIZE, 0)], GRAFFITI_SIZE);
}

/**
* Converts a graffiti from 32 bytes buffer back to a UTF-8 string
*/
export function fromGraffitiBuffer(graffiti: Uint8Array): string {
return Buffer.from(graffiti.buffer, graffiti.byteOffset, graffiti.byteLength).toString("utf8");
}

export function getDefaultGraffiti(
consensusClientVersion: ClientVersion,
executionClientVersion: ClientVersion | null | undefined,
Expand Down

0 comments on commit 06ec5f6

Please sign in to comment.