arnaucube
arnaucube/snarkjsPublic Self-hosted repository
info and print constraints added
Jordi Baylina jordi@baylina.cat
Mon, 22 Oct 2018 08:34:49 +0200
commit

5c514a897bc88887ead428a1e3f9bd7d528b61b1

parent

9b2fd3b0ab8f5ce2f41e86f5afeef676495a603b

2 files changed, 60 insertions(+), 6 deletions(-)

jump to
M cli.js → cli.js

@@ -183,7 +183,31 @@ Input filename with the public wires/signals.

Default: public.json +circuit info +============ + + snarkjs info <options> + + Print statistics of a circuit + + -c or --circuit <circuitFile> + + Filename of the compiled circuit file generated by circom. + + Default: circuit.json + +print constraints +================= + + snarkjs printconstraints <options> + + Print all the constraints of a given circuit + + -c or --circuit <circuitFile> + Filename of the compiled circuit file generated by circom. + + Default: circuit.json `) .alias("c", "circuit") .alias("pk", "provingkey")

@@ -219,7 +243,23 @@ return nstr;

} 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 @@

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<public.length; i++) { if (inputs != "") inputs = inputs + ","; inputs = inputs + p256(public[i]);
M src/circuit.js → src/circuit.js

@@ -93,22 +93,36 @@ printCostraint(c) {

const lc2str = (lc) => { 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])} ] = 0`; + console.log(S); + } + + printConstraints() { + for (let i=0; i<this.constraints.length; i++) { + this.printCostraint(this.constraints[i]); } - const S = `[ ${lc2str(c[0])} ] * [ ${lc2str(c[1])} ] - [ ${lc2str(c[2])} ]`; - console.log(S); } getSignalIdx(name) {