mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
Spelling fixes
This commit is contained in:
24
README.md
24
README.md
@@ -25,17 +25,17 @@ template 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
|
||||
|
||||
@@ -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 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;`
|
||||
|
||||
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 ....
|
||||
@@ -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.
|
||||
|
||||
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;
|
||||
@@ -100,7 +100,7 @@ lc1 === in;
|
||||
|
||||
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;
|
||||
@@ -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.
|
||||
|
||||
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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Main Constrain:
|
||||
Main Constraint:
|
||||
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) +
|
||||
+ ..
|
||||
|
||||
@@ -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]
|
||||
// https://github.com/zcash-hackworks/sapling-crypto
|
||||
// https://github.com/ebfull/bellman
|
||||
|
||||
@@ -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.
|
||||
|
||||
Main Constrain:
|
||||
Main Constraint:
|
||||
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) +
|
||||
+ ..
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
include "constants.jaz";
|
||||
include "t1.jaz";
|
||||
include "t2.jaz";
|
||||
include "sum.jaz";
|
||||
include "binsum.jaz";
|
||||
include "sigmaplus.jaz";
|
||||
|
||||
template sha256compression() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "circom",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"description": "Language to generate logica circuits",
|
||||
"main": "index.js",
|
||||
"directories": {
|
||||
@@ -37,6 +37,6 @@
|
||||
"eslint": "^5.0.1",
|
||||
"eslint-plugin-mocha": "^5.0.0",
|
||||
"jison": "^0.4.18",
|
||||
"zksnark": "0.0.3"
|
||||
"zksnark": "0.0.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ function compile(srcFile) {
|
||||
}
|
||||
},
|
||||
currentComponent: "",
|
||||
constrains: [],
|
||||
constraints: [],
|
||||
components: {},
|
||||
templates: {},
|
||||
functions: {},
|
||||
@@ -64,7 +64,7 @@ function compile(srcFile) {
|
||||
|
||||
exec(ctx, ast);
|
||||
|
||||
reduceConstrains(ctx);
|
||||
reduceConstraints(ctx);
|
||||
generateWitnessNames(ctx);
|
||||
|
||||
if (ctx.error) {
|
||||
@@ -176,15 +176,15 @@ function generateWitnessNames(ctx) {
|
||||
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)) {
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
[ 5*s2 + 6*s3] * [ s2 + ] - [s0 + 2* s2] = 0
|
||||
@@ -267,7 +267,7 @@ is converted to
|
||||
|
||||
*/
|
||||
|
||||
function buildConstrains(ctx) {
|
||||
function buildConstraints(ctx) {
|
||||
const res = [];
|
||||
|
||||
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 B = {};
|
||||
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]);
|
||||
}
|
||||
|
||||
@@ -830,7 +830,7 @@ function execConstrain(ctx, ast) {
|
||||
if (res.type == "ERROR") return error(ctx, ast, res.errStr);
|
||||
|
||||
if (!lc.isZero(res)) {
|
||||
ctx.constrains.push(lc.toQEQ(res));
|
||||
ctx.constraints.push(lc.toQEQ(res));
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user