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

bun support for groth16.fullProve: add singleThreaded option #490

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/curves.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export async function getCurveFromR(r) {
return curve;
}

export async function getCurveFromQ(q) {
export async function getCurveFromQ(q, singleThreaded = false) {
let curve;
if (Scalar.eq(q, bn128q)) {
curve = await buildBn128();
curve = await buildBn128(singleThreaded);
} else if (Scalar.eq(q, bls12381q)) {
curve = await buildBls12381();
} else {
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, singleThreaded = false) {
const input = unstringifyBigInts(_input);

const wtns= {
type: "mem"
};
await wtns_calculate(input, wasmFile, wtns);
return await groth16_prove(zkeyFileName, wtns, logger);
return await groth16_prove(zkeyFileName, wtns, logger, singleThreaded);
}
4 changes: 2 additions & 2 deletions src/groth16_prove.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import { log2 } from "./misc.js";
import { Scalar, utils, BigBuffer } from "ffjavascript";
const {stringifyBigInts} = utils;

export default async function groth16Prove(zkeyFileName, witnessFileName, logger) {
export default async function groth16Prove(zkeyFileName, witnessFileName, logger, singleThreaded = false) {
const {fd: fdWtns, sections: sectionsWtns} = await binFileUtils.readBinFile(witnessFileName, "wtns", 2, 1<<25, 1<<23);

const wtns = await wtnsUtils.readHeader(fdWtns, sectionsWtns);

const {fd: fdZKey, sections: sectionsZKey} = await binFileUtils.readBinFile(zkeyFileName, "zkey", 2, 1<<25, 1<<23);

const zkey = await zkeyUtils.readHeader(fdZKey, sectionsZKey);
const zkey = await zkeyUtils.readHeader(fdZKey, sectionsZKey, undefined, singleThreaded);

if (zkey.protocol != "groth16") {
throw new Error("zkey file is not groth16");
Expand Down
8 changes: 4 additions & 4 deletions src/zkey_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ async function readG2(fd, curve, toObject) {
}


export async function readHeader(fd, sections, toObject) {
export async function readHeader(fd, sections, toObject, singleThreaded = false) {
// Read Header
/////////////////////
await binFileUtils.startReadUniqueSection(fd, sections, 1);
const protocolId = await fd.readULE32();
await binFileUtils.endReadSection(fd);

if (protocolId === GROTH16_PROTOCOL_ID) {
return await readHeaderGroth16(fd, sections, toObject);
return await readHeaderGroth16(fd, sections, toObject, singleThreaded);
} else if (protocolId === PLONK_PROTOCOL_ID) {
return await readHeaderPlonk(fd, sections, toObject);
} else if (protocolId === FFLONK_PROTOCOL_ID) {
Expand All @@ -226,7 +226,7 @@ export async function readHeader(fd, sections, toObject) {



async function readHeaderGroth16(fd, sections, toObject) {
async function readHeaderGroth16(fd, sections, toObject, singleThreaded = false) {
const zkey = {};

zkey.protocol = "groth16";
Expand All @@ -241,7 +241,7 @@ async function readHeaderGroth16(fd, sections, toObject) {
const n8r = await fd.readULE32();
zkey.n8r = n8r;
zkey.r = await binFileUtils.readBigInt(fd, n8r);
zkey.curve = await getCurve(zkey.q);
zkey.curve = await getCurve(zkey.q, singleThreaded);
zkey.nVars = await fd.readULE32();
zkey.nPublic = await fd.readULE32();
zkey.domainSize = await fd.readULE32();
Expand Down