mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-06 18:56:40 +01:00
compute block added
This commit is contained in:
@@ -49,4 +49,14 @@ describe("Sum test", () => {
|
||||
// await compiler(path.join(__dirname, "circuits", "assignsignal.circom"));
|
||||
// }, /Cannot assign to a signal .*/);
|
||||
// });
|
||||
it("Should compile a code with compute", async () => {
|
||||
const cirDef = await compiler(path.join(__dirname, "circuits", "compute.circom"));
|
||||
|
||||
const circuit = new snarkjs.Circuit(cirDef);
|
||||
|
||||
const witness = circuit.calculateWitness({ "x": 6});
|
||||
assert(witness[0].equals(bigInt(1)));
|
||||
assert(witness[1].equals(bigInt(37)));
|
||||
assert(witness[2].equals(bigInt(6)));
|
||||
});
|
||||
});
|
||||
|
||||
17
test/circuits/compute.circom
Normal file
17
test/circuits/compute.circom
Normal file
@@ -0,0 +1,17 @@
|
||||
template X() {
|
||||
signal input x;
|
||||
signal output y;
|
||||
signal x2;
|
||||
signal x3;
|
||||
var a;
|
||||
compute {
|
||||
a = (x*x*x+6)/x;
|
||||
y <-- a;
|
||||
}
|
||||
|
||||
x2 <== x*x;
|
||||
x3 <== x2*x;
|
||||
x*y === x3+6;
|
||||
}
|
||||
|
||||
component main = X();
|
||||
Reference in New Issue
Block a user