Skip to content

Commit

Permalink
added curve termination to generateProof
Browse files Browse the repository at this point in the history
  • Loading branch information
mllwchrry committed Oct 29, 2024
1 parent 0ff40d7 commit e9c053c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/core/protocols/Groth16Implementer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { terminateCurve } from "../../utils";

export class Groth16Implementer extends AbstractProtocolImplementer<"groth16"> {
public async generateProof(inputs: Signals, zKeyFilePath: string, wasmFilePath: string): Promise<Groth16ProofStruct> {
return (await snarkjs.groth16.fullProve(inputs, wasmFilePath, zKeyFilePath)) as Groth16ProofStruct;
const fullProof = await snarkjs.groth16.fullProve(inputs, wasmFilePath, zKeyFilePath);

await terminateCurve();

return fullProof;
}

public async verifyProof(proof: Groth16ProofStruct, vKeyFilePath: string): Promise<boolean> {
Expand Down
6 changes: 5 additions & 1 deletion src/core/protocols/PlonkImplementer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { terminateCurve } from "../../utils";

export class PlonkImplementer extends AbstractProtocolImplementer<"plonk"> {
public async generateProof(inputs: Signals, zKeyFilePath: string, wasmFilePath: string): Promise<PlonkProofStruct> {
return (await snarkjs.plonk.fullProve(inputs, wasmFilePath, zKeyFilePath)) as PlonkProofStruct;
const fullProof = await snarkjs.plonk.fullProve(inputs, wasmFilePath, zKeyFilePath);

await terminateCurve();

return fullProof as PlonkProofStruct;
}

public async verifyProof(proof: PlonkProofStruct, vKeyFilePath: string): Promise<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import * as snarkjs from "snarkjs";
import { BN128_CURVE_NAME } from "./constants";

export async function terminateCurve() {
(await (snarkjs as any).curves.getCurveFromName(BN128_CURVE_NAME)).terminate();
await (await (snarkjs as any).curves.getCurveFromName(BN128_CURVE_NAME)).terminate();
}

0 comments on commit e9c053c

Please sign in to comment.