Verbose added
Jordi Baylina jordi@baylina.cat
Sun, 22 Sep 2019 12:56:05 +0200
4 files changed,
19 insertions(+),
79 deletions(-)
M
cli.js
→
cli.js
@@ -34,8 +34,16 @@ .usage("circom [input source circuit file] -o [output definition circuit file]")
.alias("o", "output") .help("h") .alias("h", "help") - .alias("v", "verbose") - .alias("f", "fast") + .option("verbose", { + alias: "v", + type: "boolean", + description: "Run with verbose logging" + }) + .option("fast", { + alias: "f", + type: "boolean", + description: "Do not optimize constraints" + }) .epilogue(`Copyright (C) 2018 0kims association This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it@@ -57,7 +65,7 @@
const fullFileName = path.resolve(process.cwd(), inputFile); const outName = argv.output ? argv.output : "circuit.json"; -compiler(fullFileName, {reduceConstraints: !argv.fast}).then( (cir) => { +compiler(fullFileName, {reduceConstraints: !argv.fast, verbose: argv.verbose}).then( (cir) => { fs.writeFileSync(outName, JSON.stringify(cir, null, 1), "utf8"); process.exit(0); }, (err) => {
M
src/compiler.js
→
src/compiler.js
@@ -65,7 +65,8 @@ templates: {},
functions: {}, functionParams: {}, filePath: fullFilePath, - fileName: fullFileName + fileName: fullFileName, + verbose: options.verbose || false };@@ -75,8 +76,10 @@ if (!ctx.components["main"]) {
throw new Error("A main component must be defined"); } + if (ctx.verbose) console.log("Classify Signals"); classifySignals(ctx); + if (ctx.verbose) console.log("Reduce Constraints"); reduceConstants(ctx); if (options.reduceConstraints) {@@ -217,6 +220,7 @@
function reduceConstants(ctx) { const newConstraints = []; for (let i=0; i<ctx.constraints.length; i++) { + if ((ctx.verbose)&&(i%10000 == 0)) console.log("reducing constants: ", i); const c = lc.canonize(ctx, ctx.constraints[i]); if (!lc.isZero(c)) { newConstraints.push(c);@@ -231,6 +235,7 @@ let possibleConstraints = Object.keys(ctx.constraints);
while (possibleConstraints.length>0) { let nextPossibleConstraints = {}; for (let i in possibleConstraints) { + if ((ctx.verbose)&&(i%10000 == 0)) console.log("reducing constraints: ", i); if (!ctx.constraints[i]) continue; const c = ctx.constraints[i];
M
src/exec.js
→
src/exec.js
@@ -1075,6 +1075,8 @@ if (!lc.isZero(res)) {
ctx.constraints.push(lc.toQEQ(res)); } + if (ctx.constraints.length % 10000 == 0) console.log("Constraints: " + ctx.constraints.length); + return res; }
D
test/circuits/circuit.json
@@ -1,75 +0,0 @@
-{ - "mainCode": "{\n}\n", - "signalName2Idx": { - "one": 0, - "main.in": 2, - "main.out": 1, - "main.internal.in": 2, - "main.internal.out": 2 - }, - "components": [ - { - "name": "main", - "params": {}, - "template": "InOut", - "inputSignals": 1 - }, - { - "name": "main.internal", - "params": {}, - "template": "Internal", - "inputSignals": 1 - } - ], - "componentName2Idx": { - "main": 0, - "main.internal": 1 - }, - "signals": [ - { - "names": [ - "one" - ], - "triggerComponents": [] - }, - { - "names": [ - "main.out" - ], - "triggerComponents": [] - }, - { - "names": [ - "main.in", - "main.internal.in", - "main.internal.out" - ], - "triggerComponents": [ - 0, - 1 - ] - } - ], - "constraints": [ - [ - {}, - {}, - { - "1": "21888242871839275222246405745257275088548364400416034343698204186575808495616", - "2": "1" - } - ] - ], - "templates": { - "Internal": "function(ctx) {\n ctx.setSignal(\"out\", [], ctx.getSignal(\"in\", []));\n}\n", - "InOut": "function(ctx) {\n ctx.setPin(\"internal\", [], \"in\", [], ctx.getSignal(\"in\", []));\n ctx.setSignal(\"out\", [], ctx.getPin(\"internal\", [], \"out\", []));\n}\n" - }, - "functions": {}, - "nPrvInputs": 0, - "nPubInputs": 1, - "nInputs": 1, - "nOutputs": 1, - "nVars": 3, - "nConstants": 0, - "nSignals": 3 -}