import pot with -nopoints

This commit is contained in:
Jordi Baylina 2020-08-20 10:44:00 +02:00
parent d170783f84
commit aeef63c3bf
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
6 changed files with 246 additions and 50 deletions

@ -2420,7 +2420,7 @@ async function newAccumulator(curve, power, fileName, logger) {
const nTauG1 = (1 << power) * 2 -1; const nTauG1 = (1 << power) * 2 -1;
for (let i=0; i< nTauG1; i++) { for (let i=0; i< nTauG1; i++) {
await fd.write(buffG1); await fd.write(buffG1);
if ((logger)&&((i%100000) == 0)&&i) logger.info("tauG1: " + i); if ((logger)&&((i%100000) == 0)&&i) logger.log("tauG1: " + i);
} }
await endWriteSection(fd); await endWriteSection(fd);
@ -2552,6 +2552,9 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
await Blake2b.ready(); await Blake2b.ready();
const noHash = new Uint8Array(64);
for (let i=0; i<64; i++) noHash[i] = 0xFF;
const {fd: fdOld, sections} = await readBinFile$1(oldPtauFilename, "ptau", 1); const {fd: fdOld, sections} = await readBinFile$1(oldPtauFilename, "ptau", 1);
const {curve, power} = await readPTauHeader(fdOld, sections); const {curve, power} = await readPTauHeader(fdOld, sections);
const contributions = await readContributions(fdOld, curve, sections); const contributions = await readContributions(fdOld, curve, sections);
@ -2584,11 +2587,16 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
lastChallengeHash = calculateFirstChallengeHash(curve, power, logger); lastChallengeHash = calculateFirstChallengeHash(curve, power, logger);
} }
const fdNew = await createBinFile(newPTauFilename, "ptau", 1, 7); const fdNew = await createBinFile(newPTauFilename, "ptau", 1, importPoints ? 7: 2);
await writePTauHeader(fdNew, curve, power); await writePTauHeader(fdNew, curve, power);
const contributionPreviousHash = await fdResponse.read(64); const contributionPreviousHash = await fdResponse.read(64);
if (hashIsEqual(noHash,lastChallengeHash)) {
lastChallengeHash = contributionPreviousHash;
contributions[contributions.length-1].nextChallenge = lastChallengeHash;
}
if(!hashIsEqual(contributionPreviousHash,lastChallengeHash)) if(!hashIsEqual(contributionPreviousHash,lastChallengeHash))
throw new Error("Wrong contribution. this contribution is not based on the previus hash"); throw new Error("Wrong contribution. this contribution is not based on the previus hash");
@ -2620,18 +2628,22 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
if (logger) logger.info(formatHash(hashResponse, "Contribution Response Hash imported: ")); if (logger) logger.info(formatHash(hashResponse, "Contribution Response Hash imported: "));
if (importPoints) {
const nextChallengeHasher = new Blake2b(64); const nextChallengeHasher = new Blake2b(64);
nextChallengeHasher.update(hashResponse); nextChallengeHasher.update(hashResponse);
await hashSection(fdNew, "G1", 2, (1 << power) * 2 -1, "tauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 2, (1 << power) * 2 -1, "tauG1", logger);
await hashSection(fdNew, "G2", 3, (1 << power) , "tauG2", logger); await hashSection(nextChallengeHasher, fdNew, "G2", 3, (1 << power) , "tauG2", logger);
await hashSection(fdNew, "G1", 4, (1 << power) , "alphaTauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 4, (1 << power) , "alphaTauG1", logger);
await hashSection(fdNew, "G1", 5, (1 << power) , "betaTauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 5, (1 << power) , "betaTauG1", logger);
await hashSection(fdNew, "G2", 6, 1 , "betaG2", logger); await hashSection(nextChallengeHasher, fdNew, "G2", 6, 1 , "betaG2", logger);
currentContribution.nextChallenge = nextChallengeHasher.digest(); currentContribution.nextChallenge = nextChallengeHasher.digest();
if (logger) logger.info(formatHash(currentContribution.nextChallenge, "Next Challenge Hash: ")); if (logger) logger.info(formatHash(currentContribution.nextChallenge, "Next Challenge Hash: "));
} else {
currentContribution.nextChallenge = noHash;
}
contributions.push(currentContribution); contributions.push(currentContribution);
@ -2644,6 +2656,14 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
return currentContribution.nextChallenge; return currentContribution.nextChallenge;
async function processSection(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) { async function processSection(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
if (importPoints) {
return await processSectionImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName);
} else {
return await processSectionNoImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName);
}
}
async function processSectionImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
const G = curve[groupName]; const G = curve[groupName];
const scG = G.F.n8; const scG = G.F.n8;
@ -2681,7 +2701,36 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
} }
async function hashSection(fdTo, groupName, sectionId, nPoints, sectionName, logger) { async function processSectionNoImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
const G = curve[groupName];
const scG = G.F.n8;
const singularPoints = [];
const nPointsChunk = Math.floor((1<<24)/scG);
for (let i=0; i< nPoints; i += nPointsChunk) {
if (logger) logger.debug(`Importing ${sectionName}: ${i}/${nPoints}`);
const n = Math.min(nPoints-i, nPointsChunk);
const buffC = await fdFrom.read(n * scG);
hasherResponse.update(buffC);
for (let j=0; j<singularPointIndexes.length; j++) {
const sp = singularPointIndexes[j];
if ((sp >=i) && (sp < i+n)) {
const P = G.fromRprCompressed(buffC, (sp-i)*scG);
singularPoints.push(P);
}
}
}
return singularPoints;
}
async function hashSection(nextChallengeHasher, fdTo, groupName, sectionId, nPoints, sectionName, logger) {
const G = curve[groupName]; const G = curve[groupName];
const sG = G.F.n8*2; const sG = G.F.n8*2;

@ -2218,7 +2218,7 @@ async function newAccumulator(curve, power, fileName, logger) {
const nTauG1 = (1 << power) * 2 -1; const nTauG1 = (1 << power) * 2 -1;
for (let i=0; i< nTauG1; i++) { for (let i=0; i< nTauG1; i++) {
await fd.write(buffG1); await fd.write(buffG1);
if ((logger)&&((i%100000) == 0)&&i) logger.info("tauG1: " + i); if ((logger)&&((i%100000) == 0)&&i) logger.log("tauG1: " + i);
} }
await endWriteSection(fd); await endWriteSection(fd);
@ -2350,6 +2350,9 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
await Blake2b.ready(); await Blake2b.ready();
const noHash = new Uint8Array(64);
for (let i=0; i<64; i++) noHash[i] = 0xFF;
const {fd: fdOld, sections} = await readBinFile(oldPtauFilename, "ptau", 1); const {fd: fdOld, sections} = await readBinFile(oldPtauFilename, "ptau", 1);
const {curve, power} = await readPTauHeader(fdOld, sections); const {curve, power} = await readPTauHeader(fdOld, sections);
const contributions = await readContributions(fdOld, curve, sections); const contributions = await readContributions(fdOld, curve, sections);
@ -2382,11 +2385,16 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
lastChallengeHash = calculateFirstChallengeHash(curve, power, logger); lastChallengeHash = calculateFirstChallengeHash(curve, power, logger);
} }
const fdNew = await createBinFile(newPTauFilename, "ptau", 1, 7); const fdNew = await createBinFile(newPTauFilename, "ptau", 1, importPoints ? 7: 2);
await writePTauHeader(fdNew, curve, power); await writePTauHeader(fdNew, curve, power);
const contributionPreviousHash = await fdResponse.read(64); const contributionPreviousHash = await fdResponse.read(64);
if (hashIsEqual(noHash,lastChallengeHash)) {
lastChallengeHash = contributionPreviousHash;
contributions[contributions.length-1].nextChallenge = lastChallengeHash;
}
if(!hashIsEqual(contributionPreviousHash,lastChallengeHash)) if(!hashIsEqual(contributionPreviousHash,lastChallengeHash))
throw new Error("Wrong contribution. this contribution is not based on the previus hash"); throw new Error("Wrong contribution. this contribution is not based on the previus hash");
@ -2418,18 +2426,22 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
if (logger) logger.info(formatHash(hashResponse, "Contribution Response Hash imported: ")); if (logger) logger.info(formatHash(hashResponse, "Contribution Response Hash imported: "));
if (importPoints) {
const nextChallengeHasher = new Blake2b(64); const nextChallengeHasher = new Blake2b(64);
nextChallengeHasher.update(hashResponse); nextChallengeHasher.update(hashResponse);
await hashSection(fdNew, "G1", 2, (1 << power) * 2 -1, "tauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 2, (1 << power) * 2 -1, "tauG1", logger);
await hashSection(fdNew, "G2", 3, (1 << power) , "tauG2", logger); await hashSection(nextChallengeHasher, fdNew, "G2", 3, (1 << power) , "tauG2", logger);
await hashSection(fdNew, "G1", 4, (1 << power) , "alphaTauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 4, (1 << power) , "alphaTauG1", logger);
await hashSection(fdNew, "G1", 5, (1 << power) , "betaTauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 5, (1 << power) , "betaTauG1", logger);
await hashSection(fdNew, "G2", 6, 1 , "betaG2", logger); await hashSection(nextChallengeHasher, fdNew, "G2", 6, 1 , "betaG2", logger);
currentContribution.nextChallenge = nextChallengeHasher.digest(); currentContribution.nextChallenge = nextChallengeHasher.digest();
if (logger) logger.info(formatHash(currentContribution.nextChallenge, "Next Challenge Hash: ")); if (logger) logger.info(formatHash(currentContribution.nextChallenge, "Next Challenge Hash: "));
} else {
currentContribution.nextChallenge = noHash;
}
contributions.push(currentContribution); contributions.push(currentContribution);
@ -2442,6 +2454,14 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
return currentContribution.nextChallenge; return currentContribution.nextChallenge;
async function processSection(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) { async function processSection(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
if (importPoints) {
return await processSectionImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName);
} else {
return await processSectionNoImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName);
}
}
async function processSectionImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
const G = curve[groupName]; const G = curve[groupName];
const scG = G.F.n8; const scG = G.F.n8;
@ -2479,7 +2499,36 @@ async function importResponse(oldPtauFilename, contributionFilename, newPTauFile
} }
async function hashSection(fdTo, groupName, sectionId, nPoints, sectionName, logger) { async function processSectionNoImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
const G = curve[groupName];
const scG = G.F.n8;
const singularPoints = [];
const nPointsChunk = Math.floor((1<<24)/scG);
for (let i=0; i< nPoints; i += nPointsChunk) {
if (logger) logger.debug(`Importing ${sectionName}: ${i}/${nPoints}`);
const n = Math.min(nPoints-i, nPointsChunk);
const buffC = await fdFrom.read(n * scG);
hasherResponse.update(buffC);
for (let j=0; j<singularPointIndexes.length; j++) {
const sp = singularPointIndexes[j];
if ((sp >=i) && (sp < i+n)) {
const P = G.fromRprCompressed(buffC, (sp-i)*scG);
singularPoints.push(P);
}
}
}
return singularPoints;
}
async function hashSection(nextChallengeHasher, fdTo, groupName, sectionId, nPoints, sectionName, logger) {
const G = curve[groupName]; const G = curve[groupName];
const sG = G.F.n8*2; const sG = G.F.n8*2;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -8,6 +8,9 @@ export default async function importResponse(oldPtauFilename, contributionFilena
await Blake2b.ready(); await Blake2b.ready();
const noHash = new Uint8Array(64);
for (let i=0; i<64; i++) noHash[i] = 0xFF;
const {fd: fdOld, sections} = await binFileUtils.readBinFile(oldPtauFilename, "ptau", 1); const {fd: fdOld, sections} = await binFileUtils.readBinFile(oldPtauFilename, "ptau", 1);
const {curve, power} = await utils.readPTauHeader(fdOld, sections); const {curve, power} = await utils.readPTauHeader(fdOld, sections);
const contributions = await utils.readContributions(fdOld, curve, sections); const contributions = await utils.readContributions(fdOld, curve, sections);
@ -40,11 +43,16 @@ export default async function importResponse(oldPtauFilename, contributionFilena
lastChallengeHash = utils.calculateFirstChallengeHash(curve, power, logger); lastChallengeHash = utils.calculateFirstChallengeHash(curve, power, logger);
} }
const fdNew = await binFileUtils.createBinFile(newPTauFilename, "ptau", 1, 7); const fdNew = await binFileUtils.createBinFile(newPTauFilename, "ptau", 1, importPoints ? 7: 2);
await utils.writePTauHeader(fdNew, curve, power); await utils.writePTauHeader(fdNew, curve, power);
const contributionPreviousHash = await fdResponse.read(64); const contributionPreviousHash = await fdResponse.read(64);
if (misc.hashIsEqual(noHash,lastChallengeHash)) {
lastChallengeHash = contributionPreviousHash;
contributions[contributions.length-1].nextChallenge = lastChallengeHash;
}
if(!misc.hashIsEqual(contributionPreviousHash,lastChallengeHash)) if(!misc.hashIsEqual(contributionPreviousHash,lastChallengeHash))
throw new Error("Wrong contribution. this contribution is not based on the previus hash"); throw new Error("Wrong contribution. this contribution is not based on the previus hash");
@ -76,18 +84,22 @@ export default async function importResponse(oldPtauFilename, contributionFilena
if (logger) logger.info(misc.formatHash(hashResponse, "Contribution Response Hash imported: ")); if (logger) logger.info(misc.formatHash(hashResponse, "Contribution Response Hash imported: "));
if (importPoints) {
const nextChallengeHasher = new Blake2b(64); const nextChallengeHasher = new Blake2b(64);
nextChallengeHasher.update(hashResponse); nextChallengeHasher.update(hashResponse);
await hashSection(fdNew, "G1", 2, (1 << power) * 2 -1, "tauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 2, (1 << power) * 2 -1, "tauG1", logger);
await hashSection(fdNew, "G2", 3, (1 << power) , "tauG2", logger); await hashSection(nextChallengeHasher, fdNew, "G2", 3, (1 << power) , "tauG2", logger);
await hashSection(fdNew, "G1", 4, (1 << power) , "alphaTauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 4, (1 << power) , "alphaTauG1", logger);
await hashSection(fdNew, "G1", 5, (1 << power) , "betaTauG1", logger); await hashSection(nextChallengeHasher, fdNew, "G1", 5, (1 << power) , "betaTauG1", logger);
await hashSection(fdNew, "G2", 6, 1 , "betaG2", logger); await hashSection(nextChallengeHasher, fdNew, "G2", 6, 1 , "betaG2", logger);
currentContribution.nextChallenge = nextChallengeHasher.digest(); currentContribution.nextChallenge = nextChallengeHasher.digest();
if (logger) logger.info(misc.formatHash(currentContribution.nextChallenge, "Next Challenge Hash: ")); if (logger) logger.info(misc.formatHash(currentContribution.nextChallenge, "Next Challenge Hash: "));
} else {
currentContribution.nextChallenge = noHash;
}
contributions.push(currentContribution); contributions.push(currentContribution);
@ -100,6 +112,14 @@ export default async function importResponse(oldPtauFilename, contributionFilena
return currentContribution.nextChallenge; return currentContribution.nextChallenge;
async function processSection(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) { async function processSection(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
if (importPoints) {
return await processSectionImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName);
} else {
return await processSectionNoImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName);
}
}
async function processSectionImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
const G = curve[groupName]; const G = curve[groupName];
const scG = G.F.n8; const scG = G.F.n8;
@ -137,7 +157,36 @@ export default async function importResponse(oldPtauFilename, contributionFilena
} }
async function hashSection(fdTo, groupName, sectionId, nPoints, sectionName, logger) { async function processSectionNoImportPoints(fdFrom, fdTo, groupName, sectionId, nPoints, singularPointIndexes, sectionName) {
const G = curve[groupName];
const scG = G.F.n8;
const singularPoints = [];
const nPointsChunk = Math.floor((1<<24)/scG);
for (let i=0; i< nPoints; i += nPointsChunk) {
if (logger) logger.debug(`Importing ${sectionName}: ${i}/${nPoints}`);
const n = Math.min(nPoints-i, nPointsChunk);
const buffC = await fdFrom.read(n * scG);
hasherResponse.update(buffC);
for (let j=0; j<singularPointIndexes.length; j++) {
const sp = singularPointIndexes[j];
if ((sp >=i) && (sp < i+n)) {
const P = G.fromRprCompressed(buffC, (sp-i)*scG);
singularPoints.push(P);
}
}
}
return singularPoints;
}
async function hashSection(nextChallengeHasher, fdTo, groupName, sectionId, nPoints, sectionName, logger) {
const G = curve[groupName]; const G = curve[groupName];
const sG = G.F.n8*2; const sG = G.F.n8*2;

@ -68,7 +68,7 @@ export default async function newAccumulator(curve, power, fileName, logger) {
const nTauG1 = (1 << power) * 2 -1; const nTauG1 = (1 << power) * 2 -1;
for (let i=0; i< nTauG1; i++) { for (let i=0; i< nTauG1; i++) {
await fd.write(buffG1); await fd.write(buffG1);
if ((logger)&&((i%100000) == 0)&&i) logger.info("tauG1: " + i); if ((logger)&&((i%100000) == 0)&&i) logger.log("tauG1: " + i);
} }
await binFileUtils.endWriteSection(fd); await binFileUtils.endWriteSection(fd);