@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,658 @@
1
+ /**
2
+ * @link [https://www.evm.codes/#5f?fork=shanghai]
3
+ * @zk-counters
4
+ * - 100 steps
5
+ * @process-opcode
6
+ * - stack input: none
7
+ * - stack output: [0]
8
+ */
9
+ opPUSH0:
10
+ ; checks zk-counters
11
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
12
+
13
+ ; check out-of-gas
14
+ GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas)
15
+ ; store stack output
16
+ 0 :MSTORE(SP++); [0 => SP]
17
+ ; check stack overflow
18
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
19
+
20
+ /**
21
+ * @link [https://www.evm.codes/#60?fork=berlin]
22
+ * @zk-counters
23
+ * - 100 steps (stack) || 400 steps (calldata)
24
+ * - 1 binary (stack) || 0 binary (calldata)
25
+ * @process-opcode
26
+ * - stack input: none
27
+ * - stack output: [pushed_value]
28
+ */
29
+ opPUSH1:
30
+ ; check is a deploy
31
+ ; if is a deploy, get bytes from memory else, get bytes from stack
32
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
33
+
34
+ opPUSH2:
35
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
36
+
37
+ opPUSH3:
38
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
39
+
40
+ opPUSH4:
41
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
42
+
43
+ opPUSH5:
44
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
45
+
46
+ opPUSH6:
47
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
48
+
49
+ opPUSH7:
50
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
51
+
52
+ opPUSH8:
53
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
54
+
55
+ opPUSH9:
56
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
57
+
58
+ opPUSH10:
59
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
60
+
61
+ opPUSH11:
62
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
63
+
64
+ opPUSH12:
65
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
66
+
67
+ opPUSH13:
68
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
69
+
70
+ opPUSH14:
71
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
72
+
73
+ opPUSH15:
74
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
75
+
76
+ opPUSH16:
77
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
78
+
79
+ opPUSH17:
80
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
81
+
82
+ opPUSH18:
83
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
84
+
85
+ opPUSH19:
86
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
87
+
88
+ opPUSH20:
89
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
90
+
91
+ opPUSH21:
92
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
93
+
94
+ opPUSH22:
95
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
96
+
97
+ opPUSH23:
98
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
99
+
100
+ opPUSH24:
101
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
102
+
103
+ opPUSH25:
104
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
105
+
106
+ opPUSH26:
107
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
108
+
109
+ opPUSH27:
110
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
111
+
112
+ opPUSH28:
113
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
114
+
115
+ opPUSH29:
116
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
117
+
118
+ opPUSH30:
119
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
120
+
121
+ opPUSH31:
122
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
123
+
124
+ opPUSH32:
125
+ $ => B :MLOAD(isCreateContract), JMPNZ(opAuxPUSHB, opAuxPUSHA)
126
+
127
+ opAuxPUSHA:
128
+ ; checks zk-counters
129
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
130
+
131
+ $ => B :MLOAD(bytecodeLength)
132
+ PC + D - B :JMPN(opAuxPUSHA2)
133
+ B - PC => D
134
+
135
+ opAuxPUSHA2:
136
+ ; check out-of-gas
137
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
138
+ ; read bytes from calldata
139
+ D => E :CALL(readPush); in: [D,E: bytes to read] out: [E: value read]
140
+ ; store stack output
141
+ E :MSTORE(SP++); [pushed_value(E) => SP]
142
+ ; check stack overflow
143
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow)
144
+ ; rectify PC
145
+ PC + D => PC :JMP(readCode)
146
+
147
+ opAuxPUSHB:
148
+ ; checks zk-counters
149
+ %MAX_CNT_STEPS - STEP - 400 :JMPN(outOfCountersStep)
150
+ ; check is a create/create2
151
+ $ => A :MLOAD(isCreate), JMPNZ(opAuxPUSHBcreate)
152
+ $ => B :MLOAD(txCalldataLen)
153
+ PC + D - B :JMPN(opAuxPUSHB2)
154
+ B - PC => D
155
+
156
+ opAuxPUSHB2:
157
+ ; set bytes length to read to C
158
+ 0 => A
159
+ D - 1 => C :JMPN(opAuxPUSHBend)
160
+
161
+
162
+ opAuxPUSHBloop:
163
+ ; checks zk-counters
164
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
165
+ ; get position where data starts in the tx
166
+ $ => HASHPOS :MLOAD(dataStarts)
167
+ ; add PC to data starts to point the bytes to read for the push
168
+ HASHPOS + PC => HASHPOS
169
+ PC + 1 => PC
170
+ ; get memory pointer for hashing
171
+ $ => E :MLOAD(batchHashDataId)
172
+ $ => B :HASHK1(E)
173
+ ; accumulate hash value
174
+ A + B => A
175
+ ; decrease length for loop
176
+ C - 1 => C :JMPN(opAuxPUSHBend)
177
+ 1 => D :CALL(SHLarith); in: [A: value, D: #bytes to left shift] out: [A: shifted result]
178
+ :JMP(opAuxPUSHBloop)
179
+
180
+ opAuxPUSHBend:
181
+ ; check out-of-gas
182
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
183
+ ; store stack output (value)
184
+ A :MSTORE(SP++); [pushed_value(E) => SP]
185
+ ; check stack overflow
186
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
187
+
188
+ opAuxPUSHBcreate:
189
+ ; get bytes length
190
+ $ => B :MLOAD(txCalldataLen)
191
+ ; PUSH in a create, we need to get bytes from memory (not calldata)
192
+ ; get pushed bytes from previous context memory
193
+ $ => CTX :MLOAD(originCTX)
194
+ ; get offset call position
195
+ $ => E :MLOAD(argsOffsetCall)
196
+ ; increase current program counter (PC) to offset for getting pushed bytes to read
197
+ E + PC => E
198
+ D => C
199
+ C - B + PC :JMPN(opAuxPUSHBcreate2)
200
+ 0 => A
201
+ B - PC => C :JMPZ(opfinalPUSHBcreate)
202
+
203
+ opAuxPUSHBcreate2:
204
+ ; set length to read to C for MLOADX call
205
+ :CALL(MLOADX); in: [E: offset, C: length] out: [A: value, E: new offset]
206
+ ; increase to PC the length of the read bytes
207
+ PC + D => PC
208
+ ; put in the lowest significant bytes, align value to right
209
+ 32 - D => D :CALL(SHRarith); in: [A: value, D: #bytes to right shift] out: [A: shifted result]
210
+
211
+ opfinalPUSHBcreate:
212
+ ; return to current context
213
+ $ => CTX :MLOAD(currentCTX), JMP(opAuxPUSHBend)
214
+
215
+ /**
216
+ * @link [https://www.evm.codes/#80?fork=berlin]
217
+ * @zk-counters
218
+ * - 100 steps
219
+ * @process-opcode
220
+ * - stack input: [value]
221
+ * - stack output: [duplicated_value, original_value]
222
+ */
223
+ opDUP1:
224
+ ; checks zk-counters
225
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
226
+
227
+ ; check stack underflow
228
+ SP - 1 :JMPN(stackUnderflow)
229
+
230
+ ; check out-of-gas
231
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
232
+
233
+ $ => A :MLOAD(SP-1); [value => A]
234
+
235
+ ; store duplicated value
236
+ A :MSTORE(SP++); [duplicated_value(A) => SP]
237
+
238
+ ; check stack overflow
239
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
240
+
241
+ opDUP2:
242
+
243
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
244
+
245
+ SP - 2 :JMPN(stackUnderflow)
246
+
247
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
248
+
249
+ $ => A :MLOAD(SP-2)
250
+ A :MSTORE(SP++)
251
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
252
+
253
+ opDUP3:
254
+
255
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
256
+
257
+ SP - 3 :JMPN(stackUnderflow)
258
+
259
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
260
+
261
+ $ => A :MLOAD(SP-3)
262
+ A :MSTORE(SP++)
263
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
264
+
265
+ opDUP4:
266
+
267
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
268
+
269
+ SP - 4 :JMPN(stackUnderflow)
270
+
271
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
272
+
273
+ $ => A :MLOAD(SP-4)
274
+ A :MSTORE(SP++)
275
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
276
+
277
+ opDUP5:
278
+
279
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
280
+
281
+ SP - 5 :JMPN(stackUnderflow)
282
+
283
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
284
+
285
+ $ => A :MLOAD(SP-5)
286
+ A :MSTORE(SP++)
287
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
288
+
289
+ opDUP6:
290
+
291
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
292
+
293
+ SP - 6 :JMPN(stackUnderflow)
294
+
295
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
296
+
297
+ $ => A :MLOAD(SP-6)
298
+ A :MSTORE(SP++)
299
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
300
+
301
+ opDUP7:
302
+
303
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
304
+
305
+ SP - 7 :JMPN(stackUnderflow)
306
+
307
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
308
+
309
+ $ => A :MLOAD(SP-7)
310
+ A :MSTORE(SP++)
311
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
312
+
313
+ opDUP8:
314
+
315
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
316
+
317
+ SP - 8 :JMPN(stackUnderflow)
318
+
319
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
320
+
321
+ $ => A :MLOAD(SP-8)
322
+ A :MSTORE(SP++)
323
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
324
+
325
+ opDUP9:
326
+
327
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
328
+
329
+ SP - 9 :JMPN(stackUnderflow)
330
+
331
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
332
+
333
+ $ => A :MLOAD(SP-9)
334
+ A :MSTORE(SP++)
335
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
336
+
337
+ opDUP10:
338
+
339
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
340
+
341
+ SP - 10 :JMPN(stackUnderflow)
342
+
343
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
344
+
345
+ $ => A :MLOAD(SP-10)
346
+ A :MSTORE(SP++)
347
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
348
+
349
+ opDUP11:
350
+
351
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
352
+
353
+ SP - 11 :JMPN(stackUnderflow)
354
+
355
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
356
+
357
+ $ => A :MLOAD(SP-11)
358
+ A :MSTORE(SP++)
359
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
360
+
361
+ opDUP12:
362
+
363
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
364
+
365
+ SP - 12 :JMPN(stackUnderflow)
366
+
367
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
368
+
369
+ $ => A :MLOAD(SP-12)
370
+ A :MSTORE(SP++)
371
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
372
+
373
+ opDUP13:
374
+
375
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
376
+
377
+ SP - 13 :JMPN(stackUnderflow)
378
+
379
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
380
+
381
+ $ => A :MLOAD(SP-13)
382
+ A :MSTORE(SP++)
383
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
384
+
385
+ opDUP14:
386
+
387
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
388
+
389
+ SP - 14 :JMPN(stackUnderflow)
390
+
391
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
392
+
393
+ $ => A :MLOAD(SP-14)
394
+ A :MSTORE(SP++)
395
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
396
+
397
+ opDUP15:
398
+
399
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
400
+
401
+ SP - 15 :JMPN(stackUnderflow)
402
+
403
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
404
+
405
+ $ => A :MLOAD(SP-15)
406
+ A :MSTORE(SP++)
407
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
408
+
409
+ opDUP16:
410
+
411
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
412
+
413
+ SP - 16 :JMPN(stackUnderflow)
414
+
415
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
416
+
417
+ $ => A :MLOAD(SP-16)
418
+ A :MSTORE(SP++)
419
+ %MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
420
+
421
+ /**
422
+ * @link [https://www.evm.codes/#90?fork=berlin]
423
+ * @zk-counters
424
+ * - 100 steps
425
+ * @process-opcode
426
+ * - stack input: [value_to_swap_a, value_to_swap_b]
427
+ * - stack output: [swapped_value_a, swapped_value_b]
428
+ */
429
+ opSWAP1:
430
+ ; checks zk-counters
431
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
432
+
433
+ ; check stack underflow
434
+ SP - 2 :JMPN(stackUnderflow)
435
+
436
+ ; check out-of-gas
437
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
438
+
439
+ ; read values from stack
440
+ $ => A :MLOAD(SP-1); [value_to_swap_a => A]
441
+ $ => B :MLOAD(SP-2); [value_to_swap_b => B]
442
+ ; store swapped value a
443
+ A :MSTORE(SP-2); [swapped_value_a => SP]
444
+ ; store swapped value b
445
+ B :MSTORE(SP-1), JMP(readCode); [swapped_value_b => SP]
446
+
447
+ opSWAP2:
448
+
449
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
450
+
451
+ SP - 3 :JMPN(stackUnderflow)
452
+
453
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
454
+
455
+ $ => A :MLOAD(SP-1)
456
+ $ => B :MLOAD(SP-3)
457
+ A :MSTORE(SP-3)
458
+ B :MSTORE(SP-1), JMP(readCode)
459
+
460
+ opSWAP3:
461
+
462
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
463
+
464
+ SP - 4 :JMPN(stackUnderflow)
465
+
466
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
467
+
468
+ $ => A :MLOAD(SP-1)
469
+ $ => B :MLOAD(SP-4)
470
+ A :MSTORE(SP-4)
471
+ B :MSTORE(SP-1), JMP(readCode)
472
+
473
+ opSWAP4:
474
+
475
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
476
+
477
+ SP - 5 :JMPN(stackUnderflow)
478
+
479
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
480
+
481
+ $ => A :MLOAD(SP-1)
482
+ $ => B :MLOAD(SP-5)
483
+ A :MSTORE(SP-5)
484
+ B :MSTORE(SP-1), JMP(readCode)
485
+
486
+ opSWAP5:
487
+
488
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
489
+
490
+ SP - 6 :JMPN(stackUnderflow)
491
+
492
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
493
+
494
+ $ => A :MLOAD(SP-1)
495
+ $ => B :MLOAD(SP-6)
496
+ A :MSTORE(SP-6)
497
+ B :MSTORE(SP-1), JMP(readCode)
498
+
499
+ opSWAP6:
500
+
501
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
502
+
503
+ SP - 7 :JMPN(stackUnderflow)
504
+
505
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
506
+
507
+ $ => A :MLOAD(SP-1)
508
+ $ => B :MLOAD(SP-7)
509
+ A :MSTORE(SP-7)
510
+ B :MSTORE(SP-1), JMP(readCode)
511
+
512
+ opSWAP7:
513
+
514
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
515
+
516
+ SP - 8 :JMPN(stackUnderflow)
517
+
518
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
519
+
520
+ $ => A :MLOAD(SP-1)
521
+ $ => B :MLOAD(SP-8)
522
+ A :MSTORE(SP-8)
523
+ B :MSTORE(SP-1), JMP(readCode)
524
+
525
+ opSWAP8:
526
+
527
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
528
+
529
+ SP - 9 :JMPN(stackUnderflow)
530
+
531
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
532
+
533
+ $ => A :MLOAD(SP-1)
534
+ $ => B :MLOAD(SP-9)
535
+ A :MSTORE(SP-9)
536
+ B :MSTORE(SP-1), JMP(readCode)
537
+
538
+ opSWAP9:
539
+
540
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
541
+
542
+ SP - 10 :JMPN(stackUnderflow)
543
+
544
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
545
+
546
+ $ => A :MLOAD(SP-1)
547
+ $ => B :MLOAD(SP-10)
548
+ A :MSTORE(SP-10)
549
+ B :MSTORE(SP-1), JMP(readCode)
550
+
551
+ opSWAP10:
552
+
553
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
554
+
555
+ SP - 11 :JMPN(stackUnderflow)
556
+
557
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
558
+
559
+ $ => A :MLOAD(SP-1)
560
+ $ => B :MLOAD(SP-11)
561
+ A :MSTORE(SP-11)
562
+ B :MSTORE(SP-1), JMP(readCode)
563
+
564
+ opSWAP11:
565
+
566
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
567
+
568
+ SP - 12 :JMPN(stackUnderflow)
569
+
570
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
571
+
572
+ $ => A :MLOAD(SP-1)
573
+ $ => B :MLOAD(SP-12)
574
+ A :MSTORE(SP-12)
575
+ B :MSTORE(SP-1), JMP(readCode)
576
+
577
+ opSWAP12:
578
+
579
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
580
+
581
+ SP - 13 :JMPN(stackUnderflow)
582
+
583
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
584
+
585
+ $ => A :MLOAD(SP-1)
586
+ $ => B :MLOAD(SP-13)
587
+ A :MSTORE(SP-13)
588
+ B :MSTORE(SP-1), JMP(readCode)
589
+
590
+ opSWAP13:
591
+
592
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
593
+
594
+ SP - 14 :JMPN(stackUnderflow)
595
+
596
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
597
+
598
+ $ => A :MLOAD(SP-1)
599
+ $ => B :MLOAD(SP-14)
600
+ A :MSTORE(SP-14)
601
+ B :MSTORE(SP-1), JMP(readCode)
602
+
603
+ opSWAP14:
604
+
605
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
606
+
607
+ SP - 15 :JMPN(stackUnderflow)
608
+
609
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
610
+
611
+ $ => A :MLOAD(SP-1)
612
+ $ => B :MLOAD(SP-15)
613
+ A :MSTORE(SP-15)
614
+ B :MSTORE(SP-1), JMP(readCode)
615
+
616
+ opSWAP15:
617
+
618
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
619
+
620
+ SP - 16 :JMPN(stackUnderflow)
621
+
622
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
623
+
624
+ $ => A :MLOAD(SP-1)
625
+ $ => B :MLOAD(SP-16)
626
+ A :MSTORE(SP-16)
627
+ B :MSTORE(SP-1), JMP(readCode)
628
+
629
+ opSWAP16:
630
+
631
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
632
+
633
+ SP - 17 :JMPN(stackUnderflow)
634
+
635
+ GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
636
+
637
+ $ => A :MLOAD(SP-1)
638
+ $ => B :MLOAD(SP-17)
639
+ A :MSTORE(SP-17)
640
+ B :MSTORE(SP-1), JMP(readCode)
641
+
642
+ /**
643
+ * @link [https://www.evm.codes/#50?fork=berlin]
644
+ * @zk-counters
645
+ * - 100 steps
646
+ * @process-opcode
647
+ * - stack input: [stack_item]
648
+ * - stack output: none
649
+ */
650
+ opPOP:
651
+ ; checks zk-counters
652
+ %MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
653
+
654
+ ; check stack underflow
655
+ SP - 1 => SP :JMPN(stackUnderflow)
656
+
657
+ ; check out-of-gas
658
+ GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas, readCode)