From 5c514a897bc88887ead428a1e3f9bd7d528b61b1 Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Mon, 22 Oct 2018 08:34:49 +0200 Subject: [PATCH] info and print constraints added --- cli.js | 44 ++++++++++++++++++++++++++++++++++++++++++-- src/circuit.js | 22 ++++++++++++++++++---- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/cli.js b/cli.js index 8fa4b51..0428de1 100644 --- a/cli.js +++ b/cli.js @@ -183,7 +183,31 @@ generate call parameters Default: public.json +circuit info +============ + snarkjs info + + Print statistics of a circuit + + -c or --circuit + + Filename of the compiled circuit file generated by circom. + + Default: circuit.json + +print constraints +================= + + snarkjs printconstraints + + Print all the constraints of a given circuit + + -c or --circuit + + Filename of the compiled circuit file generated by circom. + + Default: circuit.json `) .alias("c", "circuit") .alias("pk", "provingkey") @@ -219,7 +243,23 @@ function p256(n) { } try { - if (argv._[0].toUpperCase() == "SETUP") { + if (argv._[0].toUpperCase() == "INFO") { + const cirDef = JSON.parse(fs.readFileSync(circuitName, "utf8")); + const cir = new zkSnark.Circuit(cirDef); + + console.log(`# Wires: ${cir.nVars}`); + console.log(`# Constraints: ${cir.nConstraints}`); + console.log(`# Private Inputs: ${cir.nPrvInputs}`); + console.log(`# Public Inputs: ${cir.nPubInputs}`); + console.log(`# Outputs: ${cir.nOutputs}`); + + } else if (argv._[0].toUpperCase() == "PRINTCONSTRAINTS") { + const cirDef = JSON.parse(fs.readFileSync(circuitName, "utf8")); + const cir = new zkSnark.Circuit(cirDef); + + cir.printConstraints(); + + } else if (argv._[0].toUpperCase() == "SETUP") { const cirDef = JSON.parse(fs.readFileSync(circuitName, "utf8")); const cir = new zkSnark.Circuit(cirDef); const setup = zkSnark.setup(cir); @@ -322,7 +362,7 @@ try { const public = unstringifyBigInts(JSON.parse(fs.readFileSync(publicName, "utf8"))); const proof = unstringifyBigInts(JSON.parse(fs.readFileSync(proofName, "utf8"))); - inputs = ""; + let inputs = ""; for (let i=0; i { let S = ""; for (let k in lc) { - const name = this.signals[k].names[0]; + let name = this.signals[k].names[0]; + if (name == "one") name = ""; let v = bigInt(lc[k]); let vs; if (!v.lesserOrEquals(__P__.shr(bigInt(1)))) { v = __P__.sub(v); vs = "-"+v.toString(); } else { - vs = "+"+v.toString(); + if (S!="") { + vs = "+"+v.toString(); + } else { + vs = ""; + } + if (vs!="1") { + vs = vs + v.toString();; + } } S= S + " " + vs + name; } return S; - } - const S = `[ ${lc2str(c[0])} ] * [ ${lc2str(c[1])} ] - [ ${lc2str(c[2])} ]`; + }; + const S = `[ ${lc2str(c[0])} ] * [ ${lc2str(c[1])} ] - [ ${lc2str(c[2])} ] = 0`; console.log(S); } + printConstraints() { + for (let i=0; i