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.

74 lines
1.9 KiB

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