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.

73 lines
1.9 KiB

  1. const chai = require("chai");
  2. const path = require("path");
  3. const assert = chai.assert;
  4. const bigInt = require("big-integer");
  5. const tester = require("circom").tester;
  6. function print(circuit, w, s) {
  7. console.log(s + ": " + w[circuit.getSignalIdx(s)]);
  8. }
  9. function getBits(v, n) {
  10. const res = [];
  11. for (let i=0; i<n; i++) {
  12. if (v.shiftRight(i).isOdd()) {
  13. res.push(bigInt.one);
  14. } else {
  15. res.push(bigInt.zero);
  16. }
  17. }
  18. return res;
  19. }
  20. const q = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617");
  21. describe("Aliascheck test", function () {
  22. this.timeout(100000);
  23. let cir;
  24. before( async() => {
  25. cir = await tester(path.join(__dirname, "circuits", "aliascheck_test.circom"));
  26. });
  27. it("Satisfy the aliastest 0", async () => {
  28. const inp = getBits(bigInt.zero, 254);
  29. await cir.calculateWitness({in: inp}, true);
  30. });
  31. it("Satisfy the aliastest 3", async () => {
  32. const inp = getBits(bigInt(3), 254);
  33. await cir.calculateWitness({in: inp}, true);
  34. });
  35. it("Satisfy the aliastest q-1", async () => {
  36. const inp = getBits(q.minus(bigInt.one), 254);
  37. await cir.calculateWitness({in: inp}, true);
  38. });
  39. it("Should not satisfy an input of q", async () => {
  40. const inp = getBits(q, 254);
  41. try {
  42. await cir.calculateWitness({in: inp}, true);
  43. assert(false);
  44. } catch(err) {
  45. assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
  46. }
  47. });
  48. it("Should not satisfy all ones", async () => {
  49. const inp = getBits(bigInt(1).shiftLeft(254).minus(bigInt.one), 254);
  50. try {
  51. await cir.calculateWitness({in: inp}, true);
  52. assert(false);
  53. } catch(err) {
  54. assert(/Constraint\sdoesn't\smatch(.*)1\s!=\s0/.test(err.message) );
  55. }
  56. });
  57. });