mirror of
https://github.com/tornadocash/snarkjs.git
synced 2024-11-01 07:45:43 +01:00
Parallelize lagrange evaluations
This commit is contained in:
parent
f8715d7f7e
commit
8bc1df6e01
@ -3779,13 +3779,18 @@ async function preparePhase2(oldPtauFilename, newPTauFilename, logger) {
|
||||
}
|
||||
await endReadSection$1(fdOld, true);
|
||||
|
||||
|
||||
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
|
||||
/*
|
||||
if (p <= curve.Fr.s) {
|
||||
buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
} else if (p == curve.Fr.s+1) {
|
||||
const smallM = 1<<curve.Fr.s;
|
||||
let t0 = new ffjavascript.BigBuffer( smallM * sGmid );
|
||||
let t1 = new ffjavascript.BigBuffer( smallM * sGmid );
|
||||
let t0 = new BigBuffer( smallM * sGmid );
|
||||
let t1 = new BigBuffer( smallM * sGmid );
|
||||
|
||||
const shift_to_small_m = Fr.exp(Fr.shift, smallM);
|
||||
const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one));
|
||||
@ -3826,10 +3831,8 @@ async function preparePhase2(oldPtauFilename, newPTauFilename, logger) {
|
||||
if (logger) logger.error("Power too big");
|
||||
throw new Error("Power to big");
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -3947,19 +3950,24 @@ async function convert(oldPtauFilename, newPTauFilename, logger) {
|
||||
}
|
||||
await endReadSection$1(fdOld, true);
|
||||
|
||||
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
|
||||
/*
|
||||
if (p <= curve.Fr.s) {
|
||||
buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
} else if (p == curve.Fr.s+1) {
|
||||
const smallM = 1<<curve.Fr.s;
|
||||
let t0 = new ffjavascript.BigBuffer( smallM * sGmid );
|
||||
let t1 = new ffjavascript.BigBuffer( smallM * sGmid );
|
||||
let t0 = new BigBuffer( smallM * sGmid );
|
||||
let t1 = new BigBuffer( smallM * sGmid );
|
||||
|
||||
const shift_to_small_m = Fr.exp(Fr.shift, smallM);
|
||||
const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one));
|
||||
|
||||
let sInvAcc = Fr.one;
|
||||
for (let i=0; i<smallM; i++) {
|
||||
if (i%10000) logger.debug(`sectionName prepare L calc: ${sectionName}, ${i}/${smallM}`);
|
||||
const ti = buff.slice(i*sGin, (i+1)*sGin);
|
||||
const tmi = buff.slice((i+smallM)*sGin, (i+smallM+1)*sGin);
|
||||
|
||||
@ -3987,14 +3995,14 @@ async function convert(oldPtauFilename, newPTauFilename, logger) {
|
||||
t0 = await G.ifft(t0, "jacobian", "affine", logger, sectionName + " t0");
|
||||
await fdNew.write(t0);
|
||||
t0 = null;
|
||||
t1 = await G.ifft(t1, "jacobian", "affine", logger, sectionName + " t0");
|
||||
t1 = await G.ifft(t1, "jacobian", "affine", logger, sectionName + " t1");
|
||||
await fdNew.write(t1);
|
||||
|
||||
} else {
|
||||
if (logger) logger.error("Power too big");
|
||||
throw new Error("Power to big");
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -3569,13 +3569,18 @@ async function preparePhase2(oldPtauFilename, newPTauFilename, logger) {
|
||||
}
|
||||
await endReadSection(fdOld, true);
|
||||
|
||||
|
||||
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
|
||||
/*
|
||||
if (p <= curve.Fr.s) {
|
||||
buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
} else if (p == curve.Fr.s+1) {
|
||||
const smallM = 1<<curve.Fr.s;
|
||||
let t0 = new ffjavascript.BigBuffer( smallM * sGmid );
|
||||
let t1 = new ffjavascript.BigBuffer( smallM * sGmid );
|
||||
let t0 = new BigBuffer( smallM * sGmid );
|
||||
let t1 = new BigBuffer( smallM * sGmid );
|
||||
|
||||
const shift_to_small_m = Fr.exp(Fr.shift, smallM);
|
||||
const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one));
|
||||
@ -3616,10 +3621,8 @@ async function preparePhase2(oldPtauFilename, newPTauFilename, logger) {
|
||||
if (logger) logger.error("Power too big");
|
||||
throw new Error("Power to big");
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -3737,19 +3740,24 @@ async function convert(oldPtauFilename, newPTauFilename, logger) {
|
||||
}
|
||||
await endReadSection(fdOld, true);
|
||||
|
||||
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
|
||||
/*
|
||||
if (p <= curve.Fr.s) {
|
||||
buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
} else if (p == curve.Fr.s+1) {
|
||||
const smallM = 1<<curve.Fr.s;
|
||||
let t0 = new ffjavascript.BigBuffer( smallM * sGmid );
|
||||
let t1 = new ffjavascript.BigBuffer( smallM * sGmid );
|
||||
let t0 = new BigBuffer( smallM * sGmid );
|
||||
let t1 = new BigBuffer( smallM * sGmid );
|
||||
|
||||
const shift_to_small_m = Fr.exp(Fr.shift, smallM);
|
||||
const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one));
|
||||
|
||||
let sInvAcc = Fr.one;
|
||||
for (let i=0; i<smallM; i++) {
|
||||
if (i%10000) logger.debug(`sectionName prepare L calc: ${sectionName}, ${i}/${smallM}`);
|
||||
const ti = buff.slice(i*sGin, (i+1)*sGin);
|
||||
const tmi = buff.slice((i+smallM)*sGin, (i+smallM+1)*sGin);
|
||||
|
||||
@ -3777,14 +3785,14 @@ async function convert(oldPtauFilename, newPTauFilename, logger) {
|
||||
t0 = await G.ifft(t0, "jacobian", "affine", logger, sectionName + " t0");
|
||||
await fdNew.write(t0);
|
||||
t0 = null;
|
||||
t1 = await G.ifft(t1, "jacobian", "affine", logger, sectionName + " t0");
|
||||
t1 = await G.ifft(t1, "jacobian", "affine", logger, sectionName + " t1");
|
||||
await fdNew.write(t1);
|
||||
|
||||
} else {
|
||||
if (logger) logger.error("Power too big");
|
||||
throw new Error("Power to big");
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
140
build/snarkjs.js
140
build/snarkjs.js
File diff suppressed because one or more lines are too long
2
build/snarkjs.min.js
vendored
2
build/snarkjs.min.js
vendored
File diff suppressed because one or more lines are too long
14
package-lock.json
generated
14
package-lock.json
generated
@ -672,19 +672,19 @@
|
||||
"integrity": "sha512-LwvI75nCVs83EsuKpT+cL7M7T3VNdY4O50nLi4jnVZcxvqbWWqX43dM2GDrNHeD5uaX+ug0Di5RcvnTTI+hEAQ=="
|
||||
},
|
||||
"ffjavascript": {
|
||||
"version": "0.2.14",
|
||||
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.14.tgz",
|
||||
"integrity": "sha512-4uJKZ7cgzmpOOmpxcPL0bz1cGNj9394UUlJHlPUkg/5YSge+9u5l1kRRvrhNN7uRpLF1qJcXHCUEUgnN9clXCg==",
|
||||
"version": "0.2.16",
|
||||
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.16.tgz",
|
||||
"integrity": "sha512-U7kmhXkQjvn4v8hx4h3MYCRI0Za+nu4utoPag3zVBNEOALiDprWhT4Hv3nfxpBZLieQZoUJhtZBLoKAWZu0g2w==",
|
||||
"requires": {
|
||||
"big-integer": "^1.6.48",
|
||||
"wasmcurves": "0.0.7",
|
||||
"wasmcurves": "0.0.8",
|
||||
"worker-threads": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"wasmcurves": {
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.0.7.tgz",
|
||||
"integrity": "sha512-dWqIddIc1YTdZhR6JNX9f4qCY2IjlkxQboU5jiEWejJ9gmYoOLmMD3CK8sQaNT0UJkvfrkpQVfbgdVv+Uik3kg==",
|
||||
"version": "0.0.8",
|
||||
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.0.8.tgz",
|
||||
"integrity": "sha512-CYCPh8K2LhPaGy3fvI+yinL1U53XBlJFVKznICS+JeKVv61Lx0gpWNe2NnHSD25YfTihv1HcUeSe+wxgFLIjYw==",
|
||||
"requires": {
|
||||
"big-integer": "^1.6.42",
|
||||
"blakejs": "^1.1.0"
|
||||
|
@ -41,7 +41,7 @@
|
||||
"blake2b-wasm": "https://github.com/jbaylina/blake2b-wasm.git",
|
||||
"circom_runtime": "0.1.5",
|
||||
"fastfile": "0.0.15",
|
||||
"ffjavascript": "0.2.14",
|
||||
"ffjavascript": "0.2.16",
|
||||
"logplease": "^1.2.15",
|
||||
"r1csfile": "0.0.12"
|
||||
},
|
||||
|
@ -74,6 +74,10 @@ export default async function convert(oldPtauFilename, newPTauFilename, logger)
|
||||
}
|
||||
await binFileUtils.endReadSection(fdOld, true);
|
||||
|
||||
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
|
||||
/*
|
||||
if (p <= curve.Fr.s) {
|
||||
buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
@ -87,6 +91,7 @@ export default async function convert(oldPtauFilename, newPTauFilename, logger)
|
||||
|
||||
let sInvAcc = Fr.one;
|
||||
for (let i=0; i<smallM; i++) {
|
||||
if (i%10000) logger.debug(`sectionName prepare L calc: ${sectionName}, ${i}/${smallM}`);
|
||||
const ti = buff.slice(i*sGin, (i+1)*sGin);
|
||||
const tmi = buff.slice((i+smallM)*sGin, (i+smallM+1)*sGin);
|
||||
|
||||
@ -114,14 +119,14 @@ export default async function convert(oldPtauFilename, newPTauFilename, logger)
|
||||
t0 = await G.ifft(t0, "jacobian", "affine", logger, sectionName + " t0");
|
||||
await fdNew.write(t0);
|
||||
t0 = null;
|
||||
t1 = await G.ifft(t1, "jacobian", "affine", logger, sectionName + " t0");
|
||||
t1 = await G.ifft(t1, "jacobian", "affine", logger, sectionName + " t1");
|
||||
await fdNew.write(t1);
|
||||
|
||||
} else {
|
||||
if (logger) logger.error("Power too big");
|
||||
throw new Error("Power to big");
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,6 +64,11 @@ export default async function preparePhase2(oldPtauFilename, newPTauFilename, lo
|
||||
}
|
||||
await binFileUtils.endReadSection(fdOld, true);
|
||||
|
||||
|
||||
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
|
||||
/*
|
||||
if (p <= curve.Fr.s) {
|
||||
buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
|
||||
await fdNew.write(buff);
|
||||
@ -111,10 +116,8 @@ export default async function preparePhase2(oldPtauFilename, newPTauFilename, lo
|
||||
if (logger) logger.error("Power too big");
|
||||
throw new Error("Power to big");
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ describe("Full process", function () {
|
||||
|
||||
before( async () => {
|
||||
curve = await getCurveFromName("bn128");
|
||||
curve.Fr.s = 10;
|
||||
});
|
||||
after( async () => {
|
||||
await curve.terminate();
|
||||
|
Loading…
Reference in New Issue
Block a user