You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1000 B

6 years ago
  1. const chai = require("chai");
  2. const path = require("path");
  3. const zkSnark = require("zksnark");
  4. const compiler = require("circom");
  5. const assert = chai.assert;
  6. const bigInt = require("big-integer");
  7. describe("Mux4 test", () => {
  8. it("Should create a constant multiplexer", async () => {
  9. const cirDef = await compiler(path.join(__dirname, "circuits", "mux4_1.circom"));
  10. // console.log(JSON.stringify(cirDef, null, 1));
  11. // assert.equal(cirDef.nVars, 2);
  12. const circuit = new zkSnark.Circuit(cirDef);
  13. console.log("NConstrains: " + circuit.nConstraints);
  14. for (i=0; i<16; i++) {
  15. const w = circuit.calculateWitness({ "selector": zkSnark.bigInt(i).toString() });
  16. assert(w[0].equals(zkSnark.bigInt(1)));
  17. console.log(i + " -> " + w[circuit.getSignalIdx("main.out")].toString());
  18. // assert(w[circuit.getSignalIdx("main.out")].equals(zkSnark.bigInt("100").add(zkSnark.bigInt(i))));
  19. }
  20. });
  21. });