Parallelize lagrange evaluations

This commit is contained in:
Jordi Baylina 2020-09-07 18:24:09 +02:00
parent f8715d7f7e
commit 8bc1df6e01
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
9 changed files with 169 additions and 60 deletions

View File

@ -3779,13 +3779,18 @@ async function preparePhase2(oldPtauFilename, newPTauFilename, logger) {
} }
await endReadSection$1(fdOld, true); await endReadSection$1(fdOld, true);
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff);
/*
if (p <= curve.Fr.s) { if (p <= curve.Fr.s) {
buff = await G.ifft(buff, "affine", "affine", logger, sectionName); buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff); await fdNew.write(buff);
} else if (p == curve.Fr.s+1) { } else if (p == curve.Fr.s+1) {
const smallM = 1<<curve.Fr.s; const smallM = 1<<curve.Fr.s;
let t0 = new ffjavascript.BigBuffer( smallM * sGmid ); let t0 = new BigBuffer( smallM * sGmid );
let t1 = new ffjavascript.BigBuffer( smallM * sGmid ); let t1 = new BigBuffer( smallM * sGmid );
const shift_to_small_m = Fr.exp(Fr.shift, smallM); const shift_to_small_m = Fr.exp(Fr.shift, smallM);
const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one)); 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"); if (logger) logger.error("Power too big");
throw new Error("Power to big"); throw new Error("Power to big");
} }
*/
} }
} }
} }
@ -3947,19 +3950,24 @@ async function convert(oldPtauFilename, newPTauFilename, logger) {
} }
await endReadSection$1(fdOld, true); await endReadSection$1(fdOld, true);
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff);
/*
if (p <= curve.Fr.s) { if (p <= curve.Fr.s) {
buff = await G.ifft(buff, "affine", "affine", logger, sectionName); buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff); await fdNew.write(buff);
} else if (p == curve.Fr.s+1) { } else if (p == curve.Fr.s+1) {
const smallM = 1<<curve.Fr.s; const smallM = 1<<curve.Fr.s;
let t0 = new ffjavascript.BigBuffer( smallM * sGmid ); let t0 = new BigBuffer( smallM * sGmid );
let t1 = new ffjavascript.BigBuffer( smallM * sGmid ); let t1 = new BigBuffer( smallM * sGmid );
const shift_to_small_m = Fr.exp(Fr.shift, smallM); const shift_to_small_m = Fr.exp(Fr.shift, smallM);
const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one)); const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one));
let sInvAcc = Fr.one; let sInvAcc = Fr.one;
for (let i=0; i<smallM; i++) { 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 ti = buff.slice(i*sGin, (i+1)*sGin);
const tmi = buff.slice((i+smallM)*sGin, (i+smallM+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"); t0 = await G.ifft(t0, "jacobian", "affine", logger, sectionName + " t0");
await fdNew.write(t0); await fdNew.write(t0);
t0 = null; 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); await fdNew.write(t1);
} else { } else {
if (logger) logger.error("Power too big"); if (logger) logger.error("Power too big");
throw new Error("Power to big"); throw new Error("Power to big");
} }
*/
} }

View File

@ -3569,13 +3569,18 @@ async function preparePhase2(oldPtauFilename, newPTauFilename, logger) {
} }
await endReadSection(fdOld, true); await endReadSection(fdOld, true);
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff);
/*
if (p <= curve.Fr.s) { if (p <= curve.Fr.s) {
buff = await G.ifft(buff, "affine", "affine", logger, sectionName); buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff); await fdNew.write(buff);
} else if (p == curve.Fr.s+1) { } else if (p == curve.Fr.s+1) {
const smallM = 1<<curve.Fr.s; const smallM = 1<<curve.Fr.s;
let t0 = new ffjavascript.BigBuffer( smallM * sGmid ); let t0 = new BigBuffer( smallM * sGmid );
let t1 = new ffjavascript.BigBuffer( smallM * sGmid ); let t1 = new BigBuffer( smallM * sGmid );
const shift_to_small_m = Fr.exp(Fr.shift, smallM); const shift_to_small_m = Fr.exp(Fr.shift, smallM);
const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one)); 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"); if (logger) logger.error("Power too big");
throw new Error("Power to big"); throw new Error("Power to big");
} }
*/
} }
} }
} }
@ -3737,19 +3740,24 @@ async function convert(oldPtauFilename, newPTauFilename, logger) {
} }
await endReadSection(fdOld, true); await endReadSection(fdOld, true);
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff);
/*
if (p <= curve.Fr.s) { if (p <= curve.Fr.s) {
buff = await G.ifft(buff, "affine", "affine", logger, sectionName); buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff); await fdNew.write(buff);
} else if (p == curve.Fr.s+1) { } else if (p == curve.Fr.s+1) {
const smallM = 1<<curve.Fr.s; const smallM = 1<<curve.Fr.s;
let t0 = new ffjavascript.BigBuffer( smallM * sGmid ); let t0 = new BigBuffer( smallM * sGmid );
let t1 = new ffjavascript.BigBuffer( smallM * sGmid ); let t1 = new BigBuffer( smallM * sGmid );
const shift_to_small_m = Fr.exp(Fr.shift, smallM); const shift_to_small_m = Fr.exp(Fr.shift, smallM);
const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one)); const one_over_denom = Fr.inv(Fr.sub(shift_to_small_m, Fr.one));
let sInvAcc = Fr.one; let sInvAcc = Fr.one;
for (let i=0; i<smallM; i++) { 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 ti = buff.slice(i*sGin, (i+1)*sGin);
const tmi = buff.slice((i+smallM)*sGin, (i+smallM+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"); t0 = await G.ifft(t0, "jacobian", "affine", logger, sectionName + " t0");
await fdNew.write(t0); await fdNew.write(t0);
t0 = null; 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); await fdNew.write(t1);
} else { } else {
if (logger) logger.error("Power too big"); if (logger) logger.error("Power too big");
throw new Error("Power to big"); throw new Error("Power to big");
} }
*/
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

14
package-lock.json generated
View File

@ -672,19 +672,19 @@
"integrity": "sha512-LwvI75nCVs83EsuKpT+cL7M7T3VNdY4O50nLi4jnVZcxvqbWWqX43dM2GDrNHeD5uaX+ug0Di5RcvnTTI+hEAQ==" "integrity": "sha512-LwvI75nCVs83EsuKpT+cL7M7T3VNdY4O50nLi4jnVZcxvqbWWqX43dM2GDrNHeD5uaX+ug0Di5RcvnTTI+hEAQ=="
}, },
"ffjavascript": { "ffjavascript": {
"version": "0.2.14", "version": "0.2.16",
"resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.14.tgz", "resolved": "https://registry.npmjs.org/ffjavascript/-/ffjavascript-0.2.16.tgz",
"integrity": "sha512-4uJKZ7cgzmpOOmpxcPL0bz1cGNj9394UUlJHlPUkg/5YSge+9u5l1kRRvrhNN7uRpLF1qJcXHCUEUgnN9clXCg==", "integrity": "sha512-U7kmhXkQjvn4v8hx4h3MYCRI0Za+nu4utoPag3zVBNEOALiDprWhT4Hv3nfxpBZLieQZoUJhtZBLoKAWZu0g2w==",
"requires": { "requires": {
"big-integer": "^1.6.48", "big-integer": "^1.6.48",
"wasmcurves": "0.0.7", "wasmcurves": "0.0.8",
"worker-threads": "^1.0.0" "worker-threads": "^1.0.0"
}, },
"dependencies": { "dependencies": {
"wasmcurves": { "wasmcurves": {
"version": "0.0.7", "version": "0.0.8",
"resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.0.7.tgz", "resolved": "https://registry.npmjs.org/wasmcurves/-/wasmcurves-0.0.8.tgz",
"integrity": "sha512-dWqIddIc1YTdZhR6JNX9f4qCY2IjlkxQboU5jiEWejJ9gmYoOLmMD3CK8sQaNT0UJkvfrkpQVfbgdVv+Uik3kg==", "integrity": "sha512-CYCPh8K2LhPaGy3fvI+yinL1U53XBlJFVKznICS+JeKVv61Lx0gpWNe2NnHSD25YfTihv1HcUeSe+wxgFLIjYw==",
"requires": { "requires": {
"big-integer": "^1.6.42", "big-integer": "^1.6.42",
"blakejs": "^1.1.0" "blakejs": "^1.1.0"

View File

@ -41,7 +41,7 @@
"blake2b-wasm": "https://github.com/jbaylina/blake2b-wasm.git", "blake2b-wasm": "https://github.com/jbaylina/blake2b-wasm.git",
"circom_runtime": "0.1.5", "circom_runtime": "0.1.5",
"fastfile": "0.0.15", "fastfile": "0.0.15",
"ffjavascript": "0.2.14", "ffjavascript": "0.2.16",
"logplease": "^1.2.15", "logplease": "^1.2.15",
"r1csfile": "0.0.12" "r1csfile": "0.0.12"
}, },

View File

@ -74,6 +74,10 @@ export default async function convert(oldPtauFilename, newPTauFilename, logger)
} }
await binFileUtils.endReadSection(fdOld, true); await binFileUtils.endReadSection(fdOld, true);
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff);
/*
if (p <= curve.Fr.s) { if (p <= curve.Fr.s) {
buff = await G.ifft(buff, "affine", "affine", logger, sectionName); buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff); await fdNew.write(buff);
@ -87,6 +91,7 @@ export default async function convert(oldPtauFilename, newPTauFilename, logger)
let sInvAcc = Fr.one; let sInvAcc = Fr.one;
for (let i=0; i<smallM; i++) { 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 ti = buff.slice(i*sGin, (i+1)*sGin);
const tmi = buff.slice((i+smallM)*sGin, (i+smallM+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"); t0 = await G.ifft(t0, "jacobian", "affine", logger, sectionName + " t0");
await fdNew.write(t0); await fdNew.write(t0);
t0 = null; 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); await fdNew.write(t1);
} else { } else {
if (logger) logger.error("Power too big"); if (logger) logger.error("Power too big");
throw new Error("Power to big"); throw new Error("Power to big");
} }
*/
} }

View File

@ -64,6 +64,11 @@ export default async function preparePhase2(oldPtauFilename, newPTauFilename, lo
} }
await binFileUtils.endReadSection(fdOld, true); await binFileUtils.endReadSection(fdOld, true);
buff = await G.lagrangeEvaluations(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff);
/*
if (p <= curve.Fr.s) { if (p <= curve.Fr.s) {
buff = await G.ifft(buff, "affine", "affine", logger, sectionName); buff = await G.ifft(buff, "affine", "affine", logger, sectionName);
await fdNew.write(buff); await fdNew.write(buff);
@ -111,10 +116,8 @@ export default async function preparePhase2(oldPtauFilename, newPTauFilename, lo
if (logger) logger.error("Power too big"); if (logger) logger.error("Power too big");
throw new Error("Power to big"); throw new Error("Power to big");
} }
*/
} }
} }
} }

View File

@ -27,6 +27,7 @@ describe("Full process", function () {
before( async () => { before( async () => {
curve = await getCurveFromName("bn128"); curve = await getCurveFromName("bn128");
curve.Fr.s = 10;
}); });
after( async () => { after( async () => {
await curve.terminate(); await curve.terminate();