Browse Source

fast mode

feature/witness_bin
Jordi Baylina 5 years ago
parent
commit
534efcf355
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
7 changed files with 69 additions and 62 deletions
  1. +0
    -44
      circuit.json
  2. +2
    -1
      cli.js
  3. +48
    -7
      package-lock.json
  4. +1
    -1
      package.json
  5. +16
    -7
      src/compiler.js
  6. +1
    -1
      test/cases.js
  7. +1
    -1
      test/circuits/mixvarsignal.circom

+ 0
- 44
circuit.json

@ -1,44 +0,0 @@
{
"mainCode": "{\n}\n",
"signalName2Idx": {
"one": 0,
"main.out": 1
},
"components": [
{
"name": "main",
"params": {},
"template": "A",
"inputSignals": 0
}
],
"componentName2Idx": {
"main": 0
},
"signals": [
{
"names": [
"one"
],
"triggerComponents": []
},
{
"names": [
"main.out"
],
"triggerComponents": []
}
],
"constraints": [],
"templates": {
"A": "function(ctx) {\n ctx.setSignal(\"out\", [], \"3\");\n ctx.assert(ctx.getSignal(\"out\", []), \"3\");\n}\n"
},
"functions": {},
"nPrvInputs": 0,
"nPubInputs": 0,
"nInputs": 0,
"nOutputs": 0,
"nVars": 1,
"nConstants": 1,
"nSignals": 2
}

+ 2
- 1
cli.js

@ -35,6 +35,7 @@ const argv = require("yargs")
.help("h")
.alias("h", "help")
.alias("v", "verbose")
.alias("f", "fast")
.epilogue(`Copyright (C) 2018 0kims association
This program comes with ABSOLUTELY NO WARRANTY;
This is free software, and you are welcome to redistribute it
@ -56,7 +57,7 @@ if (argv._.length == 0) {
const fullFileName = path.resolve(process.cwd(), inputFile);
const outName = argv.output ? argv.output : "circuit.json";
compiler(fullFileName).then( (cir) => {
compiler(fullFileName, {reduceConstraints: !argv.fast}).then( (cir) => {
fs.writeFileSync(outName, JSON.stringify(cir, null, 1), "utf8");
process.exit(0);
}, (err) => {

+ 48
- 7
package-lock.json

@ -119,6 +119,15 @@
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.43.tgz",
"integrity": "sha512-9dULc9jsKmXl0Aeunug8wbF+58n+hQoFjqClN7WeZwGLh0XJUWyJJ9Ee+Ep+Ql/J9fRsTVaeThp8MhiCCrY0Jg=="
},
"bindings": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz",
"integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==",
"dev": true,
"requires": {
"file-uri-to-path": "1.0.0"
}
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -542,6 +551,12 @@
"flat-cache": "^2.0.1"
}
},
"file-uri-to-path": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
"integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==",
"dev": true
},
"find-up": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz",
@ -807,6 +822,18 @@
"nomnom": ">= 1.5.x"
}
},
"keccak": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/keccak/-/keccak-2.0.0.tgz",
"integrity": "sha512-rKe/lRr0KGhjoz97cwg+oeT1Rj/Y4cjae6glArioUC8JBF9ROGZctwIaaruM7d7naovME4Q8WcQSO908A8qcyQ==",
"dev": true,
"requires": {
"bindings": "^1.2.1",
"inherits": "^2.0.3",
"nan": "^2.2.1",
"safe-buffer": "^5.1.0"
}
},
"lcid": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz",
@ -920,6 +947,12 @@
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=",
"dev": true
},
"nan": {
"version": "2.14.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz",
"integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==",
"dev": true
},
"natural-compare": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz",
@ -1183,6 +1216,12 @@
"tslib": "^1.9.0"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
@ -1229,15 +1268,17 @@
}
},
"snarkjs": {
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.9.tgz",
"integrity": "sha512-UMiONT6f86bTB0AyT7bC+QsMgv2wwMk4qz7CYvTK6assojA4poEocJuEc5wl/awHsibQTbX2zNqqnO+IAYMfTA==",
"version": "0.1.14",
"resolved": "https://registry.npmjs.org/snarkjs/-/snarkjs-0.1.14.tgz",
"integrity": "sha512-mNsWx5K0ojz73689ZARwqyY62ENvW43movC+WMEHVYsFdcX9lpG+ZjiJGvnQh7LkYg2WY2lFzsXTUZI35TxqeA==",
"dev": true,
"requires": {
"big-integer": "^1.6.35",
"chai": "^4.1.2",
"eslint": "^5.3.0",
"yargs": "^12.0.2"
"big-integer": "^1.6.43",
"chai": "^4.2.0",
"escape-string-regexp": "^1.0.5",
"eslint": "^5.16.0",
"keccak": "^2.0.0",
"yargs": "^12.0.5"
}
},
"source-map": {

+ 1
- 1
package.json

@ -38,6 +38,6 @@
"eslint": "^5.16.0",
"eslint-plugin-mocha": "^5.3.0",
"jison": "^0.4.18",
"snarkjs": "0.1.9"
"snarkjs": "0.1.14"
}
}

+ 16
- 7
src/compiler.js

@ -33,7 +33,13 @@ const parser = require("../parser/jaz.js").parser;
const timeout = ms => new Promise(res => setTimeout(res, ms));
async function compile(srcFile) {
async function compile(srcFile, options) {
if (!options) {
options = {};
}
if (typeof options.reduceConstraints === "undefined") {
options.reduceConstraints = true;
}
const fullFileName = srcFile;
const fullFilePath = path.dirname(fullFileName);
@ -70,13 +76,16 @@ async function compile(srcFile) {
}
classifySignals(ctx);
reduceConstants(ctx);
// Repeat while reductions are performed
let oldNConstrains = -1;
while (ctx.constraints.length != oldNConstrains) {
oldNConstrains = ctx.constraints.length;
reduceConstrains(ctx);
if (options.reduceConstraints) {
reduceConstants(ctx);
// Repeat while reductions are performed
let oldNConstrains = -1;
while (ctx.constraints.length != oldNConstrains) {
oldNConstrains = ctx.constraints.length;
reduceConstrains(ctx);
}
}
generateWitnessNames(ctx);

+ 1
- 1
test/cases.js

@ -41,7 +41,7 @@ describe("Sum test", () => {
const witness = circuit.calculateWitness({ "i": 111});
assert(witness[0].equals(bigInt(1)));
assert(witness[1].equals(bigInt(111)));
assert(witness[1].equals(bigInt(111*111)));
assert(witness[2].equals(bigInt(111)));
});
// it("Should assign signal ERROR", async () => {

+ 1
- 1
test/circuits/mixvarsignal.circom

@ -8,7 +8,7 @@ template X() {
}
i === r;
out <== r;
out <== i*i;
}
component main = X();

Loading…
Cancel
Save