Browse Source

Spelling fixed

master
Jordi Baylina 5 years ago
parent
commit
5177e17037
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
12 changed files with 33 additions and 93 deletions
  1. +6
    -6
      README.md
  2. +1
    -1
      package.json
  3. +1
    -1
      src/calculateWitness.js
  4. +8
    -8
      src/circuit.js
  5. +0
    -62
      src/constants.js
  6. +1
    -1
      src/polfield.js
  7. +2
    -0
      src/prover.js
  8. +10
    -10
      src/setup.js
  9. +1
    -1
      test/circuit/sum.json
  10. +1
    -1
      test/pols.js
  11. +1
    -1
      vk_proof.json
  12. +1
    -1
      vk_verifier.json

+ 6
- 6
README.md

@ -34,17 +34,17 @@ const circuit = new zkSnark.Circuit(circuitDef);
```
// `signalId` can always be a number or an alias string
circuit.nConstrains; // number of constrains
circuit.nConstraints; // number of constraints
circuit.nSignals; // number of signals
circuit.nPublic; // number of public signals (nOutputs + nPublicInputs)
// The array of signals is always sorted in this order:
// [ 1, outputs, publicInputs, privedInputs, internalSignals, constants]
// [ 1, outputs, publicInputs, privateInputs, internalSignals, constants]
// returns a,b and c coeficients of the `signalId` on a given `constrain`
circuit.a(constrain, signalId)
circuit.b(constrain, signalId)
circuit.c(constrain, signalId)
// returns a,b and c coeficients of the `signalId` on a given `constraint`
circuit.a(constraint, signalId)
circuit.b(constraint, signalId)
circuit.c(constraint, signalId)
circuit.nOutputs // number of public outputs
circuit.pubInputs // number of public inputs

+ 1
- 1
package.json

@ -1,6 +1,6 @@
{
"name": "zksnark",
"version": "0.0.3",
"version": "0.0.4",
"description": "zkSnark implementation in javascript",
"main": "index.js",
"scripts": {

+ 1
- 1
src/calculateWitness.js

@ -221,7 +221,7 @@ class RTCtx {
const ba = bigInt(a);
const bb = bigInt(b);
if (!ba.equals(bb)) {
throw new Error("Constrain doesn't match: " + ba.toString() + " != " + bb.toString());
throw new Error("Constraint doesn't match: " + ba.toString() + " != " + bb.toString());
}
}
}

+ 8
- 8
src/circuit.js

@ -32,13 +32,13 @@ module.exports = class Circuit {
this.nSignals = circuitDef.nSignals;
this.nConstants = circuitDef.nConstants;
this.nConstrains = circuitDef.constrains.length;
this.nConstraints = circuitDef.constraints.length;
this.signalName2Idx = circuitDef.signalName2Idx;
this.components = circuitDef.components;
this.componentName2Idx = circuitDef.componentName2Idx;
this.signals = circuitDef.signals;
this.constrains = circuitDef.constrains;
this.constraints = circuitDef.constraints;
this.templates = {};
for (let t in circuitDef.templates) {
@ -110,15 +110,15 @@ module.exports = class Circuit {
return this.signals[ this.getSignalIdx(i) ].names.join(", ");
}
a(constrain, signalIdx) {
return bigInt(this.constrains[constrain][0][signalIdx] || 0 );
a(constraint, signalIdx) {
return bigInt(this.constraints[constraint][0][signalIdx] || 0 );
}
b(constrain, signalIdx) {
return bigInt(this.constrains[constrain][1][signalIdx] || 0);
b(constraint, signalIdx) {
return bigInt(this.constraints[constraint][1][signalIdx] || 0);
}
c(constrain, signalIdx) {
return bigInt(this.constrains[constrain][2][signalIdx] || 0);
c(constraint, signalIdx) {
return bigInt(this.constraints[constraint][2][signalIdx] || 0);
}
};

+ 0
- 62
src/constants.js

@ -1,62 +0,0 @@
/*
Copyright 2018 0kims association
This file is part of zksnark javascript library.
zksnark javascript library 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.
zksnark javascript library 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 zksnark javascript library. If not, see <https://www.gnu.org/licenses/>.
*/
const bigInt = require("big-integer");
const F1Field = require("./f1field");
const F2Field = require("./f1field");
const C = {
// Module of the field
q : bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583"),
// Order of the group
r : bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"),
g1 : [ bigInt(1), bigInt(2) ],
g2 :
[
[
bigInt("10857046999023057135944570762232829481370756359578518086990519993285655852781"),
bigInt("11559732032986387107991004021392285783925812861821192530917403151452391805634")
],
[
bigInt("8495653923123431417604973247489272438418190587263600148770280649306958101930"),
bigInt("4082367875863433681332203403145435568316851327593401208105741076214120093531")
]
],
f2nonResidue: bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208582"),
f6nonResidue: [ bigInt("9"), bigInt("1") ],
f12nonResidue: [
]
};
const F1 = new F1Field(C.q);
const F2 = new F2Field(C.q);
C.two_inv= F1.inverse(bigInt(2));
C.coef_b = bigInt(3);
C.twist = [bigInt(9) , bigInt(1)];
C.twist_coeff_b = F2.mulScalar( F2.inverse(C.twist), C.coef_b );
module.exports = C;

+ 1
- 1
src/polfield.js

@ -18,7 +18,7 @@
*/
/*
This library do operations on polinomials where their coefficients are in field F
This library do operations on polynomials where their coefficients are in field F
The polynomial P(x) = p0 + p1 * x + p2 * x^2 + p3 * x^3, ...
is represented by the array [ p0, p1, p2, p3, ... ]

+ 2
- 0
src/prover.js

@ -95,6 +95,8 @@ module.exports = function genProof(vk_proof, witness) {
const h = PolF.div(polFull, vk_proof.polZ );
console.log(h.length + "/" + vk_proof.hExps.length);
for (let i = 0; i < h.length; i++) {
proof.pi_h = G1.add( proof.pi_h, G1.mulScalar( vk_proof.hExps[i], h[i]));
}

+ 10
- 10
src/setup.js

@ -43,7 +43,7 @@ module.exports = function setup(circuit) {
toxic: {}
};
calculatePolinomials(setup, circuit);
calculatePolynomials(setup, circuit);
setup.toxic.t = F.random();
calculateEncriptedValuesAtT(setup, circuit);
calculateHexps(setup, circuit);
@ -51,8 +51,8 @@ module.exports = function setup(circuit) {
return setup;
};
function calculatePolinomials(setup, circuit) {
// Calculate the points that must cross each polinomial
function calculatePolynomials(setup, circuit) {
// Calculate the points that must cross each polynomial
setup.toxic.aExtra = [];
setup.toxic.bExtra = [];
@ -64,7 +64,7 @@ function calculatePolinomials(setup, circuit) {
aPoints[s] = [];
bPoints[s] = [];
cPoints[s] = [];
for (let c=0; c<circuit.nConstrains; c++) {
for (let c=0; c<circuit.nConstraints; c++) {
aPoints[s].push([[bigInt(c), F.one], [circuit.a(c, s), F.one]]);
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]]);
@ -73,12 +73,12 @@ function calculatePolinomials(setup, circuit) {
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]]);
aPoints[s].push([[bigInt(circuit.nConstraints), F.one], [setup.toxic.aExtra[s], F.one]]);
bPoints[s].push([[bigInt(circuit.nConstraints), F.one], [setup.toxic.aExtra[s], F.one]]);
cPoints[s].push([[bigInt(circuit.nConstraints), F.one], [setup.toxic.aExtra[s], F.one]]);
}
// Calculate the polinomials using Lagrange
// Calculate the polynomials using Lagrange
setup.vk_proof.polsA = [];
setup.vk_proof.polsB = [];
setup.vk_proof.polsC = [];
@ -94,10 +94,10 @@ function calculatePolinomials(setup, circuit) {
}
// Calculate Z polinomial
// Calculate Z polynomial
// Z = 1
setup.vk_proof.polZ = [bigInt(1)];
for (let c=0; c<circuit.nConstrains; c++) {
for (let c=0; c<circuit.nConstraints; c++) {
// Z = Z * (x - p_c)
setup.vk_proof.polZ = PolF.mul(
setup.vk_proof.polZ,

+ 1
- 1
test/circuit/sum.json

@ -1155,7 +1155,7 @@
"triggerComponents": []
}
],
"constrains": [
"constraints": [
[
{
"4": "1"

+ 1
- 1
test/pols.js

@ -26,7 +26,7 @@ const assert = chai.assert;
const r = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
describe("Polinomial field", () => {
describe("Polynomial field", () => {
it("Should compute a multiplication", () => {
const PF = new PolField(new ZqField(r));

+ 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":[["7785852424866942827567248153177252939222290906182691438082699528717261848112","14498487571140582006229521774123197624792208304995460366041293455685310260821","1"],["10089186025810067574406329116352287427202151507453454942488303185615585009763","17480610045118135048097764965111383435546896631536763842128581740796692699545","1"],["7958582426685674530371319836968288880305942218180473830509366672077811746037","10638141525118745391331643953261526086411343214394172786686412004744903280719","1"]],"vk_a":[["12566476700762111387137638462830143693098966342488031797140199812463702270691","10761117940182937104105395766999898001336380831618788449416100226892191721352"],["19356030820036623417777165953349381769963830588263613016091378865373303462959","18978533904220143511207404775924520995666097373381834434667481778541007087709"],["1","0"]],"vk_b":["17043210079194738757796936679118088906904204909725217298217365257820271414495","6707474775531150240403871468575244487808879053949462404945041228167524099845","1"],"vk_c":[["9865170618584112823441502162349285335860423740128360526669357554747472154699","20632604718736815280919467681151136499210670980285160959222493223050513546737"],["14082216868713174642563399832185872527728254502321978474744586860936084370133","5685222283821451402334606207202637975255815512242614931036232914597987353342"],["1","0"]],"vk_gb_1":["9836395603840470046963943712532881651486509931256407713019946950913137629778","14094948388393434838547760783099810192358837696587972297173500041190367621741","1"],"vk_gb_2":[["10587661408747044872089155440730374654971725374954943430414222839166754618438","2651255471732063779449759857880587162577951271595365104927101365422800353575"],["7699696976839240235764497561272408204654578388769442088875499039868922178043","12736174663397154234466813918688257074075249792170264326428492908710414485777"],["1","0"]],"vk_g":[["16743811095305513197394434499991440630928809821202268624747413762738629515203","13558714849344702204918921046456627261658997126791422789906958103126834063528"],["5893688669347543877075775593021751388729139028769910418467883741922299058562","3517258497343919686729984857929694939897364088993819600570135956125448214649"],["1","0"]],"vk_z":[["14315684838123152822561898371476735839014217469791062349956797159719883767","2872518261424628556632141313617513762966654266713260679885493065940055845946"],["16343384596178098264749066292007666749105974458588741482468417161840088549271","4270162096643902647870128224797797634127338751539821383607674884042111088595"],["1","0"]]}
{"nPublic":2,"A":[["3637773176081378898560920488479447664808686140589141111416828387323509313363","15875541771365846014934910252981235661896769183737578580632907974539469486976","1"],["14777479131488445242799452238344407206478810512186247358198120698313315050041","5356982137173814919301183761964573668028574609208978571125540294080745453871","1"],["18245693191312441605861595198291164323787574754994285397334300756707166036886","8550860596707258875012538056000724474475850231024915505562526236928010119429","1"]],"vk_a":[["19733536866000798861760986509040601534134039332242290863594006492821626558257","3574000288307733872040324383873947110807681923946372724448970704070475305091"],["9846093448888396292054892982149976594121483692498645350405320006490671135315","2526416074274910695773283691493686580549159044181613208245342381245699519710"],["1","0"]],"vk_b":["21519757242376157330596542708591390653686725844395558333399808947244959245422","20437192233646619858809222101263071478074769481153859275046670548718093041407","1"],"vk_c":[["7272691117257904020777667820850021309855996756017298056292102013870667715318","20782649573408998306997675726582655935768252596827661952399995392856420320048"],["5925256708904566192155168643173042292372178727348314003798101972062711722223","7010226110278500086806390554201911886184448840530552001850220584425158152736"],["1","0"]],"vk_gb_1":["1089888802389522147907571241333919419022699990047031428837376833081865375903","4362458238352542383441615506127665077185901534039174815789589366951319493680","1"],"vk_gb_2":[["19500442107251725998364605841628724998940594250892934039372001117227125337913","4978756559912007357110568317638558114607062204011621101084663028641818493253"],["11286818538548171749183235199187991796692175953478661763059994137748126566131","17079985928284731514134730921114796771503675698372644344141877399555481047812"],["1","0"]],"vk_g":[["784194074827378098570940801561385520734997918701589851782356562773331633835","8206606848283424022271594811323777897629325908071588841434496529785108113372"],["2093074207549829188850564452784081788461493947764854989690710576880640439862","10445094236928996442757806802780182552082567972208955899870184420247111797383"],["1","0"]],"vk_z":[["6294750560576125313190178510883080654832572122528978047064401330036173489271","696125902685669713882504035752853462314223221823245536961332693277852357929"],["20827272118648083910015369330315081762759065653999721916309855409092631056673","1434457059944452243253787430529549090293004579522386759641058090142469898647"],["1","0"]]}

Loading…
Cancel
Save