mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
for loops
This commit is contained in:
9
test/circuits/add.circom
Normal file
9
test/circuits/add.circom
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
template Add() {
|
||||
signal input in[2];
|
||||
signal output out;
|
||||
|
||||
out <== in[0] + in[1];
|
||||
}
|
||||
|
||||
component main = Add();
|
||||
16
test/circuits/addconst1.circom
Normal file
16
test/circuits/addconst1.circom
Normal 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
1
test/circuits/addin.json
Normal file
@@ -0,0 +1 @@
|
||||
{"in":[1,2]}
|
||||
14
test/circuits/forrolled.circom
Normal file
14
test/circuits/forrolled.circom
Normal 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();
|
||||
10
test/circuits/forunrolled.circom
Normal file
10
test/circuits/forunrolled.circom
Normal 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);
|
||||
@@ -1 +1 @@
|
||||
{ "in1": 1, "in2": [2,3], "in3":[[4,5],[6,7],[8,9]] }
|
||||
{"in": 0}
|
||||
|
||||
5
test/circuits/out.json
Normal file
5
test/circuits/out.json
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
"1"
|
||||
,"0"
|
||||
,"0"
|
||||
]
|
||||
Reference in New Issue
Block a user