Browse Source

Verbose added

feature/witness_bin
Jordi Baylina 5 years ago
parent
commit
51ff27b9c6
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
4 changed files with 19 additions and 79 deletions
  1. +11
    -3
      cli.js
  2. +6
    -1
      src/compiler.js
  3. +2
    -0
      src/exec.js
  4. +0
    -75
      test/circuits/circuit.json

+ 11
- 3
cli.js

@ -34,8 +34,16 @@ const argv = require("yargs")
.alias("o", "output") .alias("o", "output")
.help("h") .help("h")
.alias("h", "help") .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 .epilogue(`Copyright (C) 2018 0kims association
This program comes with ABSOLUTELY NO WARRANTY; This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it 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 fullFileName = path.resolve(process.cwd(), inputFile);
const outName = argv.output ? argv.output : "circuit.json"; 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"); fs.writeFileSync(outName, JSON.stringify(cir, null, 1), "utf8");
process.exit(0); process.exit(0);
}, (err) => { }, (err) => {

+ 6
- 1
src/compiler.js

@ -65,7 +65,8 @@ async function compile(srcFile, options) {
functions: {}, functions: {},
functionParams: {}, functionParams: {},
filePath: fullFilePath, 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"); throw new Error("A main component must be defined");
} }
if (ctx.verbose) console.log("Classify Signals");
classifySignals(ctx); classifySignals(ctx);
if (ctx.verbose) console.log("Reduce Constraints");
reduceConstants(ctx); reduceConstants(ctx);
if (options.reduceConstraints) { if (options.reduceConstraints) {
@ -217,6 +220,7 @@ function generateWitnessNames(ctx) {
function reduceConstants(ctx) { function reduceConstants(ctx) {
const newConstraints = []; const newConstraints = [];
for (let i=0; i<ctx.constraints.length; i++) { 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]); const c = lc.canonize(ctx, ctx.constraints[i]);
if (!lc.isZero(c)) { if (!lc.isZero(c)) {
newConstraints.push(c); newConstraints.push(c);
@ -231,6 +235,7 @@ function reduceConstrains(ctx) {
while (possibleConstraints.length>0) { while (possibleConstraints.length>0) {
let nextPossibleConstraints = {}; let nextPossibleConstraints = {};
for (let i in possibleConstraints) { for (let i in possibleConstraints) {
if ((ctx.verbose)&&(i%10000 == 0)) console.log("reducing constraints: ", i);
if (!ctx.constraints[i]) continue; if (!ctx.constraints[i]) continue;
const c = ctx.constraints[i]; const c = ctx.constraints[i];

+ 2
- 0
src/exec.js

@ -1075,6 +1075,8 @@ function execConstrain(ctx, ast) {
ctx.constraints.push(lc.toQEQ(res)); ctx.constraints.push(lc.toQEQ(res));
} }
if (ctx.constraints.length % 10000 == 0) console.log("Constraints: " + ctx.constraints.length);
return res; return res;
} }

+ 0
- 75
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
}

Loading…
Cancel
Save