Browse Source

info and print constraints added

master
Jordi Baylina 6 years ago
parent
commit
5c514a897b
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
2 changed files with 60 additions and 6 deletions
  1. +42
    -2
      cli.js
  2. +18
    -4
      src/circuit.js

+ 42
- 2
cli.js

@ -183,7 +183,31 @@ generate call parameters
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 @@ 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<public.length; i++) {
if (inputs != "") inputs = inputs + ",";
inputs = inputs + p256(public[i]);

+ 18
- 4
src/circuit.js

@ -93,24 +93,38 @@ module.exports = class Circuit {
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])} ]`;
};
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]);
}
}
getSignalIdx(name) {
if (typeof(this.signalName2Idx[name]) != "undefined") return this.signalName2Idx[name];
if (!isNaN(name)) return Number(name);

Loading…
Cancel
Save