Skip to content

Commit

Permalink
Merge branch 'master' into feature/wtns-memSize-option
Browse files Browse the repository at this point in the history
# Conflicts:
#	build/browser.esm.js
#	build/cli.cjs
#	build/main.cjs
#	build/snarkjs.js
#	build/snarkjs.min.js
  • Loading branch information
OBrezhniev committed Sep 10, 2024
2 parents a5c16af + 0c580e5 commit a4bef47
Show file tree
Hide file tree
Showing 32 changed files with 283 additions and 271 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ This information fits with our mental map of the circuit we created: we had two
snarkjs r1cs print circuit.r1cs circuit.sym
```

To double check, we print the constraints of the circuit.
To double-check, we print the constraints of the circuit.

You should see a thousand constraints of the form:

Expand Down Expand Up @@ -318,7 +318,7 @@ EOT
Now, we use the Javascript/WASM program created by `circom` in the directory *circuit_js* to create the witness (values of all the wires) for our inputs:

```sh
circuit_js$ node generate_witness.js circuit.wasm ../input.json ../witness.wtns
node generate_witness.js circuit.wasm ../input.json ../witness.wtns
```

We can check if the generated witness complies with the `r1cs` file with the following command:
Expand Down Expand Up @@ -481,7 +481,7 @@ snarkjs fflonk verify verification_key.json public.json proof.json
snarkjs groth16 verify verification_key.json public.json proof.json
```

We use the this command to verify the proof, passing in the `verification_key` we exported earlier.
We use this command to verify the proof, passing in the `verification_key` we exported earlier.

If all is well, you should see that `OK` has been outputted to your console. This signifies the proof is valid.

Expand Down Expand Up @@ -610,7 +610,7 @@ the Random Beacon Model](https://eprint.iacr.org/2017/1050.pdf)
- [Perpetual Powers of Tau](https://github.com/weijiekoh/perpetualpowersoftau)
- [Powers of Tau](https://github.com/ebfull/powersoftau)
- [Trusted setup ceremonies explored](https://www.zeroknowledge.fm/133)
- [Simple react projct using snarkjs](https://github.com/LHerskind/snarkjs-react)
- [Simple react project using snarkjs](https://github.com/LHerskind/snarkjs-react)

## Final note

Expand Down
103 changes: 53 additions & 50 deletions build/browser.esm.js

Large diffs are not rendered by default.

111 changes: 57 additions & 54 deletions build/cli.cjs

Large diffs are not rendered by default.

103 changes: 53 additions & 50 deletions build/main.cjs

Large diffs are not rendered by default.

105 changes: 54 additions & 51 deletions build/snarkjs.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/snarkjs.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const commands = [
},
{
cmd: "powersoftau truncate <powersoftau.ptau>",
description: "Generate diferent powers of tau with smoller sizes ",
description: "Generate different powers of tau with smaller sizes ",
longDescription: " This process generates smaller ptau files from a bigger power ptau",
alias: ["ptt"],
options: "-verbose|v",
Expand Down Expand Up @@ -175,7 +175,7 @@ const commands = [
},
{
cmd: "wtns check [circuit.r1cs] [[witness.wtns]",
description: "Check if a specific witness of a circuit fullfills the r1cs constraints",
description: "Check if a specific witness of a circuit fulfills the r1cs constraints",
alias: ["wchk"],
action: wtnsCheck
},
Expand Down Expand Up @@ -366,7 +366,7 @@ TODO COMMANDS
},
{
cmd: "witness verify <circuit.r1cs> <witness.wtns>",
description: "Verify a witness agains a r1cs",
description: "Verify a witness against a r1cs",
alias: ["wv"],
action: witnessVerify
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"zcash",
"ethereum",
"zero",
"knowlage",
"knowledge",
"cryptography",
"circuit"
],
Expand Down
4 changes: 2 additions & 2 deletions smart_contract_tests/test/smart_contracts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ describe("Smart contracts test suite", function () {
const VerifierFactory = await ethers.getContractFactory("PlonkVerifier");
verifierContract = await VerifierFactory.deploy();

// Verifiy the proof in the smart contract
// Verify the proof in the smart contract
const proof =
[
ethers.utils.hexZeroPad(ethers.BigNumber.from(proofJson.A[0]).toHexString(), 32),
Expand Down Expand Up @@ -209,7 +209,7 @@ describe("Smart contracts test suite", function () {
const VerifierFactory = await ethers.getContractFactory("FflonkVerifier");
verifierContract = await VerifierFactory.deploy();

// Verifiy the proof in the smart contract
// Verify the proof in the smart contract
const { evaluations, polynomials } = proofJson;

const proof =
Expand Down
2 changes: 1 addition & 1 deletion src/clprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default async function clProcessor(commands) {
console.log("");
console.log("Usage:");
console.log(" snarkjs <full command> ... <options>");
console.log(" or snarkjs <shorcut> ... <options>");
console.log(" or snarkjs <shortcut> ... <options>");
console.log("");
console.log("Type snarkjs <command> --help to get more information for that command");
console.log("");
Expand Down
2 changes: 1 addition & 1 deletion src/fflonk_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default async function fflonkSetup(r1csFilename, ptauFilename, zkeyFilena
await computeFFConstraints(curve.Fr, r1cs, logger);
if (globalThis.gc) globalThis.gc();

// As the t polynomial is n+5 whe need at least a power of 4
// As the t polynomial is n+5 we need at least a power of 4
//TODO check!!!!
// NOTE : plonkConstraints + 2 = #constraints + blinding coefficients for each wire polynomial
settings.cirPower = Math.max(FF_T_POL_DEG_MIN, log2((plonkConstraints.length + 2) - 1) + 1);
Expand Down
2 changes: 1 addition & 1 deletion src/groth16_prove.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async function buildABC1(curve, zkey, witness, coeffs, logger) {
}

/*
async function buldABC(curve, zkey, witness, coeffs, logger) {
async function buildABC(curve, zkey, witness, coeffs, logger) {
const concurrency = curve.tm.concurrency;
const sCoef = 4*3 + zkey.n8r;
Expand Down
2 changes: 1 addition & 1 deletion src/mpc_applykey.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as binFileUtils from "@iden3/binfileutils";

/*
This function creates a new section in the fdTo file with id idSection.
It multiplies the pooints in fdFrom by first, first*inc, first*inc^2, ....
It multiplies the points in fdFrom by first, first*inc, first*inc^2, ....
nPoint Times.
It also updates the newChallengeHasher with the new points
*/
Expand Down
6 changes: 3 additions & 3 deletions src/plonk_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default async function plonkSetup(r1csName, ptauName, zkeyName, logger) {
}

let cirPower = log2(plonkConstraints.length -1) +1;
if (cirPower < 3) cirPower = 3; // As the t polinomal is n+5 whe need at least a power of 4
if (cirPower < 3) cirPower = 3; // As the t polynomial is n+5 we need at least a power of 4
const domainSize = 2 ** cirPower;

if (logger) logger.info("Plonk constraints: " + plonkConstraints.length);
Expand Down Expand Up @@ -343,8 +343,8 @@ export default async function plonkSetup(r1csName, ptauName, zkeyName, logger) {
let o=0;
buffOutV.setUint32(o, addition[0], true); o+=4;
buffOutV.setUint32(o, addition[1], true); o+=4;
// The value is storen in Montgomery. stored = v*R
// so when montgomery multiplicated by the witness it result = v*R*w/R = v*w
// The value is stored in Montgomery. stored = v*R
// so when montgomery multiplied by the witness, it's result = v*R*w/R = v*w
buffOut.set(addition[2], o); o+= n8r;
buffOut.set(addition[3], o); o+= n8r;
await fdZKey.write(buffOut);
Expand Down
2 changes: 1 addition & 1 deletion src/powersoftau_beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default async function beacon(oldPtauFilename, newPTauFilename, name, be
return false;
}
if (beaconHash.length>=256) {
if (logger) logger.error("Maximum lenght of beacon hash is 255 bytes");
if (logger) logger.error("Maximum length of beacon hash is 255 bytes");
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/powersoftau_challenge_contribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import * as misc from "./misc.js";
import { applyKeyToChallengeSection } from "./mpc_applykey.js";
import * as keyPair from "./keypair.js";

export default async function challengeContribute(curve, challengeFilename, responesFileName, entropy, logger) {
export default async function challengeContribute(curve, challengeFilename, responseFileName, entropy, logger) {
await Blake2b.ready();

const fdFrom = await fastFile.readExisting(challengeFilename);
Expand All @@ -63,7 +63,7 @@ export default async function challengeContribute(curve, challengeFilename, resp

const rng = await misc.getRandomRng(entropy);

const fdTo = await fastFile.createOverride(responesFileName);
const fdTo = await fastFile.createOverride(responseFileName);

// Calculate the hash
const challengeHasher = Blake2b(64);
Expand Down
6 changes: 3 additions & 3 deletions src/powersoftau_import.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export default async function importResponse(oldPtauFilename, contributionFilena
if (name) currentContribution.name = name;

const sG1 = curve.F1.n8*2;
const scG1 = curve.F1.n8; // Compresed size
const scG1 = curve.F1.n8; // Compressed size
const sG2 = curve.F2.n8*2;
const scG2 = curve.F2.n8; // Compresed size
const scG2 = curve.F2.n8; // Compressed size

const fdResponse = await fastFile.readExisting(contributionFilename);

Expand Down Expand Up @@ -73,7 +73,7 @@ export default async function importResponse(oldPtauFilename, contributionFilena
}

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 previous hash");

const hasherResponse = new Blake2b(64);
hasherResponse.update(contributionPreviousHash);
Expand Down
2 changes: 1 addition & 1 deletion src/powersoftau_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async function readContribution(fd, curve) {
}
}
if (fd.pos != curPos + paramLength) {
throw new Error("Parametes do not match");
throw new Error("Parameters do not match");
}

return c;
Expand Down
2 changes: 1 addition & 1 deletion src/wtns_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default async function wtnsCheck(r1csFilename, wtnsFilename, logger) {
logger.info(" WITNESS CHECK");
logger.info(` Curve: ${r1cs.curve.name}`);
logger.info(` Vars (wires): ${r1cs.nVars}`);
logger.info(` Ouputs: ${r1cs.nOutputs}`);
logger.info(` Outputs: ${r1cs.nOutputs}`);
logger.info(` Public Inputs: ${r1cs.nPubInputs}`);
logger.info(` Private Inputs: ${r1cs.nPrvInputs}`);
logger.info(` Labels: ${r1cs.nLabels}`);
Expand Down
8 changes: 4 additions & 4 deletions src/zkey_beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default async function beacon(zkeyNameOld, zkeyNameNew, name, beaconHashS
return false;
}
if (beaconHash.length>=256) {
if (logger) logger.error("Maximum lenght of beacon hash is 255 bytes");
if (logger) logger.error("Maximum length of beacon hash is 255 bytes");
return false;
}

Expand Down Expand Up @@ -124,9 +124,9 @@ export default async function beacon(zkeyNameOld, zkeyNameNew, name, beaconHashS
const contributionHasher = Blake2b(64);
utils.hashPubKey(contributionHasher, curve, curContribution);

const contribuionHash = contributionHasher.digest();
const contributionHash = contributionHasher.digest();

if (logger) logger.info(misc.formatHash(contribuionHash, "Contribution Hash: "));
if (logger) logger.info(misc.formatHash(contributionHash, "Contribution Hash: "));

return contribuionHash;
return contributionHash;
}
10 changes: 5 additions & 5 deletions src/zkey_bellman_contribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { applyKeyToChallengeSection } from "./mpc_applykey.js";
import { hashPubKey } from "./zkey_utils.js";
import { hashToG2 as hashToG2 } from "./keypair.js";

export default async function bellmanContribute(curve, challengeFilename, responesFileName, entropy, logger) {
export default async function bellmanContribute(curve, challengeFilename, responseFileName, entropy, logger) {
await Blake2b.ready();

const rng = await misc.getRandomRng(entropy);
Expand All @@ -55,7 +55,7 @@ export default async function bellmanContribute(curve, challengeFilename, respon
const sG2 = curve.G2.F.n8*2;

const fdFrom = await fastFile.readExisting(challengeFilename);
const fdTo = await fastFile.createOverride(responesFileName);
const fdTo = await fastFile.createOverride(responseFileName);


await copy(sG1); // alpha1
Expand Down Expand Up @@ -110,9 +110,9 @@ export default async function bellmanContribute(curve, challengeFilename, respon
mpcParams.csHash = await fdFrom.read(64);
transcriptHasher.update(mpcParams.csHash);

const nConttributions = await fdFrom.readUBE32();
const nContributions = await fdFrom.readUBE32();
mpcParams.contributions = [];
for (let i=0; i<nConttributions; i++) {
for (let i=0; i<nContributions; i++) {
const c = { delta:{} };
c.deltaAfter = await readG1();
c.delta.g1_s = await readG1();
Expand All @@ -139,7 +139,7 @@ export default async function bellmanContribute(curve, challengeFilename, respon


//////////
/// Write COntribution
/// Write Contribution
//////////

await fdTo.write(mpcParams.csHash);
Expand Down
6 changes: 3 additions & 3 deletions src/zkey_contribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ export default async function phase2contribute(zkeyNameOld, zkeyNameNew, name, e
const contributionHasher = Blake2b(64);
utils.hashPubKey(contributionHasher, curve, curContribution);

const contribuionHash = contributionHasher.digest();
const contributionHash = contributionHasher.digest();

if (logger) logger.info(misc.formatHash(mpcParams.csHash, "Circuit Hash: "));
if (logger) logger.info(misc.formatHash(contribuionHash, "Contribution Hash: "));
if (logger) logger.info(misc.formatHash(contributionHash, "Contribution Hash: "));

return contribuionHash;
return contributionHash;
}
2 changes: 1 addition & 1 deletion src/zkey_export_bellman.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default async function phase2exportMPCParams(zkeyName, mpcparamsName, log
buffBasesH_Tau = await curve.G1.fft(buffBasesH_Lodd, "affine", "jacobian", logger);
buffBasesH_Tau = await curve.G1.batchApplyKey(buffBasesH_Tau, curve.Fr.neg(curve.Fr.e(2)), curve.Fr.w[zkey.power+1], "jacobian", "affine", logger);

// Remove last element. (The degree of H will be allways m-2)
// Remove last element. (The degree of H will be always m-2)
buffBasesH_Tau = buffBasesH_Tau.slice(0, buffBasesH_Tau.byteLength - sG1);
buffBasesH_Tau = await curve.G1.batchLEMtoU(buffBasesH_Tau);
await writePointArray("G1", buffBasesH_Tau);
Expand Down
10 changes: 5 additions & 5 deletions src/zkey_import_bellman.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export default async function phase2importMPCParams(zkeyNameOld, mpcparamsName,
// csHash
newMPCParams.csHash = await fdMPCParams.read(64);

const nConttributions = await fdMPCParams.readUBE32();
const nContributions = await fdMPCParams.readUBE32();
newMPCParams.contributions = [];
for (let i=0; i<nConttributions; i++) {
for (let i=0; i<nContributions; i++) {
const c = { delta:{} };
c.deltaAfter = await readG1(fdMPCParams);
c.delta.g1_s = await readG1(fdMPCParams);
Expand Down Expand Up @@ -85,13 +85,13 @@ export default async function phase2importMPCParams(zkeyNameOld, mpcparamsName,

for (let i=0; i<oldMPCParams.contributions.length; i++) {
if (!contributionIsEqual(oldMPCParams.contributions[i], newMPCParams.contributions[i])) {
if (logger) logger.error(`Previos contribution ${i} does not match`);
if (logger) logger.error(`Previous contribution ${i} does not match`);
return false;
}
}


// Set the same name to all new controbutions
// Set the same name to all new contributions
if (name) {
for (let i=oldMPCParams.contributions.length; i<newMPCParams.contributions.length; i++) {
newMPCParams.contributions[i].name = name;
Expand Down Expand Up @@ -144,7 +144,7 @@ export default async function phase2importMPCParams(zkeyNameOld, mpcparamsName,
await fdZKeyNew.write(buffH);
await binFileUtils.endWriteSection(fdZKeyNew);

// C Secion (L section)
// C Section (L section)
const nL = await fdMPCParams.readUBE32();
if (nL != (zkeyHeader.nVars-zkeyHeader.nPublic-1)) {
if (logger) logger.error("Invalid number of points in L");
Expand Down
2 changes: 1 addition & 1 deletion src/zkey_new.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export default async function newZKey(r1csName, ptauName, zkeyName, logger) {
if (cirPower < curve.Fr.s) {
let sTauG1 = await readSection(fdPTau, sectionsPTau, 12, (domainSize*2-1)*sG1, domainSize*2*sG1);
for (let i=0; i< domainSize; i++) {
if ((logger)&&(i%10000 == 0)) logger.debug(`spliting buffer: ${i}/${domainSize}`);
if ((logger)&&(i%10000 == 0)) logger.debug(`splitting buffer: ${i}/${domainSize}`);
const buff = sTauG1.slice( (i*2+1)*sG1, (i*2+1)*sG1 + sG1 );
buffOut.set(buff, i*sG1);
}
Expand Down
4 changes: 2 additions & 2 deletions src/zkey_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function writeZKey(fileName, zkey) {
const Rr = Scalar.mod(Scalar.shl(1, n8r*8), zkey.r);
const R2r = Scalar.mod(Scalar.mul(Rr,Rr), zkey.r);

// Write Pols (A and B (C can be ommited))
// Write Pols (A and B (C can be omitted))
///////////

zkey.ccoefs = zkey.ccoefs.filter(c => c.matrix<2);
Expand Down Expand Up @@ -479,7 +479,7 @@ async function readContribution(fd, curve, toObject) {
}
}
if (fd.pos != curPos + paramLength) {
throw new Error("Parametes do not match");
throw new Error("Parameters do not match");
}

return c;
Expand Down
Loading

0 comments on commit a4bef47

Please sign in to comment.