mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
constants
This commit is contained in:
@@ -87,4 +87,14 @@ describe("basic cases", function () {
|
||||
]
|
||||
);
|
||||
});
|
||||
it("constants1", async () => {
|
||||
await doTest(
|
||||
"constants1.circom",
|
||||
[
|
||||
[{in: 0}, {out: 42}],
|
||||
[{in: 10}, {out: 52}],
|
||||
[{in: __P__.minus(2)}, {out: 40}],
|
||||
]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
39
test/circuits/constants1.circom
Normal file
39
test/circuits/constants1.circom
Normal file
@@ -0,0 +1,39 @@
|
||||
|
||||
|
||||
|
||||
template Add(n) {
|
||||
signal input in[n];
|
||||
signal output out;
|
||||
|
||||
var lc = 0;
|
||||
for (var i=0; i<n; i++) {
|
||||
lc = lc + in[i];
|
||||
}
|
||||
|
||||
out <== lc;
|
||||
}
|
||||
|
||||
function FAdd(a,b) {
|
||||
return a+b;
|
||||
}
|
||||
|
||||
template Main() {
|
||||
signal input in;
|
||||
signal output out;
|
||||
|
||||
var o = FAdd(3,4);
|
||||
o = o + FAdd(3,4);
|
||||
o = o + FAdd(3,4); // o = 21
|
||||
|
||||
component A1 = Add(2);
|
||||
A1.in[0] <== in;
|
||||
A1.in[1] <== o;
|
||||
|
||||
component A2 = Add(2);
|
||||
A2.in[0] <== A1.out;
|
||||
A2.in[1] <== o;
|
||||
|
||||
out <== A2.out; // in + 42
|
||||
}
|
||||
|
||||
component main = Main();
|
||||
Reference in New Issue
Block a user