@ -0,0 +1,58 @@ |
|||
#!/usr/bin/env node
|
|||
|
|||
/* |
|||
Copyright 2018 0kims association |
|||
|
|||
This file is part of jaz (Zero Knowlage Circuit compiler). |
|||
|
|||
jaz is free software: you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation, either version 3 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
jaz is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with jaz. If not, see <https://www.gnu.org/licenses/>.
|
|||
*/ |
|||
|
|||
/* eslint-disable no-console */ |
|||
|
|||
const fs = require("fs"); |
|||
const path = require("path"); |
|||
|
|||
const compiler = require("./src/compiler"); |
|||
|
|||
const argv = require("yargs") |
|||
.version(function() { |
|||
return require("./package").version; |
|||
}) |
|||
.usage("jaz -s [input source circuit file] -o [output definition circuit file]") |
|||
.alias("s", "source") |
|||
.alias("o", "output") |
|||
.require(["s","o"]) |
|||
.help("h") |
|||
.alias("h", "help") |
|||
.epilogue(`Copyright (C) 2018 0kims association
|
|||
This program comes with ABSOLUTELY NO WARRANTY; |
|||
This is free software, and you are welcome to redistribute it |
|||
under certain conditions; see the COPYING file in the official |
|||
repo directory at https://github.com/iden3/jaz `)
|
|||
.argv; |
|||
|
|||
const fullFileName = path.resolve(process.cwd(), argv.source); |
|||
|
|||
compiler(fullFileName).then( (cir) => { |
|||
fs.writeFileSync(argv.output, JSON.stringify(cir, null, 1), "utf8"); |
|||
}, (err) => { |
|||
console.error(`ERROR at ${err.errFile}:${err.pos.first_line},${err.pos.first_column}-${err.pos.last_line},${err.pos.last_column} ${err.errStr}`); |
|||
console.error(JSON.stringify(err.ast, null, 1)); |
|||
process.exit(1); |
|||
}); |
|||
|
|||
|
|||
|
|||
|
@ -1,290 +0,0 @@ |
|||
{ |
|||
"mainCode": "{\n {\n }\n}\n", |
|||
"signalName2Idx": { |
|||
"one": 0, |
|||
"main.in": 1, |
|||
"main.h0.out[0]": 2, |
|||
"main.h0.out[1]": 3, |
|||
"main.h0.out[2]": 4, |
|||
"main.h0.out[3]": 5, |
|||
"main.h0.out[4]": 6, |
|||
"main.h0.out[5]": 7, |
|||
"main.h0.out[6]": 8, |
|||
"main.h0.out[7]": 9, |
|||
"main.h0.out[8]": 10, |
|||
"main.h0.out[9]": 11, |
|||
"main.h0.out[10]": 12, |
|||
"main.h0.out[11]": 13, |
|||
"main.h0.out[12]": 14, |
|||
"main.h0.out[13]": 15, |
|||
"main.h0.out[14]": 16, |
|||
"main.h0.out[15]": 17, |
|||
"main.h0.out[16]": 18, |
|||
"main.h0.out[17]": 19, |
|||
"main.h0.out[18]": 20, |
|||
"main.h0.out[19]": 21, |
|||
"main.h0.out[20]": 22, |
|||
"main.h0.out[21]": 23, |
|||
"main.h0.out[22]": 24, |
|||
"main.h0.out[23]": 25, |
|||
"main.h0.out[24]": 26, |
|||
"main.h0.out[25]": 27, |
|||
"main.h0.out[26]": 28, |
|||
"main.h0.out[27]": 29, |
|||
"main.h0.out[28]": 30, |
|||
"main.h0.out[29]": 31, |
|||
"main.h0.out[30]": 32, |
|||
"main.h0.out[31]": 33 |
|||
}, |
|||
"components": [ |
|||
{ |
|||
"name": "main", |
|||
"params": {}, |
|||
"template": "A", |
|||
"inputSignals": 1 |
|||
}, |
|||
{ |
|||
"name": "main.h0", |
|||
"params": { |
|||
"x": "8" |
|||
}, |
|||
"template": "K", |
|||
"inputSignals": 0 |
|||
} |
|||
], |
|||
"componentName2Idx": { |
|||
"main": 0, |
|||
"main.h0": 1 |
|||
}, |
|||
"signals": [ |
|||
{ |
|||
"names": [ |
|||
"one" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.in" |
|||
], |
|||
"triggerComponents": [ |
|||
0 |
|||
] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[0]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[1]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[2]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[3]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[4]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[5]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[6]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[7]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[8]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[9]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[10]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[11]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[12]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[13]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[14]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[15]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[16]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[17]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[18]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[19]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[20]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[21]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[22]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[23]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[24]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[25]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[26]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[27]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[28]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[29]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[30]" |
|||
], |
|||
"triggerComponents": [] |
|||
}, |
|||
{ |
|||
"names": [ |
|||
"main.h0.out[31]" |
|||
], |
|||
"triggerComponents": [] |
|||
} |
|||
], |
|||
"constrains": [ |
|||
[ |
|||
{}, |
|||
{}, |
|||
{ |
|||
"0": "21888242871839275222246405745257275088548364400416034343698204186572184114537", |
|||
"1": "1" |
|||
} |
|||
] |
|||
], |
|||
"templates": { |
|||
"H": "function(ctx) {\n ctx.setVar(\"c\", [], [\"1779033703\",\"3144134277\",\"1013904242\",\"2773480762\",\"1359893119\",\"2600822924\",\"528734635\",\"1541459225\"]);\n for (ctx.setVar(\"i\", [], \"0\");bigInt(ctx.getVar(\"i\",[])).lt(bigInt(\"32\")) ? 1 : 0;(ctx.setVar(\"i\", [], bigInt(ctx.getVar(\"i\",[])).add(bigInt(\"1\")).mod(__P__))).add(__P__).sub(bigInt(1)).mod(__P__))\n {\n ctx.setSignal(\"out\", [ctx.getVar(\"i\",[])], bigInt(bigInt(ctx.getVar(\"i\",[])).greater(bigInt(256)) ? 0 : bigInt(ctx.getVar(\"c\",[ctx.getVar(\"x\",[])])).shr(bigInt(ctx.getVar(\"i\",[]))).and(__MASK__)).and(bigInt(\"1\")).and(__MASK__));\n ctx.assert(ctx.getSignal(\"out\", [ctx.getVar(\"i\",[])]), bigInt(bigInt(ctx.getVar(\"i\",[])).greater(bigInt(256)) ? 0 : bigInt(ctx.getVar(\"c\",[ctx.getVar(\"x\",[])])).shr(bigInt(ctx.getVar(\"i\",[]))).and(__MASK__)).and(bigInt(\"1\")).and(__MASK__));\n }\n}\n", |
|||
"K": "function(ctx) {\n ctx.setVar(\"c\", [], [\"1116352408\",\"1899447441\",\"3049323471\",\"3921009573\",\"961987163\",\"1508970993\",\"2453635748\",\"2870763221\",\"3624381080\",\"310598401\",\"607225278\",\"1426881987\",\"1925078388\",\"2162078206\",\"2614888103\",\"3248222580\",\"3835390401\",\"4022224774\",\"264347078\",\"604807628\",\"770255983\",\"1249150122\",\"1555081692\",\"1996064986\",\"2554220882\",\"2821834349\",\"2952996808\",\"3210313671\",\"3336571891\",\"3584528711\",\"113926993\",\"338241895\",\"666307205\",\"773529912\",\"1294757372\",\"1396182291\",\"1695183700\",\"1986661051\",\"2177026350\",\"2456956037\",\"2730485921\",\"2820302411\",\"3259730800\",\"3345764771\",\"3516065817\",\"3600352804\",\"4094571909\",\"275423344\",\"430227734\",\"506948616\",\"659060556\",\"883997877\",\"958139571\",\"1322822218\",\"1537002063\",\"1747873779\",\"1955562222\",\"2024104815\",\"2227730452\",\"2361852424\",\"2428436474\",\"2756734187\",\"3204031479\",\"3329325298\"]);\n for (ctx.setVar(\"i\", [], \"0\");bigInt(ctx.getVar(\"i\",[])).lt(bigInt(\"32\")) ? 1 : 0;(ctx.setVar(\"i\", [], bigInt(ctx.getVar(\"i\",[])).add(bigInt(\"1\")).mod(__P__))).add(__P__).sub(bigInt(1)).mod(__P__))\n {\n ctx.setSignal(\"out\", [ctx.getVar(\"i\",[])], bigInt(bigInt(ctx.getVar(\"i\",[])).greater(bigInt(256)) ? 0 : bigInt(ctx.getVar(\"c\",[ctx.getVar(\"x\",[])])).shr(bigInt(ctx.getVar(\"i\",[]))).and(__MASK__)).and(bigInt(\"1\")).and(__MASK__));\n ctx.assert(ctx.getSignal(\"out\", [ctx.getVar(\"i\",[])]), bigInt(bigInt(ctx.getVar(\"i\",[])).greater(bigInt(256)) ? 0 : bigInt(ctx.getVar(\"c\",[ctx.getVar(\"x\",[])])).shr(bigInt(ctx.getVar(\"i\",[]))).and(__MASK__)).and(bigInt(\"1\")).and(__MASK__));\n }\n}\n", |
|||
"A": "function(ctx) {\n ctx.setVar(\"lc\", [], \"0\");\n ctx.setVar(\"e\", [], \"1\");\n for (ctx.setVar(\"i\", [], \"0\");bigInt(ctx.getVar(\"i\",[])).lt(bigInt(\"32\")) ? 1 : 0;(ctx.setVar(\"i\", [], bigInt(ctx.getVar(\"i\",[])).add(bigInt(\"1\")).mod(__P__))).add(__P__).sub(bigInt(1)).mod(__P__))\n {\n ctx.setVar(\"lc\", [], bigInt(ctx.getVar(\"lc\",[])).add(bigInt(bigInt(ctx.getVar(\"e\",[])).mul(bigInt(ctx.getPin(\"h0\", [], \"out\", [ctx.getVar(\"i\",[])]))).mod(__P__))).mod(__P__));\n ctx.setVar(\"e\", [], bigInt(ctx.getVar(\"e\",[])).mul(bigInt(\"2\")).mod(__P__));\n }\n ctx.assert(ctx.getVar(\"lc\",[]), ctx.getSignal(\"in\", []));\n}\n" |
|||
}, |
|||
"functions": {}, |
|||
"nPrvInputs": 0, |
|||
"nPubInputs": 1, |
|||
"nInputs": 1, |
|||
"nOutputs": 0, |
|||
"nVars": 2, |
|||
"nConstants": 32, |
|||
"nSignals": 34 |
|||
} |
@ -1,3 +0,0 @@ |
|||
{ |
|||
"inp": "3" |
|||
} |
@ -1,3 +0,0 @@ |
|||
{ |
|||
"in": "10" |
|||
} |
@ -1,4 +0,0 @@ |
|||
{ |
|||
"s1": "24", |
|||
"s2": "1" |
|||
} |
@ -1,27 +0,0 @@ |
|||
{ |
|||
"inp[0][0]": 100, |
|||
"inp[0][1]": 101, |
|||
"inp[0][2]": 102, |
|||
"inp[0][3]": 103, |
|||
"inp[0][4]": 104, |
|||
"inp[0][5]": 105, |
|||
"inp[0][6]": 106, |
|||
"inp[0][7]": 107, |
|||
"inp[1][0]": 110, |
|||
"inp[1][1]": 111, |
|||
"inp[1][2]": 112, |
|||
"inp[1][3]": 113, |
|||
"inp[1][4]": 114, |
|||
"inp[1][5]": 115, |
|||
"inp[1][6]": 116, |
|||
"inp[1][7]": 117, |
|||
"inp[2][0]": 120, |
|||
"inp[2][1]": 121, |
|||
"inp[2][2]": 122, |
|||
"inp[2][3]": 123, |
|||
"inp[2][4]": 124, |
|||
"inp[2][5]": 125, |
|||
"inp[2][6]": 126, |
|||
"inp[2][7]": 127, |
|||
"sel": 1 |
|||
} |
@ -1,154 +0,0 @@ |
|||
const bigInt = require("big-integer"); |
|||
const __P__ = new bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583"); |
|||
const __MASK__ = new bigInt(2).pow(253).minus(1); |
|||
const circuit = {}; |
|||
module.exports = circuit; |
|||
|
|||
circuit.signals={ |
|||
"one": { |
|||
"fullName": "one", |
|||
"value": "1", |
|||
"equivalence": "", |
|||
"direction": "", |
|||
"id": 0 |
|||
}, |
|||
"main.s1": { |
|||
"fullName": "main.s1", |
|||
"direction": "IN", |
|||
"component": "main", |
|||
"equivalence": "", |
|||
"alias": [ |
|||
"main.s1" |
|||
], |
|||
"id": 1 |
|||
}, |
|||
"main.s2": { |
|||
"fullName": "main.s2", |
|||
"direction": "IN", |
|||
"component": "main", |
|||
"equivalence": "", |
|||
"alias": [ |
|||
"main.s2" |
|||
], |
|||
"id": 2 |
|||
}, |
|||
"main.s3": { |
|||
"fullName": "main.s3", |
|||
"direction": "OUT", |
|||
"component": "main", |
|||
"equivalence": "", |
|||
"alias": [ |
|||
"main.s3" |
|||
], |
|||
"id": 3 |
|||
} |
|||
}; |
|||
|
|||
circuit.components={ |
|||
"main": { |
|||
"signals": [ |
|||
"main.s1", |
|||
"main.s2", |
|||
"main.s3" |
|||
], |
|||
"params": {}, |
|||
"template": "AND", |
|||
"inputSignals": 2 |
|||
} |
|||
}; |
|||
|
|||
circuit.signalConstrains=[ |
|||
{ |
|||
"type": "QEQ", |
|||
"a": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.s1": "21888242871839275222246405745257275088696311157297823662689037894645226208582" |
|||
} |
|||
}, |
|||
"b": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.s2": "1" |
|||
} |
|||
}, |
|||
"c": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.s3": "1" |
|||
} |
|||
} |
|||
}, |
|||
{ |
|||
"type": "QEQ", |
|||
"a": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.s1": "1" |
|||
} |
|||
}, |
|||
"b": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.s1": "1", |
|||
"one": "21888242871839275222246405745257275088696311157297823662689037894645226208582" |
|||
} |
|||
}, |
|||
"c": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": {} |
|||
} |
|||
}, |
|||
{ |
|||
"type": "QEQ", |
|||
"a": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.s2": "1" |
|||
} |
|||
}, |
|||
"b": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.s2": "1", |
|||
"one": "21888242871839275222246405745257275088696311157297823662689037894645226208582" |
|||
} |
|||
}, |
|||
"c": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": {} |
|||
} |
|||
} |
|||
]; |
|||
|
|||
circuit.witnessNames=[ |
|||
[ |
|||
"one" |
|||
], |
|||
[ |
|||
"main.s1" |
|||
], |
|||
[ |
|||
"main.s2" |
|||
], |
|||
[ |
|||
"main.s3" |
|||
] |
|||
]; |
|||
|
|||
{ |
|||
} |
|||
|
|||
circuit.templates = {}; |
|||
|
|||
circuit.templates["AND"] = function(ctx) { |
|||
ctx.setSignal("s3", [], bigInt(ctx.getSignal("s1", [])).times(ctx.getSignal("s2", [])).mod(__P__)); |
|||
ctx.assert(ctx.getSignal("s3", []), bigInt(ctx.getSignal("s1", [])).times(ctx.getSignal("s2", [])).mod(__P__)); |
|||
ctx.assert(bigInt(ctx.getSignal("s1", [])).times(bigInt(ctx.getSignal("s1", [])).add(__P__).minus("1").mod(__P__)).mod(__P__), "0"); |
|||
ctx.assert(bigInt(ctx.getSignal("s2", [])).times(bigInt(ctx.getSignal("s2", [])).add(__P__).minus("1").mod(__P__)).mod(__P__), "0"); |
|||
} |
|||
; |
|||
circuit.functionParams={}; |
|||
|
|||
|
|||
circuit.functions = {}; |
@ -1 +0,0 @@ |
|||
["1","0","1","0"] |
@ -1 +0,0 @@ |
|||
["1","100","101","102","103","104","105","106","107","110","111","112","113","114","115","116","117","120","121","122","123","124","125","126","127","1","110","111","112","113","114","115","116","117","0","1","0","1","0","110","0","0","111","0","0","112","0","0","113","0","0","114","0","0","115","0","0","116","0","0","117","0"] |
@ -1 +0,0 @@ |
|||
["1","10","0","1","0","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"] |
@ -1 +0,0 @@ |
|||
["1","3624381080","3624381080","0","0","0","1","1","0","0","1","0","1","0","1","0","1","0","1","1","1","1","0","0","0","0","0","0","0","0","1","1","0","1","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"] |
@ -1,27 +0,0 @@ |
|||
/* eslint-disable no-console */ |
|||
|
|||
const fs = require("fs"); |
|||
const path = require("path"); |
|||
|
|||
const compiler = require("./compiler"); |
|||
|
|||
const argv = require("yargs") |
|||
.usage("jaz -s [input source circuit file] -o [output definition circuit file]") |
|||
.alias("s", "source") |
|||
.alias("o", "output") |
|||
.require(["s","o"]) |
|||
.argv; |
|||
|
|||
const fullFileName = path.resolve(process.cwd(), argv.source); |
|||
|
|||
compiler(fullFileName).then( (cir) => { |
|||
fs.writeFileSync(argv.output, JSON.stringify(cir, null, 1), "utf8"); |
|||
}, (err) => { |
|||
console.error(`ERROR at ${err.errFile}:${err.pos.first_line},${err.pos.first_column}-${err.pos.last_line},${err.pos.last_column} ${err.errStr}`); |
|||
console.error(JSON.stringify(err.ast, null, 1)); |
|||
process.exit(1); |
|||
}); |
|||
|
|||
|
|||
|
|||
|
@ -1,27 +0,0 @@ |
|||
const fs = require("fs"); |
|||
const path = require("path"); |
|||
|
|||
const calculateWitness = require("./calculateWitness.js"); |
|||
|
|||
const argv = require("optimist") |
|||
.alias("i", "input") |
|||
.alias("o", "output") |
|||
.alias("c", "circuit") |
|||
.argv; |
|||
|
|||
const circuit = require(path.resolve(argv.circuit)); |
|||
|
|||
const inputSignals = JSON.parse(fs.readFileSync(argv.input, "utf8")); |
|||
|
|||
try { |
|||
const w = calculateWitness(circuit, inputSignals); |
|||
fs.writeFileSync(argv.output, JSON.stringify(w), "utf8"); |
|||
} catch(err) { |
|||
console.log("ERROR: " + err); |
|||
console.log(err.stack); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
@ -1 +0,0 @@ |
|||
["1","111","222","333","1","1","1","1","0","1","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1","1","1","1","0","1","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","1","0","1","1","0","0","1","0","1","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0","0"] |
@ -1 +0,0 @@ |
|||
a[1][2].b[3][4] <== c[5][6].d[7][8] |
@ -1,189 +0,0 @@ |
|||
const bigInt = require("big-integer"); |
|||
const __P__ = new bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583"); |
|||
const __MASK__ = new bigInt(2).pow(253).minus(1); |
|||
const circuit = {}; |
|||
module.exports = circuit; |
|||
|
|||
circuit.signals={ |
|||
"one": { |
|||
"fullName": "one", |
|||
"value": "1", |
|||
"equivalence": "", |
|||
"direction": "", |
|||
"id": 0 |
|||
}, |
|||
"main.inp": { |
|||
"fullName": "main.inp", |
|||
"direction": "IN", |
|||
"component": "main", |
|||
"equivalence": "", |
|||
"alias": [ |
|||
"main.inp" |
|||
], |
|||
"id": 1 |
|||
}, |
|||
"main.out[0]": { |
|||
"fullName": "main.out[0]", |
|||
"direction": "OUT", |
|||
"component": "main", |
|||
"equivalence": "", |
|||
"alias": [ |
|||
"main.out[0]" |
|||
], |
|||
"id": 2 |
|||
}, |
|||
"main.out[1]": { |
|||
"fullName": "main.out[1]", |
|||
"direction": "OUT", |
|||
"component": "main", |
|||
"equivalence": "", |
|||
"alias": [ |
|||
"main.out[1]" |
|||
], |
|||
"id": 3 |
|||
}, |
|||
"main.out[2]": { |
|||
"fullName": "main.out[2]", |
|||
"direction": "OUT", |
|||
"component": "main", |
|||
"equivalence": "", |
|||
"alias": [ |
|||
"main.out[2]" |
|||
], |
|||
"id": 4 |
|||
} |
|||
}; |
|||
|
|||
circuit.components={ |
|||
"main": { |
|||
"signals": [ |
|||
"main.inp", |
|||
"main.out[0]", |
|||
"main.out[1]", |
|||
"main.out[2]" |
|||
], |
|||
"params": { |
|||
"n": "3" |
|||
}, |
|||
"template": "toBin", |
|||
"inputSignals": 1 |
|||
} |
|||
}; |
|||
|
|||
circuit.signalConstrains=[ |
|||
{ |
|||
"type": "QEQ", |
|||
"a": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.out[0]": "1" |
|||
} |
|||
}, |
|||
"b": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.out[0]": "1", |
|||
"one": "21888242871839275222246405745257275088696311157297823662689037894645226208582" |
|||
} |
|||
}, |
|||
"c": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": {} |
|||
} |
|||
}, |
|||
{ |
|||
"type": "QEQ", |
|||
"a": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.out[1]": "1" |
|||
} |
|||
}, |
|||
"b": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.out[1]": "1", |
|||
"one": "21888242871839275222246405745257275088696311157297823662689037894645226208582" |
|||
} |
|||
}, |
|||
"c": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": {} |
|||
} |
|||
}, |
|||
{ |
|||
"type": "QEQ", |
|||
"a": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.out[2]": "1" |
|||
} |
|||
}, |
|||
"b": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.out[2]": "1", |
|||
"one": "21888242871839275222246405745257275088696311157297823662689037894645226208582" |
|||
} |
|||
}, |
|||
"c": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": {} |
|||
} |
|||
}, |
|||
{ |
|||
"type": "QEQ", |
|||
"a": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": {} |
|||
}, |
|||
"b": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": {} |
|||
}, |
|||
"c": { |
|||
"type": "LINEARCOMBINATION", |
|||
"values": { |
|||
"main.out[0]": "1", |
|||
"main.out[1]": "2", |
|||
"main.out[2]": "4", |
|||
"main.inp": "21888242871839275222246405745257275088696311157297823662689037894645226208582" |
|||
} |
|||
} |
|||
} |
|||
]; |
|||
|
|||
circuit.witnessNames=[ |
|||
[ |
|||
"one" |
|||
], |
|||
[ |
|||
"main.inp" |
|||
], |
|||
[ |
|||
"main.out[0]" |
|||
], |
|||
[ |
|||
"main.out[1]" |
|||
], |
|||
[ |
|||
"main.out[2]" |
|||
] |
|||
]; |
|||
|
|||
{ |
|||
} |
|||
|
|||
circuit.templates = []; |
|||
|
|||
circuit.templates["toBin"] = function(ctx) { |
|||
ctx.setVar("lc1", [], "0"); |
|||
for (ctx.setVar("i", [], "0");bigInt(ctx.getVar("i",[])).lt(ctx.getVar("n",[])) ? 1 : 0;(ctx.setVar("i", [], bigInt(ctx.getVar("i",[])).add("1").mod(__P__))).add(__P__).minus(1).mod(__P__)) |
|||
{ |
|||
ctx.setSignal("out", [ctx.getVar("i",[])], bigInt(bigInt(ctx.getVar("i",[])).greater(256) ? 0 : bigInt(ctx.getSignal("inp", [])).shiftRight(bigInt(ctx.getVar("i",[])).value).and(__MASK__)).and("1").and(__MASK__)); |
|||
ctx.assert(bigInt(bigInt(ctx.getSignal("out", [ctx.getVar("i",[])])).times(bigInt(ctx.getSignal("out", [ctx.getVar("i",[])])).add(__P__).minus("1").mod(__P__)).mod(__P__)).equals("0")); |
|||
ctx.setVar("lc1", [], bigInt(ctx.getVar("lc1",[])).add(bigInt(ctx.getSignal("out", [ctx.getVar("i",[])])).times(bigInt("2").modPow(ctx.getVar("i",[]), __P__)).mod(__P__)).mod(__P__)); |
|||
} |
|||
ctx.assert(bigInt(ctx.getVar("lc1",[])).equals(ctx.getSignal("inp", []))); |
|||
} |
|||
; |
@ -1 +0,0 @@ |
|||
["1","3","1","1","0"] |