Skip to content

Support for wtns calc and prover options #517

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

Merged
merged 12 commits into from
Oct 18, 2024
272 changes: 185 additions & 87 deletions browser_tests/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion browser_tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"test": "node test/launch-groth16.js"
},
"devDependencies": {
"puppeteer": "22.15.0",
"puppeteer": "^23.5.3",
"ffjavascript": "^0.3.0",
"st": "3.0.0"
}
Expand Down
7 changes: 5 additions & 2 deletions browser_tests/test/launch-groth16.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ const server = http
.listen(1337);

const browser = await puppeteer.launch({
headless: "new",
headless: true,
args: [
// Necessary to have WebCrypto on localhost
"--allow-insecure-localhost",
// Necessary to download the PTAU file from AWS within the tests
"--disable-web-security"
"--disable-web-security",
// Disable the sandbox to run in GHA
"--no-sandbox",

],
});
const page = await browser.newPage();
Expand Down
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
Loading
Loading