@zkasm/zkevm-rom 0.0.1-security → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @zkasm/zkevm-rom might be problematic. Click here for more details.

Files changed (232) hide show
  1. package/.eslintrc.js +33 -0
  2. package/.github/CODEOWNERS +14 -0
  3. package/.github/ISSUE_TEMPLATE/bug.yml +38 -0
  4. package/.github/ISSUE_TEMPLATE/feature.yml +26 -0
  5. package/.github/ISSUE_TEMPLATE/question.yml +26 -0
  6. package/.github/workflows/main.yaml +40 -0
  7. package/LICENSE +636 -0
  8. package/README.md +23 -5
  9. package/audits/Hexens_Polygon_zkEVM_PUBLIC_27.02.23.pdf +0 -0
  10. package/audits/Polygon-zkEVM-Public-v1.1-verichains-19-03-2024.pdf +0 -0
  11. package/audits/zkEVM-ROM-upgrade-1-Spearbit-30-May.pdf +0 -0
  12. package/audits/zkEVM-ROM-upgrade-2-Spearbit-21-August.pdf +0 -0
  13. package/audits/zkEVM-engagement-1-Spearbit-27-March.pdf +0 -0
  14. package/audits/zkEVM-engagement-2-Spearbit-27-March.pdf +0 -0
  15. package/audits/zkEVM-engagement-3-Spearbit-6-April.pdf +0 -0
  16. package/counters/README.md +45 -0
  17. package/counters/counters-executor.js +80 -0
  18. package/counters/countersConstants.zkasm +370 -0
  19. package/counters/endIncludes.zkasm +18 -0
  20. package/counters/initIncludes.zkasm +2 -0
  21. package/counters/tests/MLOAD32.zkasm +27 -0
  22. package/counters/tests/MLOADX.zkasm +30 -0
  23. package/counters/tests/MSTORE32.zkasm +32 -0
  24. package/counters/tests/MSTOREX.zkasm +36 -0
  25. package/counters/tests/SHLarith.zkasm +28 -0
  26. package/counters/tests/SHLarithBit.zkasm +28 -0
  27. package/counters/tests/SHRarith.zkasm +28 -0
  28. package/counters/tests/SHRarithBit.zkasm +28 -0
  29. package/counters/tests/abs.zkasm +29 -0
  30. package/counters/tests/addBatchHashByteByByte.zkasm +31 -0
  31. package/counters/tests/computeGasSendCall.zkasm +30 -0
  32. package/counters/tests/divArith.zkasm +27 -0
  33. package/counters/tests/expAD.zkasm +30 -0
  34. package/counters/tests/getLenBits.zkasm +30 -0
  35. package/counters/tests/getLenBytes.zkasm +32 -0
  36. package/counters/tests/isEmptyAccount.zkasm +30 -0
  37. package/counters/tests/mulARITH.zkasm +28 -0
  38. package/counters/tests/offsetUtil.zkasm +29 -0
  39. package/counters/tests/opADDMOD.zkasm +28 -0
  40. package/counters/tests/opAdd.zkasm +27 -0
  41. package/counters/tests/opBLOCKHASH.zkasm +28 -0
  42. package/counters/tests/opCALL.zkasm +41 -0
  43. package/counters/tests/opCALLCODE.zkasm +41 -0
  44. package/counters/tests/opCALLDATACOPY.zkasm +28 -0
  45. package/counters/tests/opCALLDATALOAD.zkasm +27 -0
  46. package/counters/tests/opCODECOPY.zkasm +28 -0
  47. package/counters/tests/opCREATE.zkasm +35 -0
  48. package/counters/tests/opCREATE2.zkasm +35 -0
  49. package/counters/tests/opDELEGATECALL.zkasm +35 -0
  50. package/counters/tests/opDIV.zkasm +27 -0
  51. package/counters/tests/opEXP.zkasm +29 -0
  52. package/counters/tests/opEXTCODECOPY.zkasm +29 -0
  53. package/counters/tests/opMOD.zkasm +27 -0
  54. package/counters/tests/opMUL.zkasm +27 -0
  55. package/counters/tests/opMULMOD.zkasm +28 -0
  56. package/counters/tests/opRETURN.zkasm +32 -0
  57. package/counters/tests/opRETURNDATACOPY.zkasm +29 -0
  58. package/counters/tests/opREVERT.zkasm +32 -0
  59. package/counters/tests/opSDIV.zkasm +28 -0
  60. package/counters/tests/opSHA3.zkasm +28 -0
  61. package/counters/tests/opSIGNEXTEND.zkasm +27 -0
  62. package/counters/tests/opSMOD.zkasm +28 -0
  63. package/counters/tests/opSTATICCALL.zkasm +35 -0
  64. package/counters/tests/opSUB.zkasm +27 -0
  65. package/counters/tests/saveMem.zkasm +31 -0
  66. package/docs/opcode-cost-zk-counters.md +315 -0
  67. package/docs/usage-ecrecover.md +51 -0
  68. package/index.js +43 -0
  69. package/main/block-info.zkasm +204 -0
  70. package/main/constants.zkasm +145 -0
  71. package/main/ecrecover/addFpEc.zkasm +31 -0
  72. package/main/ecrecover/checkSqrtFpEc.zkasm +1558 -0
  73. package/main/ecrecover/constEc.zkasm +13 -0
  74. package/main/ecrecover/ecrecover.zkasm +280 -0
  75. package/main/ecrecover/invFnEc.zkasm +44 -0
  76. package/main/ecrecover/invFpEc.zkasm +45 -0
  77. package/main/ecrecover/mulFnEc.zkasm +36 -0
  78. package/main/ecrecover/mulFpEc.zkasm +36 -0
  79. package/main/ecrecover/mulPointEc.zkasm +311 -0
  80. package/main/ecrecover/sqFpEc.zkasm +38 -0
  81. package/main/ecrecover/sqrtFpEc.zkasm +70 -0
  82. package/main/end.zkasm +4 -0
  83. package/main/l2-tx-hash.zkasm +159 -0
  84. package/main/load-change-l2-block-utils.zkasm +11 -0
  85. package/main/load-change-l2-block.zkasm +28 -0
  86. package/main/load-tx-rlp-utils.zkasm +72 -0
  87. package/main/load-tx-rlp.zkasm +431 -0
  88. package/main/main.zkasm +237 -0
  89. package/main/map-opcodes.zkasm +274 -0
  90. package/main/modexp/array_lib/array_add_AGTB.zkasm +123 -0
  91. package/main/modexp/array_lib/array_add_short.zkasm +85 -0
  92. package/main/modexp/array_lib/array_div.zkasm +215 -0
  93. package/main/modexp/array_lib/array_div_long.zkasm +284 -0
  94. package/main/modexp/array_lib/array_div_short.zkasm +222 -0
  95. package/main/modexp/array_lib/array_mul.zkasm +97 -0
  96. package/main/modexp/array_lib/array_mul_long.zkasm +156 -0
  97. package/main/modexp/array_lib/array_mul_short.zkasm +127 -0
  98. package/main/modexp/array_lib/array_square.zkasm +246 -0
  99. package/main/modexp/array_lib/unused/array_add.zkasm +100 -0
  100. package/main/modexp/array_lib/unused/array_is_odd.zkasm +23 -0
  101. package/main/modexp/array_lib/unused/array_is_one.zkasm +33 -0
  102. package/main/modexp/array_lib/unused/array_is_zero.zkasm +34 -0
  103. package/main/modexp/array_lib/unused/array_sub_AGTB.zkasm +111 -0
  104. package/main/modexp/array_lib/unused/array_unshift.zkasm +37 -0
  105. package/main/modexp/array_lib/utils/array_compare.zkasm +82 -0
  106. package/main/modexp/array_lib/utils/array_trim.zkasm +49 -0
  107. package/main/modexp/constants.zkasm +5 -0
  108. package/main/modexp/modexp.zkasm +296 -0
  109. package/main/modexp/modexp_utils.zkasm +230 -0
  110. package/main/opcodes/arithmetic.zkasm +357 -0
  111. package/main/opcodes/block.zkasm +163 -0
  112. package/main/opcodes/calldata-returndata-code.zkasm +619 -0
  113. package/main/opcodes/comparison.zkasm +446 -0
  114. package/main/opcodes/context-information.zkasm +169 -0
  115. package/main/opcodes/create-terminate-context.zkasm +1011 -0
  116. package/main/opcodes/crypto.zkasm +96 -0
  117. package/main/opcodes/flow-control.zkasm +126 -0
  118. package/main/opcodes/logs.zkasm +193 -0
  119. package/main/opcodes/stack-operations.zkasm +658 -0
  120. package/main/opcodes/storage-memory.zkasm +313 -0
  121. package/main/pairings/BN254/addPointBN254.zkasm +245 -0
  122. package/main/pairings/BN254/ecAdd.zkasm +312 -0
  123. package/main/pairings/BN254/ecMul.zkasm +159 -0
  124. package/main/pairings/BN254/escalarMulBN254.zkasm +155 -0
  125. package/main/pairings/BN254/lineDiffPointsBN254.zkasm +83 -0
  126. package/main/pairings/BN254/lineSamePointsBN254.zkasm +96 -0
  127. package/main/pairings/FP12BN254/CYCLOFP12BN254/compressFp12BN254.zkasm +49 -0
  128. package/main/pairings/FP12BN254/CYCLOFP12BN254/decompressFp12BN254.zkasm +236 -0
  129. package/main/pairings/FP12BN254/CYCLOFP12BN254/expByXCompCycloFp12BN254.zkasm +444 -0
  130. package/main/pairings/FP12BN254/CYCLOFP12BN254/squareCompCycloFp12BN254.zkasm +212 -0
  131. package/main/pairings/FP12BN254/CYCLOFP12BN254/squareCycloFp12BN254.zkasm +228 -0
  132. package/main/pairings/FP12BN254/CYCLOFP12BN254/xBinDecompBN254.zkasm +64 -0
  133. package/main/pairings/FP12BN254/frob2Fp12BN254.zkasm +80 -0
  134. package/main/pairings/FP12BN254/frob3Fp12BN254.zkasm +96 -0
  135. package/main/pairings/FP12BN254/frobFp12BN254.zkasm +96 -0
  136. package/main/pairings/FP12BN254/inverseFp12BN254.zkasm +289 -0
  137. package/main/pairings/FP12BN254/mulFp12BN254.zkasm +408 -0
  138. package/main/pairings/FP12BN254/sparseMulAFp12BN254.zkasm +296 -0
  139. package/main/pairings/FP12BN254/sparseMulBFp12BN254.zkasm +291 -0
  140. package/main/pairings/FP12BN254/squareFp12BN254.zkasm +376 -0
  141. package/main/pairings/FP2BN254/addFp2BN254.zkasm +19 -0
  142. package/main/pairings/FP2BN254/escalarMulFp2BN254.zkasm +20 -0
  143. package/main/pairings/FP2BN254/invFp2BN254.zkasm +66 -0
  144. package/main/pairings/FP2BN254/mulFp2BN254.zkasm +19 -0
  145. package/main/pairings/FP2BN254/squareFp2BN254.zkasm +21 -0
  146. package/main/pairings/FP2BN254/subFp2BN254.zkasm +19 -0
  147. package/main/pairings/FP4BN254/squareFp4BN254.zkasm +76 -0
  148. package/main/pairings/FP6BN254/addFp6BN254.zkasm +59 -0
  149. package/main/pairings/FP6BN254/escalarMulFp6BN254.zkasm +51 -0
  150. package/main/pairings/FP6BN254/inverseFp6BN254.zkasm +208 -0
  151. package/main/pairings/FP6BN254/mulFp6BN254.zkasm +201 -0
  152. package/main/pairings/FP6BN254/sparseMulAFp6BN254.zkasm +65 -0
  153. package/main/pairings/FP6BN254/sparseMulBFp6BN254.zkasm +134 -0
  154. package/main/pairings/FP6BN254/sparseMulCFp6BN254.zkasm +128 -0
  155. package/main/pairings/FP6BN254/squareFp6BN254.zkasm +147 -0
  156. package/main/pairings/FP6BN254/subFp6BN254.zkasm +59 -0
  157. package/main/pairings/FPBN254/addFpBN254.zkasm +29 -0
  158. package/main/pairings/FPBN254/invFpBN254.zkasm +55 -0
  159. package/main/pairings/FPBN254/mulFpBN254.zkasm +29 -0
  160. package/main/pairings/FPBN254/reduceFpBN254.zkasm +25 -0
  161. package/main/pairings/FPBN254/squareFpBN254.zkasm +31 -0
  162. package/main/pairings/FPBN254/subFpBN254.zkasm +36 -0
  163. package/main/pairings/FRBN254/reduceFrBN254.zkasm +25 -0
  164. package/main/pairings/constants.zkasm +62 -0
  165. package/main/pairings/ecPairing.zkasm +244 -0
  166. package/main/pairings/finalExpBN254.zkasm +2095 -0
  167. package/main/pairings/halfPairingBN254.zkasm +428 -0
  168. package/main/pairings/loopLengthBN254.zkasm +75 -0
  169. package/main/pairings/millerLoopBN254.zkasm +741 -0
  170. package/main/pairings/pairingBN254.zkasm +481 -0
  171. package/main/pairings/unused/addFp12BN254.zkasm +130 -0
  172. package/main/pairings/unused/expByXCycloFp12BN254.zkasm +411 -0
  173. package/main/pairings/unused/expFp12BN254.zkasm +333 -0
  174. package/main/pairings/unused/subFp12BN254.zkasm +130 -0
  175. package/main/pairings/unused/xPseudoBinDecompBN254.zkasm +68 -0
  176. package/main/pairings/utilsTests/expCycloFp12BN254.zkasm +334 -0
  177. package/main/precompiled/end.zkasm +42 -0
  178. package/main/precompiled/identity.zkasm +99 -0
  179. package/main/precompiled/pre-ecAdd.zkasm +84 -0
  180. package/main/precompiled/pre-ecMul.zkasm +82 -0
  181. package/main/precompiled/pre-ecPairing.zkasm +72 -0
  182. package/main/precompiled/pre-ecrecover.zkasm +71 -0
  183. package/main/precompiled/pre-modexp.zkasm +367 -0
  184. package/main/precompiled/pre-sha2-256.zkasm +125 -0
  185. package/main/precompiled/revert-precompiled.zkasm +25 -0
  186. package/main/precompiled/selector.zkasm +77 -0
  187. package/main/process-change-l2-block.zkasm +147 -0
  188. package/main/process-tx.zkasm +587 -0
  189. package/main/tables/2-exp.zkasm +260 -0
  190. package/main/touched.zkasm +118 -0
  191. package/main/utils.zkasm +2335 -0
  192. package/main/vars.zkasm +117 -0
  193. package/package.json +62 -3
  194. package/test/bytes-length.zkasm +39 -0
  195. package/test/ecrecover.zkasm +538 -0
  196. package/test/lt4-test.zkasm +38 -0
  197. package/test/mstorex.zkasm +191 -0
  198. package/test/opcalldatacopy.ignore.zkasm +331 -0
  199. package/test/performance/read-push.zkasm +71 -0
  200. package/test/read-push.zkasm +304 -0
  201. package/test/testArrayArith.zkasm +1099 -0
  202. package/test/testArrayUtils.zkasm +335 -0
  203. package/test/testCycloFp12ArithBN254.zkasm +548 -0
  204. package/test/testEcAdd.zkasm +252 -0
  205. package/test/testEcMul.zkasm +231 -0
  206. package/test/testEcPairing.zkasm +436 -0
  207. package/test/testFinalExpBn254.zkasm +139 -0
  208. package/test/testFp12ArithBN254.zkasm +692 -0
  209. package/test/testFp2ArithBN254.zkasm +185 -0
  210. package/test/testFp4ArithBN254.zkasm +128 -0
  211. package/test/testFp6ArithBN254.zkasm +260 -0
  212. package/test/testFpArithBN254.zkasm +159 -0
  213. package/test/testFrArithBN254.zkasm +113 -0
  214. package/test/testHalfPairingBN254.zkasm +285 -0
  215. package/test/testModExp.zkasm +586 -0
  216. package/test/testModExpReturn.zkasm +81 -0
  217. package/test/testPairingBN254.zkasm +463 -0
  218. package/test/testPointArithBN254.zkasm +270 -0
  219. package/test/testSHA256.zkasm +27 -0
  220. package/test/touched-assert.zkasm +59 -0
  221. package/test/utils-expAD.zkasm +48 -0
  222. package/test/utils-getLenBytes.zkasm +36 -0
  223. package/tools/audit-tools/registry-op-checker.js +71 -0
  224. package/tools/get-not-used-labels.js +31 -0
  225. package/tools/helpers/helpers.js +47 -0
  226. package/tools/modexp-utils/README.md +5 -0
  227. package/tools/modexp-utils/modexp-test-gen.js +168 -0
  228. package/tools/modexp-utils/modexp-test-int.sage +37 -0
  229. package/tools/parallel-testing/checker.sh +6 -0
  230. package/tools/parallel-testing/gen-parallel-tests.js +78 -0
  231. package/tools/parallel-testing/parallel-tests-sample/sample.test.js +136 -0
  232. package/tools/run-tests-zkasm.js +83 -0
@@ -0,0 +1,270 @@
1
+ ; constants needed by executor C++
2
+ CONST %N = 2**19
3
+ CONST %MAX_CNT_STEPS_LIMIT = %N
4
+ CONST %MAX_CNT_ARITH_LIMIT = %N
5
+ CONST %MAX_CNT_BINARY_LIMIT = %N
6
+ CONST %MAX_CNT_MEM_ALIGN_LIMIT = %N
7
+ CONST %MAX_CNT_KECCAK_F_LIMIT = %N
8
+ CONST %MAX_CNT_PADDING_PG_LIMIT = %N
9
+ CONST %MAX_CNT_POSEIDON_G_LIMIT = %N
10
+
11
+ INCLUDE "../main/pairings/constants.zkasm"
12
+
13
+ VAR GLOBAL lastHashKId
14
+ VAR GLOBAL lastHashPId
15
+
16
+ VAR GLOBAL initial_A
17
+ VAR GLOBAL initial_B
18
+ VAR GLOBAL initial_C
19
+ VAR GLOBAL initial_D
20
+ VAR GLOBAL initial_E
21
+ VAR GLOBAL initial_CTX
22
+ VAR GLOBAL initial_SP
23
+ VAR GLOBAL initial_PC
24
+ VAR GLOBAL initial_GAS
25
+ VAR GLOBAL initial_SR
26
+ VAR GLOBAL initial_RR
27
+ VAR GLOBAL initial_HASHPOS
28
+ VAR GLOBAL initial_RCX
29
+
30
+ start:
31
+
32
+ STEP => A
33
+ 0 :ASSERT
34
+
35
+
36
+ A :MSTORE(initial_A)
37
+ B :MSTORE(initial_B)
38
+ C :MSTORE(initial_C)
39
+ D :MSTORE(initial_D)
40
+ E :MSTORE(initial_E)
41
+ CTX :MSTORE(initial_CTX)
42
+ SP :MSTORE(initial_SP)
43
+ PC :MSTORE(initial_PC)
44
+ GAS :MSTORE(initial_GAS)
45
+ SR :MSTORE(initial_SR)
46
+ RR :MSTORE(initial_RR)
47
+ HASHPOS :MSTORE(initial_HASHPOS)
48
+ RCX :MSTORE(initial_RCX)
49
+ 0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, RR, HASHPOS, RCX
50
+
51
+ -1 :MSTORE(lastHashKId)
52
+ -1 :MSTORE(lastHashPId)
53
+
54
+
55
+ ; 1] Point addition
56
+ ; 0 + 0 = 0
57
+ 0n :MSTORE(addPointBN254_P1_x1)
58
+ 0n :MSTORE(addPointBN254_P1_x2)
59
+ 0n :MSTORE(addPointBN254_P1_y1)
60
+ 0n :MSTORE(addPointBN254_P1_y2)
61
+ 0n :MSTORE(addPointBN254_P2_x1)
62
+ 0n :MSTORE(addPointBN254_P2_x2)
63
+ 0n :MSTORE(addPointBN254_P2_y1)
64
+ 0n :MSTORE(addPointBN254_P2_y2)
65
+ :CALL(addPointBN254)
66
+ 0n :MLOAD(addPointBN254_P3_x1)
67
+ 0n :MLOAD(addPointBN254_P3_x2)
68
+ 0n :MLOAD(addPointBN254_P3_y1)
69
+ 0n :MLOAD(addPointBN254_P3_y2)
70
+
71
+ ; 0 + P2 = P2
72
+ 0n :MSTORE(addPointBN254_P1_x1)
73
+ 0n :MSTORE(addPointBN254_P1_x2)
74
+ 0n :MSTORE(addPointBN254_P1_y1)
75
+ 0n :MSTORE(addPointBN254_P1_y2)
76
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(addPointBN254_P2_x1)
77
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(addPointBN254_P2_x2)
78
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(addPointBN254_P2_y1)
79
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(addPointBN254_P2_y2)
80
+ :CALL(addPointBN254)
81
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MLOAD(addPointBN254_P3_x1)
82
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MLOAD(addPointBN254_P3_x2)
83
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MLOAD(addPointBN254_P3_y1)
84
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MLOAD(addPointBN254_P3_y2)
85
+
86
+ ; P1 + 0 = P1
87
+ 18029695676650738226693292988307914797657423701064905010927197838374790804409n :MSTORE(addPointBN254_P1_x1)
88
+ 14583779054894525174450323658765874724019480979794335525732096752006891875705n :MSTORE(addPointBN254_P1_x2)
89
+ 2140229616977736810657479771656733941598412651537078903776637920509952744750n :MSTORE(addPointBN254_P1_y1)
90
+ 11474861747383700316476719153975578001603231366361248090558603872215261634898n :MSTORE(addPointBN254_P1_y2)
91
+ 0n :MSTORE(addPointBN254_P2_x1)
92
+ 0n :MSTORE(addPointBN254_P2_x2)
93
+ 0n :MSTORE(addPointBN254_P2_y1)
94
+ 0n :MSTORE(addPointBN254_P2_y2)
95
+ :CALL(addPointBN254)
96
+ 18029695676650738226693292988307914797657423701064905010927197838374790804409n :MLOAD(addPointBN254_P3_x1)
97
+ 14583779054894525174450323658765874724019480979794335525732096752006891875705n :MLOAD(addPointBN254_P3_x2)
98
+ 2140229616977736810657479771656733941598412651537078903776637920509952744750n :MLOAD(addPointBN254_P3_y1)
99
+ 11474861747383700316476719153975578001603231366361248090558603872215261634898n :MLOAD(addPointBN254_P3_y2)
100
+
101
+ ; P1 + (-P1) = 0
102
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(addPointBN254_P1_x1)
103
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(addPointBN254_P1_x2)
104
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(addPointBN254_P1_y1)
105
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(addPointBN254_P1_y2)
106
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(addPointBN254_P2_x1)
107
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(addPointBN254_P2_x2)
108
+ 13392588948715843804641432497768002650278120570034223513918757245338268106653n :MSTORE(addPointBN254_P2_y1)
109
+ 17805874995975841540914202342111839520379459829704422454583296818431106115052n :MSTORE(addPointBN254_P2_y2)
110
+ :CALL(addPointBN254)
111
+ 0n :MLOAD(addPointBN254_P3_x1)
112
+ 0n :MLOAD(addPointBN254_P3_x2)
113
+ 0n :MLOAD(addPointBN254_P3_y1)
114
+ 0n :MLOAD(addPointBN254_P3_y2)
115
+
116
+ ; P1 + P1 = 2·P1
117
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(addPointBN254_P1_x1)
118
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(addPointBN254_P1_x2)
119
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(addPointBN254_P1_y1)
120
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(addPointBN254_P1_y2)
121
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(addPointBN254_P2_x1)
122
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(addPointBN254_P2_x2)
123
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(addPointBN254_P2_y1)
124
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(addPointBN254_P2_y2)
125
+ :CALL(addPointBN254)
126
+ 18029695676650738226693292988307914797657423701064905010927197838374790804409n :MLOAD(addPointBN254_P3_x1)
127
+ 14583779054894525174450323658765874724019480979794335525732096752006891875705n :MLOAD(addPointBN254_P3_x2)
128
+ 2140229616977736810657479771656733941598412651537078903776637920509952744750n :MLOAD(addPointBN254_P3_y1)
129
+ 11474861747383700316476719153975578001603231366361248090558603872215261634898n :MLOAD(addPointBN254_P3_y2)
130
+
131
+ ; P1 + P2 = P3
132
+ 18029695676650738226693292988307914797657423701064905010927197838374790804409n :MSTORE(addPointBN254_P1_x1)
133
+ 14583779054894525174450323658765874724019480979794335525732096752006891875705n :MSTORE(addPointBN254_P1_x2)
134
+ 2140229616977736810657479771656733941598412651537078903776637920509952744750n :MSTORE(addPointBN254_P1_y1)
135
+ 11474861747383700316476719153975578001603231366361248090558603872215261634898n :MSTORE(addPointBN254_P1_y2)
136
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(addPointBN254_P2_x1)
137
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(addPointBN254_P2_x2)
138
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(addPointBN254_P2_y1)
139
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(addPointBN254_P2_y2)
140
+ :CALL(addPointBN254)
141
+ 2725019753478801796453339367788033689375851816420509565303521482350756874229n :MLOAD(addPointBN254_P3_x1)
142
+ 7273165102799931111715871471550377909735733521218303035754523677688038059653n :MLOAD(addPointBN254_P3_x2)
143
+ 2512659008974376214222774206987427162027254181373325676825515531566330959255n :MLOAD(addPointBN254_P3_y1)
144
+ 957874124722006818841961785324909313781880061366718538693995380805373202866n :MLOAD(addPointBN254_P3_y2)
145
+
146
+ ; 2] Escalar multiplication
147
+ 0n :MSTORE(escalarMulBN254_k)
148
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(escalarMulBN254_P_x1)
149
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(escalarMulBN254_P_x2)
150
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(escalarMulBN254_P_y1)
151
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(escalarMulBN254_P_y2)
152
+ :CALL(escalarMulBN254)
153
+ 0n :MLOAD(escalarMulBN254_Q_x1)
154
+ 0n :MLOAD(escalarMulBN254_Q_x2)
155
+ 0n :MLOAD(escalarMulBN254_Q_y1)
156
+ 0n :MLOAD(escalarMulBN254_Q_y2)
157
+
158
+ %BN254_SIX_TIMES_X_SQ :MSTORE(escalarMulBN254_k)
159
+ 0n :MSTORE(escalarMulBN254_P_x1)
160
+ 0n :MSTORE(escalarMulBN254_P_x2)
161
+ 0n :MSTORE(escalarMulBN254_P_y1)
162
+ 0n :MSTORE(escalarMulBN254_P_y2)
163
+ :CALL(escalarMulBN254)
164
+ 0n :MLOAD(escalarMulBN254_Q_x1)
165
+ 0n :MLOAD(escalarMulBN254_Q_x2)
166
+ 0n :MLOAD(escalarMulBN254_Q_y1)
167
+ 0n :MLOAD(escalarMulBN254_Q_y2)
168
+
169
+ %BN254_SIX_TIMES_X_SQ :MSTORE(escalarMulBN254_k)
170
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(escalarMulBN254_P_x1)
171
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(escalarMulBN254_P_x2)
172
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(escalarMulBN254_P_y1)
173
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(escalarMulBN254_P_y2)
174
+ :CALL(escalarMulBN254)
175
+ 13824868563399673693405984206252027284526901521624614945388441201916943098448n :MLOAD(escalarMulBN254_Q_x1)
176
+ 6070174842523651825461006324987645339257276059765462992338211551285097849152n :MLOAD(escalarMulBN254_Q_x2)
177
+ 4224873494559498571787136390356590572898009346319218613936276445484292886657n :MLOAD(escalarMulBN254_Q_y1)
178
+ 14979195929948718632567968180703131754953567972706796447883440492471033097811n :MLOAD(escalarMulBN254_Q_y2)
179
+
180
+ %BN254_R :MSTORE(escalarMulBN254_k)
181
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(escalarMulBN254_P_x1)
182
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(escalarMulBN254_P_x2)
183
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(escalarMulBN254_P_y1)
184
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(escalarMulBN254_P_y2)
185
+ :CALL(escalarMulBN254)
186
+ 0n :MLOAD(escalarMulBN254_Q_x1)
187
+ 0n :MLOAD(escalarMulBN254_Q_x2)
188
+ 0n :MLOAD(escalarMulBN254_Q_y1)
189
+ 0n :MLOAD(escalarMulBN254_Q_y2)
190
+
191
+ ; 3] Tangent line to a point
192
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(lineSamePointsBN254_P_x1)
193
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(lineSamePointsBN254_P_x2)
194
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(lineSamePointsBN254_P_y1)
195
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(lineSamePointsBN254_P_y2)
196
+ 1n :MSTORE(lineSamePointsBN254_Q_x)
197
+ 2n :MSTORE(lineSamePointsBN254_Q_y)
198
+ :CALL(lineSamePointsBN254)
199
+ 5866721355212621053956121605984270769408822799517647453365718615957338215267n :MLOAD(lineSamePointsBN254_l11_x)
200
+ 10805765471263851218954508755716868212208493914051915959293621483915454724277n :MLOAD(lineSamePointsBN254_l11_y)
201
+ 441787448737107494458538247410558220237964585327985295018200621859384744906n :MLOAD(lineSamePointsBN254_l13_x)
202
+ 16376088161625424614405301418083801678984212103591999741784373000936238959085n :MLOAD(lineSamePointsBN254_l13_y)
203
+ 12094372820654450448173487244699814664976451191756576932392084702582606199137n :MLOAD(lineSamePointsBN254_l22_x)
204
+ 16329471503453734725328813612581742273267405310373604832422964304856480374124n :MLOAD(lineSamePointsBN254_l22_y)
205
+
206
+ ; 4] Line passing through two different points
207
+ 10857046999023057135944570762232829481370756359578518086990519993285655852781n :MSTORE(lineDiffPointsBN254_P1_x1)
208
+ 11559732032986387107991004021392285783925812861821192530917403151452391805634n :MSTORE(lineDiffPointsBN254_P1_x2)
209
+ 8495653923123431417604973247489272438418190587263600148770280649306958101930n :MSTORE(lineDiffPointsBN254_P1_y1)
210
+ 4082367875863433681332203403145435568316851327593401208105741076214120093531n :MSTORE(lineDiffPointsBN254_P1_y2)
211
+ 18029695676650738226693292988307914797657423701064905010927197838374790804409n :MSTORE(lineDiffPointsBN254_P2_x1)
212
+ 14583779054894525174450323658765874724019480979794335525732096752006891875705n :MSTORE(lineDiffPointsBN254_P2_x2)
213
+ 2140229616977736810657479771656733941598412651537078903776637920509952744750n :MSTORE(lineDiffPointsBN254_P2_y1)
214
+ 11474861747383700316476719153975578001603231366361248090558603872215261634898n :MSTORE(lineDiffPointsBN254_P2_y2)
215
+ 1n :MSTORE(lineDiffPointsBN254_Q_x)
216
+ 2n :MSTORE(lineDiffPointsBN254_Q_y)
217
+ :CALL(lineDiffPointsBN254)
218
+ 14345297355255362181497444452150170632573334682972773847873355690178269903256n :MLOAD(lineDiffPointsBN254_l12_x)
219
+ 6048094043816276132918639274747177880187336235946285989629387201109000140142n :MLOAD(lineDiffPointsBN254_l12_y)
220
+ 6355424306145694606947493475832538496819777935726521244993642728797005357180n :MLOAD(lineDiffPointsBN254_l22_x)
221
+ 14495749000319008587101889994427132655409931118529976780236175098644084667216n :MLOAD(lineDiffPointsBN254_l22_y)
222
+ 4617834131706974237889373560251879390068389218389281828469153443366136187126n :MLOAD(lineDiffPointsBN254_l23_x)
223
+ 18535807517613687025007129469892030737201813557688282181535107728189048279364n :MLOAD(lineDiffPointsBN254_l23_y)
224
+
225
+
226
+ end:
227
+
228
+ $ => A :MLOAD(initial_A)
229
+ $ => B :MLOAD(initial_B)
230
+ $ => C :MLOAD(initial_C)
231
+ $ => D :MLOAD(initial_D)
232
+ $ => E :MLOAD(initial_E)
233
+ $ => CTX :MLOAD(initial_CTX)
234
+ $ => SP :MLOAD(initial_SP)
235
+ $ => PC :MLOAD(initial_PC)
236
+ $ => GAS :MLOAD(initial_GAS)
237
+ $ => SR :MLOAD(initial_SR)
238
+ $ => RR :MLOAD(initial_RR)
239
+ $ => HASHPOS :MLOAD(initial_HASHPOS)
240
+ $ => RCX :MLOAD(initial_RCX)
241
+
242
+ ; label finalizeExecution needed by executor C++
243
+ finalizeExecution:
244
+ ${beforeLast()} : JMPN(finalizeExecution)
245
+
246
+ : JMP(start)
247
+ opINVALID:
248
+ ; label checkAndSaveFrom needed by executor C++
249
+ checkAndSaveFrom:
250
+ :JMP(opINVALID)
251
+
252
+
253
+ INCLUDE "../main/pairings/FRBN254/reduceFrBN254.zkasm"
254
+
255
+ INCLUDE "../main/pairings/FPBN254/reduceFpBN254.zkasm"
256
+ INCLUDE "../main/pairings/FPBN254/addFpBN254.zkasm"
257
+ INCLUDE "../main/pairings/FPBN254/subFpBN254.zkasm"
258
+ INCLUDE "../main/pairings/FPBN254/mulFpBN254.zkasm"
259
+
260
+ INCLUDE "../main/pairings/FP2BN254/addFp2BN254.zkasm"
261
+ INCLUDE "../main/pairings/FP2BN254/subFp2BN254.zkasm"
262
+ INCLUDE "../main/pairings/FP2BN254/escalarMulFp2BN254.zkasm"
263
+ INCLUDE "../main/pairings/FP2BN254/mulFp2BN254.zkasm"
264
+ INCLUDE "../main/pairings/FP2BN254/squareFp2BN254.zkasm"
265
+ INCLUDE "../main/pairings/FP2BN254/invFp2BN254.zkasm"
266
+
267
+ INCLUDE "../main/pairings/BN254/addPointBN254.zkasm"
268
+ INCLUDE "../main/pairings/BN254/escalarMulBN254.zkasm"
269
+ INCLUDE "../main/pairings/BN254/lineSamePointsBN254.zkasm"
270
+ INCLUDE "../main/pairings/BN254/lineDiffPointsBN254.zkasm"
@@ -0,0 +1,27 @@
1
+
2
+ start:
3
+ STEP => A
4
+ 0 :ASSERT ; Ensure it is the beginning of the execution
5
+ 1 => C :MSTORE(txCalldataLen)
6
+ 1 :MSTORE(originCTX)
7
+ 1 :MSTORE(calldataCTX)
8
+ 1 => CTX
9
+ 0 => E
10
+ 0xFF00000000000000000000000000000000000000000000000000000000000000n :MSTORE(MEM:E)
11
+
12
+ 2 :MSTORE(currentCTX)
13
+ 2 => CTX
14
+
15
+ $ => E :MLOAD(sha256DataId)
16
+ 0 => E :MSTORE(sha256DataOffset)
17
+ 0 => HASHPOS
18
+ RR :MSTORE(tmpZkSHA256)
19
+ :CALL(SHA256data)
20
+ $ => E :MLOAD(sha256Hash)
21
+
22
+ 0xa8100ae6aa1940d0b663bb31cd466142ebbdbd5187131b92d93818987832eb89n => A
23
+ E :ASSERT
24
+
25
+ :JMP(finalizeExecution)
26
+
27
+ INCLUDE "../main/main.zkasm"
@@ -0,0 +1,59 @@
1
+ start:
2
+ ; set root state & init root touched
3
+ 0xABCDEFn => SR
4
+ :CALL(initTouchedTree)
5
+
6
+ ; check touched root is 0
7
+ $ => A :MLOAD(touchedSR)
8
+ 0 :ASSERT
9
+
10
+ ; set address
11
+ 0x0123456789012345678901234567890123456789n => A
12
+ ; if the address is cold [0 if warm, 1 if cold]
13
+ ; cold address
14
+ :CALL(isColdAddress)
15
+ D => A
16
+ 1 :ASSERT
17
+
18
+ ; warm address
19
+ 0x0123456789012345678901234567890123456789n => A
20
+ :CALL(isColdAddress)
21
+ D => A
22
+ 0 :ASSERT
23
+
24
+ ; set address & storage position
25
+ 0x0123456789012345678901234567890123456789n => A
26
+ 0xAn => C
27
+ ; if the storage slot is cold [0 if warm, 1 if cold]
28
+ ; cold slot and mark it as warm
29
+ :CALL(isColdSlot)
30
+ 1 :ASSERT
31
+
32
+ ; warm slot
33
+ 0x0123456789012345678901234567890123456789n => A
34
+ 0xAn => C
35
+ :CALL(isColdSlot)
36
+ 0 :ASSERT
37
+
38
+ ; warm precompiled
39
+ 0x3n => A
40
+ :CALL(isColdAddress)
41
+ D => A
42
+ 0 :ASSERT
43
+
44
+ ; cold zero address
45
+ 0x0n => A
46
+ :CALL(isColdAddress)
47
+ D => A
48
+ 1 :ASSERT
49
+
50
+ ; warm zero address
51
+ 0x0n => A
52
+ :CALL(isColdAddress)
53
+ D => A
54
+ 0 :ASSERT
55
+
56
+ 0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, HASHPOS, RR ; Set all registers to 0
57
+ :JMP(finalizeExecution)
58
+
59
+ INCLUDE "../main/main.zkasm"
@@ -0,0 +1,48 @@
1
+ VAR GLOBAL test
2
+ start:
3
+ 4 => A
4
+ 2 => D
5
+ :CALL(expAD)
6
+ A :MSTORE(test)
7
+ 16 => A
8
+ $ :MLOAD(test),ASSERT
9
+
10
+ 16 => A
11
+ 8 => D
12
+ :CALL(expAD)
13
+ A :MSTORE(test)
14
+ 0x100000000n => A
15
+ $ :MLOAD(test),ASSERT
16
+
17
+ 2 => A
18
+ 256 => D
19
+ :CALL(expAD)
20
+ A :MSTORE(test)
21
+ 0 => A
22
+ $ :MLOAD(test),ASSERT
23
+
24
+ 2 => A
25
+ 255 => D
26
+ :CALL(expAD)
27
+ A :MSTORE(test)
28
+ 0x8000000000000000000000000000000000000000000000000000000000000000n => A
29
+ $ :MLOAD(test),ASSERT
30
+
31
+ 2 => A
32
+ 255 => D
33
+ :CALL(expAD)
34
+ A :MSTORE(test)
35
+ 0x8000000000000000000000000000000000000000000000000000000000000000n => A
36
+ $ :MLOAD(test),ASSERT
37
+
38
+ 3 => A
39
+ 0x8000n => D
40
+ :CALL(expAD)
41
+ A :MSTORE(test)
42
+ 0xf2eda75a1e9624437a4f18c1316372866f14b6bf3f7ff7441996f65b747a0001n => A
43
+ $ :MLOAD(test),ASSERT
44
+
45
+ 0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, HASHPOS, RR ; Set all registers to 0
46
+ :JMP(finalizeExecution)
47
+
48
+ INCLUDE "../main/main.zkasm"
@@ -0,0 +1,36 @@
1
+ VAR GLOBAL test
2
+ start:
3
+ 0x66 => B
4
+ :CALL(getLenBytes)
5
+ A :MSTORE(test)
6
+ 1 => A
7
+ $ :MLOAD(test),ASSERT
8
+
9
+ 0x6666 => B
10
+ :CALL(getLenBytes)
11
+ A :MSTORE(test)
12
+ 2 => A
13
+ $ :MLOAD(test),ASSERT
14
+
15
+ 0x666666 => B
16
+ :CALL(getLenBytes)
17
+ A :MSTORE(test)
18
+ 3 => A
19
+ $ :MLOAD(test),ASSERT
20
+
21
+ 0x66666666 => B
22
+ :CALL(getLenBytes)
23
+ A :MSTORE(test)
24
+ 4 => A
25
+ $ :MLOAD(test),ASSERT
26
+
27
+ 0x666666666666n => B
28
+ :CALL(getLenBytes)
29
+ A :MSTORE(test)
30
+ 6 => A
31
+ $ :MLOAD(test),ASSERT
32
+
33
+ 0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, HASHPOS, RR ; Set all registers to 0
34
+ :JMP(finalizeExecution)
35
+
36
+ INCLUDE "../main/main.zkasm"
@@ -0,0 +1,71 @@
1
+ /* eslint-disable no-use-before-define */
2
+ /* eslint-disable no-continue */
3
+ /* eslint-disable no-restricted-syntax */
4
+ const rom = require('../../build/rom.json');
5
+ const argv = require('yargs');
6
+
7
+ /**
8
+ * This script checks if there are new registry operations in the rom build. It compares it with the rom input selected
9
+ * The result is logged in the console.
10
+ */
11
+ async function main() {
12
+ // load rom input
13
+ let input = {};
14
+
15
+ if (argv._.length === 0) {
16
+ console.log('You need to specify an input file');
17
+ process.exit(1);
18
+ } else if (argv._.length === 1) {
19
+ console.log('path input: ', argv._[0]);
20
+ input = JSON.parse(await fs.promises.readFile(argv._[0], 'utf8'));
21
+ } else {
22
+ console.log('Only one input file at a time is permitted');
23
+ process.exit(1);
24
+ }
25
+
26
+ // Find free inputs at rom's build
27
+ const regOpFound = getRegOpFromBuild(rom.program);
28
+ const prevRegOpFound = getRegOpFromBuild(input.program);
29
+ const diffFound = [];
30
+ // Compare found registers with previous rom
31
+ for (const op of regOpFound) {
32
+ const found = prevRegOpFound.find((item) => item.key === op.key);
33
+ if (!found) {
34
+ diffFound.push(op);
35
+ }
36
+ }
37
+ // Log warnings, f.e. a free input with more than one occurrence
38
+ for (const op of diffFound) {
39
+ console.log(`WARNING: Found new registry operation at ${op.fileName}:${op.line}->${op.lineStr}`);
40
+ }
41
+ console.log('FINISHED');
42
+ }
43
+
44
+ function getRegOpFromBuild(build) {
45
+ const regOpFound = [];
46
+ // Check all steps
47
+ for (const step of build) {
48
+ let count = 0;
49
+ // Get steps where we operate with registers
50
+ for (const key of Object.keys(step)) {
51
+ if (key === 'inA' || key === 'inB' || key === 'inC' || key === 'inD' || key === 'inE' || key === 'inF') {
52
+ if (step.lineStr.includes('*')) {
53
+ count += 1;
54
+ }
55
+ if (Object.keys(step).includes('CONST')) {
56
+ count += 1;
57
+ }
58
+ count += 1;
59
+ }
60
+ }
61
+ // Save steps with more than one register operation
62
+ if (count > 1) {
63
+ // Remove spaces from string
64
+ step.key = `${step.lineStr.replace(/\s/g, '')}-${step.fileName}`;
65
+ regOpFound.push(step);
66
+ }
67
+ }
68
+
69
+ return regOpFound;
70
+ }
71
+ main();
@@ -0,0 +1,31 @@
1
+ const fs = require('fs');
2
+ const rom = require('../build/rom.json');
3
+
4
+ async function main() {
5
+ const labelsAddr = Object.values(rom.labels);
6
+ const { program } = rom;
7
+ for (let i = 0; i < program.length; i++) {
8
+ const { jmpAddr, elseAddr } = program[i];
9
+ if (jmpAddr) {
10
+ const indexJmp = labelsAddr.indexOf(jmpAddr);
11
+ if (indexJmp !== -1) {
12
+ labelsAddr.splice(indexJmp, 1);
13
+ }
14
+ }
15
+ if (elseAddr) {
16
+ const indexElse = labelsAddr.indexOf(elseAddr);
17
+ if (indexElse !== -1) {
18
+ labelsAddr.splice(indexElse, 1);
19
+ }
20
+ }
21
+ }
22
+ const filteredLabels = [];
23
+ for (let j = 0; j < labelsAddr.length; j++) {
24
+ filteredLabels.push(Object.keys(rom.labels).find((key) => rom.labels[key] === labelsAddr[j]));
25
+ }
26
+ console.log(filteredLabels);
27
+ await fs.writeFileSync('no-used-labels.json', JSON.stringify(filteredLabels, null, 2));
28
+ // await fs.writeFileSync('no-used-labelsAddr-Addr.json', JSON.stringify(labelsAddr, null, 2));
29
+ }
30
+
31
+ main();
@@ -0,0 +1,47 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+ const { compile, newCommitPolsArray } = require('pilcom');
5
+
6
+ const buildPoseidon = require('@0xpolygonhermez/zkevm-commonjs').getPoseidon;
7
+
8
+ // Global paths to build Main PIL to fill polynomials in tests
9
+ const pathMainPil = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zkevm-proverjs/pil/main.pil');
10
+ const fileCachePil = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zkevm-proverjs/cache-main-pil.json');
11
+
12
+ async function compilePil() {
13
+ if (!fs.existsSync(fileCachePil)) {
14
+ const poseidon = await buildPoseidon();
15
+ const { F } = poseidon;
16
+ const pilConfig = {
17
+ defines: { N: 4096 },
18
+ namespaces: ['Main', 'Global'],
19
+ disableUnusedError: true,
20
+ };
21
+ const p = await compile(F, pathMainPil, null, pilConfig);
22
+ fs.writeFileSync(fileCachePil, `${JSON.stringify(p, null, 1)}\n`, 'utf8');
23
+ }
24
+
25
+ const pil = JSON.parse(fs.readFileSync(fileCachePil));
26
+
27
+ return newCommitPolsArray(pil);
28
+ }
29
+
30
+ // Get all zkasm test files
31
+ function getTestFiles(pathZkasm) {
32
+ // check if path provided is a file or a directory
33
+ const stats = fs.statSync(pathZkasm);
34
+
35
+ if (!stats.isDirectory()) {
36
+ return [pathZkasm];
37
+ }
38
+
39
+ const filesNames = fs.readdirSync(pathZkasm).filter((name) => name.endsWith('.zkasm'));
40
+
41
+ return filesNames.map((fileName) => path.join(pathZkasm, fileName));
42
+ }
43
+
44
+ module.exports = {
45
+ compilePil,
46
+ getTestFiles,
47
+ };
@@ -0,0 +1,5 @@
1
+ ## Notes
2
+
3
+ The file `modexp-test-gen.js` automatically geneates a zkasm file, executes it some specified number of times and outputs a json file containing the record of the counters. At this moment, it is hardcoded to work for the operation `array_div(array_mul(a, b),c)`, where `a` and `b` was chosen to be $2^{256} - 3$, while `c` was chosen to be $2^{256} - 1$ to achieve the maximum complexity in the operation.
4
+
5
+ The `modexp-test-init.sage` takes the counters in the json file and, for each different counter, interpolates the multivariate polynomial (having as evaluation points the lenght of the inputs in the previous file) that evaluates to the counters.