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
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. const chai = require("chai");
  2. const path = require("path");
  3. const snarkjs = require("snarkjs");
  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 snarkjs.Circuit(cirDef);
  13. console.log("NConstrains: " + circuit.nConstraints);
  14. for (i=0; i<16; i++) {
  15. const w = circuit.calculateWitness({ "selector": snarkjs.bigInt(i).toString() });
  16. assert(w[0].equals(snarkjs.bigInt(1)));
  17. console.log(i + " -> " + w[circuit.getSignalIdx("main.out")].toString());
  18. // assert(w[circuit.getSignalIdx("main.out")].equals(snarkjs.bigInt("100").add(snarkjs.bigInt(i))));
  19. }
  20. });
  21. });