Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for wtns calc and prover options #517

Merged
merged 12 commits into from
Oct 18, 2024
33 changes: 18 additions & 15 deletions build/browser.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3394,11 +3394,13 @@ async function builder(code, options) {
// If we can't look up the patch version, assume the lowest
let patchVersion = 0;

let codeIsWebAssemblyInstance = false;

// If code is already prepared WebAssembly.Instance, we use it directly
if (code instanceof WebAssembly.Instance) {
instance = code;
codeIsWebAssemblyInstance = true;
} else {

let memorySize = 32767;

if (options.memorySize) {
Expand Down Expand Up @@ -3558,9 +3560,13 @@ async function builder(code, options) {
// We explicitly check for major version 2 in case there's a circom v3 in the future
if (majorVersion === 2) {
wc = new WitnessCalculatorCircom2(instance, sanityCheck);
} else {
// TODO: Maybe we want to check for the explicit version 1 before choosing this?
} else if (majorVersion === 1) {
if (codeIsWebAssemblyInstance) {
throw new Error('Loading code from WebAssembly instance is not supported for circom version 1');
}
wc = new WitnessCalculatorCircom1(memory, instance, sanityCheck);
} else {
throw new Error(`Unsupported circom version: ${majorVersion}`);
}
return wc;

Expand Down Expand Up @@ -3938,7 +3944,7 @@ async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) {
await fdWasm.close();

const wc = await builder(wasm, options);
if (wc.circom_version() == 1) {
if (wc.circom_version() === 1) {
const w = await wc.calculateBinWitness(input);

const fdWtns = await createBinFile(wtnsFileName, "wtns", 2, 2);
Expand Down Expand Up @@ -3975,13 +3981,13 @@ async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) {
*/
const {unstringifyBigInts: unstringifyBigInts$a} = utils;

async function groth16FullProve(_input, wasmFile, zkeyFileName, logger) {
async function groth16FullProve(_input, wasmFile, zkeyFileName, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$a(_input);

const wtns= {
type: "mem"
};
await wtnsCalculate(input, wasmFile, wtns);
await wtnsCalculate(input, wasmFile, wtns, wtnsCalcOptions);
return await groth16Prove(zkeyFileName, wtns, logger);
}

Expand Down Expand Up @@ -7043,10 +7049,7 @@ async function wtnsDebug(_input, wasmFileName, wtnsFileName, symName, options, l
const wasm = await fdWasm.read(fdWasm.totalSize);
await fdWasm.close();


let wcOps = {
sanityCheck: true
};
const wcOps = {...options, sanityCheck: true};
let sym = await loadSymbols(symName);
if (options.set) {
if (!sym) sym = await loadSymbols(symName);
Expand Down Expand Up @@ -7074,7 +7077,7 @@ async function wtnsDebug(_input, wasmFileName, wtnsFileName, symName, options, l
wcOps.sym = sym;

const wc = await builder(wasm, wcOps);
const w = await wc.calculateWitness(input);
const w = await wc.calculateWitness(input, true);

const fdWtns = await createBinFile(wtnsFileName, "wtns", 2, 2);

Expand Down Expand Up @@ -12801,13 +12804,13 @@ async function plonk16Prove(zkeyFileName, witnessFileName, logger) {
*/
const {unstringifyBigInts: unstringifyBigInts$5} = utils;

async function plonkFullProve(_input, wasmFile, zkeyFileName, logger) {
async function plonkFullProve(_input, wasmFile, zkeyFileName, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$5(_input);

const wtns= {
type: "mem"
};
await wtnsCalculate(input, wasmFile, wtns);
await wtnsCalculate(input, wasmFile, wtns, wtnsCalcOptions);
return await plonk16Prove(zkeyFileName, wtns, logger);
}

Expand Down Expand Up @@ -15392,13 +15395,13 @@ async function fflonkProve(zkeyFileName, witnessFileName, logger) {
*/
const {unstringifyBigInts: unstringifyBigInts$2} = utils;

async function fflonkFullProve(_input, wasmFilename, zkeyFilename, logger) {
async function fflonkFullProve(_input, wasmFilename, zkeyFilename, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$2(_input);

const wtns= {type: "mem"};

// Compute the witness
await wtnsCalculate(input, wasmFilename, wtns);
await wtnsCalculate(input, wasmFilename, wtns, wtnsCalcOptions);

// Compute the proof
return await fflonkProve(zkeyFilename, wtns, logger);
Expand Down
21 changes: 9 additions & 12 deletions build/cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6072,7 +6072,7 @@ async function wtnsCalculate$1(_input, wasmFileName, wtnsFileName, options) {
await fdWasm.close();

const wc = await circom_runtime.WitnessCalculatorBuilder(wasm, options);
if (wc.circom_version() == 1) {
if (wc.circom_version() === 1) {
const w = await wc.calculateBinWitness(input);

const fdWtns = await binFileUtils__namespace.createBinFile(wtnsFileName, "wtns", 2, 2);
Expand Down Expand Up @@ -6109,13 +6109,13 @@ async function wtnsCalculate$1(_input, wasmFileName, wtnsFileName, options) {
*/
const {unstringifyBigInts: unstringifyBigInts$9} = ffjavascript.utils;

async function groth16FullProve$1(_input, wasmFile, zkeyFileName, logger) {
async function groth16FullProve$1(_input, wasmFile, zkeyFileName, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$9(_input);

const wtns= {
type: "mem"
};
await wtnsCalculate$1(input, wasmFile, wtns);
await wtnsCalculate$1(input, wasmFile, wtns, wtnsCalcOptions);
return await groth16Prove$1(zkeyFileName, wtns, logger);
}

Expand Down Expand Up @@ -9004,13 +9004,13 @@ async function plonk16Prove(zkeyFileName, witnessFileName, logger) {
*/
const {unstringifyBigInts: unstringifyBigInts$6} = ffjavascript.utils;

async function plonkFullProve$1(_input, wasmFile, zkeyFileName, logger) {
async function plonkFullProve$1(_input, wasmFile, zkeyFileName, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$6(_input);

const wtns= {
type: "mem"
};
await wtnsCalculate$1(input, wasmFile, wtns);
await wtnsCalculate$1(input, wasmFile, wtns, wtnsCalcOptions);
return await plonk16Prove(zkeyFileName, wtns, logger);
}

Expand Down Expand Up @@ -11569,13 +11569,13 @@ async function fflonkProve$1(zkeyFileName, witnessFileName, logger) {
*/
const {unstringifyBigInts: unstringifyBigInts$3} = ffjavascript.utils;

async function fflonkFullProve$1(_input, wasmFilename, zkeyFilename, logger) {
async function fflonkFullProve$1(_input, wasmFilename, zkeyFilename, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$3(_input);

const wtns= {type: "mem"};

// Compute the witness
await wtnsCalculate$1(input, wasmFilename, wtns);
await wtnsCalculate$1(input, wasmFilename, wtns, wtnsCalcOptions);

// Compute the proof
return await fflonkProve$1(zkeyFilename, wtns, logger);
Expand Down Expand Up @@ -12257,10 +12257,7 @@ async function wtnsDebug$1(_input, wasmFileName, wtnsFileName, symName, options,
const wasm = await fdWasm.read(fdWasm.totalSize);
await fdWasm.close();


let wcOps = {
sanityCheck: true
};
const wcOps = {...options, sanityCheck: true};
let sym = await loadSymbols(symName);
if (options.set) {
if (!sym) sym = await loadSymbols(symName);
Expand Down Expand Up @@ -12288,7 +12285,7 @@ async function wtnsDebug$1(_input, wasmFileName, wtnsFileName, symName, options,
wcOps.sym = sym;

const wc = await circom_runtime.WitnessCalculatorBuilder(wasm, wcOps);
const w = await wc.calculateWitness(input);
const w = await wc.calculateWitness(input, true);

const fdWtns = await binFileUtils__namespace.createBinFile(wtnsFileName, "wtns", 2, 2);

Expand Down
21 changes: 9 additions & 12 deletions build/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) {
await fdWasm.close();

const wc = await circom_runtime.WitnessCalculatorBuilder(wasm, options);
if (wc.circom_version() == 1) {
if (wc.circom_version() === 1) {
const w = await wc.calculateBinWitness(input);

const fdWtns = await binFileUtils__namespace.createBinFile(wtnsFileName, "wtns", 2, 2);
Expand Down Expand Up @@ -1299,13 +1299,13 @@ async function wtnsCalculate(_input, wasmFileName, wtnsFileName, options) {
*/
const {unstringifyBigInts: unstringifyBigInts$a} = ffjavascript.utils;

async function groth16FullProve(_input, wasmFile, zkeyFileName, logger) {
async function groth16FullProve(_input, wasmFile, zkeyFileName, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$a(_input);

const wtns= {
type: "mem"
};
await wtnsCalculate(input, wasmFile, wtns);
await wtnsCalculate(input, wasmFile, wtns, wtnsCalcOptions);
return await groth16Prove(zkeyFileName, wtns, logger);
}

Expand Down Expand Up @@ -4017,10 +4017,7 @@ async function wtnsDebug(_input, wasmFileName, wtnsFileName, symName, options, l
const wasm = await fdWasm.read(fdWasm.totalSize);
await fdWasm.close();


let wcOps = {
sanityCheck: true
};
const wcOps = {...options, sanityCheck: true};
let sym = await loadSymbols(symName);
if (options.set) {
if (!sym) sym = await loadSymbols(symName);
Expand Down Expand Up @@ -4048,7 +4045,7 @@ async function wtnsDebug(_input, wasmFileName, wtnsFileName, symName, options, l
wcOps.sym = sym;

const wc = await circom_runtime.WitnessCalculatorBuilder(wasm, wcOps);
const w = await wc.calculateWitness(input);
const w = await wc.calculateWitness(input, true);

const fdWtns = await binFileUtils__namespace.createBinFile(wtnsFileName, "wtns", 2, 2);

Expand Down Expand Up @@ -9114,13 +9111,13 @@ async function plonk16Prove(zkeyFileName, witnessFileName, logger) {
*/
const {unstringifyBigInts: unstringifyBigInts$5} = ffjavascript.utils;

async function plonkFullProve(_input, wasmFile, zkeyFileName, logger) {
async function plonkFullProve(_input, wasmFile, zkeyFileName, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$5(_input);

const wtns= {
type: "mem"
};
await wtnsCalculate(input, wasmFile, wtns);
await wtnsCalculate(input, wasmFile, wtns, wtnsCalcOptions);
return await plonk16Prove(zkeyFileName, wtns, logger);
}

Expand Down Expand Up @@ -11707,13 +11704,13 @@ async function fflonkProve(zkeyFileName, witnessFileName, logger) {
*/
const {unstringifyBigInts: unstringifyBigInts$2} = ffjavascript.utils;

async function fflonkFullProve(_input, wasmFilename, zkeyFilename, logger) {
async function fflonkFullProve(_input, wasmFilename, zkeyFilename, logger, wtnsCalcOptions) {
const input = unstringifyBigInts$2(_input);

const wtns= {type: "mem"};

// Compute the witness
await wtnsCalculate(input, wasmFilename, wtns);
await wtnsCalculate(input, wasmFilename, wtns, wtnsCalcOptions);

// Compute the proof
return await fflonkProve(zkeyFilename, wtns, logger);
Expand Down
35 changes: 19 additions & 16 deletions build/snarkjs.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/snarkjs.min.js

Large diffs are not rendered by default.

33 changes: 19 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@iden3/binfileutils": "0.0.12",
"bfj": "^7.0.2",
"blake2b-wasm": "^2.4.0",
"circom_runtime": "0.1.25",
"circom_runtime": "0.1.26",
"ejs": "^3.1.6",
"fastfile": "0.0.20",
"ffjavascript": "0.3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/fflonk_full_prove.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import wtns_calculate from "./wtns_calculate.js";
import {utils} from "ffjavascript";
const {unstringifyBigInts} = utils;

export default async function fflonkFullProve(_input, wasmFilename, zkeyFilename, logger) {
export default async function fflonkFullProve(_input, wasmFilename, zkeyFilename, logger, wtnsCalcOptions) {
const input = unstringifyBigInts(_input);

const wtns= {type: "mem"};

// Compute the witness
await wtns_calculate(input, wasmFilename, wtns);
await wtns_calculate(input, wasmFilename, wtns, wtnsCalcOptions);

// Compute the proof
return await fflonkProve(zkeyFilename, wtns, logger);
Expand Down
4 changes: 2 additions & 2 deletions src/groth16_fullprove.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import wtns_calculate from "./wtns_calculate.js";
import {utils} from "ffjavascript";
const {unstringifyBigInts} = utils;

export default async function groth16FullProve(_input, wasmFile, zkeyFileName, logger) {
export default async function groth16FullProve(_input, wasmFile, zkeyFileName, logger, wtnsCalcOptions) {
const input = unstringifyBigInts(_input);

const wtns= {
type: "mem"
};
await wtns_calculate(input, wasmFile, wtns);
await wtns_calculate(input, wasmFile, wtns, wtnsCalcOptions);
return await groth16_prove(zkeyFileName, wtns, logger);
}
Loading
Loading