Skip to content

Commit

Permalink
perf(proof): use cached curve rather than a new one
Browse files Browse the repository at this point in the history
  • Loading branch information
cedoor committed Oct 12, 2023
1 parent 36958e0 commit 60dc748
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/proof/src/groth16/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default async function groth16Verify(_vk_verifier: any, _publicSignals: a
const proof = unstringifyBigInts(_proof)
const publicSignals = unstringifyBigInts(_publicSignals)

const curve = await buildBn128(undefined, undefined)
// @ts-ignore
const curve = globalThis.curve_bn128 ?? (await buildBn128(undefined, undefined))

const IC0 = curve.G1.fromObject(vk_verifier.IC[0])
const IC = new Uint8Array(curve.G1.F.n8 * 2 * publicSignals.length)
Expand Down
5 changes: 4 additions & 1 deletion packages/proof/src/groth16/zkey-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ async function readHeaderGroth16(fd: any, sections: any, toObject: any) {
const n8r = await fd.readULE32()
zkey.n8r = n8r
zkey.r = await binFileUtils.readBigInt(fd, n8r)
zkey.curve = await buildBn128(undefined, undefined)

// @ts-ignore
zkey.curve = globalThis.curve_bn128 ?? (await buildBn128(undefined, undefined))

zkey.nVars = await fd.readULE32()
zkey.nPublic = await fd.readULE32()
zkey.domainSize = await fd.readULE32()
Expand Down

0 comments on commit 60dc748

Please sign in to comment.