for loops

This commit is contained in:
Jordi Baylina
2019-11-28 15:10:59 +01:00
parent 66291a0efe
commit 93330f065b
24 changed files with 1385 additions and 81 deletions

9
test/circuits/add.circom Normal file
View File

@@ -0,0 +1,9 @@
template Add() {
signal input in[2];
signal output out;
out <== in[0] + in[1];
}
component main = Add();

View File

@@ -0,0 +1,16 @@
template AddConst(c) {
signal input in;
signal output out;
var a = 2;
var b = 3;
a=a+b;
a=a+4;
a=a+c;
out <== 5 + a + in;
}
// It should out <== in + 1+2+3+4+5 = in + 15
component main = AddConst(1);

1
test/circuits/addin.json Normal file
View File

@@ -0,0 +1 @@
{"in":[1,2]}

View File

@@ -0,0 +1,14 @@
template ForRolled() {
signal input in;
signal output out;
var acc = 0;
for (var i=0; i<in; i = i+1) {
acc = acc + 1;
}
out <== acc;
}
component main = ForRolled();

View File

@@ -0,0 +1,10 @@
template ForUnrolled(n) {
signal input in;
signal output out[n];
for (var i=0; i<n; i = i+1) {
out[i] <== in + i;
}
}
component main = ForUnrolled(3);

View File

@@ -1 +1 @@
{ "in1": 1, "in2": [2,3], "in3":[[4,5],[6,7],[8,9]] }
{"in": 0}

5
test/circuits/out.json Normal file
View File

@@ -0,0 +1,5 @@
[
"1"
,"0"
,"0"
]