diff --git a/main/constants.zkasm b/main/constants.zkasm index 62ca8b1d..60d0a6c1 100644 --- a/main/constants.zkasm +++ b/main/constants.zkasm @@ -9,7 +9,7 @@ CONST %LOCAL_EXIT_ROOT_STORAGE_POS = 1 CONST %LAST_TX_STORAGE_POS = 0 CONST %STATE_ROOT_STORAGE_POS = 1 CONST %MAX_MEM_EXPANSION_BYTES = 0x3fffe0 -CONST %FORK_ID = 4 +CONST %FORK_ID = 5 ; RLP CONST %MIN_VALUE_SHORT = 128 diff --git a/main/ecrecover/ecrecover.zkasm b/main/ecrecover/ecrecover.zkasm index 98436c4a..e77e0b60 100644 --- a/main/ecrecover/ecrecover.zkasm +++ b/main/ecrecover/ecrecover.zkasm @@ -72,7 +72,7 @@ ecrecover_store_args: 0n => A $ :EQ,JMPC(ecrecover_s_is_zero) - ; r and s in [1, FNEC-1] + ; compute r inverse $ => A :MLOAD(ecrecover_r),CALL(invFnEc) B :MSTORE(ecrecover_r_inv) diff --git a/main/load-tx-rlp.zkasm b/main/load-tx-rlp.zkasm index b58fd9db..74e1d7bd 100644 --- a/main/load-tx-rlp.zkasm +++ b/main/load-tx-rlp.zkasm @@ -17,7 +17,7 @@ INCLUDE "load-tx-rlp-utils.zkasm" loadTx_rlp: ; check one keccak is available to begin processing the RLP $ => D :MLOAD(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - 1 - D :JMPN(handleOOCKatRLP) + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - 1 - D :JMPN(outOfCountersKeccak) ; A new hash with position 0 is started 0 => HASHPOS @@ -59,7 +59,7 @@ endList: 136 :MSTORE(arithB), CALL(divARITH); in: [arithA, arithB] out: [arithRes1: arithA/arithB, arithRes2: arithA%arithB] $ => B :MLOAD(arithRes1) $ => D :MLOAD(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - B - D - 1:JMPN(handleOOCKatRLP) + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - B - D - 1:JMPN(outOfCountersKeccak) ;; Read RLP 'nonce' ; 64 bits max @@ -290,10 +290,10 @@ vREADTx: ;;;;;;;;; ;; update bytes parsed $ => A :MLOAD(batchL2DataParsed) - A + C => A :MSTORE(batchL2DataParsed) + A + C :MSTORE(batchL2DataParsed) ;; increase number of transaction to process $ => A :MLOAD(pendingTxs) - A + 1 => A :MSTORE(pendingTxs) + A + 1 :MSTORE(pendingTxs) ;; compute signature $ => A :HASHKDIGEST(E) A :MSTORE(txHash), JMP(txLoopRLP) @@ -301,19 +301,11 @@ vREADTx: ;;;;;;;;; ;; E - Handler error RLP fields ;;;;;;;;; -handleOOCBatRLP: - $${eventLog(onError, OOCB)} :JMP(handleOOCatRLP) -handleOOCKatRLP: - $${eventLog(onError, OOCK)} :JMP(handleOOCatRLP) -handleOOCSatRLP: - $${eventLog(onError, OOCS)} :JMP(handleOOCatRLP) -handleOOCatRLP: - $ => SR :MLOAD(batchSR) - invalidTxRLP: ;; Append all missing 'batchL2Data' to 'batchDataHash' bytes $ => B :MLOAD(batchL2DataLength) $ => C :MLOAD(batchHashPos) + $${p = C} $ => HASHPOS :MLOAD(batchHashPos) $ => E :MLOAD(batchHashDataId) diff --git a/main/main.zkasm b/main/main.zkasm index ec4b62c4..199e049c 100644 --- a/main/main.zkasm +++ b/main/main.zkasm @@ -87,7 +87,7 @@ skipSetGlobalExitRoot: $ => B :MLOAD(arithRes1) ; Compute minimum necessary keccaks to finish the batch B + 1 + %MIN_CNT_KECCAK_BATCH => B :MSTORE(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - B :JMPN(handleOOCKatRLP) + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - B :JMPN(outOfCountersKeccak) ;;;;;;;;;;;;;;;;;; ;; C - Loop parsing RLP transactions @@ -102,6 +102,8 @@ skipSetGlobalExitRoot: A :MSTORE(ctxTxToUse) ; Points at first context to be used when processing transactions $${var p = 0} + ; set flag isLoadingRLP to 1 + 1 :MSTORE(isLoadingRLP) txLoopRLP: $ => A :MLOAD(lastCtxUsed) @@ -110,7 +112,10 @@ txLoopRLP: $ => A :MLOAD(batchL2DataLength) $ => C :MLOAD(batchL2DataParsed) C - A :JMPN(loadTx_rlp, endCheckRLP) + endCheckRLP: + ; set flag isLoadingRLP to 0 + 0 :MSTORE(isLoadingRLP) :JMP(txLoop) ;;;;;;;;;;;;;;;;;; @@ -120,7 +125,7 @@ endCheckRLP: txLoop: $ => A :MLOAD(pendingTxs) - A-1 => A :MSTORE(pendingTxs), JMPN(processTxsEnd) + A-1 :MSTORE(pendingTxs), JMPN(processTxsEnd) $ => A :MLOAD(ctxTxToUse) ; Load first context used by transaction A+1 => CTX :MSTORE(ctxTxToUse),JMP(processTx) diff --git a/main/map-opcodes.zkasm b/main/map-opcodes.zkasm index f0f754ad..720c41fa 100644 --- a/main/map-opcodes.zkasm +++ b/main/map-opcodes.zkasm @@ -111,7 +111,7 @@ mapping_opcodes: :JMP(opINVALID) ; 0x5C :JMP(opINVALID) ; 0x5D :JMP(opINVALID) ; 0x5E - :JMP(opINVALID) ; 0x5F + :JMP(opPUSH0) ; 0x5F :JMP(opPUSH1) ; 0x60 :JMP(opPUSH2) ; 0x61 :JMP(opPUSH3) ; 0x62 diff --git a/main/opcodes/stack-operations.zkasm b/main/opcodes/stack-operations.zkasm index cb1dc3be..12669f2b 100644 --- a/main/opcodes/stack-operations.zkasm +++ b/main/opcodes/stack-operations.zkasm @@ -7,6 +7,15 @@ * - stack input: none * - stack output: [pushed_value] */ + +opPUSH0: + ; check out-of-gas + GAS - %GAS_QUICK_STEP => GAS :JMPN(outOfGas) + ; store stack output + 0 :MSTORE(SP++); [0 => SP] + ; check stack overflow + %CALLDATA_OFFSET - SP :JMPN(stackOverflow, readCode) + opPUSH1: ; number of bytes to push to D 1 => D diff --git a/main/utils.zkasm b/main/utils.zkasm index 6e6d9aab..d9fe5d7e 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -928,6 +928,7 @@ handleError: handleBatchError: ; restore init state root and finish batch $ => SR :MLOAD(batchSR) + $ :MLOAD(isLoadingRLP),JMPNZ(invalidTxRLP) $${eventLog(onFinishTx)} $${eventLog(onFinishBatch)} :JMP(processTxsEnd) @@ -1153,19 +1154,20 @@ finalPush: VAR GLOBAL tmpVarDaddB VAR GLOBAL tmpZkPCaddB VAR GLOBAL auxBytes + ;@info: adds data to batchHashdata byte by byte ;@in: A: bytes to add ;@in D: bytes length addBatchHashByteByByte: - %MAX_CNT_STEPS - STEP - 10 :JMPN(handleOOCSatRLP) + %MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep) RR :MSTORE(tmpZkPCaddB) A :MSTORE(auxBytes) D :MSTORE(tmpVarDaddB) 1 => D utilsAddBatchHashBytebyByteLoop: - %MAX_CNT_STEPS - STEP - 50 :JMPN(handleOOCSatRLP) - %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(handleOOCBatRLP) + %MAX_CNT_STEPS - STEP - 50 :JMPN(outOfCountersStep) + %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) 32 - D => D $ => A :MLOAD(auxBytes), CALL(SHRarith); in: [A: value, D: #bytes to right shift] out: [A: shifted result] ; get last byte in A diff --git a/main/vars.zkasm b/main/vars.zkasm index 96e7b6a4..aae52f65 100644 --- a/main/vars.zkasm +++ b/main/vars.zkasm @@ -48,6 +48,7 @@ VAR GLOBAL SPw ; aux variable to store Stack pointer 'SP' VAR GLOBAL auxSR ; auxiliary variable. Temporary state root VAR GLOBAL txRLPLength ; transaction RLP list length VAR GLOBAL txDataRead ; aux variable to check transaction 'data' left that needs to be read +VAR GLOBAL isLoadingRLP ; flag to determine if the function is called from RLP loop VAR CTX txGasLimit ; transaction parameter: 'gas limit' VAR CTX txDestAddr ; transaction parameter: 'to' diff --git a/package.json b/package.json index 15e7297f..4017ac1c 100644 --- a/package.json +++ b/package.json @@ -41,9 +41,9 @@ "yargs": "^17.5.1" }, "devDependencies": { - "@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs#c9adbddba82cb1dcc3b03f3dcb0f317627ac05b8", - "@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#v1.1.0-fork.4", - "@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v1.0.0", + "@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs#3bc0368dd67caf92d38e3cbebe7b030e78c54e35", + "@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#v1.2.0-rc.1-fork.5", + "@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v1.0.1-rc.3", "chai": "^4.3.6", "chalk": "^3.0.0", "eslint": "^8.25.0",