Verify blobs count matches commitments count (#113)

This commit is contained in:
Daniel Coffman 2023-02-01 12:56:03 -08:00 committed by GitHub
parent 97c46a8532
commit c6fa137cd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -245,6 +245,13 @@ Napi::Value VerifyAggregateKzgProof(const Napi::CallbackInfo& info) {
auto proof_bytes = proof_param.As<Napi::Uint8Array>().Data();
auto blobs_count = blobs_param.Length();
auto commitments_count = commitments_param.Length();
if (blobs_count != commitments_count) {
Napi::Error::New(env, "verifyAggregateKzgProof requires blobs count to match expectedKzgCommitments count")
.ThrowAsJavaScriptException();
return env.Undefined();
}
auto blobs = (Blob*)calloc(blobs_count, sizeof(Blob));
if (blobs == NULL) {

View File

@ -116,6 +116,17 @@ describe("C-KZG", () => {
).toThrowError("verify_aggregate_kzg_proof failed with error code: 1");
});
it("throws the expected error when given fewer commitments than blobs", () => {
let blobs = new Array(1).fill(0).map(generateRandomBlob);
let commitments = [] as Uint8Array[];
let proof = computeAggregateKzgProof(blobs);
expect(() =>
verifyAggregateKzgProof(blobs, commitments, proof),
).toThrowError(
"verifyAggregateKzgProof requires blobs count to match expectedKzgCommitments count",
);
});
describe("computing commitment from blobs", () => {
it("throws as expected when given an argument of invalid type", () => {
// @ts-expect-error