@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,77 @@
|
|
1
|
+
INCLUDE "pre-ecrecover.zkasm"
|
2
|
+
INCLUDE "revert-precompiled.zkasm"
|
3
|
+
INCLUDE "identity.zkasm"
|
4
|
+
INCLUDE "pre-ecAdd.zkasm"
|
5
|
+
INCLUDE "pre-ecMul.zkasm"
|
6
|
+
INCLUDE "pre-ecPairing.zkasm"
|
7
|
+
INCLUDE "pre-modexp.zkasm"
|
8
|
+
INCLUDE "pre-sha2-256.zkasm"
|
9
|
+
INCLUDE "../pairings/constants.zkasm"
|
10
|
+
INCLUDE "../pairings/BN254/ecAdd.zkasm"
|
11
|
+
INCLUDE "../pairings/BN254/ecMul.zkasm"
|
12
|
+
INCLUDE "../pairings/ecPairing.zkasm"
|
13
|
+
INCLUDE "../pairings/FRBN254/reduceFrBN254.zkasm"
|
14
|
+
INCLUDE "../pairings/FPBN254/addFpBN254.zkasm"
|
15
|
+
INCLUDE "../pairings/FPBN254/subFpBN254.zkasm"
|
16
|
+
INCLUDE "../pairings/FPBN254/mulFpBN254.zkasm"
|
17
|
+
INCLUDE "../pairings/FPBN254/squareFpBN254.zkasm"
|
18
|
+
INCLUDE "../pairings/FPBN254/invFpBN254.zkasm"
|
19
|
+
INCLUDE "../pairings/FPBN254/reduceFpBN254.zkasm"
|
20
|
+
INCLUDE "../pairings/FP2BN254/addFp2BN254.zkasm"
|
21
|
+
INCLUDE "../pairings/FP2BN254/subFp2BN254.zkasm"
|
22
|
+
INCLUDE "../pairings/FP2BN254/mulFp2BN254.zkasm"
|
23
|
+
INCLUDE "../pairings/FP2BN254/squareFp2BN254.zkasm"
|
24
|
+
INCLUDE "../pairings/FP2BN254/escalarMulFp2BN254.zkasm"
|
25
|
+
INCLUDE "../pairings/FP2BN254/invFp2BN254.zkasm"
|
26
|
+
INCLUDE "../pairings/FP4BN254/squareFp4BN254.zkasm"
|
27
|
+
INCLUDE "../pairings/FP6BN254/addFp6BN254.zkasm"
|
28
|
+
INCLUDE "../pairings/FP6BN254/subFp6BN254.zkasm"
|
29
|
+
INCLUDE "../pairings/FP6BN254/mulFp6BN254.zkasm"
|
30
|
+
INCLUDE "../pairings/FP6BN254/escalarMulFp6BN254.zkasm"
|
31
|
+
INCLUDE "../pairings/FP6BN254/sparseMulAFp6BN254.zkasm"
|
32
|
+
INCLUDE "../pairings/FP6BN254/sparseMulBFp6BN254.zkasm"
|
33
|
+
INCLUDE "../pairings/FP6BN254/sparseMulCFp6BN254.zkasm"
|
34
|
+
INCLUDE "../pairings/FP6BN254/squareFp6BN254.zkasm"
|
35
|
+
INCLUDE "../pairings/FP6BN254/inverseFp6BN254.zkasm"
|
36
|
+
INCLUDE "../pairings/FP12BN254/mulFp12BN254.zkasm"
|
37
|
+
INCLUDE "../pairings/FP12BN254/sparseMulAFp12BN254.zkasm"
|
38
|
+
INCLUDE "../pairings/FP12BN254/sparseMulBFp12BN254.zkasm"
|
39
|
+
INCLUDE "../pairings/FP12BN254/squareFp12BN254.zkasm"
|
40
|
+
INCLUDE "../pairings/FP12BN254/inverseFp12BN254.zkasm"
|
41
|
+
INCLUDE "../pairings/FP12BN254/frobFp12BN254.zkasm"
|
42
|
+
INCLUDE "../pairings/FP12BN254/frob2Fp12BN254.zkasm"
|
43
|
+
INCLUDE "../pairings/FP12BN254/frob3Fp12BN254.zkasm"
|
44
|
+
INCLUDE "../pairings/FP12BN254/CYCLOFP12BN254/xBinDecompBN254.zkasm"
|
45
|
+
INCLUDE "../pairings/FP12BN254/CYCLOFP12BN254/compressFp12BN254.zkasm"
|
46
|
+
INCLUDE "../pairings/FP12BN254/CYCLOFP12BN254/decompressFp12BN254.zkasm"
|
47
|
+
INCLUDE "../pairings/FP12BN254/CYCLOFP12BN254/squareCompCycloFp12BN254.zkasm"
|
48
|
+
INCLUDE "../pairings/FP12BN254/CYCLOFP12BN254/squareCycloFp12BN254.zkasm"
|
49
|
+
INCLUDE "../pairings/FP12BN254/CYCLOFP12BN254/expByXCompCycloFp12BN254.zkasm"
|
50
|
+
INCLUDE "../pairings/BN254/addPointBN254.zkasm"
|
51
|
+
INCLUDE "../pairings/BN254/escalarMulBN254.zkasm"
|
52
|
+
INCLUDE "../pairings/BN254/lineSamePointsBN254.zkasm"
|
53
|
+
INCLUDE "../pairings/BN254/lineDiffPointsBN254.zkasm"
|
54
|
+
INCLUDE "../pairings/halfPairingBN254.zkasm"
|
55
|
+
INCLUDE "../pairings/millerLoopBN254.zkasm"
|
56
|
+
INCLUDE "../pairings/loopLengthBN254.zkasm"
|
57
|
+
INCLUDE "../pairings/finalExpBN254.zkasm"
|
58
|
+
INCLUDE "end.zkasm"
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Selector precompiled contract to run
|
62
|
+
* Current precompiled supported: ECRECOVER, SHA2-256, IDENTITY, MODEXP, ECADD, ECMUL, ECPAIRING
|
63
|
+
* @param {A} - Precompiled address
|
64
|
+
* @dev Any call to an unsupported precompiled will result in a revert
|
65
|
+
* - All gas is refunded
|
66
|
+
* - 0 is returned
|
67
|
+
*/
|
68
|
+
selectorPrecompiled:
|
69
|
+
A - 2 :JMPN(funcECRECOVER)
|
70
|
+
A - 3 :JMPN(funcSHA256)
|
71
|
+
A - 4 :JMPN(revertPrecompiled) ;:JMPN(RIPEMD160)
|
72
|
+
A - 5 :JMPN(IDENTITY)
|
73
|
+
A - 6 :JMPN(revertPrecompiled) ;:JMPN(funcModexp)
|
74
|
+
A - 7 :JMPN(funcEcAdd)
|
75
|
+
A - 8 :JMPN(funcEcMul)
|
76
|
+
A - 9 :JMPN(funcEcPairing)
|
77
|
+
A - 10 :JMPN(revertPrecompiled) ;:JMPN(BLAKE2F)
|
@@ -0,0 +1,147 @@
|
|
1
|
+
processChangeL2Block:
|
2
|
+
|
3
|
+
; checks zk-counters
|
4
|
+
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE*6 :JMPN(outOfCountersPoseidon)
|
5
|
+
$ => A :MLOAD(cntKeccakPreProcess)
|
6
|
+
%MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 2 :JMPN(outOfCountersKeccak)
|
7
|
+
%MAX_CNT_STEPS - STEP - 500 :JMPN(outOfCountersStep)
|
8
|
+
%MAX_CNT_BINARY - CNT_BINARY - 8 :JMPN(outOfCountersBinary)
|
9
|
+
|
10
|
+
; If it is not the first transaction, we must consolidate previous block
|
11
|
+
$ => A :MLOAD(currentTx)
|
12
|
+
A - 1 :JMPZ(continueProcessChangeL2Block)
|
13
|
+
:CALL(consolidateBlock)
|
14
|
+
|
15
|
+
continueProcessChangeL2Block:
|
16
|
+
$${eventLog(onStartBlock)}
|
17
|
+
; Reset tx index, logIndex and cumulative gas used
|
18
|
+
0 :MSTORE(txIndex)
|
19
|
+
0 :MSTORE(cumulativeGasUsed)
|
20
|
+
0 :MSTORE(currentLogIndex)
|
21
|
+
;; Set block hash (current state root) on storage
|
22
|
+
; Update state root mapping
|
23
|
+
32 => D
|
24
|
+
0 => HASHPOS ; A new hash with position 0 is started
|
25
|
+
$ => E :MLOAD(lastHashKIdUsed)
|
26
|
+
E + 1 => E :MSTORE(lastHashKIdUsed)
|
27
|
+
|
28
|
+
%ADDRESS_SYSTEM => A
|
29
|
+
%SMT_KEY_SC_STORAGE => B
|
30
|
+
$ => C :MLOAD(blockNum)
|
31
|
+
C :HASHK(E)
|
32
|
+
%STATE_ROOT_STORAGE_POS :HASHK(E)
|
33
|
+
HASHPOS :HASHKLEN(E)
|
34
|
+
$ => C :HASHKDIGEST(E)
|
35
|
+
SR => D :MSTORE(previousBlockHash)
|
36
|
+
$ => SR :SSTORE, CALL(initBlockInfoTree)
|
37
|
+
|
38
|
+
; Read block number, increase it by 1 and write it
|
39
|
+
; Get last block number
|
40
|
+
$ => A :MLOAD(blockNum)
|
41
|
+
|
42
|
+
; Update last block number at system storage
|
43
|
+
1 => B
|
44
|
+
$ => D :ADD, MSTORE(blockNum)
|
45
|
+
%LAST_BLOCK_STORAGE_POS => C
|
46
|
+
%ADDRESS_SYSTEM => A
|
47
|
+
%SMT_KEY_SC_STORAGE => B
|
48
|
+
$ => SR :SSTORE
|
49
|
+
|
50
|
+
; Load current timestamp
|
51
|
+
%TIMESTAMP_STORAGE_POS => C
|
52
|
+
%ADDRESS_SYSTEM => A
|
53
|
+
%SMT_KEY_SC_STORAGE => B
|
54
|
+
$ => A :SLOAD ; currentTimestamp => A
|
55
|
+
|
56
|
+
$ => B :MLOAD(timestampLimit) ; timestampLimit => B
|
57
|
+
|
58
|
+
; If it is NOT a forced tx ==> verify Timestamp & L1InfoRoot
|
59
|
+
$ :MLOAD(isForced), JMPZ(verifyTimestampAndL1InfoRoot)
|
60
|
+
|
61
|
+
; forced batch
|
62
|
+
; - update timestamp only if currentTimestamp < limitTimestamp
|
63
|
+
; - set blockHash to default
|
64
|
+
$ => C :MLOAD(forcedBlockHashL1)
|
65
|
+
C :MSTORE(blockHashL1InfoTree)
|
66
|
+
A :MSTORE(timestamp)
|
67
|
+
$ :LT, JMPNC(initSetGERL1InfoTree)
|
68
|
+
|
69
|
+
newForcedTimestamp:
|
70
|
+
B :MSTORE(timestamp), JMP(setNewTimestamp)
|
71
|
+
|
72
|
+
verifyTimestampAndL1InfoRoot:
|
73
|
+
$ => B :MLOAD(deltaTimestamp)
|
74
|
+
; Addition of two values of 8 bytes [B: currentTimestamp(A) + deltaTimestamp(B)]
|
75
|
+
$ => B :ADD, MSTORE(timestamp)
|
76
|
+
|
77
|
+
; Verify (currentTimestamp + deltaTimestamp) <= limitTimestamp
|
78
|
+
$ => A :MLOAD(timestampLimit)
|
79
|
+
$ :LT, JMPC(invalidChangeL2BlockLimitTimestamp)
|
80
|
+
|
81
|
+
; Set new timestamp
|
82
|
+
%TIMESTAMP_STORAGE_POS => C
|
83
|
+
%ADDRESS_SYSTEM => A
|
84
|
+
%SMT_KEY_SC_STORAGE => B
|
85
|
+
$ => D :MLOAD(timestamp)
|
86
|
+
$ => SR :SSTORE
|
87
|
+
|
88
|
+
; check indexL1InfoTree != 0 to verify data L1InfoTree
|
89
|
+
$ :MLOAD(indexL1InfoTree), JMPZ(skipSetGERL1InfoTree)
|
90
|
+
|
91
|
+
${getL1InfoGER(mem.indexL1InfoTree)} => A :MSTORE(gerL1InfoTree)
|
92
|
+
${getL1InfoBlockHash(mem.indexL1InfoTree)} => B :MSTORE(blockHashL1InfoTree)
|
93
|
+
${getL1InfoTimestamp(mem.indexL1InfoTree)} => C :MSTORE(timestampL1InfoTree)
|
94
|
+
:CALL(verifyMerkleProof)
|
95
|
+
|
96
|
+
; Verify (currentTimestamp + deltaTimestamp) >= l1InfoRoot.timestamp
|
97
|
+
$ => A :MLOAD(timestamp)
|
98
|
+
$ => B :MLOAD(timestampL1InfoTree)
|
99
|
+
$ :LT, JMPC(invalidChangeL2BlockMinTimestamp, initSetGERL1InfoTree)
|
100
|
+
|
101
|
+
setNewTimestamp:
|
102
|
+
; Set new timestamp
|
103
|
+
%TIMESTAMP_STORAGE_POS => C
|
104
|
+
%ADDRESS_SYSTEM => A
|
105
|
+
%SMT_KEY_SC_STORAGE => B
|
106
|
+
$ => D :MLOAD(timestamp)
|
107
|
+
$ => SR :SSTORE
|
108
|
+
|
109
|
+
initSetGERL1InfoTree:
|
110
|
+
; Set new GER
|
111
|
+
$ => A :MLOAD(gerL1InfoTree)
|
112
|
+
; If it is a forced tx ==> gerL1InfoTree = l1InfoRoot
|
113
|
+
$ :MLOAD(isForced), JMPZ(setGERL1InfoTree)
|
114
|
+
$ => A :MLOAD(l1InfoRoot)
|
115
|
+
A :MSTORE(gerL1InfoTree)
|
116
|
+
|
117
|
+
setGERL1InfoTree:
|
118
|
+
0 => B
|
119
|
+
; Do not set if zero
|
120
|
+
$ :EQ, JMPC(skipSetGERL1InfoTree)
|
121
|
+
0 => HASHPOS
|
122
|
+
$ => E :MLOAD(lastHashKIdUsed)
|
123
|
+
E + 1 => E :MSTORE(lastHashKIdUsed)
|
124
|
+
|
125
|
+
32 => D
|
126
|
+
A :HASHK(E)
|
127
|
+
%GLOBAL_EXIT_ROOT_STORAGE_POS :HASHK(E) ; Storage position of the global exit root map
|
128
|
+
HASHPOS :HASHKLEN(E)
|
129
|
+
$ => C :HASHKDIGEST(E)
|
130
|
+
|
131
|
+
; read blockHashL1InfoTree given the l1InfoRoot
|
132
|
+
; skip overwrite blockHashL1 if it is different than 0 (already set)
|
133
|
+
%ADDRESS_GLOBAL_EXIT_ROOT_MANAGER_L2 => A
|
134
|
+
%SMT_KEY_SC_STORAGE => B
|
135
|
+
$ => A :SLOAD
|
136
|
+
0 => B
|
137
|
+
$ :EQ, JMPNC(skipSetGERL1InfoTree)
|
138
|
+
|
139
|
+
; write blockhashL1
|
140
|
+
%ADDRESS_GLOBAL_EXIT_ROOT_MANAGER_L2 => A
|
141
|
+
%SMT_KEY_SC_STORAGE => B
|
142
|
+
$ => D :MLOAD(blockHashL1InfoTree)
|
143
|
+
$ => SR :SSTORE ; Store 'blockHashL1InfoTree' in storage position 'keccak256(gerL1InfoTree, 0)'
|
144
|
+
|
145
|
+
skipSetGERL1InfoTree:
|
146
|
+
:CALL(setupNewBlockInfoTree)
|
147
|
+
:JMP(txLoop)
|