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.

174 lines
7.0 KiB

  1. const path = require("path");
  2. const chai = require("chai");
  3. const assert = chai.assert;
  4. const wasm_tester = require("circom_tester").wasm;
  5. const c_tester = require("circom_tester").c;
  6. const utils = require("./utils");
  7. describe("Theta test", function () {
  8. this.timeout(100000);
  9. it ("Theta (testvector generated from go)", async () => {
  10. const cir = await wasm_tester(path.join(__dirname, "circuits", "theta_test.circom"));
  11. const input =
  12. utils.intsToBigInts([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]);
  13. const expectedOut =
  14. utils.intsToBigInts([26,9,13,29,47,31,14,8,22,34,16,3,3,19,37,21,24,30,12,56,14,29,25,9,51]);
  15. const stateIn = utils.u64ArrayToBits(input);
  16. const expectedOutBits = utils.u64ArrayToBits(expectedOut);
  17. const witness = await cir.calculateWitness({ "in": stateIn }, true);
  18. const stateOut = witness.slice(1, 1+(25*64));
  19. const stateOutU64 = utils.bitsToU64Array(stateOut);
  20. // console.log(stateOutU64, expectedOut);
  21. assert.deepEqual(stateOutU64, expectedOut);
  22. });
  23. it ("Theta (same test as previous, but using c_tester to ensure that"+
  24. "circom_tester with c works as expected)", async () => {
  25. const cir = await c_tester(path.join(__dirname, "circuits", "theta_test.circom"));
  26. const input =
  27. utils.intsToBigInts([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]);
  28. const expectedOut =
  29. utils.intsToBigInts([26,9,13,29,47,31,14,8,22,34,16,3,3,19,37,21,24,30,12,56,14,29,25,9,51]);
  30. const stateIn = utils.u64ArrayToBits(input);
  31. const expectedOutBits = utils.u64ArrayToBits(expectedOut);
  32. const witness = await cir.calculateWitness({ "in": stateIn }, true);
  33. const stateOut = witness.slice(1, 1+(25*64));
  34. const stateOutU64 = utils.bitsToU64Array(stateOut);
  35. // console.log(stateOutU64, expectedOut);
  36. assert.deepEqual(stateOutU64, expectedOut);
  37. });
  38. it ("Theta (testvector generated from go)", async () => {
  39. const cir = await wasm_tester(path.join(__dirname, "circuits", "theta_test.circom"));
  40. // const cir = await c_tester(path.join(__dirname, "circuits", "theta_test.circom"));
  41. const input = utils.strsToBigInts(["26388279066651", "246290629787648",
  42. "26388279902208", "25165850", "246290605457408", "7784628352",
  43. "844424965783552", "2305843009213694083", "844432714760192",
  44. "2305843009249345539", "637534226", "14848", "641204224", "14354",
  45. "3670528", "6308236288", "2130304761856", "648518346341354496",
  46. "6309216256", "648520476645130240", "4611706359392501763",
  47. "792677514882318336", "20340965113972", "4611732197915754499",
  48. "792633534417207412"]);
  49. const expectedOut = utils.strsToBigInts(["3749081831850030700",
  50. "1297317621190464868", "10017560217643747862",
  51. "7854780639862409219", "13836147678645575967",
  52. "3749090635727681271", "1297915755455157604",
  53. "12323429615135705749", "7855062122598582297",
  54. "16141814766035214620", "3749090628446369381",
  55. "1297071330560683876", "10017586606556924438",
  56. "7854780639837253643", "13835971756788491039",
  57. "3749090634251287159", "1297070162329376100",
  58. "9369068259580659222", "7854780645071013913",
  59. "14484490034407743775", "8360757404916954740",
  60. "1801500877105239396", "10017570663003408994",
  61. "3243123208712177690", "14628605291203076459"]);
  62. const stateIn = utils.u64ArrayToBits(input);
  63. const expectedOutBits = utils.u64ArrayToBits(expectedOut);
  64. const witness = await cir.calculateWitness({ "in": stateIn }, true);
  65. const stateOut = witness.slice(1, 1+(25*64));
  66. const stateOutU64 = utils.bitsToU64Array(stateOut);
  67. assert.deepEqual(stateOutU64, expectedOut);
  68. });
  69. });
  70. describe("RhoPi test", function () {
  71. this.timeout(100000);
  72. it ("RhoPi (testvector generated from go)", async () => {
  73. const cir = await wasm_tester(path.join(__dirname, "circuits", "rhopi_test.circom"));
  74. const input =
  75. utils.intsToBigInts([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]);
  76. const expectedOut = utils.strsToBigInts(["0", "105553116266496",
  77. "105553116266496", "37748736", "393216", "805306368", "9437184",
  78. "80", "562949953421312", "13835058055282163714", "2", "448",
  79. "436207616", "4864", "5242880", "536870912", "343597383680",
  80. "11264", "557056", "1657324662872342528", "9223372036854775808",
  81. "288230376151711744", "7696581394432", "32985348833280", "84"]);
  82. const stateIn = utils.u64ArrayToBits(input);
  83. const expectedOutBits = utils.u64ArrayToBits(expectedOut);
  84. const witness = await cir.calculateWitness({ "in": stateIn }, true);
  85. const stateOut = witness.slice(1, 1+(25*64));
  86. const stateOutU64 = utils.bitsToU64Array(stateOut);
  87. // console.log(stateOutU64, expectedOut);
  88. assert.deepEqual(stateOutU64, expectedOut);
  89. });
  90. });
  91. describe("Chi test", function () {
  92. this.timeout(100000);
  93. it ("Chi (testvector generated from go)", async () => {
  94. const cir = await wasm_tester(path.join(__dirname, "circuits", "chi_test.circom"));
  95. const input =
  96. utils.intsToBigInts([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]);
  97. const expectedOut = utils.intsToBigInts([2, 0, 6, 3, 5, 4, 14, 6, 12,
  98. 11, 14, 10, 14, 13, 15, 14, 18, 16, 30, 3, 22, 20, 30, 19, 25]);
  99. const stateIn = utils.u64ArrayToBits(input);
  100. const expectedOutBits = utils.u64ArrayToBits(expectedOut);
  101. const witness = await cir.calculateWitness({ "in": stateIn }, true);
  102. const stateOut = witness.slice(1, 1+(25*64));
  103. const stateOutU64 = utils.bitsToU64Array(stateOut);
  104. // console.log(stateOutU64, expectedOut);
  105. assert.deepEqual(stateOutU64, expectedOut);
  106. });
  107. });
  108. describe("Iota test", function () {
  109. this.timeout(100000);
  110. it ("Iota 3 (testvector generated from go)", async () => {
  111. const cir = await wasm_tester(path.join(__dirname, "circuits", "iota3_test.circom"));
  112. const input =
  113. utils.intsToBigInts([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]);
  114. const expectedOut =
  115. utils.strsToBigInts(["9223372039002292224",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]);
  116. const stateIn = utils.u64ArrayToBits(input);
  117. const expectedOutBits = utils.u64ArrayToBits(expectedOut);
  118. const witness = await cir.calculateWitness({ "in": stateIn }, true);
  119. const stateOut = witness.slice(1, 1+(25*64));
  120. const stateOutU64 = utils.bitsToU64Array(stateOut);
  121. // console.log(stateOutU64, expectedOut);
  122. assert.deepEqual(stateOutU64, expectedOut);
  123. });
  124. it ("Iota 10 (testvector generated from go)", async () => {
  125. const cir = await wasm_tester(path.join(__dirname, "circuits", "iota10_test.circom"));
  126. const input =
  127. utils.strsToBigInts(["9223372039002292224",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]);
  128. const expectedOut =
  129. utils.strsToBigInts(["9223372036854775817",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]);
  130. const stateIn = utils.u64ArrayToBits(input);
  131. const expectedOutBits = utils.u64ArrayToBits(expectedOut);
  132. const witness = await cir.calculateWitness({ "in": stateIn }, true);
  133. const stateOut = witness.slice(1, 1+(25*64));
  134. const stateOutU64 = utils.bitsToU64Array(stateOut);
  135. // console.log(stateOutU64, expectedOut);
  136. assert.deepEqual(stateOutU64, expectedOut);
  137. });
  138. });