Actually return the result of verify_kzg_proof
This commit is contained in:
parent
4bfce9ad15
commit
32011119cd
|
@ -315,11 +315,11 @@ Napi::Value VerifyKzgProof(const Napi::CallbackInfo& info) {
|
|||
}
|
||||
|
||||
bool out;
|
||||
if (verify_kzg_proof(&out, &commitment, &fz, &fy, &proof, kzgSettings) == C_KZG_OK) {
|
||||
return Napi::Boolean::New(env, true);
|
||||
if (verify_kzg_proof(&out, &commitment, &fz, &fy, &proof, kzgSettings) != C_KZG_OK) {
|
||||
return Napi::Boolean::New(env, false);
|
||||
}
|
||||
|
||||
return Napi::Boolean::New(env, false);
|
||||
return Napi::Boolean::New(env, out);
|
||||
}
|
||||
|
||||
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
||||
|
|
|
@ -50,6 +50,9 @@ const kzg: KZG = bindings("kzg.node");
|
|||
export const FIELD_ELEMENTS_PER_BLOB = kzg.FIELD_ELEMENTS_PER_BLOB;
|
||||
export const BYTES_PER_FIELD = kzg.BYTES_PER_FIELD;
|
||||
|
||||
const isCommitmentValid = (commitment: KZGCommitment) =>
|
||||
commitment.length === 48;
|
||||
|
||||
// Stored as internal state
|
||||
let setupHandle: SetupHandle | undefined;
|
||||
|
||||
|
@ -96,6 +99,9 @@ export function verifyKzgProof(
|
|||
if (!setupHandle) {
|
||||
throw new Error("You must call loadTrustedSetup to initialize KZG.");
|
||||
}
|
||||
if (!isCommitmentValid(polynomialKzg)) {
|
||||
throw new Error("Invalid polynomialKzg");
|
||||
}
|
||||
return kzg.verifyKzgProof(polynomialKzg, z, y, kzgProof, setupHandle);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@ describe("C-KZG", () => {
|
|||
|
||||
it("verifies a proof at a given commitment point", () => {
|
||||
const blob = generateRandomBlob();
|
||||
const commitment = blobToKzgCommitment(blob);
|
||||
const polynomialCommitment = blobToKzgCommitment(blob);
|
||||
const proof = computeAggregateKzgProof([blob]);
|
||||
|
||||
// It doesn't seem to matter what is passed here...
|
||||
// TODO: How do I test this? How do I get values of z and y?
|
||||
const z = Uint8Array.from(new Array(32).fill(0));
|
||||
const y = Uint8Array.from(new Array(32).fill(0));
|
||||
const y = Uint8Array.from(blob.slice(0, 32));
|
||||
|
||||
expect(verifyKzgProof(commitment, z, y, proof)).toBe(true);
|
||||
expect(verifyKzgProof(polynomialCommitment, z, y, proof)).toBe(true);
|
||||
});
|
||||
|
||||
it("computes the correct commitments and aggregate proofs from blobs", () => {
|
||||
|
|
Loading…
Reference in New Issue