@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.
- package/.eslintrc.js +33 -0
- package/.github/CODEOWNERS +14 -0
- package/.github/ISSUE_TEMPLATE/bug.yml +38 -0
- package/.github/ISSUE_TEMPLATE/feature.yml +26 -0
- package/.github/ISSUE_TEMPLATE/question.yml +26 -0
- package/.github/workflows/main.yaml +40 -0
- package/LICENSE +636 -0
- package/README.md +23 -5
- package/audits/Hexens_Polygon_zkEVM_PUBLIC_27.02.23.pdf +0 -0
- package/audits/Polygon-zkEVM-Public-v1.1-verichains-19-03-2024.pdf +0 -0
- package/audits/zkEVM-ROM-upgrade-1-Spearbit-30-May.pdf +0 -0
- package/audits/zkEVM-ROM-upgrade-2-Spearbit-21-August.pdf +0 -0
- package/audits/zkEVM-engagement-1-Spearbit-27-March.pdf +0 -0
- package/audits/zkEVM-engagement-2-Spearbit-27-March.pdf +0 -0
- package/audits/zkEVM-engagement-3-Spearbit-6-April.pdf +0 -0
- package/counters/README.md +45 -0
- package/counters/counters-executor.js +80 -0
- package/counters/countersConstants.zkasm +370 -0
- package/counters/endIncludes.zkasm +18 -0
- package/counters/initIncludes.zkasm +2 -0
- package/counters/tests/MLOAD32.zkasm +27 -0
- package/counters/tests/MLOADX.zkasm +30 -0
- package/counters/tests/MSTORE32.zkasm +32 -0
- package/counters/tests/MSTOREX.zkasm +36 -0
- package/counters/tests/SHLarith.zkasm +28 -0
- package/counters/tests/SHLarithBit.zkasm +28 -0
- package/counters/tests/SHRarith.zkasm +28 -0
- package/counters/tests/SHRarithBit.zkasm +28 -0
- package/counters/tests/abs.zkasm +29 -0
- package/counters/tests/addBatchHashByteByByte.zkasm +31 -0
- package/counters/tests/computeGasSendCall.zkasm +30 -0
- package/counters/tests/divArith.zkasm +27 -0
- package/counters/tests/expAD.zkasm +30 -0
- package/counters/tests/getLenBits.zkasm +30 -0
- package/counters/tests/getLenBytes.zkasm +32 -0
- package/counters/tests/isEmptyAccount.zkasm +30 -0
- package/counters/tests/mulARITH.zkasm +28 -0
- package/counters/tests/offsetUtil.zkasm +29 -0
- package/counters/tests/opADDMOD.zkasm +28 -0
- package/counters/tests/opAdd.zkasm +27 -0
- package/counters/tests/opBLOCKHASH.zkasm +28 -0
- package/counters/tests/opCALL.zkasm +41 -0
- package/counters/tests/opCALLCODE.zkasm +41 -0
- package/counters/tests/opCALLDATACOPY.zkasm +28 -0
- package/counters/tests/opCALLDATALOAD.zkasm +27 -0
- package/counters/tests/opCODECOPY.zkasm +28 -0
- package/counters/tests/opCREATE.zkasm +35 -0
- package/counters/tests/opCREATE2.zkasm +35 -0
- package/counters/tests/opDELEGATECALL.zkasm +35 -0
- package/counters/tests/opDIV.zkasm +27 -0
- package/counters/tests/opEXP.zkasm +29 -0
- package/counters/tests/opEXTCODECOPY.zkasm +29 -0
- package/counters/tests/opMOD.zkasm +27 -0
- package/counters/tests/opMUL.zkasm +27 -0
- package/counters/tests/opMULMOD.zkasm +28 -0
- package/counters/tests/opRETURN.zkasm +32 -0
- package/counters/tests/opRETURNDATACOPY.zkasm +29 -0
- package/counters/tests/opREVERT.zkasm +32 -0
- package/counters/tests/opSDIV.zkasm +28 -0
- package/counters/tests/opSHA3.zkasm +28 -0
- package/counters/tests/opSIGNEXTEND.zkasm +27 -0
- package/counters/tests/opSMOD.zkasm +28 -0
- package/counters/tests/opSTATICCALL.zkasm +35 -0
- package/counters/tests/opSUB.zkasm +27 -0
- package/counters/tests/saveMem.zkasm +31 -0
- package/docs/opcode-cost-zk-counters.md +315 -0
- package/docs/usage-ecrecover.md +51 -0
- package/index.js +43 -0
- package/main/block-info.zkasm +204 -0
- package/main/constants.zkasm +145 -0
- package/main/ecrecover/addFpEc.zkasm +31 -0
- package/main/ecrecover/checkSqrtFpEc.zkasm +1558 -0
- package/main/ecrecover/constEc.zkasm +13 -0
- package/main/ecrecover/ecrecover.zkasm +280 -0
- package/main/ecrecover/invFnEc.zkasm +44 -0
- package/main/ecrecover/invFpEc.zkasm +45 -0
- package/main/ecrecover/mulFnEc.zkasm +36 -0
- package/main/ecrecover/mulFpEc.zkasm +36 -0
- package/main/ecrecover/mulPointEc.zkasm +311 -0
- package/main/ecrecover/sqFpEc.zkasm +38 -0
- package/main/ecrecover/sqrtFpEc.zkasm +70 -0
- package/main/end.zkasm +4 -0
- package/main/l2-tx-hash.zkasm +159 -0
- package/main/load-change-l2-block-utils.zkasm +11 -0
- package/main/load-change-l2-block.zkasm +28 -0
- package/main/load-tx-rlp-utils.zkasm +72 -0
- package/main/load-tx-rlp.zkasm +431 -0
- package/main/main.zkasm +237 -0
- package/main/map-opcodes.zkasm +274 -0
- package/main/modexp/array_lib/array_add_AGTB.zkasm +123 -0
- package/main/modexp/array_lib/array_add_short.zkasm +85 -0
- package/main/modexp/array_lib/array_div.zkasm +215 -0
- package/main/modexp/array_lib/array_div_long.zkasm +284 -0
- package/main/modexp/array_lib/array_div_short.zkasm +222 -0
- package/main/modexp/array_lib/array_mul.zkasm +97 -0
- package/main/modexp/array_lib/array_mul_long.zkasm +156 -0
- package/main/modexp/array_lib/array_mul_short.zkasm +127 -0
- package/main/modexp/array_lib/array_square.zkasm +246 -0
- package/main/modexp/array_lib/unused/array_add.zkasm +100 -0
- package/main/modexp/array_lib/unused/array_is_odd.zkasm +23 -0
- package/main/modexp/array_lib/unused/array_is_one.zkasm +33 -0
- package/main/modexp/array_lib/unused/array_is_zero.zkasm +34 -0
- package/main/modexp/array_lib/unused/array_sub_AGTB.zkasm +111 -0
- package/main/modexp/array_lib/unused/array_unshift.zkasm +37 -0
- package/main/modexp/array_lib/utils/array_compare.zkasm +82 -0
- package/main/modexp/array_lib/utils/array_trim.zkasm +49 -0
- package/main/modexp/constants.zkasm +5 -0
- package/main/modexp/modexp.zkasm +296 -0
- package/main/modexp/modexp_utils.zkasm +230 -0
- package/main/opcodes/arithmetic.zkasm +357 -0
- package/main/opcodes/block.zkasm +163 -0
- package/main/opcodes/calldata-returndata-code.zkasm +619 -0
- package/main/opcodes/comparison.zkasm +446 -0
- package/main/opcodes/context-information.zkasm +169 -0
- package/main/opcodes/create-terminate-context.zkasm +1011 -0
- package/main/opcodes/crypto.zkasm +96 -0
- package/main/opcodes/flow-control.zkasm +126 -0
- package/main/opcodes/logs.zkasm +193 -0
- package/main/opcodes/stack-operations.zkasm +658 -0
- package/main/opcodes/storage-memory.zkasm +313 -0
- package/main/pairings/BN254/addPointBN254.zkasm +245 -0
- package/main/pairings/BN254/ecAdd.zkasm +312 -0
- package/main/pairings/BN254/ecMul.zkasm +159 -0
- package/main/pairings/BN254/escalarMulBN254.zkasm +155 -0
- package/main/pairings/BN254/lineDiffPointsBN254.zkasm +83 -0
- package/main/pairings/BN254/lineSamePointsBN254.zkasm +96 -0
- package/main/pairings/FP12BN254/CYCLOFP12BN254/compressFp12BN254.zkasm +49 -0
- package/main/pairings/FP12BN254/CYCLOFP12BN254/decompressFp12BN254.zkasm +236 -0
- package/main/pairings/FP12BN254/CYCLOFP12BN254/expByXCompCycloFp12BN254.zkasm +444 -0
- package/main/pairings/FP12BN254/CYCLOFP12BN254/squareCompCycloFp12BN254.zkasm +212 -0
- package/main/pairings/FP12BN254/CYCLOFP12BN254/squareCycloFp12BN254.zkasm +228 -0
- package/main/pairings/FP12BN254/CYCLOFP12BN254/xBinDecompBN254.zkasm +64 -0
- package/main/pairings/FP12BN254/frob2Fp12BN254.zkasm +80 -0
- package/main/pairings/FP12BN254/frob3Fp12BN254.zkasm +96 -0
- package/main/pairings/FP12BN254/frobFp12BN254.zkasm +96 -0
- package/main/pairings/FP12BN254/inverseFp12BN254.zkasm +289 -0
- package/main/pairings/FP12BN254/mulFp12BN254.zkasm +408 -0
- package/main/pairings/FP12BN254/sparseMulAFp12BN254.zkasm +296 -0
- package/main/pairings/FP12BN254/sparseMulBFp12BN254.zkasm +291 -0
- package/main/pairings/FP12BN254/squareFp12BN254.zkasm +376 -0
- package/main/pairings/FP2BN254/addFp2BN254.zkasm +19 -0
- package/main/pairings/FP2BN254/escalarMulFp2BN254.zkasm +20 -0
- package/main/pairings/FP2BN254/invFp2BN254.zkasm +66 -0
- package/main/pairings/FP2BN254/mulFp2BN254.zkasm +19 -0
- package/main/pairings/FP2BN254/squareFp2BN254.zkasm +21 -0
- package/main/pairings/FP2BN254/subFp2BN254.zkasm +19 -0
- package/main/pairings/FP4BN254/squareFp4BN254.zkasm +76 -0
- package/main/pairings/FP6BN254/addFp6BN254.zkasm +59 -0
- package/main/pairings/FP6BN254/escalarMulFp6BN254.zkasm +51 -0
- package/main/pairings/FP6BN254/inverseFp6BN254.zkasm +208 -0
- package/main/pairings/FP6BN254/mulFp6BN254.zkasm +201 -0
- package/main/pairings/FP6BN254/sparseMulAFp6BN254.zkasm +65 -0
- package/main/pairings/FP6BN254/sparseMulBFp6BN254.zkasm +134 -0
- package/main/pairings/FP6BN254/sparseMulCFp6BN254.zkasm +128 -0
- package/main/pairings/FP6BN254/squareFp6BN254.zkasm +147 -0
- package/main/pairings/FP6BN254/subFp6BN254.zkasm +59 -0
- package/main/pairings/FPBN254/addFpBN254.zkasm +29 -0
- package/main/pairings/FPBN254/invFpBN254.zkasm +55 -0
- package/main/pairings/FPBN254/mulFpBN254.zkasm +29 -0
- package/main/pairings/FPBN254/reduceFpBN254.zkasm +25 -0
- package/main/pairings/FPBN254/squareFpBN254.zkasm +31 -0
- package/main/pairings/FPBN254/subFpBN254.zkasm +36 -0
- package/main/pairings/FRBN254/reduceFrBN254.zkasm +25 -0
- package/main/pairings/constants.zkasm +62 -0
- package/main/pairings/ecPairing.zkasm +244 -0
- package/main/pairings/finalExpBN254.zkasm +2095 -0
- package/main/pairings/halfPairingBN254.zkasm +428 -0
- package/main/pairings/loopLengthBN254.zkasm +75 -0
- package/main/pairings/millerLoopBN254.zkasm +741 -0
- package/main/pairings/pairingBN254.zkasm +481 -0
- package/main/pairings/unused/addFp12BN254.zkasm +130 -0
- package/main/pairings/unused/expByXCycloFp12BN254.zkasm +411 -0
- package/main/pairings/unused/expFp12BN254.zkasm +333 -0
- package/main/pairings/unused/subFp12BN254.zkasm +130 -0
- package/main/pairings/unused/xPseudoBinDecompBN254.zkasm +68 -0
- package/main/pairings/utilsTests/expCycloFp12BN254.zkasm +334 -0
- package/main/precompiled/end.zkasm +42 -0
- package/main/precompiled/identity.zkasm +99 -0
- package/main/precompiled/pre-ecAdd.zkasm +84 -0
- package/main/precompiled/pre-ecMul.zkasm +82 -0
- package/main/precompiled/pre-ecPairing.zkasm +72 -0
- package/main/precompiled/pre-ecrecover.zkasm +71 -0
- package/main/precompiled/pre-modexp.zkasm +367 -0
- package/main/precompiled/pre-sha2-256.zkasm +125 -0
- package/main/precompiled/revert-precompiled.zkasm +25 -0
- package/main/precompiled/selector.zkasm +77 -0
- package/main/process-change-l2-block.zkasm +147 -0
- package/main/process-tx.zkasm +587 -0
- package/main/tables/2-exp.zkasm +260 -0
- package/main/touched.zkasm +118 -0
- package/main/utils.zkasm +2335 -0
- package/main/vars.zkasm +117 -0
- package/package.json +62 -3
- package/test/bytes-length.zkasm +39 -0
- package/test/ecrecover.zkasm +538 -0
- package/test/lt4-test.zkasm +38 -0
- package/test/mstorex.zkasm +191 -0
- package/test/opcalldatacopy.ignore.zkasm +331 -0
- package/test/performance/read-push.zkasm +71 -0
- package/test/read-push.zkasm +304 -0
- package/test/testArrayArith.zkasm +1099 -0
- package/test/testArrayUtils.zkasm +335 -0
- package/test/testCycloFp12ArithBN254.zkasm +548 -0
- package/test/testEcAdd.zkasm +252 -0
- package/test/testEcMul.zkasm +231 -0
- package/test/testEcPairing.zkasm +436 -0
- package/test/testFinalExpBn254.zkasm +139 -0
- package/test/testFp12ArithBN254.zkasm +692 -0
- package/test/testFp2ArithBN254.zkasm +185 -0
- package/test/testFp4ArithBN254.zkasm +128 -0
- package/test/testFp6ArithBN254.zkasm +260 -0
- package/test/testFpArithBN254.zkasm +159 -0
- package/test/testFrArithBN254.zkasm +113 -0
- package/test/testHalfPairingBN254.zkasm +285 -0
- package/test/testModExp.zkasm +586 -0
- package/test/testModExpReturn.zkasm +81 -0
- package/test/testPairingBN254.zkasm +463 -0
- package/test/testPointArithBN254.zkasm +270 -0
- package/test/testSHA256.zkasm +27 -0
- package/test/touched-assert.zkasm +59 -0
- package/test/utils-expAD.zkasm +48 -0
- package/test/utils-getLenBytes.zkasm +36 -0
- package/tools/audit-tools/registry-op-checker.js +71 -0
- package/tools/get-not-used-labels.js +31 -0
- package/tools/helpers/helpers.js +47 -0
- package/tools/modexp-utils/README.md +5 -0
- package/tools/modexp-utils/modexp-test-gen.js +168 -0
- package/tools/modexp-utils/modexp-test-int.sage +37 -0
- package/tools/parallel-testing/checker.sh +6 -0
- package/tools/parallel-testing/gen-parallel-tests.js +78 -0
- package/tools/parallel-testing/parallel-tests-sample/sample.test.js +136 -0
- package/tools/run-tests-zkasm.js +83 -0
@@ -0,0 +1,446 @@
|
|
1
|
+
/**
|
2
|
+
* @link [https://www.evm.codes/#10?fork=berlin]
|
3
|
+
* @zk-counters
|
4
|
+
* - 1 binary
|
5
|
+
* - 20 steps
|
6
|
+
* @process-opcode
|
7
|
+
* - stack input: [a, b]
|
8
|
+
* - stack output: [a < b]
|
9
|
+
*/
|
10
|
+
opLT:
|
11
|
+
; checks zk-counters
|
12
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
13
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
14
|
+
|
15
|
+
; check stack underflow
|
16
|
+
SP - 2 :JMPN(stackUnderflow)
|
17
|
+
|
18
|
+
; check out-of-gas
|
19
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
20
|
+
|
21
|
+
; read two items from stack
|
22
|
+
SP - 1 => SP
|
23
|
+
$ => A :MLOAD(SP--) ; [a => A]
|
24
|
+
$ => B :MLOAD(SP) ; [a => B]
|
25
|
+
|
26
|
+
; call binary:lessThan state machine
|
27
|
+
; and push the result into the stack
|
28
|
+
$ :LT, MSTORE(SP++), JMP(readCode) ; [(a < b) => SP]
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @link [https://www.evm.codes/#11?fork=berlin]
|
32
|
+
* @zk-counters
|
33
|
+
* - 1 binary
|
34
|
+
* - 20 steps
|
35
|
+
* @process-opcode
|
36
|
+
* - stack input: [a, b]
|
37
|
+
* - stack output: [a > b]
|
38
|
+
*/
|
39
|
+
opGT:
|
40
|
+
; checks zk-counters
|
41
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
42
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
43
|
+
|
44
|
+
; check stack underflow
|
45
|
+
SP - 2 :JMPN(stackUnderflow)
|
46
|
+
|
47
|
+
; check out-of-gas
|
48
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
49
|
+
|
50
|
+
; read two items from the stack
|
51
|
+
SP - 1 => SP
|
52
|
+
$ => B :MLOAD(SP--) ; [a => B]
|
53
|
+
$ => A :MLOAD(SP) ; [b => A]
|
54
|
+
|
55
|
+
; call binary:lessThan state machine
|
56
|
+
; and push the result into the stack
|
57
|
+
$ :LT, MSTORE(SP++), JMP(readCode) ; [(b < a) => SP]
|
58
|
+
|
59
|
+
/**
|
60
|
+
* @link [https://www.evm.codes/#12?fork=berlin]
|
61
|
+
* @zk-counters
|
62
|
+
* - 1 binary
|
63
|
+
* - 20 steps
|
64
|
+
* @process-opcode
|
65
|
+
* - stack input: [a, b]
|
66
|
+
* - stack output: [signed(a < b)]
|
67
|
+
*/
|
68
|
+
opSLT:
|
69
|
+
; checks zk-counters
|
70
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
71
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
72
|
+
|
73
|
+
; check stack underflow
|
74
|
+
SP - 2 :JMPN(stackUnderflow)
|
75
|
+
|
76
|
+
; check out-of-gas
|
77
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
78
|
+
|
79
|
+
; read two items from the stack
|
80
|
+
SP - 1 => SP
|
81
|
+
$ => A :MLOAD(SP--) ; [a => A]
|
82
|
+
$ => B :MLOAD(SP) ; [b => B]
|
83
|
+
|
84
|
+
; call binary:SignedLessThan state machine
|
85
|
+
; and push the result into the stack
|
86
|
+
$ :SLT, MSTORE(SP++), JMP(readCode) ; [signed(a < b) => SP]
|
87
|
+
|
88
|
+
/**
|
89
|
+
* @link [https://www.evm.codes/#13?fork=berlin]
|
90
|
+
* @zk-counters
|
91
|
+
* - 1 binary
|
92
|
+
* - 20 steps
|
93
|
+
* @process-opcode
|
94
|
+
* - stack input: [a, b]
|
95
|
+
* - stack output: [signed(a > b)]
|
96
|
+
*/
|
97
|
+
opSGT:
|
98
|
+
; checks zk-counters
|
99
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
100
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
101
|
+
|
102
|
+
; check stack underflow
|
103
|
+
SP - 2 :JMPN(stackUnderflow)
|
104
|
+
|
105
|
+
; check out-of-gas
|
106
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
107
|
+
|
108
|
+
; read two items from the stack
|
109
|
+
SP - 1 => SP
|
110
|
+
$ => B :MLOAD(SP--) ; [a => B]
|
111
|
+
$ => A :MLOAD(SP) ; [b => A]
|
112
|
+
|
113
|
+
; call binary:SignedLessThan state machine
|
114
|
+
; and push the result into the stack
|
115
|
+
$ :SLT, MSTORE(SP++), JMP(readCode) ; [signed(b < a) => SP]
|
116
|
+
|
117
|
+
/**
|
118
|
+
* @link [https://www.evm.codes/#14?fork=berlin]
|
119
|
+
* @zk-counters
|
120
|
+
* - 1 binary
|
121
|
+
* - 20 steps
|
122
|
+
* @process-opcode
|
123
|
+
* - stack input: [a, b]
|
124
|
+
* - stack output: [a == b]
|
125
|
+
*/
|
126
|
+
opEQ:
|
127
|
+
; checks zk-counters
|
128
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
129
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
130
|
+
|
131
|
+
; check stack underflow
|
132
|
+
SP - 2 :JMPN(stackUnderflow)
|
133
|
+
|
134
|
+
; check out-of-gas
|
135
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
136
|
+
|
137
|
+
; read two items from the stack
|
138
|
+
SP - 1 => SP
|
139
|
+
$ => A :MLOAD(SP--) ; [a => A]
|
140
|
+
$ => B :MLOAD(SP) ; [b => B]
|
141
|
+
|
142
|
+
; call binary:Equal state machine
|
143
|
+
; and push the result into the stack
|
144
|
+
$ :EQ, MSTORE(SP++), JMP(readCode) ; [(a == b) => SP]
|
145
|
+
|
146
|
+
/**
|
147
|
+
* @link [https://www.evm.codes/#15?fork=berlin]
|
148
|
+
* @zk-counters
|
149
|
+
* - 1 binary
|
150
|
+
* - 20 steps
|
151
|
+
* @process-opcode
|
152
|
+
* - stack input: [a]
|
153
|
+
* - stack output: [a == 0]
|
154
|
+
*/
|
155
|
+
opISZERO:
|
156
|
+
; checks zk-counters
|
157
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
158
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
159
|
+
|
160
|
+
; check stack underflow
|
161
|
+
SP - 1 :JMPN(stackUnderflow)
|
162
|
+
|
163
|
+
; check out-of-gas
|
164
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
165
|
+
|
166
|
+
; read one item from stack
|
167
|
+
$ => A :MLOAD(SP-1) ; [a => B]
|
168
|
+
0 => B
|
169
|
+
|
170
|
+
; call binary:Equal state machine
|
171
|
+
; and push the result into the stack
|
172
|
+
$ :EQ, MSTORE(SP-1), JMP(readCode) ; [(a == 0) ==> SP]
|
173
|
+
|
174
|
+
/**
|
175
|
+
* @link [https://www.evm.codes/#16?fork=berlin]
|
176
|
+
* @zk-counters
|
177
|
+
* - 1 binary
|
178
|
+
* - 20 steps
|
179
|
+
* @process-opcode
|
180
|
+
* - stack input: [a, b]
|
181
|
+
* - stack output: [a & b]
|
182
|
+
*/
|
183
|
+
opAND:
|
184
|
+
; checks zk-counters
|
185
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
186
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
187
|
+
|
188
|
+
; check stack underflow
|
189
|
+
SP - 2 :JMPN(stackUnderflow)
|
190
|
+
|
191
|
+
; check out-of-gas
|
192
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
193
|
+
|
194
|
+
; read two items from the stack
|
195
|
+
SP - 1 => SP
|
196
|
+
$ => A :MLOAD(SP--) ; [a => A]
|
197
|
+
$ => B :MLOAD(SP) ; [b => B]
|
198
|
+
|
199
|
+
; call binary:And state machine
|
200
|
+
; and push the result into the stack
|
201
|
+
$ :AND, MSTORE(SP++), JMP(readCode) ; [ a & b => SP]
|
202
|
+
|
203
|
+
/**
|
204
|
+
* @link [https://www.evm.codes/#17?fork=berlin]
|
205
|
+
* @zk-counters
|
206
|
+
* - 1 binary
|
207
|
+
* - 20 steps
|
208
|
+
* @process-opcode
|
209
|
+
* - stack input: [a, b]
|
210
|
+
* - stack output: [a | b]
|
211
|
+
*/
|
212
|
+
opOR:
|
213
|
+
; checks zk-counters
|
214
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
215
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
216
|
+
|
217
|
+
; check stack underflow
|
218
|
+
SP - 2 :JMPN(stackUnderflow)
|
219
|
+
|
220
|
+
; check out-of-gas
|
221
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
222
|
+
|
223
|
+
; read two items from the stack
|
224
|
+
SP - 1 => SP
|
225
|
+
$ => A :MLOAD(SP--)
|
226
|
+
$ => B :MLOAD(SP)
|
227
|
+
|
228
|
+
; call binary:Or state machine
|
229
|
+
; and push the result into the stack
|
230
|
+
$ :OR, MSTORE(SP++), JMP(readCode) ; [ a | b => SP]
|
231
|
+
|
232
|
+
/**
|
233
|
+
* @link [https://www.evm.codes/#18?fork=berlin]
|
234
|
+
* @zk-counters
|
235
|
+
* - 1 binary
|
236
|
+
* - 20 steps
|
237
|
+
* @process-opcode
|
238
|
+
* - stack input: [a, b]
|
239
|
+
* - stack output: [a ^ b]
|
240
|
+
*/
|
241
|
+
opXOR:
|
242
|
+
; checks zk-counters
|
243
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
244
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
245
|
+
|
246
|
+
; check stack underflow
|
247
|
+
SP - 2 :JMPN(stackUnderflow)
|
248
|
+
|
249
|
+
; check out-of-gas
|
250
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
251
|
+
|
252
|
+
; read two items from the stack
|
253
|
+
SP - 1 => SP
|
254
|
+
$ => A :MLOAD(SP--) ; [a => A]
|
255
|
+
$ => B :MLOAD(SP) ; [b => B]
|
256
|
+
|
257
|
+
; call binary:Xor state machine
|
258
|
+
; and push the result into the stack
|
259
|
+
$ :XOR,MSTORE(SP++), JMP(readCode) ; [ a ^ b => SP]
|
260
|
+
|
261
|
+
/**
|
262
|
+
* @link [https://www.evm.codes/#19?fork=berlin]
|
263
|
+
* @zk-counters
|
264
|
+
* - 1 binary
|
265
|
+
* - 20 steps
|
266
|
+
* @process-opcode
|
267
|
+
* - stack input: [a]
|
268
|
+
* - stack output: [ ~a ]
|
269
|
+
*/
|
270
|
+
opNOT:
|
271
|
+
; checks zk-counters
|
272
|
+
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)
|
273
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
274
|
+
|
275
|
+
; check stack underflow
|
276
|
+
SP - 1 :JMPN(stackUnderflow)
|
277
|
+
|
278
|
+
; check out-of-gas
|
279
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
280
|
+
|
281
|
+
; read one item from the stack
|
282
|
+
$ => A :MLOAD(SP-1)
|
283
|
+
|
284
|
+
0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn => B ; 2**256 - 1 =>
|
285
|
+
$ => A :XOR,MSTORE(SP-1), JMP(readCode) ; [ NOT a => SP]
|
286
|
+
|
287
|
+
/**
|
288
|
+
* @link [https://www.evm.codes/#1a?fork=berlin]
|
289
|
+
* @zk-counters
|
290
|
+
* - 30 steps
|
291
|
+
* - 2 binary
|
292
|
+
* @process-opcode
|
293
|
+
* - stack input: [byte offset, 32-byte value]
|
294
|
+
* - stack output: [byte]
|
295
|
+
*/
|
296
|
+
opBYTE:
|
297
|
+
; checks zk-counters
|
298
|
+
%MAX_CNT_STEPS - STEP - 30 :JMPN(outOfCountersStep)
|
299
|
+
%MAX_CNT_BINARY - CNT_BINARY - 2 :JMPN(outOfCountersBinary)
|
300
|
+
|
301
|
+
; check stack underflow
|
302
|
+
SP - 2 :JMPN(stackUnderflow)
|
303
|
+
|
304
|
+
; check out-of-gas
|
305
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
306
|
+
|
307
|
+
; read two items from the stack
|
308
|
+
SP - 1 => SP
|
309
|
+
$ => B :MLOAD(SP--) ; [byte offset => B]
|
310
|
+
$ => C :MLOAD(SP) ; [32-byte value => C]
|
311
|
+
|
312
|
+
; if the byte offset is out of range --> go to opBYTE0
|
313
|
+
31 => A
|
314
|
+
$ => D :SUB, JMPC(opBYTE0)
|
315
|
+
|
316
|
+
; call util function
|
317
|
+
C => A
|
318
|
+
:CALL(SHRarith) ; in: [A: value, D: #bytes to right shift] out: [A: shifted result]
|
319
|
+
|
320
|
+
; call binary:and state machine and push to the stack
|
321
|
+
255 => B
|
322
|
+
$ :AND, MSTORE(SP++), JMP(readCode) ; [ A & 255 => SP]
|
323
|
+
|
324
|
+
opBYTE0:
|
325
|
+
0 :MSTORE(SP++), JMP(readCode) ; [ 0 => SP]
|
326
|
+
|
327
|
+
/**
|
328
|
+
* @link [https://www.evm.codes/#1c?fork=berlin]
|
329
|
+
* @zk-counters
|
330
|
+
* - 20 steps
|
331
|
+
* @process-opcode
|
332
|
+
* - stack input: [shift, value]
|
333
|
+
* - stack output: [value >> shift]
|
334
|
+
*/
|
335
|
+
opSHR:
|
336
|
+
; checks zk-counters
|
337
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
338
|
+
|
339
|
+
; check stack underflow
|
340
|
+
SP - 2 :JMPN(stackUnderflow)
|
341
|
+
|
342
|
+
; check out-of-gas
|
343
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
344
|
+
|
345
|
+
; read two items from the stack
|
346
|
+
SP - 1 => SP
|
347
|
+
$ => D :MLOAD(SP--) ; [shift => D]
|
348
|
+
; call SHRarithBit util
|
349
|
+
$ => A :MLOAD(SP), CALL(SHRarithBit) ; [value => A]; [ A >> D => A]
|
350
|
+
A :MSTORE(SP++), JMP(readCode) ; [ A => SP]
|
351
|
+
|
352
|
+
/**
|
353
|
+
* @link [https://www.evm.codes/#1b?fork=berlin]
|
354
|
+
* @zk-counters
|
355
|
+
* - 20 steps
|
356
|
+
* @process-opcode
|
357
|
+
* - stack input: [shift, value]
|
358
|
+
* - stack output: [value << shift]
|
359
|
+
*/
|
360
|
+
opSHL:
|
361
|
+
; checks zk-counters
|
362
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
363
|
+
|
364
|
+
; check stack underflow
|
365
|
+
SP - 2 :JMPN(stackUnderflow)
|
366
|
+
|
367
|
+
; check out-of-gas
|
368
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
369
|
+
|
370
|
+
; read two items from the stack
|
371
|
+
SP - 1 => SP
|
372
|
+
$ => D :MLOAD(SP--)
|
373
|
+
$ => A :MLOAD(SP)
|
374
|
+
|
375
|
+
; CALL shl util
|
376
|
+
:CALL(SHLarithBit) ; [ A << D => A]
|
377
|
+
A :MSTORE(SP++), JMP(readCode) ; [A => SP]
|
378
|
+
|
379
|
+
/**
|
380
|
+
* @link [https://www.evm.codes/#1d?fork=berlin]
|
381
|
+
* @zk-counters
|
382
|
+
* - 5 binary
|
383
|
+
* - 100 steps
|
384
|
+
* @process-opcode
|
385
|
+
* - stack input: [shift, value]
|
386
|
+
* - stack output: [value >> shift (signed)]
|
387
|
+
*/
|
388
|
+
opSAR:
|
389
|
+
; checks zk-counters
|
390
|
+
%MAX_CNT_BINARY - CNT_BINARY - 5 :JMPN(outOfCountersBinary)
|
391
|
+
%MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
|
392
|
+
|
393
|
+
; check stack underflow
|
394
|
+
SP - 2 :JMPN(stackUnderflow)
|
395
|
+
|
396
|
+
; check out-of-gas
|
397
|
+
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
|
398
|
+
|
399
|
+
; read two items from the stack
|
400
|
+
SP - 1 => SP
|
401
|
+
$ => C :MLOAD(SP--) ; [shift (bits) => C]
|
402
|
+
$ => A :MLOAD(SP) ; [value => A]
|
403
|
+
|
404
|
+
; Sign of A [1 if negative, 0 positive] in E
|
405
|
+
0 => B
|
406
|
+
$ => E :SLT ; [sign(A) => E]
|
407
|
+
|
408
|
+
; check shift is less than 256 bits
|
409
|
+
A => D ; [value => D]
|
410
|
+
C => B ; [shift (bits) => B]
|
411
|
+
256 => A
|
412
|
+
$ :LT, JMPC(maxShiftSAR)
|
413
|
+
|
414
|
+
; compute result depending on sign
|
415
|
+
E :JMPZ(positiveValue, negativeValue)
|
416
|
+
|
417
|
+
positiveValue:
|
418
|
+
; call SHRarithBit util
|
419
|
+
D => A
|
420
|
+
C => D :CALL(SHRarithBit) ; [shift (bits) => D]; [ A >> D => A]
|
421
|
+
:JMP(endSAR)
|
422
|
+
|
423
|
+
negativeValue:
|
424
|
+
D => A
|
425
|
+
%MAX_UINT_256 => B
|
426
|
+
$ => A :XOR ; [~A => A]
|
427
|
+
C => D :CALL(SHRarithBit) ; [shift (bits) => D]; [ A >> D => A]
|
428
|
+
$ => A :XOR, JMP(endSAR) ; [~A => A]
|
429
|
+
|
430
|
+
endSAR:
|
431
|
+
; check shifted result is greater than 0
|
432
|
+
0 => B
|
433
|
+
$ :EQ, JMPC(maxShiftSAR)
|
434
|
+
A :MSTORE(SP++), JMP(readCode) ; [(value >> shift (signed)) => SP]
|
435
|
+
|
436
|
+
|
437
|
+
; return 0 if sign is positive. return %MAX_UINT_256 if sign is negative
|
438
|
+
maxShiftSAR:
|
439
|
+
0 => D ; [sign positive: 0 => D]
|
440
|
+
|
441
|
+
; check sign negative or positive
|
442
|
+
E :JMPZ(endMaxShiftSAR)
|
443
|
+
%MAX_UINT_256 => D ; [sign negative: MAX_UINT_256 => D]
|
444
|
+
|
445
|
+
endMaxShiftSAR:
|
446
|
+
D :MSTORE(SP++), JMP(readCode) ; [(value >> shift (signed)) => SP]
|
@@ -0,0 +1,169 @@
|
|
1
|
+
/**
|
2
|
+
* @link [https://www.evm.codes/#30?fork=berlin]
|
3
|
+
* @zk-counters
|
4
|
+
* - 20 steps
|
5
|
+
* @process-opcode
|
6
|
+
* - stack input: []
|
7
|
+
* - stack output: [address]
|
8
|
+
*/
|
9
|
+
opADDRESS:
|
10
|
+
; checks zk-counters
|
11
|
+
%MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep)
|
12
|
+
; check out-of-gas
|
13
|
+
GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas)
|
14
|
+
; check is a create
|
15
|
+
$ => A :MLOAD(isCreateContract), JMPNZ(opADDRESSdeploy)
|
16
|
+
; load current storage address
|
17
|
+
$ => A :MLOAD(storageAddr), JMP(opADDRESSend)
|
18
|
+
|
19
|
+
opADDRESSdeploy:
|
20
|
+
; load create contract address
|
21
|
+
$ => A :MLOAD(createContractAddress)
|
22
|
+
|
23
|
+
opADDRESSend:
|
24
|
+
A :MSTORE(SP++); [address(A) => SP]
|
25
|
+
; check stack overflow
|
26
|
+
%MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
|
27
|
+
|
28
|
+
/**
|
29
|
+
* @link [https://www.evm.codes/#47?fork=berlin]
|
30
|
+
* @zk-counters
|
31
|
+
* - %MAX_CNT_POSEIDON_SLOAD_SSTORE poseidon
|
32
|
+
* - 10 steps
|
33
|
+
* @process-opcode
|
34
|
+
* - stack input: []
|
35
|
+
* - stack output: [balance]
|
36
|
+
*/
|
37
|
+
opSELFBALANCE:
|
38
|
+
; checks zk-counters
|
39
|
+
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE :JMPN(outOfCountersPoseidon)
|
40
|
+
%MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep)
|
41
|
+
; check out-of-gas
|
42
|
+
GAS - %GAS_FAST_STEP => GAS :JMPN(outOfGas)
|
43
|
+
|
44
|
+
$ => A :MLOAD(storageAddr)
|
45
|
+
; set key for smt balance query
|
46
|
+
0 => B,C
|
47
|
+
; balance in D
|
48
|
+
$ => D :SLOAD
|
49
|
+
D :MSTORE(SP++); [balance(D) => SP]
|
50
|
+
; check stack overflow
|
51
|
+
%MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @link [https://www.evm.codes/#31?fork=berlin]
|
55
|
+
* @zk-counters
|
56
|
+
* - %MAX_CNT_POSEIDON_SLOAD_SSTORE poseidon
|
57
|
+
* - 10 steps
|
58
|
+
* @process-opcode
|
59
|
+
* - stack input: [address]
|
60
|
+
* - stack output: [balance]
|
61
|
+
*/
|
62
|
+
opBALANCE:
|
63
|
+
; checks zk-counters
|
64
|
+
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE :JMPN(outOfCountersPoseidon)
|
65
|
+
%MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep)
|
66
|
+
; check stack underflow
|
67
|
+
SP - 1 :JMPN(stackUnderflow)
|
68
|
+
; Mask address to 20 bytes
|
69
|
+
$ => A :MLOAD(SP-1), CALL(maskAddress); [address => A]; in: [A: address] out: [A: masked address]
|
70
|
+
; set key for smt balance query
|
71
|
+
0 => B,C
|
72
|
+
; balance in D
|
73
|
+
$ => D :SLOAD
|
74
|
+
D :MSTORE(SP-1), CALL(isColdAddress); [balance(D) => SP]; in: [A: address] out: [D: 0 if warm, 1 if cold]
|
75
|
+
; check out-of-gas
|
76
|
+
GAS - %WARM_STORAGE_READ_GAS - D * %COLD_ACCOUNT_ACCESS_COST_REDUCED => GAS :JMPN(outOfGas, readCode)
|
77
|
+
|
78
|
+
/**
|
79
|
+
* @link [https://www.evm.codes/#32?fork=berlin]
|
80
|
+
* @zk-counters
|
81
|
+
* - 10 steps
|
82
|
+
* @process-opcode
|
83
|
+
* - stack input: []
|
84
|
+
* - stack output: [address]
|
85
|
+
*/
|
86
|
+
opORIGIN:
|
87
|
+
; checks zk-counters
|
88
|
+
%MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep)
|
89
|
+
; check out-of-gas
|
90
|
+
GAS-%GAS_QUICK_STEP => GAS :JMPN(outOfGas)
|
91
|
+
|
92
|
+
$ => A :MLOAD(txSrcOriginAddr)
|
93
|
+
A :MSTORE(SP++); [address(A) => SP]
|
94
|
+
; check stack overflow
|
95
|
+
%MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
|
96
|
+
|
97
|
+
/**
|
98
|
+
* @link [https://www.evm.codes/#33?fork=berlin]
|
99
|
+
* @zk-counters
|
100
|
+
* - 10 steps
|
101
|
+
* @process-opcode
|
102
|
+
* - stack input: []
|
103
|
+
* - stack output: [address]
|
104
|
+
*/
|
105
|
+
opCALLER:
|
106
|
+
; checks zk-counters
|
107
|
+
%MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep)
|
108
|
+
; check out-of-gas
|
109
|
+
GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas)
|
110
|
+
|
111
|
+
$ => A :MLOAD(txSrcAddr)
|
112
|
+
A :MSTORE(SP++); [address(A) => SP]
|
113
|
+
; check stack overflow
|
114
|
+
%MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
|
115
|
+
|
116
|
+
/**
|
117
|
+
* @link [https://www.evm.codes/#34?fork=berlin]
|
118
|
+
* @zk-counters
|
119
|
+
* - 10 steps
|
120
|
+
* @process-opcode
|
121
|
+
* - stack input: []
|
122
|
+
* - stack output: [value]
|
123
|
+
*/
|
124
|
+
opCALLVALUE:
|
125
|
+
; checks zk-counters
|
126
|
+
%MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep)
|
127
|
+
; check out-of-gas
|
128
|
+
GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas)
|
129
|
+
|
130
|
+
$ => A :MLOAD(txValue)
|
131
|
+
A :MSTORE(SP++); [value(A) => SP]
|
132
|
+
; check stack overflow
|
133
|
+
%MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
|
134
|
+
|
135
|
+
/**
|
136
|
+
* @link [https://www.evm.codes/#3A?fork=berlin]
|
137
|
+
* @zk-counters
|
138
|
+
* - 10 steps
|
139
|
+
* @process-opcode
|
140
|
+
* - stack input: []
|
141
|
+
* - stack output: [price]
|
142
|
+
*/
|
143
|
+
opGASPRICE:
|
144
|
+
; checks zk-counters
|
145
|
+
%MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep)
|
146
|
+
; check out-of-gas
|
147
|
+
GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas)
|
148
|
+
|
149
|
+
$ => A :MLOAD(txGasPrice)
|
150
|
+
A :MSTORE(SP++); [price(A) => SP]
|
151
|
+
; check stack overflow
|
152
|
+
%MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
|
153
|
+
|
154
|
+
/**
|
155
|
+
* @link [https://www.evm.codes/#5A?fork=berlin]
|
156
|
+
* @zk-counters
|
157
|
+
* - 10 steps
|
158
|
+
* @process-opcode
|
159
|
+
* - stack input: []
|
160
|
+
* - stack output: [gas]
|
161
|
+
*/
|
162
|
+
opGAS:
|
163
|
+
; checks zk-counters
|
164
|
+
%MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep)
|
165
|
+
; check out-of-gas
|
166
|
+
GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas)
|
167
|
+
GAS :MSTORE(SP++); [gas(GAS) => SP]
|
168
|
+
; check stack overflow
|
169
|
+
%MAX_STACK_SIZE - SP :JMPN(stackOverflow, readCode)
|