2018-10-21 20:51:38 +03:00
|
|
|
const path = require("path");
|
2019-12-14 22:32:45 +03:00
|
|
|
const tester = require("circom").tester;
|
2020-04-18 23:33:59 +03:00
|
|
|
const Fr = require("ffjavascript").bn128.Fr;
|
2018-10-21 20:51:38 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
describe("Mux4 test", function() {
|
|
|
|
this.timeout(100000);
|
2019-07-08 15:08:04 +03:00
|
|
|
it("Should create a constant multiplexer 4", async () => {
|
2018-10-21 20:51:38 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
const circuit = await tester(path.join(__dirname, "circuits", "mux4_1.circom"));
|
2018-10-21 20:51:38 +03:00
|
|
|
|
2018-11-27 18:03:57 +03:00
|
|
|
const ct16 = [
|
2020-04-18 23:33:59 +03:00
|
|
|
Fr.e("123"),
|
|
|
|
Fr.e("456"),
|
|
|
|
Fr.e("789"),
|
|
|
|
Fr.e("012"),
|
|
|
|
Fr.e("111"),
|
|
|
|
Fr.e("222"),
|
|
|
|
Fr.e("333"),
|
|
|
|
Fr.e("4546"),
|
|
|
|
Fr.e("134523"),
|
|
|
|
Fr.e("44356"),
|
|
|
|
Fr.e("15623"),
|
|
|
|
Fr.e("4566"),
|
|
|
|
Fr.e("1223"),
|
|
|
|
Fr.e("4546"),
|
|
|
|
Fr.e("4256"),
|
|
|
|
Fr.e("4456")
|
2018-11-27 18:03:57 +03:00
|
|
|
];
|
2018-10-21 20:51:38 +03:00
|
|
|
|
2018-11-27 18:03:57 +03:00
|
|
|
for (let i=0; i<16; i++) {
|
2020-03-26 21:24:20 +03:00
|
|
|
const w = await circuit.calculateWitness({ "selector": i }, true);
|
2018-10-21 20:51:38 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
await circuit.checkConstraints(w);
|
2019-12-04 23:57:02 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
await circuit.assertOut(w, {out: ct16[i]});
|
2018-11-27 18:03:57 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-08 15:08:04 +03:00
|
|
|
it("Should create a constant multiplexer 3", async () => {
|
2018-11-27 18:03:57 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
const circuit = await tester(path.join(__dirname, "circuits", "mux3_1.circom"));
|
2018-11-27 18:03:57 +03:00
|
|
|
|
|
|
|
const ct8 = [
|
2020-04-18 23:33:59 +03:00
|
|
|
Fr.e("37"),
|
|
|
|
Fr.e("47"),
|
|
|
|
Fr.e("53"),
|
|
|
|
Fr.e("71"),
|
|
|
|
Fr.e("89"),
|
|
|
|
Fr.e("107"),
|
|
|
|
Fr.e("163"),
|
|
|
|
Fr.e("191")
|
2018-11-27 18:03:57 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let i=0; i<8; i++) {
|
2020-03-26 21:24:20 +03:00
|
|
|
const w = await circuit.calculateWitness({ "selector": i }, true);
|
2018-11-27 18:03:57 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
await circuit.checkConstraints(w);
|
2018-11-27 18:03:57 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
await circuit.assertOut(w, {out: ct8[i]});
|
2019-07-08 15:08:04 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
it("Should create a constant multiplexer 2", async () => {
|
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
const circuit = await tester(path.join(__dirname, "circuits", "mux2_1.circom"));
|
2019-07-08 15:08:04 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
const ct4 = [
|
2020-04-18 23:33:59 +03:00
|
|
|
Fr.e("37"),
|
|
|
|
Fr.e("47"),
|
|
|
|
Fr.e("53"),
|
|
|
|
Fr.e("71"),
|
2019-07-08 15:08:04 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let i=0; i<4; i++) {
|
2020-03-26 21:24:20 +03:00
|
|
|
const w = await circuit.calculateWitness({ "selector": i }, true);
|
2019-12-04 23:57:02 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
await circuit.checkConstraints(w);
|
2019-07-08 15:08:04 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
await circuit.assertOut(w, {out: ct4[i]});
|
2019-07-08 15:08:04 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
it("Should create a constant multiplexer 1", async () => {
|
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
const circuit = await tester(path.join(__dirname, "circuits", "mux1_1.circom"));
|
2019-07-08 15:08:04 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
const ct2 = [
|
2020-04-18 23:33:59 +03:00
|
|
|
Fr.e("37"),
|
|
|
|
Fr.e("47"),
|
2019-07-08 15:08:04 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
for (let i=0; i<2; i++) {
|
2020-03-26 21:24:20 +03:00
|
|
|
const w = await circuit.calculateWitness({ "selector": i }, true);
|
2019-12-04 23:57:02 +03:00
|
|
|
|
2019-12-16 23:35:52 +03:00
|
|
|
await circuit.checkConstraints(w);
|
2019-07-08 15:08:04 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
await circuit.assertOut(w, {out: ct2[i]});
|
2018-10-21 20:51:38 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|