From 51ff27b9c6695b3dad1a3c8181b67211940a4ef3 Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Sun, 22 Sep 2019 12:56:05 +0200 Subject: [PATCH] Verbose added --- cli.js | 14 +++++-- src/compiler.js | 7 +++- src/exec.js | 2 + test/circuits/circuit.json | 75 -------------------------------------- 4 files changed, 19 insertions(+), 79 deletions(-) delete mode 100644 test/circuits/circuit.json diff --git a/cli.js b/cli.js index 5e1d34d..3aec47b 100755 --- a/cli.js +++ b/cli.js @@ -34,8 +34,16 @@ const argv = require("yargs") .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 @@ if (argv._.length == 0) { 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) => { diff --git a/src/compiler.js b/src/compiler.js index 91052c0..9c5c331 100644 --- a/src/compiler.js +++ b/src/compiler.js @@ -65,7 +65,8 @@ async function compile(srcFile, options) { functions: {}, functionParams: {}, filePath: fullFilePath, - fileName: fullFileName + fileName: fullFileName, + verbose: options.verbose || false }; @@ -75,8 +76,10 @@ async function compile(srcFile, options) { 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 generateWitnessNames(ctx) { function reduceConstants(ctx) { const newConstraints = []; for (let i=0; i0) { 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]; diff --git a/src/exec.js b/src/exec.js index 1c38159..92e6a7c 100644 --- a/src/exec.js +++ b/src/exec.js @@ -1075,6 +1075,8 @@ function execConstrain(ctx, ast) { ctx.constraints.push(lc.toQEQ(res)); } + if (ctx.constraints.length % 10000 == 0) console.log("Constraints: " + ctx.constraints.length); + return res; } diff --git a/test/circuits/circuit.json b/test/circuits/circuit.json deleted file mode 100644 index c0636c4..0000000 --- a/test/circuits/circuit.json +++ /dev/null @@ -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 -} \ No newline at end of file