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 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,168 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { execSync } = require('child_process');
4
+
5
+ const filePath = path.join(__dirname, 'tmpTest.zkasm');
6
+
7
+ const fileBefore =
8
+ `; constants needed by executor C++
9
+ CONST %N = 2**19
10
+ CONST %MAX_CNT_STEPS_LIMIT = %N
11
+ CONST %MAX_CNT_ARITH_LIMIT = %N
12
+ CONST %MAX_CNT_BINARY_LIMIT = %N
13
+ CONST %MAX_CNT_MEM_ALIGN_LIMIT = %N
14
+ CONST %MAX_CNT_KECCAK_F_LIMIT = %N
15
+ CONST %MAX_CNT_PADDING_PG_LIMIT = %N
16
+ CONST %MAX_CNT_POSEIDON_G_LIMIT = %N
17
+
18
+ VAR GLOBAL lastHashKId
19
+ VAR GLOBAL lastHashPId
20
+
21
+ VAR GLOBAL initial_A
22
+ VAR GLOBAL initial_B
23
+ VAR GLOBAL initial_C
24
+ VAR GLOBAL initial_D
25
+ VAR GLOBAL initial_E
26
+ VAR GLOBAL initial_CTX
27
+ VAR GLOBAL initial_SP
28
+ VAR GLOBAL initial_PC
29
+ VAR GLOBAL initial_GAS
30
+ VAR GLOBAL initial_SR
31
+ VAR GLOBAL initial_RR
32
+ VAR GLOBAL initial_HASHPOS
33
+ VAR GLOBAL initial_RCX
34
+
35
+ start:
36
+
37
+ STEP => A
38
+ 0 :ASSERT
39
+
40
+ A :MSTORE(initial_A)
41
+ B :MSTORE(initial_B)
42
+ C :MSTORE(initial_C)
43
+ D :MSTORE(initial_D)
44
+ E :MSTORE(initial_E)
45
+ CTX :MSTORE(initial_CTX)
46
+ SP :MSTORE(initial_SP)
47
+ PC :MSTORE(initial_PC)
48
+ GAS :MSTORE(initial_GAS)
49
+ SR :MSTORE(initial_SR)
50
+ RR :MSTORE(initial_RR)
51
+ HASHPOS :MSTORE(initial_HASHPOS)
52
+ RCX :MSTORE(initial_RCX)
53
+ 0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, RR, HASHPOS, RCX
54
+
55
+ -1 :MSTORE(lastHashKId)
56
+ -1 :MSTORE(lastHashPId)
57
+ `;
58
+ const fileAfter =
59
+ `
60
+ end:
61
+
62
+ $ => A :MLOAD(initial_A)
63
+ $ => B :MLOAD(initial_B)
64
+ $ => C :MLOAD(initial_C)
65
+ $ => D :MLOAD(initial_D)
66
+ $ => E :MLOAD(initial_E)
67
+ $ => CTX :MLOAD(initial_CTX)
68
+ $ => SP :MLOAD(initial_SP)
69
+ $ => PC :MLOAD(initial_PC)
70
+ $ => GAS :MLOAD(initial_GAS)
71
+ $ => SR :MLOAD(initial_SR)
72
+ $ => RR :MLOAD(initial_RR)
73
+ $ => HASHPOS :MLOAD(initial_HASHPOS)
74
+ $ => RCX :MLOAD(initial_RCX)
75
+
76
+ ; label finalizeExecution needed by executor C++
77
+ finalizeExecution:
78
+ \${beforeLast()} : JMPN(finalizeExecution)
79
+
80
+ : JMP(start)
81
+ opINVALID:
82
+ ; label checkAndSaveFrom needed by executor C++
83
+ checkAndSaveFrom:
84
+ :JMP(opINVALID)
85
+
86
+ INCLUDE "../main/modexp/array_lib/utils/array_trim.zkasm"
87
+ INCLUDE "../main/modexp/array_lib/utils/array_compare.zkasm"
88
+
89
+ INCLUDE "../main/modexp/array_lib/array_add_AGTB.zkasm"
90
+ INCLUDE "../main/modexp/array_lib/array_add_short.zkasm"
91
+ INCLUDE "../main/modexp/array_lib/array_mul.zkasm"
92
+ INCLUDE "../main/modexp/array_lib/array_mul_long.zkasm"
93
+ INCLUDE "../main/modexp/array_lib/array_mul_short.zkasm"
94
+ INCLUDE "../main/modexp/array_lib/array_div.zkasm"
95
+ INCLUDE "../main/modexp/array_lib/array_div_long.zkasm"
96
+ INCLUDE "../main/modexp/array_lib/array_div_short.zkasm"
97
+ `;
98
+
99
+ const counters = [];
100
+
101
+ for (let i = 1; i <= 5; i++) {
102
+ for (let j = 1; j <= i; j++) {
103
+ for (let k = 1; k <= j; k++) {
104
+ console.log(`Test (${i},${j},${k}):`);
105
+
106
+ // Define the test
107
+ let fileTest1 = `\t${i} => C\n\t${j} => D\n\t115792089237316195423570985008687907853269984665640564039457584007913129639933n :MSTORE(array_mul_inA)\n\t115792089237316195423570985008687907853269984665640564039457584007913129639933n :MSTORE(array_mul_inB)\n`
108
+
109
+ for (let l = 1; l < j; l++) {
110
+ fileTest1 += `\t${l} => E\n\t115792089237316195423570985008687907853269984665640564039457584007913129639933n :MSTORE(array_mul_inA + E)\n`
111
+ fileTest1 += `\t115792089237316195423570985008687907853269984665640564039457584007913129639933n :MSTORE(array_mul_inB + E)\n`
112
+ }
113
+
114
+ for (let l = j; l < i; l++) {
115
+ fileTest1 += `\t${l} => E\n\t115792089237316195423570985008687907853269984665640564039457584007913129639933n :MSTORE(array_mul_inA + E)\n`
116
+ }
117
+
118
+ const fileTest2 = `\t\t:CALL(array_mul)\n\t${i+j} => C\n\t${k} => D\n\t`
119
+
120
+ let fileTest3 =`$ => A :MLOAD(array_mul_out)\n\tA :MSTORE(array_div_inA)\n\t115792089237316195423570985008687907853269984665640564039457584007913129639935n :MSTORE(array_div_inB)\n\t`
121
+
122
+ for (let l = 1; l < k; l++) {
123
+ fileTest3 += `${l} => E\n\t$ => A :MLOAD(array_mul_out + E)\n\tA :MSTORE(array_div_inA + E)\n\t115792089237316195423570985008687907853269984665640564039457584007913129639935n :MSTORE(array_div_inB + E)\n\t`
124
+ }
125
+
126
+ for (let l = k; l < i + j; l++) {
127
+ fileTest3 += `${l} => E\n\t$ => A :MLOAD(array_mul_out + E)\n\tA :MSTORE(array_div_inA + E)\n\t`
128
+ }
129
+
130
+ fileTest3 += `:CALL(array_div)\n`;
131
+
132
+ const fileTest = fileTest1 + fileTest2 + fileTest3;
133
+
134
+ // Create the file
135
+ fs.writeFileSync(filePath, fileBefore + fileTest + fileAfter);
136
+
137
+ const output = execSync(
138
+ `node node_modules/@0xpolygonhermez/zkevm-proverjs/test/zkasmtest.js ${filePath} -H ./main/modexp/helper.js -N "2**24" -d`
139
+ ).toString();
140
+
141
+ // Capture the counters
142
+ const pattern = /cntArith: (\d+)n,\n cntBinary: (\d+)n,\n cntKeccakF: (\d+)n,\n cntMemAlign: (\d+)n,\n cntPoseidonG: (\d+)n,\n cntPaddingPG: (\d+)n,\n cntSteps: (\d+)/;
143
+ const matches = output.match(pattern);
144
+
145
+ if (matches) {
146
+ const [,cntArith, cntBinary, , , , , cntSteps] = matches.map(Number);
147
+ const testCounters = {
148
+ lenR: i,
149
+ lenB: j,
150
+ lenM: k,
151
+ cntArith,
152
+ cntBinary,
153
+ cntSteps,
154
+ };
155
+ console.log(testCounters);
156
+ counters.push(testCounters);
157
+ } else {
158
+ console.log('Something wrong happened with the output');
159
+ }
160
+
161
+ // Delete the file
162
+ fs.unlinkSync(filePath);
163
+ }
164
+ }
165
+ }
166
+
167
+ // Write the counters to a JSON file
168
+ fs.writeFileSync(path.join(__dirname, 'modexp-counters.json'), JSON.stringify(counters));
@@ -0,0 +1,37 @@
1
+ import json
2
+ import os
3
+
4
+ dir_path = os.path.dirname(os.path.realpath(__file__))
5
+
6
+ with open(dir_path + '/modexp-counters.json') as f:
7
+ data = json.load(f)
8
+
9
+ points = []
10
+ valuesArith = []
11
+ valuesBinary = []
12
+ valuesSteps = []
13
+ for i in range(0, len(data)):
14
+ points.append([data[i]['lenR'],data[i]['lenB'],data[i]['lenM']])
15
+ valuesArith.append(data[i]['cntArith'])
16
+ valuesBinary.append(data[i]['cntBinary'])
17
+ valuesSteps.append(data[i]['cntSteps'])
18
+
19
+ R.<x,y,z> = PolynomialRing(QQ)
20
+
21
+ def findInterpolation(points, values):
22
+ for i in range(1, 11):
23
+ for j in range(1, i+1):
24
+ for k in range(1, j+1):
25
+ try:
26
+ f = R.interpolation([i,j,k], points, values)
27
+ return f
28
+ except:
29
+ pass
30
+
31
+ f1 = findInterpolation(points, valuesArith)
32
+ f2 = findInterpolation(points, valuesBinary)
33
+ f3 = findInterpolation(points, valuesSteps)
34
+ print("f1",f1)
35
+ print("f2",f2)
36
+ print("f3",f3)
37
+ print(f1(3,2,1), f2(3,2,1), f3(3,2,1))
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+ FILE=$PWD/tools/parallel-testing/parallel-tests/checker.txt
3
+ if [ -f "$FILE" ]; then
4
+ cat "$FILE"
5
+ exit 1
6
+ fi
@@ -0,0 +1,78 @@
1
+ /* eslint-disable no-console */
2
+ /* eslint-disable import/no-extraneous-dependencies */
3
+ /* eslint-disable no-restricted-syntax */
4
+ const { expect } = require('chai');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+
8
+ const { compile } = require('pilcom');
9
+ const buildPoseidon = require('@0xpolygonhermez/zkevm-commonjs').getPoseidon;
10
+
11
+ const folderPaths = [
12
+ '../../node_modules/@0xpolygonhermez/zkevm-testvectors/inputs-executor',
13
+ '../../node_modules/@0xpolygonhermez/zkevm-testvectors/inputs-executor/ethereum-tests/GeneralStateTests',
14
+ ];
15
+
16
+ const fileCachePil = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zkevm-proverjs/cache-main-pil.json');
17
+ const pathMainPil = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zkevm-proverjs/pil/main.pil');
18
+ const inputs = [];
19
+ const testsFolder = path.join(__dirname, 'parallel-tests');
20
+ const sampleDir = path.join(__dirname, 'parallel-tests-sample/sample.test.js');
21
+ const { argv } = require('yargs');
22
+
23
+ async function genTestsFiles() {
24
+ if (!fs.existsSync(testsFolder)) {
25
+ fs.mkdirSync(testsFolder);
26
+ }
27
+ for (const inputPath of inputs) {
28
+ const name = inputPath.split('/').slice(-1)[0].replace('json', 'test.js');
29
+ const sample = fs.readFileSync(sampleDir, 'utf-8');
30
+ let test = sample.replace('%%INPUT_PATH%%', `${inputPath}`);
31
+ // Replace skip vcounters flag
32
+ if (argv.skipVCounters) {
33
+ test = test.replace('%%SKIP_VCOUNTERS%%', 'yes');
34
+ }
35
+ fs.writeFileSync(`${testsFolder}/${name}`, test);
36
+ }
37
+ expect(true).to.be.equal(true);
38
+ }
39
+
40
+ async function main() {
41
+ const poseidon = await buildPoseidon();
42
+ const { F } = poseidon;
43
+
44
+ // Add all test files to `inputs` array
45
+ for (const folder of folderPaths) {
46
+ const inputsPath = path.join(__dirname, folder);
47
+ fs.readdirSync(inputsPath).forEach((file) => {
48
+ const filePath = path.join(inputsPath, file);
49
+ // Remove json lists that are generated with gen inputs script and are not inputs
50
+ if (file.endsWith('.json') && !file.includes('testsOOC-list.json') && !file.includes('tests30M-list.json') && !file.includes('no-exec')) {
51
+ inputs.push(filePath);
52
+ } else if (fs.statSync(filePath).isDirectory() && !filePath.includes('tests-OOC')) {
53
+ fs.readdirSync(filePath).forEach((subFile) => {
54
+ const subFilePath = path.join(filePath, subFile);
55
+ if (subFile.endsWith('.json') && !subFile.includes('testsOOC-list.json') && !subFile.includes('tests30M-list.json') && !subFile.includes('no-exec')) {
56
+ inputs.push(subFilePath);
57
+ }
58
+ });
59
+ }
60
+ });
61
+ }
62
+
63
+ console.log(`Inputs executor generated: ${inputs.length}`);
64
+
65
+ const pilConfig = {
66
+ defines: { N: 4096 },
67
+ namespaces: ['Main', 'Global'],
68
+ disableUnusedError: true,
69
+ };
70
+
71
+ const pil = await compile(F, pathMainPil, null, pilConfig);
72
+ fs.writeFileSync(fileCachePil, `${JSON.stringify(pil, null, 1)}\n`, 'utf8');
73
+ genTestsFiles();
74
+ // Generate counters diff table csv file
75
+ fs.writeFileSync(path.join(__dirname, 'countersDiffs.csv'), 'Test name,vSteps,rSteps,StepsDiff,vArith,rArith,ArithDiff,vBinary,rBinary,BinaryDiff,vMemAlign,rMemAlign,memAlignDiff,vKeccaks,rKeccaks,keccaksDiff,vPoseidon,rPoseidon,PoseidonDiff,vPadding,rPadding,PaddingDiff,vSHA256,rSHA256,SHA256Diff\n', 'utf8');
76
+ }
77
+
78
+ main();
@@ -0,0 +1,136 @@
1
+ /* eslint-disable global-require */
2
+ /* eslint-disable import/no-dynamic-require */
3
+ /* eslint-disable no-use-before-define */
4
+ /* eslint-disable import/no-extraneous-dependencies */
5
+ /* eslint-disable import/extensions */
6
+ /* eslint-disable import/no-unresolved */
7
+ const { expect } = require('chai');
8
+ const fs = require('fs');
9
+ const path = require('path');
10
+
11
+ const { newCommitPolsArray } = require('pilcom');
12
+ const smMain = require('@0xpolygonhermez/zkevm-proverjs/src/sm/sm_main/sm_main');
13
+
14
+ let rom = require('../../../build/rom.json');
15
+
16
+ let stepsN = 2 ** 23;
17
+ let counters = false;
18
+
19
+ const fileCachePil = path.join(__dirname, '../../../node_modules/@0xpolygonhermez/zkevm-proverjs/cache-main-pil.json');
20
+
21
+ const checkerDir = path.join(__dirname, 'checker.txt');
22
+
23
+ const inputPath = '%%INPUT_PATH%%';
24
+ const nameFile = path.basename(inputPath);
25
+ const input = JSON.parse(fs.readFileSync(inputPath, 'utf8'));
26
+ const skipVcounters = '%%SKIP_VCOUNTERS%%';
27
+
28
+ it(`${nameFile}`, async () => {
29
+ if (fs.existsSync(checkerDir)) {
30
+ process.exit(1);
31
+ }
32
+ const pil = JSON.parse(fs.readFileSync(fileCachePil));
33
+ const cmPols = newCommitPolsArray(pil);
34
+ if (input.gasLimit) {
35
+ rom = require(`../../../build/rom-${input.gasLimit}.test.json`);
36
+ }
37
+ if (input.stepsN) {
38
+ stepsN = input.stepsN;
39
+ counters = true;
40
+ }
41
+ await runTest(cmPols, stepsN);
42
+
43
+ expect(true).to.be.equal(true);
44
+ });
45
+
46
+ async function runTest(cmPols, steps) {
47
+ try {
48
+ const config = {
49
+ debug: true,
50
+ debugInfo: {
51
+ inputName: path.basename(inputPath),
52
+ },
53
+ stepsN: steps,
54
+ counters,
55
+ assertOutputs: true,
56
+ };
57
+
58
+ const res = await smMain.execute(cmPols.Main, input, rom, config);
59
+ if (skipVcounters !== 'yes') {
60
+ compareCounters(input.virtualCounters, res.counters);
61
+ }
62
+ } catch (err) {
63
+ fs.writeFileSync(checkerDir, `Failed test ${inputPath} - ${err}}`);
64
+ throw err;
65
+ }
66
+ }
67
+
68
+ function compareCounters(virtualCounters, result) {
69
+ const countersDiff = {
70
+ steps: {
71
+ virtual: virtualCounters.steps,
72
+ real: Number(result.cntSteps),
73
+ diff: getPercentageDiff(virtualCounters.steps, Number(result.cntSteps)),
74
+ },
75
+ arith: {
76
+ virtual: virtualCounters.arith,
77
+ real: Number(result.cntArith),
78
+ diff: getPercentageDiff(virtualCounters.arith, Number(result.cntArith)),
79
+ },
80
+ binary: {
81
+ virtual: virtualCounters.binary,
82
+ real: Number(result.cntBinary),
83
+ diff: getPercentageDiff(virtualCounters.binary, Number(result.cntBinary)),
84
+ },
85
+ memAlign: {
86
+ virtual: virtualCounters.memAlign,
87
+ real: Number(result.cntMemAlign),
88
+ diff: getPercentageDiff(virtualCounters.memAlign, Number(result.cntMemAlign)),
89
+ },
90
+ keccaks: {
91
+ virtual: virtualCounters.keccaks,
92
+ real: Number(result.cntKeccakF),
93
+ diff: getPercentageDiff(virtualCounters.keccaks, Number(result.cntKeccakF)),
94
+ },
95
+ poseidon: {
96
+ virtual: virtualCounters.poseidon,
97
+ real: Number(result.cntPoseidonG),
98
+ diff: getPercentageDiff(virtualCounters.poseidon, Number(result.cntPoseidonG)),
99
+ },
100
+ padding: {
101
+ virtual: virtualCounters.padding,
102
+ real: Number(result.cntPaddingPG),
103
+ diff: getPercentageDiff(virtualCounters.padding, Number(result.cntPaddingPG)),
104
+ },
105
+ sha256: {
106
+ virtual: virtualCounters.sha256,
107
+ real: Number(result.cntSha256F),
108
+ diff: getPercentageDiff(virtualCounters.sha256, Number(result.cntSha256F)),
109
+ },
110
+ };
111
+ fs.appendFileSync(path.join(__dirname, '../countersDiffs.csv'), `${nameFile},${countersDiff.steps.virtual},${countersDiff.steps.real},${String(countersDiff.steps.diff).replace('.', ',')},${countersDiff.arith.virtual},${countersDiff.arith.real},${String(countersDiff.arith.diff).replace('.', ',')},${countersDiff.binary.virtual},${countersDiff.binary.real},${String(countersDiff.binary.diff).replace('.', ',')},${countersDiff.memAlign.virtual},${countersDiff.memAlign.real},${String(countersDiff.memAlign.diff).replace('.', ',')},${countersDiff.keccaks.virtual},${countersDiff.keccaks.real},${String(countersDiff.keccaks.diff).replace('.', ',')},${countersDiff.poseidon.virtual},${countersDiff.poseidon.real},${String(countersDiff.poseidon.diff).replace('.', ',')},${countersDiff.padding.virtual},${countersDiff.padding.real},${String(countersDiff.padding.diff).replace('.', ',')},${countersDiff.sha256.virtual},${countersDiff.sha256.real},${String(countersDiff.sha256.diff).replace('.', ',')}\n`);
112
+ // Check percentages are greater than 0
113
+ Object.keys(countersDiff).forEach((key) => {
114
+ if (Number(countersDiff[key].diff) < 0) {
115
+ throw new Error(`Negative percentage diff: ${countersDiff[key].virtual}/${countersDiff[key].real}/${countersDiff[key].diff}% at ${key}}`);
116
+ }
117
+ });
118
+ }
119
+
120
+ function getPercentageDiff(a, b) {
121
+ if (a === 0) {
122
+ // a and b are 0
123
+ if (b === 0) {
124
+ return 0;
125
+ }
126
+ // a is 0 but b is not -> fail test
127
+
128
+ return -100;
129
+ }
130
+ // a is not 0 but b is -> passed
131
+ if (b === 0) {
132
+ return 0;
133
+ }
134
+
135
+ return (((a - b) / b) * 100).toFixed(2);
136
+ }
@@ -0,0 +1,83 @@
1
+ /* eslint-disable no-restricted-syntax */
2
+ /* eslint-disable import/no-extraneous-dependencies */
3
+ /* eslint-disable no-use-before-define */
4
+ const path = require('path');
5
+ const chalk = require('chalk');
6
+ const zkasm = require('@0xpolygonhermez/zkasmcom');
7
+ const smMain = require('@0xpolygonhermez/zkevm-proverjs/src/sm/sm_main/sm_main');
8
+
9
+ const emptyInput = require('@0xpolygonhermez/zkevm-proverjs/test/inputs/empty_input.json');
10
+
11
+ const { argv } = require('yargs')
12
+ .alias('v', 'verbose');
13
+
14
+ const { compilePil, getTestFiles } = require('./helpers/helpers');
15
+
16
+ async function main() {
17
+ // Compile pil
18
+ console.log(chalk.yellow('--> Compile PIL'));
19
+ const cmPols = await compilePil();
20
+
21
+ // Get all zkasm files
22
+ const pathZkasm = path.join(process.cwd(), process.argv[2]);
23
+ const files = await getTestFiles(pathZkasm);
24
+
25
+ let wasFailed = false;
26
+ // Run all zkasm files
27
+ // eslint-disable-next-line no-restricted-syntax
28
+ console.log(chalk.yellow('--> Start running zkasm files'));
29
+ for (const file of files) {
30
+
31
+ if (file.includes('ignore')) {
32
+ continue;
33
+ }
34
+
35
+ if (await runTest(file, cmPols) == 1) {
36
+ wasFailed = true;
37
+ }
38
+ }
39
+ if (wasFailed) {
40
+ process.exit(1);
41
+ }
42
+ }
43
+
44
+ // returns true if test succeed and false if test failed
45
+ async function runTest(pathTest, cmPols) {
46
+ // Compile rom
47
+ const configZkasm = {
48
+ defines: [],
49
+ allowUndefinedLabels: true,
50
+ allowOverwriteLabels: true,
51
+ };
52
+
53
+ const config = {
54
+ debug: true,
55
+ stepsN: 8388608,
56
+ assertOutputs: false,
57
+ };
58
+ let failed = false;
59
+ // execute zkasm tests
60
+ try {
61
+ console.log(chalk.blue(' --> start'), pathTest);
62
+ const rom = await zkasm.compile(pathTest, null, configZkasm);
63
+ const result = await smMain.execute(cmPols.Main, emptyInput, rom, config);
64
+ console.log(chalk.green(' --> pass'), pathTest);
65
+ if (argv.verbose) {
66
+ console.log(chalk.blue(' --> verbose'));
67
+ console.log(chalk.blue(' --> counters'));
68
+ console.log(result.counters);
69
+ console.log(chalk.blue(' --> outputs'));
70
+ console.log(result.output);
71
+ console.log(chalk.blue(' --> logs'));
72
+ console.log(result.logs);
73
+ }
74
+ } catch (e) {
75
+ console.log(chalk.red(' --> fail'), pathTest);
76
+ console.log(e);
77
+ failed = true;
78
+ }
79
+
80
+ return failed;
81
+ }
82
+
83
+ main();