Skip to content

Commit

Permalink
Better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
dgcoffman committed Nov 17, 2022
1 parent 337164e commit 1bd9bb8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
21 changes: 4 additions & 17 deletions packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,20 @@ export async function produceBlockBody<T extends BlockType>(
if (forkSeq >= ForkSeq.capella) {
// TODO EIP-4844 Remove this when the EC includes `withdrawals`
if ((blockBody as capella.BeaconBlockBody).executionPayload.withdrawals === undefined) {
console.log(
"In Capella, but the EC returns an execution payload without withdrawals, assigning empty array"
this.logger?.warn(
"In Capella, but the EC returned an execution payload without withdrawals, assigning empty array"
);

(blockBody as capella.BeaconBlockBody).executionPayload.withdrawals = [];
}
}

if (forkSeq >= ForkSeq.eip4844) {
// TODO EIP-4844 Remove this when the EC includes `withdrawals`
// if (payload === undefined) {
// (blockBody as capella.BeaconBlockBody).executionPayload.withdrawals = [];
// }

const blobsBundle = await this.executionEngine.getBlobsBundle(payloadId);

console.log("Got blobs bundle from EL", blobsBundle);

validateBlobsAndKzgCommitments(
payload as eip4844.ExecutionPayload,
blobsBundle.blobs ?? [],
blobsBundle.kzgs ?? []
);

console.log("validateBlobsAndKzgCommitments thinks this is valid!");
validateBlobsAndKzgCommitments(payload as eip4844.ExecutionPayload, blobsBundle.blobs, blobsBundle.kzgs);

(blockBody as eip4844.BeaconBlockBody).blobKzgCommitments = blobsBundle.kzgs ?? [];
(blockBody as eip4844.BeaconBlockBody).blobKzgCommitments = blobsBundle.kzgs;
blobs = blobsBundle.blobs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,17 @@ export function validateBlobsAndKzgCommitments(
`Error validating execution payload during block construction: Blobs length of ${blobs.length} did not match KZG commitments lenght of ${blobKzgCommitments.length}`
);
}
console.log("validateBlobsAndKzgCommitments: lengths match");

// assert [blob_to_kzg_commitment(blob) == commitment for blob, commitment in zip(blobs, blob_kzg_commitments)]
blobs.forEach((blob, index) => {
try {
const computedCommitment = blobToKzgCommitment(blob);
if (computedCommitment !== blobKzgCommitments[index]) {
throw new Error(
`Error validating execution payload during block construction: KZG commitment supplied by execution client does not match that computed by Lodestar, at index ${index}`
);
} else {
console.log(
`validateBlobsAndKzgCommitments: blob at index ${index} has a matching commitment.`,
computedCommitment,
blobKzgCommitments[index]
);
}
} catch (e) {
console.log("validateBlobsAndKzgCommitments error in blobToKzgCommitment", e);
console.log(typeof blob, blob);
const computedCommitment = blobToKzgCommitment(blob);
if (computedCommitment !== blobKzgCommitments[index]) {
throw new Error(
`Error validating execution payload during block construction: KZG commitment supplied by execution client does not match that computed by Lodestar. At index ${index}. Computed: ${computedCommitment} but blobs bundle contained ${blobKzgCommitments[index]}`
);
}
});

console.log("validateBlobsAndKzgCommitments: KZG commitments match");

// assert verify_kzg_commitments_against_transactions(execution_payload.transactions, blob_kzg_commitments)
if (!verifyKzgCommitmentsAgainstTransactions(executionPayload.transactions, blobKzgCommitments)) {
throw new Error(
Expand Down

0 comments on commit 1bd9bb8

Please sign in to comment.