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.

81 lines
2.2 KiB

6 years ago
6 years ago
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 = snarkjs.bigInt;
  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 Mux4: " + circuit.nConstraints);
  14. const ct16 = [
  15. bigInt("123"),
  16. bigInt("456"),
  17. bigInt("789"),
  18. bigInt("012"),
  19. bigInt("111"),
  20. bigInt("222"),
  21. bigInt("333"),
  22. bigInt("4546"),
  23. bigInt("134523"),
  24. bigInt("44356"),
  25. bigInt("15623"),
  26. bigInt("4566"),
  27. bigInt("1223"),
  28. bigInt("4546"),
  29. bigInt("4256"),
  30. bigInt("4456")
  31. ];
  32. for (let i=0; i<16; i++) {
  33. const w = circuit.calculateWitness({ "selector": i });
  34. assert(w[0].equals(bigInt(1)));
  35. // console.log(i + " -> " + w[circuit.getSignalIdx("main.out")].toString());
  36. assert(w[circuit.getSignalIdx("main.out")].equals(ct16[i]));
  37. }
  38. });
  39. it("Should create a constant multiplexer", async () => {
  40. const cirDef = await compiler(path.join(__dirname, "circuits", "mux3_1.circom"));
  41. const circuit = new snarkjs.Circuit(cirDef);
  42. console.log("NConstrains Mux3: " + circuit.nConstraints);
  43. const ct8 = [
  44. bigInt("37"),
  45. bigInt("47"),
  46. bigInt("53"),
  47. bigInt("71"),
  48. bigInt("89"),
  49. bigInt("107"),
  50. bigInt("163"),
  51. bigInt("191")
  52. ];
  53. for (let i=0; i<8; i++) {
  54. const w = circuit.calculateWitness({ "selector": i });
  55. assert(w[0].equals(bigInt(1)));
  56. // console.log(i + " -> " + w[circuit.getSignalIdx("main.out")].toString());
  57. assert(w[circuit.getSignalIdx("main.out")].equals(ct8[i]));
  58. }
  59. });
  60. });