mirror of
https://github.com/arnaucube/circomlib.git
synced 2026-02-07 11:16:45 +01:00
Pedersen2 and BitPoints MulFix and MulAny
This commit is contained in:
@@ -5,7 +5,7 @@ const compiler = require("circom");
|
||||
|
||||
const assert = chai.assert;
|
||||
|
||||
const bigInt = require("big-integer");
|
||||
const bigInt = snarkjs.bigInt;
|
||||
|
||||
|
||||
describe("Mux4 test", () => {
|
||||
@@ -19,15 +19,63 @@ describe("Mux4 test", () => {
|
||||
|
||||
const circuit = new snarkjs.Circuit(cirDef);
|
||||
|
||||
console.log("NConstrains: " + circuit.nConstraints);
|
||||
console.log("NConstrains Mux4: " + circuit.nConstraints);
|
||||
|
||||
for (i=0; i<16; i++) {
|
||||
const w = circuit.calculateWitness({ "selector": snarkjs.bigInt(i).toString() });
|
||||
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")
|
||||
];
|
||||
|
||||
assert(w[0].equals(snarkjs.bigInt(1)));
|
||||
for (let i=0; i<16; i++) {
|
||||
const w = circuit.calculateWitness({ "selector": i });
|
||||
|
||||
console.log(i + " -> " + w[circuit.getSignalIdx("main.out")].toString());
|
||||
// assert(w[circuit.getSignalIdx("main.out")].equals(snarkjs.bigInt("100").add(snarkjs.bigInt(i))));
|
||||
assert(w[0].equals(bigInt(1)));
|
||||
|
||||
// console.log(i + " -> " + w[circuit.getSignalIdx("main.out")].toString());
|
||||
assert(w[circuit.getSignalIdx("main.out")].equals(ct16[i]));
|
||||
}
|
||||
});
|
||||
|
||||
it("Should create a constant multiplexer", async () => {
|
||||
|
||||
const cirDef = await compiler(path.join(__dirname, "circuits", "mux3_1.circom"));
|
||||
|
||||
const circuit = new snarkjs.Circuit(cirDef);
|
||||
|
||||
console.log("NConstrains Mux3: " + circuit.nConstraints);
|
||||
|
||||
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++) {
|
||||
const w = circuit.calculateWitness({ "selector": i });
|
||||
|
||||
assert(w[0].equals(bigInt(1)));
|
||||
|
||||
// console.log(i + " -> " + w[circuit.getSignalIdx("main.out")].toString());
|
||||
assert(w[circuit.getSignalIdx("main.out")].equals(ct8[i]));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user