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.
- 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,586 @@
|
|
1
|
+
; constants needed by executor C++
|
2
|
+
INCLUDE "../main/constants.zkasm"
|
3
|
+
|
4
|
+
VAR GLOBAL lastHashKId
|
5
|
+
VAR GLOBAL lastHashPId
|
6
|
+
|
7
|
+
VAR GLOBAL initial_A
|
8
|
+
VAR GLOBAL initial_B
|
9
|
+
VAR GLOBAL initial_C
|
10
|
+
VAR GLOBAL initial_D
|
11
|
+
VAR GLOBAL initial_E
|
12
|
+
VAR GLOBAL initial_CTX
|
13
|
+
VAR GLOBAL initial_SP
|
14
|
+
VAR GLOBAL initial_PC
|
15
|
+
VAR GLOBAL initial_GAS
|
16
|
+
VAR GLOBAL initial_SR
|
17
|
+
VAR GLOBAL initial_RR
|
18
|
+
VAR GLOBAL initial_HASHPOS
|
19
|
+
VAR GLOBAL initial_RCX
|
20
|
+
|
21
|
+
start:
|
22
|
+
|
23
|
+
STEP => A
|
24
|
+
0 :ASSERT
|
25
|
+
|
26
|
+
A :MSTORE(initial_A)
|
27
|
+
B :MSTORE(initial_B)
|
28
|
+
C :MSTORE(initial_C)
|
29
|
+
D :MSTORE(initial_D)
|
30
|
+
E :MSTORE(initial_E)
|
31
|
+
CTX :MSTORE(initial_CTX)
|
32
|
+
SP :MSTORE(initial_SP)
|
33
|
+
PC :MSTORE(initial_PC)
|
34
|
+
GAS :MSTORE(initial_GAS)
|
35
|
+
SR :MSTORE(initial_SR)
|
36
|
+
RR :MSTORE(initial_RR)
|
37
|
+
HASHPOS :MSTORE(initial_HASHPOS)
|
38
|
+
RCX :MSTORE(initial_RCX)
|
39
|
+
0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, RR, HASHPOS, RCX
|
40
|
+
|
41
|
+
-1 :MSTORE(lastHashKId)
|
42
|
+
-1 :MSTORE(lastHashPId)
|
43
|
+
|
44
|
+
; ; UPDATE: Edge cases are not handled by the modexp function directly
|
45
|
+
; ; EDGE CASES TESTS
|
46
|
+
; ; ---------------------------------------------------------------------------------------------
|
47
|
+
; ; 1] B == 0, E != 0, M != 0 should return 0
|
48
|
+
; 1 :MSTORE(modexp_Blen)
|
49
|
+
; 1 :MSTORE(modexp_Elen)
|
50
|
+
; 1 :MSTORE(modexp_Mlen)
|
51
|
+
|
52
|
+
; 0n :MSTORE(modexp_B)
|
53
|
+
; 3n :MSTORE(modexp_E)
|
54
|
+
; 4n :MSTORE(modexp_M)
|
55
|
+
; :CALL(modexp)
|
56
|
+
|
57
|
+
; 0n :MLOAD(modexp_out)
|
58
|
+
; 1 :MLOAD(modexp_outlen)
|
59
|
+
|
60
|
+
; 1 :MSTORE(modexp_Blen)
|
61
|
+
; 2 :MSTORE(modexp_Elen)
|
62
|
+
; 2 :MSTORE(modexp_Mlen)
|
63
|
+
|
64
|
+
; 0n :MSTORE(modexp_B)
|
65
|
+
; 0n :MSTORE(modexp_E)
|
66
|
+
; 1 => E
|
67
|
+
; 1n :MSTORE(modexp_E + E)
|
68
|
+
; 0n :MSTORE(modexp_M)
|
69
|
+
; 1 => E
|
70
|
+
; 1n :MSTORE(modexp_M + E)
|
71
|
+
; :CALL(modexp)
|
72
|
+
|
73
|
+
; 0n :MLOAD(modexp_out)
|
74
|
+
; 1 :MLOAD(modexp_outlen)
|
75
|
+
|
76
|
+
; ; 2] B != 0, E == 0, M != 0 should return 1
|
77
|
+
; 1 :MSTORE(modexp_Blen)
|
78
|
+
; 1 :MSTORE(modexp_Elen)
|
79
|
+
; 1 :MSTORE(modexp_Mlen)
|
80
|
+
|
81
|
+
; 2n :MSTORE(modexp_B)
|
82
|
+
; 0n :MSTORE(modexp_E)
|
83
|
+
; 4n :MSTORE(modexp_M)
|
84
|
+
; :CALL(modexp)
|
85
|
+
|
86
|
+
; 1n :MLOAD(modexp_out)
|
87
|
+
; 1 :MLOAD(modexp_outlen)
|
88
|
+
|
89
|
+
; 2 :MSTORE(modexp_Blen)
|
90
|
+
; 1 :MSTORE(modexp_Elen)
|
91
|
+
; 2 :MSTORE(modexp_Mlen)
|
92
|
+
|
93
|
+
; 2n :MSTORE(modexp_B)
|
94
|
+
; 1 => E
|
95
|
+
; 4n :MSTORE(modexp_B + E)
|
96
|
+
; 0n :MSTORE(modexp_E)
|
97
|
+
; 0n :MSTORE(modexp_M)
|
98
|
+
; 1 => E
|
99
|
+
; 1n :MSTORE(modexp_M + E)
|
100
|
+
; :CALL(modexp)
|
101
|
+
|
102
|
+
; 1n :MLOAD(modexp_out)
|
103
|
+
; 1 :MLOAD(modexp_outlen)
|
104
|
+
|
105
|
+
; ; 3] B != 0, E != 0, M == 0 should return 0
|
106
|
+
; 1 :MSTORE(modexp_Blen)
|
107
|
+
; 1 :MSTORE(modexp_Elen)
|
108
|
+
; 1 :MSTORE(modexp_Mlen)
|
109
|
+
|
110
|
+
; 2n :MSTORE(modexp_B)
|
111
|
+
; 1n :MSTORE(modexp_E)
|
112
|
+
; 0n :MSTORE(modexp_M)
|
113
|
+
; :CALL(modexp)
|
114
|
+
; 0n :MLOAD(modexp_out)
|
115
|
+
; 1 :MLOAD(modexp_outlen)
|
116
|
+
|
117
|
+
; 2 :MSTORE(modexp_Blen)
|
118
|
+
; 2 :MSTORE(modexp_Elen)
|
119
|
+
; 1 :MSTORE(modexp_Mlen)
|
120
|
+
|
121
|
+
; 2n :MSTORE(modexp_B)
|
122
|
+
; 1 => E
|
123
|
+
; 4n :MSTORE(modexp_B + E)
|
124
|
+
; 0n :MSTORE(modexp_E)
|
125
|
+
; 1 => E
|
126
|
+
; 4n :MSTORE(modexp_E + E)
|
127
|
+
; 0n :MSTORE(modexp_M)
|
128
|
+
; :CALL(modexp)
|
129
|
+
|
130
|
+
; 0n :MLOAD(modexp_out)
|
131
|
+
; 1 :MLOAD(modexp_outlen)
|
132
|
+
|
133
|
+
; ; 4] B != 0, E != 0, M == 1 should return 0
|
134
|
+
; 1 :MSTORE(modexp_Blen)
|
135
|
+
; 1 :MSTORE(modexp_Elen)
|
136
|
+
; 1 :MSTORE(modexp_Mlen)
|
137
|
+
|
138
|
+
; 2n :MSTORE(modexp_B)
|
139
|
+
; 1n :MSTORE(modexp_E)
|
140
|
+
; 1n :MSTORE(modexp_M)
|
141
|
+
; :CALL(modexp)
|
142
|
+
; 0n :MLOAD(modexp_out)
|
143
|
+
; 1 :MLOAD(modexp_outlen)
|
144
|
+
|
145
|
+
; 2 :MSTORE(modexp_Blen)
|
146
|
+
; 2 :MSTORE(modexp_Elen)
|
147
|
+
; 1 :MSTORE(modexp_Mlen)
|
148
|
+
|
149
|
+
; 2n :MSTORE(modexp_B)
|
150
|
+
; 1 => E
|
151
|
+
; 4n :MSTORE(modexp_B + E)
|
152
|
+
; 0n :MSTORE(modexp_E)
|
153
|
+
; 1 => E
|
154
|
+
; 4n :MSTORE(modexp_E + E)
|
155
|
+
; 1n :MSTORE(modexp_M)
|
156
|
+
; :CALL(modexp)
|
157
|
+
|
158
|
+
; 0n :MLOAD(modexp_out)
|
159
|
+
; 1 :MLOAD(modexp_outlen)
|
160
|
+
|
161
|
+
; ; 5] B == 0, E == 0, M != 0 should return 0^0 = 0
|
162
|
+
; 1 :MSTORE(modexp_Blen)
|
163
|
+
; 1 :MSTORE(modexp_Elen)
|
164
|
+
; 1 :MSTORE(modexp_Mlen)
|
165
|
+
|
166
|
+
; 0n :MSTORE(modexp_B)
|
167
|
+
; 0n :MSTORE(modexp_E)
|
168
|
+
; 4n :MSTORE(modexp_M)
|
169
|
+
; :CALL(modexp)
|
170
|
+
|
171
|
+
; 0n :MLOAD(modexp_out)
|
172
|
+
; 1 :MLOAD(modexp_outlen)
|
173
|
+
|
174
|
+
; 1 :MSTORE(modexp_Blen)
|
175
|
+
; 1 :MSTORE(modexp_Elen)
|
176
|
+
; 2 :MSTORE(modexp_Mlen)
|
177
|
+
|
178
|
+
; 0n :MSTORE(modexp_B)
|
179
|
+
; 0n :MSTORE(modexp_E)
|
180
|
+
; 0n :MSTORE(modexp_M)
|
181
|
+
; 1 => E
|
182
|
+
; 1n :MSTORE(modexp_M + E)
|
183
|
+
; :CALL(modexp)
|
184
|
+
|
185
|
+
; 0n :MLOAD(modexp_out)
|
186
|
+
; 1 :MLOAD(modexp_outlen)
|
187
|
+
|
188
|
+
; ; 6] B == 0, E != 0, M == 0 should return 0
|
189
|
+
; 1 :MSTORE(modexp_Blen)
|
190
|
+
; 1 :MSTORE(modexp_Elen)
|
191
|
+
; 1 :MSTORE(modexp_Mlen)
|
192
|
+
|
193
|
+
; 0n :MSTORE(modexp_B)
|
194
|
+
; 4n :MSTORE(modexp_E)
|
195
|
+
; 0n :MSTORE(modexp_M)
|
196
|
+
; :CALL(modexp)
|
197
|
+
|
198
|
+
; 0n :MLOAD(modexp_out)
|
199
|
+
; 1 :MLOAD(modexp_outlen)
|
200
|
+
|
201
|
+
; 1 :MSTORE(modexp_Blen)
|
202
|
+
; 2 :MSTORE(modexp_Elen)
|
203
|
+
; 1 :MSTORE(modexp_Mlen)
|
204
|
+
|
205
|
+
; 0n :MSTORE(modexp_B)
|
206
|
+
; 0n :MSTORE(modexp_E)
|
207
|
+
; 1 => E
|
208
|
+
; 1n :MSTORE(modexp_E + E)
|
209
|
+
; 0n :MSTORE(modexp_M)
|
210
|
+
; :CALL(modexp)
|
211
|
+
|
212
|
+
; 0n :MLOAD(modexp_out)
|
213
|
+
; 1 :MLOAD(modexp_outlen)
|
214
|
+
|
215
|
+
; ; 7] B != 0, E == 0, M == 0 should return 0
|
216
|
+
; 1 :MSTORE(modexp_Blen)
|
217
|
+
; 1 :MSTORE(modexp_Elen)
|
218
|
+
; 1 :MSTORE(modexp_Mlen)
|
219
|
+
|
220
|
+
; 1n :MSTORE(modexp_B)
|
221
|
+
; 0n :MSTORE(modexp_E)
|
222
|
+
; 0n :MSTORE(modexp_M)
|
223
|
+
; :CALL(modexp)
|
224
|
+
|
225
|
+
; 0n :MLOAD(modexp_out)
|
226
|
+
; 1 :MLOAD(modexp_outlen)
|
227
|
+
|
228
|
+
; 2 :MSTORE(modexp_Blen)
|
229
|
+
; 1 :MSTORE(modexp_Elen)
|
230
|
+
; 1 :MSTORE(modexp_Mlen)
|
231
|
+
|
232
|
+
; 0n :MSTORE(modexp_B)
|
233
|
+
; 1 => E
|
234
|
+
; 1n :MSTORE(modexp_B + E)
|
235
|
+
; 0n :MSTORE(modexp_E)
|
236
|
+
; 0n :MSTORE(modexp_M)
|
237
|
+
; :CALL(modexp)
|
238
|
+
|
239
|
+
; 0n :MLOAD(modexp_out)
|
240
|
+
; 1 :MLOAD(modexp_outlen)
|
241
|
+
|
242
|
+
; ; 8] B == 0, E == 0, M == 0 should return 0
|
243
|
+
; 1 :MSTORE(modexp_Blen)
|
244
|
+
; 1 :MSTORE(modexp_Elen)
|
245
|
+
; 1 :MSTORE(modexp_Mlen)
|
246
|
+
|
247
|
+
; 0n :MSTORE(modexp_B)
|
248
|
+
; 0n :MSTORE(modexp_E)
|
249
|
+
; 0n :MSTORE(modexp_M)
|
250
|
+
; :CALL(modexp)
|
251
|
+
|
252
|
+
; 0n :MLOAD(modexp_out)
|
253
|
+
; 1 :MLOAD(modexp_outlen)
|
254
|
+
; ; ---------------------------------------------------------------------------------------------
|
255
|
+
|
256
|
+
; 256 BITS EXPONENT TESTS
|
257
|
+
; ---------------------------------------------------------------------------------------------
|
258
|
+
; 1] B == k·M (at any point of the exponentiations) should return 0
|
259
|
+
1 :MSTORE(modexp_Blen)
|
260
|
+
1 :MSTORE(modexp_Elen)
|
261
|
+
1 :MSTORE(modexp_Mlen)
|
262
|
+
4n :MSTORE(modexp_B)
|
263
|
+
78n :MSTORE(modexp_E)
|
264
|
+
4n :MSTORE(modexp_M)
|
265
|
+
:CALL(modexp)
|
266
|
+
0n :MLOAD(modexp_out)
|
267
|
+
1 :MLOAD(modexp_outlen)
|
268
|
+
|
269
|
+
1 :MSTORE(modexp_Blen)
|
270
|
+
1 :MSTORE(modexp_Elen)
|
271
|
+
1 :MSTORE(modexp_Mlen)
|
272
|
+
8n :MSTORE(modexp_B)
|
273
|
+
78n :MSTORE(modexp_E)
|
274
|
+
4n :MSTORE(modexp_M)
|
275
|
+
:CALL(modexp)
|
276
|
+
0n :MLOAD(modexp_out)
|
277
|
+
1 :MLOAD(modexp_outlen)
|
278
|
+
|
279
|
+
1 :MSTORE(modexp_Blen)
|
280
|
+
1 :MSTORE(modexp_Elen)
|
281
|
+
1 :MSTORE(modexp_Mlen)
|
282
|
+
2n :MSTORE(modexp_B)
|
283
|
+
2n :MSTORE(modexp_E)
|
284
|
+
4n :MSTORE(modexp_M)
|
285
|
+
:CALL(modexp)
|
286
|
+
0n :MLOAD(modexp_out)
|
287
|
+
1 :MLOAD(modexp_outlen)
|
288
|
+
|
289
|
+
; 2] B = [100n, 2831023n, 0n, 73916234139162n], E = [2n**256n - 1n], M = [0n, 0n, 8238129386n, 23102318237n]
|
290
|
+
; Hamming weight of E is 256
|
291
|
+
4 :MSTORE(modexp_Blen)
|
292
|
+
1 :MSTORE(modexp_Elen)
|
293
|
+
4 :MSTORE(modexp_Mlen)
|
294
|
+
|
295
|
+
100n :MSTORE(modexp_B)
|
296
|
+
1 => E
|
297
|
+
2831023n :MSTORE(modexp_B + E)
|
298
|
+
2 => E
|
299
|
+
0n :MSTORE(modexp_B + E)
|
300
|
+
3 => E
|
301
|
+
73916234139162n :MSTORE(modexp_B + E)
|
302
|
+
115792089237316195423570985008687907853269984665640564039457584007913129639935n :MSTORE(modexp_E)
|
303
|
+
0n :MSTORE(modexp_M)
|
304
|
+
1 => E
|
305
|
+
0n :MSTORE(modexp_M + E)
|
306
|
+
2 => E
|
307
|
+
8238129386n :MSTORE(modexp_M + E)
|
308
|
+
3 => E
|
309
|
+
23102318237n :MSTORE(modexp_M + E)
|
310
|
+
:CALL(modexp)
|
311
|
+
0n :MLOAD(modexp_out)
|
312
|
+
1 => E
|
313
|
+
0n :MLOAD(modexp_out + E)
|
314
|
+
2 => E
|
315
|
+
25636070175539943947777314844209202718110211581133019863886488575898865601868n :MLOAD(modexp_out + E)
|
316
|
+
3 => E
|
317
|
+
4679155145n :MLOAD(modexp_out + E)
|
318
|
+
4 :MLOAD(modexp_outlen)
|
319
|
+
|
320
|
+
; 3] B = [100n, 2831023n, 0n, 73916234139162n, 100n, 2831023n, 0n, 73916234139162n,100n, 2831023n, 0n, 73916234139162n], E = [903741926349715234612309461283471234n], M = [0n, 0n, 8238129386n, 23102318237n, 1892397612351n, 7246598123051n, 8238129386n, 1264591241237897123126n]
|
321
|
+
; Hamming weight of E is 120
|
322
|
+
12 :MSTORE(modexp_Blen)
|
323
|
+
1 :MSTORE(modexp_Elen)
|
324
|
+
8 :MSTORE(modexp_Mlen)
|
325
|
+
|
326
|
+
100n :MSTORE(modexp_B)
|
327
|
+
1 => E
|
328
|
+
2831023n :MSTORE(modexp_B + E)
|
329
|
+
2 => E
|
330
|
+
0n :MSTORE(modexp_B + E)
|
331
|
+
3 => E
|
332
|
+
73916234139162n :MSTORE(modexp_B + E)
|
333
|
+
4 => E
|
334
|
+
100n :MSTORE(modexp_B + E)
|
335
|
+
5 => E
|
336
|
+
2831023n :MSTORE(modexp_B + E)
|
337
|
+
6 => E
|
338
|
+
0n :MSTORE(modexp_B + E)
|
339
|
+
7 => E
|
340
|
+
73916234139162n :MSTORE(modexp_B + E)
|
341
|
+
8 => E
|
342
|
+
100n :MSTORE(modexp_B + E)
|
343
|
+
9 => E
|
344
|
+
2831023n :MSTORE(modexp_B + E)
|
345
|
+
10 => E
|
346
|
+
0n :MSTORE(modexp_B + E)
|
347
|
+
11 => E
|
348
|
+
73916234139162n :MSTORE(modexp_B + E)
|
349
|
+
903741926349715234612309461283471234n :MSTORE(modexp_E)
|
350
|
+
0n :MSTORE(modexp_M)
|
351
|
+
1 => E
|
352
|
+
0n :MSTORE(modexp_M + E)
|
353
|
+
2 => E
|
354
|
+
8238129386n :MSTORE(modexp_M + E)
|
355
|
+
3 => E
|
356
|
+
23102318237n :MSTORE(modexp_M + E)
|
357
|
+
4 => E
|
358
|
+
1892397612351n :MSTORE(modexp_M + E)
|
359
|
+
5 => E
|
360
|
+
7246598123051n :MSTORE(modexp_M + E)
|
361
|
+
6 => E
|
362
|
+
8238129386n :MSTORE(modexp_M + E)
|
363
|
+
7 => E
|
364
|
+
1264591241237897123126n :MSTORE(modexp_M + E)
|
365
|
+
:CALL(modexp)
|
366
|
+
0n :MLOAD(modexp_out)
|
367
|
+
1 => E
|
368
|
+
0n :MLOAD(modexp_out + E)
|
369
|
+
2 => E
|
370
|
+
14984469305990977542353827078899382678368215018946198341845725551977623627446n :MLOAD(modexp_out + E)
|
371
|
+
3 => E
|
372
|
+
68986200907052834988812862957862042564780541926701277492865197684364096948359n :MLOAD(modexp_out + E)
|
373
|
+
4 => E
|
374
|
+
19960171666179366961875030436152164148711578520678689062449823687317995303656n :MLOAD(modexp_out + E)
|
375
|
+
5 => E
|
376
|
+
10163909190618518832451417682132582498490814809943760852308996448668923869413n :MLOAD(modexp_out + E)
|
377
|
+
6 => E
|
378
|
+
29735535392706191114764336807325502135962613879333248096358552087717155148899n :MLOAD(modexp_out + E)
|
379
|
+
7 => E
|
380
|
+
511131288598502431475n :MLOAD(modexp_out + E)
|
381
|
+
8 :MLOAD(modexp_outlen)
|
382
|
+
|
383
|
+
; 4] B = [7n], E = [110n], M = [7719472615821079694904732333912527190217998977709370935963838933860875309329n, 17n]
|
384
|
+
; Hamming weight of E is 5
|
385
|
+
1 :MSTORE(modexp_Blen)
|
386
|
+
1 :MSTORE(modexp_Elen)
|
387
|
+
2 :MSTORE(modexp_Mlen)
|
388
|
+
|
389
|
+
7n :MSTORE(modexp_B)
|
390
|
+
110n :MSTORE(modexp_E)
|
391
|
+
7719472615821079694904732333912527190217998977709370935963838933860875309329n :MSTORE(modexp_M)
|
392
|
+
1 => E
|
393
|
+
17n :MSTORE(modexp_M + E)
|
394
|
+
:CALL(modexp)
|
395
|
+
81730215206688390341255830729934766338330049967253209305087427132484271882414n :MLOAD(modexp_out)
|
396
|
+
1 => E
|
397
|
+
13n :MLOAD(modexp_out + E)
|
398
|
+
2 :MLOAD(modexp_outlen)
|
399
|
+
; ---------------------------------------------------------------------------------------------
|
400
|
+
|
401
|
+
; 512 BITS EXPONENT TESTS
|
402
|
+
; ---------------------------------------------------------------------------------------------
|
403
|
+
; 1] B = [2n, 1n, 1n, 1n], E = [3n, 5n], M = [4n, 6n, 7n]
|
404
|
+
; Hamming weight of E is 4
|
405
|
+
4 :MSTORE(modexp_Blen)
|
406
|
+
2 :MSTORE(modexp_Elen)
|
407
|
+
3 :MSTORE(modexp_Mlen)
|
408
|
+
|
409
|
+
2n :MSTORE(modexp_B)
|
410
|
+
1 => E
|
411
|
+
1n :MSTORE(modexp_B + E)
|
412
|
+
2 => E
|
413
|
+
1n :MSTORE(modexp_B + E)
|
414
|
+
3 => E
|
415
|
+
1n :MSTORE(modexp_B + E)
|
416
|
+
3n :MSTORE(modexp_E)
|
417
|
+
1 => E
|
418
|
+
5n :MSTORE(modexp_E + E)
|
419
|
+
4n :MSTORE(modexp_M)
|
420
|
+
1 => E
|
421
|
+
6n :MSTORE(modexp_M + E)
|
422
|
+
2 => E
|
423
|
+
7n :MSTORE(modexp_M + E)
|
424
|
+
:CALL(modexp)
|
425
|
+
16799222018138169590613227618843456355247327644003751420511040302320945803948n :MLOAD(modexp_out)
|
426
|
+
1 => E
|
427
|
+
67226185770814561827024093064262870237432709513661454124124794094744315370418n :MLOAD(modexp_out + E)
|
428
|
+
2 => E
|
429
|
+
1n :MLOAD(modexp_out + E)
|
430
|
+
3 :MLOAD(modexp_outlen)
|
431
|
+
|
432
|
+
; 2] B = [2n, 1n, 1n, 1n], E = [2n**256n - 1n, 2n**256n - 1n], M = [4n, 6n, 7n]
|
433
|
+
; Hamming weight of E is 512
|
434
|
+
4 :MSTORE(modexp_Blen)
|
435
|
+
2 :MSTORE(modexp_Elen)
|
436
|
+
3 :MSTORE(modexp_Mlen)
|
437
|
+
|
438
|
+
2n :MSTORE(modexp_B)
|
439
|
+
1 => E
|
440
|
+
1n :MSTORE(modexp_B + E)
|
441
|
+
2 => E
|
442
|
+
1n :MSTORE(modexp_B + E)
|
443
|
+
3 => E
|
444
|
+
1n :MSTORE(modexp_B + E)
|
445
|
+
115792089237316195423570985008687907853269984665640564039457584007913129639935n :MSTORE(modexp_E)
|
446
|
+
1 => E
|
447
|
+
115792089237316195423570985008687907853269984665640564039457584007913129639935n :MSTORE(modexp_E + E)
|
448
|
+
4n :MSTORE(modexp_M)
|
449
|
+
1 => E
|
450
|
+
6n :MSTORE(modexp_M + E)
|
451
|
+
2 => E
|
452
|
+
7n :MSTORE(modexp_M + E)
|
453
|
+
:CALL(modexp)
|
454
|
+
111873638420780286093512129901489267041413036926649390648147612881355784341812n :MLOAD(modexp_out)
|
455
|
+
1 => E
|
456
|
+
11181991619082508729788448443921623930160246165837402400671610626538926623319n :MLOAD(modexp_out + E)
|
457
|
+
2 => E
|
458
|
+
2n :MLOAD(modexp_out + E)
|
459
|
+
3 :MLOAD(modexp_outlen)
|
460
|
+
; ---------------------------------------------------------------------------------------------
|
461
|
+
|
462
|
+
; 768 BITS EXPONENT TESTS
|
463
|
+
; ---------------------------------------------------------------------------------------------
|
464
|
+
; ---------------------------------------------------------------------------------------------
|
465
|
+
|
466
|
+
; 1024 BITS EXPONENT TESTS
|
467
|
+
; ---------------------------------------------------------------------------------------------
|
468
|
+
; ---------------------------------------------------------------------------------------------
|
469
|
+
|
470
|
+
; ; SINGLETON TESTS TO ENSURE THE MAXIMUM INPUT LENGTH WE CAN ACHIEVE IN EACH OF BASE, EXPONENT
|
471
|
+
; ; AND MODULUS WITHOUT OVERFLOWING EITHER THE ARITH, BINARY OF STEPS COUNTERS
|
472
|
+
; ; ---------------------------------------------------------------------------------------------
|
473
|
+
; ; 1] B = [2n:1818n], E = [1n], M = [2n]
|
474
|
+
; ; Hamming weight of E is 1
|
475
|
+
; 1818 :MSTORE(modexp_Blen)
|
476
|
+
; 1 :MSTORE(modexp_Elen)
|
477
|
+
; 1 :MSTORE(modexp_Mlen)
|
478
|
+
|
479
|
+
; 1818 => E
|
480
|
+
; singleton_test1_copy_in_loop:
|
481
|
+
; E - 1 => E
|
482
|
+
; 2 :MSTORE(modexp_B + E)
|
483
|
+
; E :JMPZ(singleton_test1_modexp, singleton_test1_copy_in_loop)
|
484
|
+
|
485
|
+
; singleton_test1_modexp:
|
486
|
+
; 1n :MSTORE(modexp_E)
|
487
|
+
; 2n :MSTORE(modexp_M)
|
488
|
+
; :CALL(modexp)
|
489
|
+
; 0n :MLOAD(modexp_out)
|
490
|
+
; 1 :MLOAD(modexp_outlen)
|
491
|
+
|
492
|
+
; ; 2] B = [2n], E = [1n], M = [2n:1818]
|
493
|
+
; ; Hamming weight of E is 1
|
494
|
+
; 1 :MSTORE(modexp_Blen)
|
495
|
+
; 1 :MSTORE(modexp_Elen)
|
496
|
+
; 1818 :MSTORE(modexp_Mlen)
|
497
|
+
|
498
|
+
; 1818 => E
|
499
|
+
; singleton_test2_copy_in_loop:
|
500
|
+
; E - 1 => E
|
501
|
+
; 1 :MSTORE(modexp_M + E)
|
502
|
+
; E :JMPZ(singleton_test2_modexp, singleton_test2_copy_in_loop)
|
503
|
+
|
504
|
+
; singleton_test2_modexp:
|
505
|
+
; 2n :MSTORE(modexp_B)
|
506
|
+
; 1n :MSTORE(modexp_E)
|
507
|
+
; :CALL(modexp)
|
508
|
+
; 2n :MLOAD(modexp_out)
|
509
|
+
; 1 :MLOAD(modexp_outlen)
|
510
|
+
|
511
|
+
; ; 3] B = [2n], E = [1n:1818], M = [2n]
|
512
|
+
; ; Hamming weight of E is 1818
|
513
|
+
; 1 :MSTORE(modexp_Blen)
|
514
|
+
; 1818 :MSTORE(modexp_Elen)
|
515
|
+
; 1 :MSTORE(modexp_Mlen)
|
516
|
+
|
517
|
+
; 1818 => E
|
518
|
+
; singleton_test3_copy_in_loop:
|
519
|
+
; E - 1 => E
|
520
|
+
; 1 :MSTORE(modexp_E + E)
|
521
|
+
; E :JMPZ(singleton_test3_modexp, singleton_test3_copy_in_loop)
|
522
|
+
|
523
|
+
; singleton_test3_modexp:
|
524
|
+
; 2n :MSTORE(modexp_B)
|
525
|
+
; 2n :MSTORE(modexp_M)
|
526
|
+
; :CALL(modexp)
|
527
|
+
; 0n :MLOAD(modexp_out)
|
528
|
+
; 1 :MLOAD(modexp_outlen)
|
529
|
+
; ; ---------------------------------------------------------------------------------------------
|
530
|
+
|
531
|
+
:JMP(end)
|
532
|
+
|
533
|
+
outOfCountersBinary:
|
534
|
+
${dump(CNT_BINARY)} :JMP(end)
|
535
|
+
outOfCountersStep:
|
536
|
+
${dump(STEP)} :JMP(end)
|
537
|
+
outOfCountersArith:
|
538
|
+
${dump(CNT_ARITH)} :JMP(end)
|
539
|
+
|
540
|
+
;@info function to force a failed assert
|
541
|
+
failAssert:
|
542
|
+
1 => A
|
543
|
+
2 :ASSERT
|
544
|
+
|
545
|
+
end:
|
546
|
+
|
547
|
+
$ => A :MLOAD(initial_A)
|
548
|
+
$ => B :MLOAD(initial_B)
|
549
|
+
$ => C :MLOAD(initial_C)
|
550
|
+
$ => D :MLOAD(initial_D)
|
551
|
+
$ => E :MLOAD(initial_E)
|
552
|
+
$ => CTX :MLOAD(initial_CTX)
|
553
|
+
$ => SP :MLOAD(initial_SP)
|
554
|
+
$ => PC :MLOAD(initial_PC)
|
555
|
+
$ => GAS :MLOAD(initial_GAS)
|
556
|
+
$ => SR :MLOAD(initial_SR)
|
557
|
+
$ => RR :MLOAD(initial_RR)
|
558
|
+
$ => HASHPOS :MLOAD(initial_HASHPOS)
|
559
|
+
$ => RCX :MLOAD(initial_RCX)
|
560
|
+
|
561
|
+
; label finalizeExecution needed by executor C++
|
562
|
+
finalizeExecution:
|
563
|
+
${beforeLast()} : JMPN(finalizeExecution)
|
564
|
+
|
565
|
+
: JMP(start)
|
566
|
+
opINVALID:
|
567
|
+
; label checkAndSaveFrom needed by executor C++
|
568
|
+
checkAndSaveFrom:
|
569
|
+
:JMP(opINVALID)
|
570
|
+
|
571
|
+
INCLUDE "../main/modexp/constants.zkasm"
|
572
|
+
|
573
|
+
INCLUDE "../main/modexp/array_lib/utils/array_trim.zkasm"
|
574
|
+
INCLUDE "../main/modexp/array_lib/utils/array_compare.zkasm"
|
575
|
+
|
576
|
+
INCLUDE "../main/modexp/array_lib/array_add_AGTB.zkasm"
|
577
|
+
INCLUDE "../main/modexp/array_lib/array_add_short.zkasm"
|
578
|
+
INCLUDE "../main/modexp/array_lib/array_mul_long.zkasm"
|
579
|
+
INCLUDE "../main/modexp/array_lib/array_mul_short.zkasm"
|
580
|
+
INCLUDE "../main/modexp/array_lib/array_mul.zkasm"
|
581
|
+
INCLUDE "../main/modexp/array_lib/array_square.zkasm"
|
582
|
+
INCLUDE "../main/modexp/array_lib/array_div_short.zkasm"
|
583
|
+
INCLUDE "../main/modexp/array_lib/array_div_long.zkasm"
|
584
|
+
INCLUDE "../main/modexp/array_lib/array_div.zkasm"
|
585
|
+
|
586
|
+
INCLUDE "../main/modexp/modexp.zkasm"
|
@@ -0,0 +1,81 @@
|
|
1
|
+
; constants needed by executor C++
|
2
|
+
start:
|
3
|
+
|
4
|
+
STEP => A
|
5
|
+
0 :ASSERT
|
6
|
+
|
7
|
+
2 => CTX
|
8
|
+
1 :MSTORE(originCTX)
|
9
|
+
2 :MSTORE(currentCTX)
|
10
|
+
128 :MSTORE(retCallLength)
|
11
|
+
0 :MSTORE(retCallOffset)
|
12
|
+
4*32 :MSTORE(modexp_Bsize)
|
13
|
+
32 :MSTORE(modexp_Esize)
|
14
|
+
4*32 :MSTORE(modexp_Msize)
|
15
|
+
|
16
|
+
CTX => A
|
17
|
+
|
18
|
+
; 256 BITS EXPONENT TESTS
|
19
|
+
; ---------------------------------------------------------------------------------------------
|
20
|
+
; 1] B = [100n, 2831023n, 0n, 73916234139162n], E = [2n**256n - 1n], M = [0n, 0n, 8238129386n, 23102318237n]
|
21
|
+
; Hamming weight of E is 256
|
22
|
+
4 :MSTORE(modexp_Blen)
|
23
|
+
1 :MSTORE(modexp_Elen)
|
24
|
+
4 :MSTORE(modexp_Mlen)
|
25
|
+
|
26
|
+
100n :MSTORE(modexp_B)
|
27
|
+
1 => E
|
28
|
+
2831023n :MSTORE(modexp_B + E)
|
29
|
+
2 => E
|
30
|
+
0n :MSTORE(modexp_B + E)
|
31
|
+
3 => E
|
32
|
+
73916234139162n :MSTORE(modexp_B + E)
|
33
|
+
115792089237316195423570985008687907853269984665640564039457584007913129639935n :MSTORE(modexp_E)
|
34
|
+
0n :MSTORE(modexp_M)
|
35
|
+
1 => E
|
36
|
+
0n :MSTORE(modexp_M + E)
|
37
|
+
2 => E
|
38
|
+
8238129386n :MSTORE(modexp_M + E)
|
39
|
+
3 => E
|
40
|
+
23102318237n :MSTORE(modexp_M + E)
|
41
|
+
:JMP(callMODEXP)
|
42
|
+
|
43
|
+
INCLUDE "../main/main.zkasm"
|
44
|
+
|
45
|
+
VAR GLOBAL testModexp1
|
46
|
+
VAR GLOBAL testModexp2
|
47
|
+
VAR GLOBAL testModexp3
|
48
|
+
VAR GLOBAL testModexp4
|
49
|
+
|
50
|
+
preEnd:
|
51
|
+
0n :MLOAD(modexp_out)
|
52
|
+
1 => E
|
53
|
+
0n :MLOAD(modexp_out + E)
|
54
|
+
2 => E
|
55
|
+
25636070175539943947777314844209202718110211581133019863886488575898865601868n :MLOAD(modexp_out + E)
|
56
|
+
3 => E
|
57
|
+
4679155145n :MLOAD(modexp_out + E)
|
58
|
+
4 :MLOAD(modexp_outlen)
|
59
|
+
; get return data
|
60
|
+
1 => CTX
|
61
|
+
$ => E :MLOAD(retCallOffset),CALL(MLOAD32)
|
62
|
+
A :MSTORE(testModexp1)
|
63
|
+
:CALL(MLOAD32)
|
64
|
+
A :MSTORE(testModexp2)
|
65
|
+
:CALL(MLOAD32)
|
66
|
+
A :MSTORE(testModexp3)
|
67
|
+
:CALL(MLOAD32)
|
68
|
+
A :MSTORE(testModexp4)
|
69
|
+
;assert return data === memory
|
70
|
+
2 => CTX
|
71
|
+
0 => E :CALL(MLOAD32)
|
72
|
+
A :MLOAD(testModexp1)
|
73
|
+
:CALL(MLOAD32)
|
74
|
+
A :MLOAD(testModexp2)
|
75
|
+
:CALL(MLOAD32)
|
76
|
+
A :MLOAD(testModexp3)
|
77
|
+
:CALL(MLOAD32)
|
78
|
+
A :MLOAD(testModexp4)
|
79
|
+
|
80
|
+
0 => A,B,C,D,E,CTX, SP, PC, GAS, SR, HASHPOS, RR ; Set all registers to 0
|
81
|
+
:JMP(finalizeExecution)
|