2018-10-21 20:51:38 +03:00
|
|
|
const path = require("path");
|
2019-12-14 22:32:45 +03:00
|
|
|
const bigInt = require("big-integer");
|
|
|
|
const tester = require("circom").tester;
|
2018-10-21 20:51:38 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
describe("Mux4 test", function() {
|
|
|
|
this.timeout(100000);
|
2018-10-21 20:51:38 +03:00
|
|
|
|
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 = [
|
|
|
|
bigInt("123"),
|
|
|
|
bigInt("456"),
|
|
|
|
bigInt("789"),
|
|
|
|
bigInt("012"),
|
|
|
|
bigInt("111"),
|
|
|
|
bigInt("222"),
|
|
|
|
bigInt("333"),
|
|
|
|
bigInt("4546"),
|
|
|
|
bigInt("134523"),
|
|
|
|
bigInt("44356"),
|
|
|
|
bigInt("15623"),
|
|
|
|
bigInt("4566"),
|
|
|
|
bigInt("1223"),
|
|
|
|
bigInt("4546"),
|
|
|
|
bigInt("4256"),
|
|
|
|
bigInt("4456")
|
|
|
|
];
|
2018-10-21 20:51:38 +03:00
|
|
|
|
2018-11-27 18:03:57 +03:00
|
|
|
for (let i=0; i<16; i++) {
|
2019-12-14 22:32:45 +03:00
|
|
|
const w = await circuit.calculateWitness({ "selector": i });
|
2018-10-21 20:51:38 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
// TODO
|
|
|
|
// assert(circuit.checkWitness(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 = [
|
|
|
|
bigInt("37"),
|
|
|
|
bigInt("47"),
|
|
|
|
bigInt("53"),
|
|
|
|
bigInt("71"),
|
|
|
|
bigInt("89"),
|
|
|
|
bigInt("107"),
|
|
|
|
bigInt("163"),
|
|
|
|
bigInt("191")
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let i=0; i<8; i++) {
|
2019-12-14 22:32:45 +03:00
|
|
|
const w = await circuit.calculateWitness({ "selector": i });
|
2018-11-27 18:03:57 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
// TODO
|
|
|
|
// assert(circuit.checkWitness(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 = [
|
2019-07-08 15:08:04 +03:00
|
|
|
bigInt("37"),
|
|
|
|
bigInt("47"),
|
|
|
|
bigInt("53"),
|
|
|
|
bigInt("71"),
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let i=0; i<4; i++) {
|
2019-12-14 22:32:45 +03:00
|
|
|
const w = await circuit.calculateWitness({ "selector": i });
|
2019-12-04 23:57:02 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
// TODO
|
|
|
|
// assert(circuit.checkWitness(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 = [
|
2019-07-08 15:08:04 +03:00
|
|
|
bigInt("37"),
|
|
|
|
bigInt("47"),
|
|
|
|
];
|
|
|
|
|
|
|
|
for (let i=0; i<2; i++) {
|
2019-12-14 22:32:45 +03:00
|
|
|
const w = await circuit.calculateWitness({ "selector": i });
|
2019-12-04 23:57:02 +03:00
|
|
|
|
2019-12-14 22:32:45 +03:00
|
|
|
// TODO
|
|
|
|
// assert(circuit.checkWitness(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
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|