Browse Source

circuit in test

master
Jordi Baylina 5 years ago
parent
commit
2834d5cfc6
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
8 changed files with 2297 additions and 10 deletions
  1. +4
    -4
      package-lock.json
  2. +1
    -1
      package.json
  3. +12
    -1
      src/setup.js
  4. +2
    -1
      test/calculatewitness.js
  5. +2274
    -0
      test/circuit/sum.json
  6. +2
    -1
      test/zksnark.js
  7. +1
    -1
      vk_proof.json
  8. +1
    -1
      vk_verifier.json

+ 4
- 4
package-lock.json

@ -1,6 +1,6 @@
{
"name": "zksnark",
"version": "0.0.1",
"version": "0.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -117,9 +117,9 @@
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"big-integer": {
"version": "1.6.34",
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.34.tgz",
"integrity": "sha512-+w6B0Uo0ZvTSzDkXjoBCTNK0oe+aVL+yPi7kwGZm8hd8+Nj1AFPoxoq1Bl/mEu/G/ivOkUc1LRqVR0XeWFUzuA=="
"version": "1.6.35",
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.35.tgz",
"integrity": "sha512-jqLsX6dzmPHOhApAUyGwrpzqn3DXpdTqbOM6baPys7A423ys7IsTpcucDVGP0PmzxGsPYbW3xVOJ4SxAzI0vqQ=="
},
"brace-expansion": {
"version": "1.1.11",

+ 1
- 1
package.json

@ -22,7 +22,7 @@
"url": "git+https://github.com/iden3/zksnark.git"
},
"dependencies": {
"big-integer": "^1.6.34",
"big-integer": "^1.6.35",
"chai": "^4.1.2",
"eslint": "^5.3.0"
},

+ 12
- 1
src/setup.js

@ -53,6 +53,10 @@ module.exports = function setup(circuit) {
function calculatePolinomials(setup, circuit) {
// Calculate the points that must cross each polinomial
setup.toxic.aExtra = [];
setup.toxic.bExtra = [];
setup.toxic.cExtra = [];
const aPoints = [];
const bPoints = [];
const cPoints = [];
@ -65,7 +69,14 @@ function calculatePolinomials(setup, circuit) {
bPoints[s].push([[bigInt(c), F.one], [circuit.b(c, s), F.one]]);
cPoints[s].push([[bigInt(c), F.one], [circuit.c(c, s), F.one]]);
}
}
// Add an extra point to avoid constant polinolials.
/* setup.toxic.aExtra[s] = F.random();
setup.toxic.bExtra[s] = F.random();
setup.toxic.cExtra[s] = F.random();
aPoints[s].push([[bigInt(circuit.nConstrains), F.one], [setup.toxic.aExtra[s], F.one]]);
bPoints[s].push([[bigInt(circuit.nConstrains), F.one], [setup.toxic.aExtra[s], F.one]]);
cPoints[s].push([[bigInt(circuit.nConstrains), F.one], [setup.toxic.aExtra[s], F.one]]);
*/ }
// Calculate the polinomials using Lagrange
setup.vk_proof.polsA = [];

+ 2
- 1
test/calculatewitness.js

@ -18,6 +18,7 @@
*/
const chai = require("chai");
const fs = require("fs");
const path = require("path");
const Circuit = require("../src/circuit.js");
const BN128 = require("../src/BN128.js");
@ -29,7 +30,7 @@ const assert = chai.assert;
describe("Calculate witness", () => {
it("Should calculate the witness of a sum circuit", () => {
const cirDef = JSON.parse(fs.readFileSync("../jaz/sum.json", "utf8"));
const cirDef = JSON.parse(fs.readFileSync(path.join(__dirname, "circuit", "sum.json"), "utf8"));
const cir = new Circuit(cirDef);
const witness = cir.calculateWitness({"a": "33", "b": "34"});

+ 2274
- 0
test/circuit/sum.json
File diff suppressed because it is too large
View File


+ 2
- 1
test/zksnark.js

@ -18,6 +18,7 @@
*/
const chai = require("chai");
const fs = require("fs");
const path = require("path");
const bigInt = require("../src/bigint.js");
const Circuit = require("../src/circuit.js");
@ -61,7 +62,7 @@ function unstringifyBigInts(o) {
describe("zkSnark", () => {
it("Load a circuit, create trusted setup, create a proof and validate", () => {
const cirDef = JSON.parse(fs.readFileSync("../jaz/sum.json", "utf8"));
const cirDef = JSON.parse(fs.readFileSync(path.join(__dirname, "circuit", "sum.json"), "utf8"));
const cir = new Circuit(cirDef);
const setup = zkSnark.setup(cir);

+ 1
- 1
vk_proof.json
File diff suppressed because it is too large
View File


+ 1
- 1
vk_verifier.json

@ -1 +1 @@
{"nPublic":2,"A":[["0","1","0"],["0","1","0"],["0","1","0"]],"vk_a":[["19985519584080263762668341993856051812817149733057014039676847897200507691061","2181109597322042138352810669986217306056442448243279697032170204953641610884"],["4722245620595613996243112082132264332627940259179414874390560397321647278411","3400776435120956936886576954625279836157961389267622768619472922473391768220"],["1","0"]],"vk_b":["9051519069840476233553818286258257481055903784575902174881649290327538263582","10249312525296061515235568405559708325277139324366453224970766038859943594897","1"],"vk_c":[["15392067100266356161894239520152084489885087552022991074617650302798401582720","6938835913716473401039215900378656886520076156392484898456372827320957060549"],["16303229112737416906652062278246905354996047587380175804083493627672468770197","3031195631638642635032208301608950341246321271941279740460156045752345697664"],["1","0"]],"vk_gb_1":["1538852752139562836937566947090371851051723792584168487966672305897682596352","16127188476311614483079904515156727686697933665329864432319350972959528220824","1"],"vk_gb_2":[["10806550322041306601397452553601160495844701165830846821176429143696622197246","21238298321220717293536671894431758678097780513096350148343932876175521050942"],["1875185714310135396025943289767180264582642869919029808893525736040932860267","13563233540368735039666550808532979284671659177726104268513460550344117581117"],["1","0"]],"vk_g":[["9225948274114617389115429920681164779887821945735012305718586690526396280573","5122583398615973782513838221540123862407030722463052004069622842621525684882"],["9027408051824839381608336237739617381324291712518590297334622202654895019710","17863770299906116839710399795148692506559666892300718532448683708995182246773"],["1","0"]],"vk_z":[["20109059215884020661602388564489969108662633362863824042575059135461589049873","12339592032251407925881113482387030630502319105659351770019933632267286181208"],["14111360184024474909319460742726715101045208941393541920802560527729070343970","19784494882099453856826957379824813910027011502382221083238236524310362612962"],["1","0"]]}
{"nPublic":2,"A":[["0","1","0"],["0","1","0"],["0","1","0"]],"vk_a":[["20560152968605635047047919676756549283523817170997848427440669466397276089891","7818200049125752241522512514595555840965570134556904697441429125880983431973"],["4004622395899538748391960201261807969480869650929771125579186354842467518877","18588817277049499857912086791069903740856836703741772287766008332848801238683"],["1","0"]],"vk_b":["7675095142863148568659609174259589451633443643157677274235081172746171956542","18338594371505088398217690997908895905630211655128125704886936054880330961649","1"],"vk_c":[["970991860474890601986787809500909910117209143914824514633406060579917804831","4489472998861614386435429631561506491479661731588162275433693707556712547841"],["10480421612152685783877114152701120795938125690414386886166896214739837143779","5640799180464335612585129736766378273209064892082182915157435013613846562729"],["1","0"]],"vk_gb_1":["4728671699406973361533638453844939122296785601499319421870766751819864821810","18590397052718771409382296794461534416250066676149101531720436218867605770708","1"],"vk_gb_2":[["17844101039536210909524887542440503349088218139829556536038350017244860377748","486615893104745799154322826376187390141407828968942579410680571889220991650"],["16222046142698304277705000927939371189198509817041408962815545046461085484277","16939467019814743646851821875954149589630819655681114269447165709665490121261"],["1","0"]],"vk_g":[["18172673215462466998482333376307489788260969976249399115937860752249844438018","19760300569958518554347022518467441716192319217874332681674016606222863236037"],["17380602559151721627106163894145371007936686580900076060630372401915351905984","20709756557188364181510512059091800556109827259575108072191711716654455458177"],["1","0"]],"vk_z":[["8623243840792232633123147565914995855135594279231733924099511669061508984668","7360712253826041579457165313251304415222924008591401809078818557165549277617"],["2456098287596332925405250001167037649249238481321660217499315092313772466659","16563797406530073760270029887321638579276696184392138086412297266689741878778"],["1","0"]]}

Loading…
Cancel
Save