Browse Source

Spelling fixes

wasm
Jordi Baylina 6 years ago
parent
commit
9c67e47588
No known key found for this signature in database GPG Key ID: 7480C80C1BE43112
7 changed files with 38 additions and 38 deletions
  1. +12
    -12
      README.md
  2. +5
    -5
      circuits/multiplexer.circom
  3. +1
    -1
      circuits/sha256/binsum.circom
  4. +1
    -1
      circuits/sha256/sha256compression.circom
  5. +2
    -2
      package.json
  6. +16
    -16
      src/compiler.js
  7. +1
    -1
      src/exec.js

+ 12
- 12
README.md

@ -25,17 +25,17 @@ template NAND() {
component main = NAND(); component main = NAND();
``` ```
The language is mainly a javascript/c syntax but with extra 5 operators in order to define the constrains:
The language is mainly a javascript/c syntax but with extra 5 operators in order to define the constraints:
`<==` , `==>` This operator is used to connect signals. This operator also implies a constrain.
`<==` , `==>` This operator is used to connect signals. This operator also implies a constraint.
As you can see in the example above, `out` is assigned a value and a constrain is also generated. The assigned value must be of the form a*b+c where a,b and c are linear convinations of the signals.
As you can see in the example above, `out` is assigned a value and a constraint is also generated. The assigned value must be of the form a*b+c where a,b and c are linear convinations of the signals.
`<--` , `-->` This operators assign values to a signals but does not generate any constrain. This allow to assign any value to a signal including extrange operations like shifhts, modules, divisiones, etc. Generally this operator goes together wit a `===` operator in order to force the constrain.
`<--` , `-->` This operators assign values to a signals but does not generate any constraint. This allow to assign any value to a signal including extrange operations like shifhts, modules, divisiones, etc. Generally this operator goes together wit a `===` operator in order to force the constraint.
`===` This operator defines a constrain. The constrain must be simplificable to the form a*b+c=0 where a,b and c are linear convinations.
`===` This operator defines a constraint. The constraint must be simplificable to the form a*b+c=0 where a,b and c are linear convinations.
In the example above, we force the two inputs to be binary by adding the constrain `a*(a-1)===0` and `b*(b-1) === 0`
In the example above, we force the two inputs to be binary by adding the constraint `a*(a-1)===0` and `b*(b-1) === 0`
### Compile the circui ### Compile the circui
@ -81,10 +81,10 @@ The first thing we observe in this example is that templates can have parameters
Then we define the inputs and the outputs. We see that we can work with arrays. The program allows multidimension arrays for signals and variables. Then we define the inputs and the outputs. We see that we can work with arrays. The program allows multidimension arrays for signals and variables.
Then we need to assign the values to the different signals. In this case, we assign the value without the constrain by using the shift and & operators:
Then we need to assign the values to the different signals. In this case, we assign the value without the constraint by using the shift and & operators:
`out[i] <-- (in >> i) & 1;` `out[i] <-- (in >> i) & 1;`
But we need to define also the constrains. In this case there is a big constrain of the form:
But we need to define also the constraints. In this case there is a big constraint of the form:
``` ```
in === out[0]*2**0 + out[1]*2**1 + out[2]*2**2 .... in === out[0]*2**0 + out[1]*2**1 + out[2]*2**2 ....
@ -92,7 +92,7 @@ in === out[0]*2**0 + out[1]*2**1 + out[2]*2**2 ....
We do this by using a variable `lc1` and adding each signal multiplied by his coefficient. We do this by using a variable `lc1` and adding each signal multiplied by his coefficient.
This variable does not hold a value in compilation time, but it holds a linear combination. and it is used in the last constrain:
This variable does not hold a value in compilation time, but it holds a linear combination. and it is used in the last constraint:
``` ```
lc1 === in; lc1 === in;
@ -100,7 +100,7 @@ lc1 === in;
Finally we also have to force each output to be binary. Finally we also have to force each output to be binary.
We do this by adding this constrain for each output:
We do this by adding this constraint for each output:
``` ```
out[i] * (out[i] -1 ) === 0; out[i] * (out[i] -1 ) === 0;
@ -111,7 +111,7 @@ Lets now create a 32bits adder.
The strategy will be to first convert the number to binary, do the addition in the binary space and then finally convert it back to a number. The strategy will be to first convert the number to binary, do the addition in the binary space and then finally convert it back to a number.
We could do it directly by adding a simple constrain where out === in1 + in2, but if we do this the operation will not be module 2**32 but `r` where r is the range of the elliptic curve. In the case of regular zkSnarks typically is some prime number close to 2**253
We could do it directly by adding a simple constraint where out === in1 + in2, but if we do this the operation will not be module 2**32 but `r` where r is the range of the elliptic curve. In the case of regular zkSnarks typically is some prime number close to 2**253
With this example we also demostrate the normal patter of binarize a number, work in binary (reguular electronic circuit), and then convert the result back to a number. With this example we also demostrate the normal patter of binarize a number, work in binary (reguular electronic circuit), and then convert the result back to a number.
@ -159,7 +159,7 @@ This component creates a binary sum componet of ops operands and n bits each ope
e is Number of carries: Depends on the number of operands in the input. e is Number of carries: Depends on the number of operands in the input.
Main Constrain:
Main Constraint:
in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) + in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) +
+ in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) + + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) +
+ .. + ..

+ 5
- 5
circuits/multiplexer.circom

@ -1,8 +1,8 @@
// --> Assignation without constrain
// <-- Assignation without constrain
// === Constrain
// <== Assignation with constrain
// ==> Assignation with constrain
// --> Assignation without constraint
// <-- Assignation without constraint
// === Constraint
// <== Assignation with constraint
// ==> Assignation with constraint
// All variables are members of the field F[p] // All variables are members of the field F[p]
// https://github.com/zcash-hackworks/sapling-crypto // https://github.com/zcash-hackworks/sapling-crypto
// https://github.com/ebfull/bellman // https://github.com/ebfull/bellman

+ 1
- 1
circuits/sha256/binsum.circom

@ -7,7 +7,7 @@ This component creates a binary sum componet of ops operands and n bits each ope
e is Number of carries: Depends on the number of operands in the input. e is Number of carries: Depends on the number of operands in the input.
Main Constrain:
Main Constraint:
in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) + in[0][0] * 2^0 + in[0][1] * 2^1 + ..... + in[0][n-1] * 2^(n-1) +
+ in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) + + in[1][0] * 2^0 + in[1][1] * 2^1 + ..... + in[1][n-1] * 2^(n-1) +
+ .. + ..

+ 1
- 1
circuits/sha256/sha256compression.circom

@ -2,7 +2,7 @@
include "constants.jaz"; include "constants.jaz";
include "t1.jaz"; include "t1.jaz";
include "t2.jaz"; include "t2.jaz";
include "sum.jaz";
include "binsum.jaz";
include "sigmaplus.jaz"; include "sigmaplus.jaz";
template sha256compression() { template sha256compression() {

+ 2
- 2
package.json

@ -1,6 +1,6 @@
{ {
"name": "circom", "name": "circom",
"version": "0.0.3",
"version": "0.0.4",
"description": "Language to generate logica circuits", "description": "Language to generate logica circuits",
"main": "index.js", "main": "index.js",
"directories": { "directories": {
@ -37,6 +37,6 @@
"eslint": "^5.0.1", "eslint": "^5.0.1",
"eslint-plugin-mocha": "^5.0.0", "eslint-plugin-mocha": "^5.0.0",
"jison": "^0.4.18", "jison": "^0.4.18",
"zksnark": "0.0.3"
"zksnark": "0.0.4"
} }
} }

+ 16
- 16
src/compiler.js

@ -53,7 +53,7 @@ function compile(srcFile) {
} }
}, },
currentComponent: "", currentComponent: "",
constrains: [],
constraints: [],
components: {}, components: {},
templates: {}, templates: {},
functions: {}, functions: {},
@ -64,7 +64,7 @@ function compile(srcFile) {
exec(ctx, ast); exec(ctx, ast);
reduceConstrains(ctx);
reduceConstraints(ctx);
generateWitnessNames(ctx); generateWitnessNames(ctx);
if (ctx.error) { if (ctx.error) {
@ -176,15 +176,15 @@ function generateWitnessNames(ctx) {
ctx.totals = totals; ctx.totals = totals;
} }
function reduceConstrains(ctx) {
const newConstrains = [];
for (let i=0; i<ctx.constrains.length; i++) {
const c = lc.canonize(ctx, ctx.constrains[i]);
function reduceConstraints(ctx) {
const newConstraints = [];
for (let i=0; i<ctx.constraints.length; i++) {
const c = lc.canonize(ctx, ctx.constraints[i]);
if (!lc.isZero(c)) { if (!lc.isZero(c)) {
newConstrains.push(c);
newConstraints.push(c);
} }
} }
ctx.constrains = newConstrains;
ctx.constraints = newConstraints;
} }
@ -222,7 +222,7 @@ function buildCircuitDef(ctx, mainCode) {
}); });
} }
res.constrains = buildConstrains(ctx);
res.constraints = buildConstraints(ctx);
res.templates = ctx.templates; res.templates = ctx.templates;
@ -246,9 +246,9 @@ function buildCircuitDef(ctx, mainCode) {
} }
/* /*
Build constrains
Build constraints
A constrain like this
A constraint like this
[s1 + 2*s2 + 3*s3] * [ s2 + 5*s4] - [s0 ] = 0 [s1 + 2*s2 + 3*s3] * [ s2 + 5*s4] - [s0 ] = 0
[ 5*s2 + 6*s3] * [ s2 + ] - [s0 + 2* s2] = 0 [ 5*s2 + 6*s3] * [ s2 + ] - [s0 + 2* s2] = 0
@ -267,7 +267,7 @@ is converted to
*/ */
function buildConstrains(ctx) {
function buildConstraints(ctx) {
const res = []; const res = [];
function fillLC(dst, src) { function fillLC(dst, src) {
@ -278,14 +278,14 @@ function buildConstrains(ctx) {
} }
} }
for (let i=0; i<ctx.constrains.length; i++) {
for (let i=0; i<ctx.constraints.length; i++) {
const A = {}; const A = {};
const B = {}; const B = {};
const C = {}; const C = {};
fillLC(A, ctx.constrains[i].a);
fillLC(B, ctx.constrains[i].b);
fillLC(C, lc.negate(ctx.constrains[i].c));
fillLC(A, ctx.constraints[i].a);
fillLC(B, ctx.constraints[i].b);
fillLC(C, lc.negate(ctx.constraints[i].c));
res.push([A,B,C]); res.push([A,B,C]);
} }

+ 1
- 1
src/exec.js

@ -830,7 +830,7 @@ function execConstrain(ctx, ast) {
if (res.type == "ERROR") return error(ctx, ast, res.errStr); if (res.type == "ERROR") return error(ctx, ast, res.errStr);
if (!lc.isZero(res)) { if (!lc.isZero(res)) {
ctx.constrains.push(lc.toQEQ(res));
ctx.constraints.push(lc.toQEQ(res));
} }
return res; return res;

Loading…
Cancel
Save