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.

98 lines
2.6 KiB

5 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
  1. const path = require("path");
  2. const tester = require("circom").tester;
  3. const Fr = require("ffjavascript").bn128.Fr;
  4. describe("Mux4 test", function() {
  5. this.timeout(100000);
  6. it("Should create a constant multiplexer 4", async () => {
  7. const circuit = await tester(path.join(__dirname, "circuits", "mux4_1.circom"));
  8. const ct16 = [
  9. Fr.e("123"),
  10. Fr.e("456"),
  11. Fr.e("789"),
  12. Fr.e("012"),
  13. Fr.e("111"),
  14. Fr.e("222"),
  15. Fr.e("333"),
  16. Fr.e("4546"),
  17. Fr.e("134523"),
  18. Fr.e("44356"),
  19. Fr.e("15623"),
  20. Fr.e("4566"),
  21. Fr.e("1223"),
  22. Fr.e("4546"),
  23. Fr.e("4256"),
  24. Fr.e("4456")
  25. ];
  26. for (let i=0; i<16; i++) {
  27. const w = await circuit.calculateWitness({ "selector": i }, true);
  28. await circuit.checkConstraints(w);
  29. await circuit.assertOut(w, {out: ct16[i]});
  30. }
  31. });
  32. it("Should create a constant multiplexer 3", async () => {
  33. const circuit = await tester(path.join(__dirname, "circuits", "mux3_1.circom"));
  34. const ct8 = [
  35. Fr.e("37"),
  36. Fr.e("47"),
  37. Fr.e("53"),
  38. Fr.e("71"),
  39. Fr.e("89"),
  40. Fr.e("107"),
  41. Fr.e("163"),
  42. Fr.e("191")
  43. ];
  44. for (let i=0; i<8; i++) {
  45. const w = await circuit.calculateWitness({ "selector": i }, true);
  46. await circuit.checkConstraints(w);
  47. await circuit.assertOut(w, {out: ct8[i]});
  48. }
  49. });
  50. it("Should create a constant multiplexer 2", async () => {
  51. const circuit = await tester(path.join(__dirname, "circuits", "mux2_1.circom"));
  52. const ct4 = [
  53. Fr.e("37"),
  54. Fr.e("47"),
  55. Fr.e("53"),
  56. Fr.e("71"),
  57. ];
  58. for (let i=0; i<4; i++) {
  59. const w = await circuit.calculateWitness({ "selector": i }, true);
  60. await circuit.checkConstraints(w);
  61. await circuit.assertOut(w, {out: ct4[i]});
  62. }
  63. });
  64. it("Should create a constant multiplexer 1", async () => {
  65. const circuit = await tester(path.join(__dirname, "circuits", "mux1_1.circom"));
  66. const ct2 = [
  67. Fr.e("37"),
  68. Fr.e("47"),
  69. ];
  70. for (let i=0; i<2; i++) {
  71. const w = await circuit.calculateWitness({ "selector": i }, true);
  72. await circuit.checkConstraints(w);
  73. await circuit.assertOut(w, {out: ct2[i]});
  74. }
  75. });
  76. });