mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
roll unrolled loops with code
This commit is contained in:
@@ -287,4 +287,15 @@ describe("basic cases", function () {
|
||||
]
|
||||
);
|
||||
});
|
||||
it("Component array ", async () => {
|
||||
await doTest(
|
||||
"componentarray.circom",
|
||||
[
|
||||
[{in: 1}, {out: 1}],
|
||||
[{in: 2}, {out: 256}],
|
||||
[{in: 3}, {out: 6561}],
|
||||
[{in:-1}, {out: 1}],
|
||||
]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
28
test/circuits/componentarray.circom
Normal file
28
test/circuits/componentarray.circom
Normal file
@@ -0,0 +1,28 @@
|
||||
template Square() {
|
||||
signal input in;
|
||||
signal output out;
|
||||
|
||||
out <== in*in;
|
||||
}
|
||||
|
||||
template Main(n) {
|
||||
signal input in;
|
||||
signal output out;
|
||||
|
||||
component squares[n];
|
||||
|
||||
var i;
|
||||
|
||||
for (i=0; i<n; i++) {
|
||||
squares[i] = Square();
|
||||
if (i==0) {
|
||||
squares[i].in <== in;
|
||||
} else {
|
||||
squares[i].in <== squares[i-1].out;
|
||||
}
|
||||
}
|
||||
|
||||
squares[n-1].out ==> out;
|
||||
}
|
||||
|
||||
component main = Main(3);
|
||||
Reference in New Issue
Block a user