Verify blobs count matches commitments count (#113)
This commit is contained in:
parent
97c46a8532
commit
c6fa137cd4
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue