diff --git a/main/constants.zkasm b/main/constants.zkasm index d177f2df..ac187c9a 100644 --- a/main/constants.zkasm +++ b/main/constants.zkasm @@ -6,7 +6,7 @@ CONST %BATCH_DIFFICULTY = 0 CONST %TX_GAS_LIMIT = 30000000 CONSTL %BLOCK_GAS_LIMIT = 2**50 CONST %MAX_MEM_EXPANSION_BYTES = 0x3fffe0 -CONST %FORK_ID = 8 +CONST %FORK_ID = 9 CONST %L1INFO_TREE_LEVELS = 32 CONST %CALLDATA_RESERVED_CTX = 1 CONSTL %FOUR_GOLDILOCKS = 0xffffffff00000001ffffffff00000001ffffffff00000001ffffffff00000001n @@ -142,3 +142,4 @@ CONST %CHANGE_L2_BLOCK_TX_TYPE = 0x0b CONST %DELTA_TIMESTAMP_NUM_BYTES = 4 CONST %INDEX_L1INFOTREE_NUM_BYTES = 4 CONST %TX_TYPE_NUM_BYTES = 1 +CONSTL %L1_INFO_DATA_ZERO = 0x3cac317908c699fe873a7f6ee4e8cd63fbe9918b2315c97be91585590168e301n \ No newline at end of file diff --git a/main/process-change-l2-block.zkasm b/main/process-change-l2-block.zkasm index 75581d64..313e07f0 100644 --- a/main/process-change-l2-block.zkasm +++ b/main/process-change-l2-block.zkasm @@ -86,12 +86,12 @@ verifyTimestampAndL1InfoRoot: $ => SR :SSTORE ; check indexL1InfoTree != 0 to verify data L1InfoTree - $ :MLOAD(indexL1InfoTree), JMPZ(skipSetGERL1InfoTree) + $ :MLOAD(indexL1InfoTree), JMPZ(skipSetGERL1InfoTree) -${getL1InfoGER(mem.indexL1InfoTree)} => A :MSTORE(gerL1InfoTree) -${getL1InfoBlockHash(mem.indexL1InfoTree)} => B :MSTORE(blockHashL1InfoTree) -${getL1InfoTimestamp(mem.indexL1InfoTree)} => C :MSTORE(timestampL1InfoTree) - :CALL(verifyMerkleProof) + ${getL1InfoGER(mem.indexL1InfoTree)} => A :MSTORE(gerL1InfoTree) + ${getL1InfoBlockHash(mem.indexL1InfoTree)} => B :MSTORE(blockHashL1InfoTree) + ${getL1InfoTimestamp(mem.indexL1InfoTree)} => C :MSTORE(timestampL1InfoTree) + :CALL(verifyMerkleProof) ; Verify (currentTimestamp + deltaTimestamp) >= l1InfoRoot.timestamp $ => A :MLOAD(timestamp) diff --git a/main/utils.zkasm b/main/utils.zkasm index 4b1dab16..9044f3cf 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -845,6 +845,8 @@ invalidChangeL2BlockLimitTimestamp: $${eventLog(onError, invalid_change_l2_block_limit_timestamp)} :JMP(handleBatchError) invalidChangeL2BlockMinTimestamp: $${eventLog(onError, invalid_change_l2_block_min_timestamp)} :JMP(handleBatchError) +invalidL1InfoTreeIndex: + $${eventLog(onError, invalid_l1_info_tree_index)} :JMP(handleBatchError) outOfGas: $${eventLog(onError, OOG)} :JMP(handleError) invalidJump: @@ -1666,9 +1668,12 @@ verifyMerkleProof: ; 1 keccak for the leaf and 32 for the L1InfoTree %MAX_CNT_KECCAK_F - CNT_KECCAK_F - E - 33 :JMPN(outOfCountersKeccak) ; 7 steps at most per bit + 21 statics - %MAX_CNT_STEPS - STEP - 7 * 32 - 21 :JMPN(outOfCountersStep) + %MAX_CNT_STEPS - STEP - 7 * 32 - 25 :JMPN(outOfCountersStep) + ; check binaries + %MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary) RR :MSTORE(tmpZkPCVerifyMerkleProof) + 0 :MSTORE(isL1InfoDataZero) ;;;;;;;;;;;;;;;;;;;;; ;; compute leaf value @@ -1692,8 +1697,14 @@ verifyMerkleProof: ; compute l1InfoTree Leaf value HASHPOS :HASHKLEN(E) - $ => C :HASHKDIGEST(E) ; initial value + $ => C, A :HASHKDIGEST(E) ; initial value + ; allow to set value to all zeroes if all its values are zero + %L1_INFO_DATA_ZERO => B + $ :EQ, JMPNC(continueVerifyMerkleProof) + 1 :MSTORE(isL1InfoDataZero) + 0 => C +continueVerifyMerkleProof: ; initialization registers for smt verify 0 => D, A @@ -2261,6 +2272,7 @@ hashBranchEnd31: verifyMerkleProofEnd: $ => A :MLOAD(l1InfoRoot) C :ASSERT + $ :MLOAD(isL1InfoDataZero), JMPNZ(invalidL1InfoTreeIndex) verifyMerkleProofReturn: $ => RR :MLOAD(tmpZkPCVerifyMerkleProof) diff --git a/main/vars.zkasm b/main/vars.zkasm index 63ec168f..3ef0e6c5 100644 --- a/main/vars.zkasm +++ b/main/vars.zkasm @@ -56,6 +56,8 @@ VAR GLOBAL isLoadingRLP ; flag to determine if the function is called from RLP l VAR GLOBAL globalCalldataMemoryOffset ; Aux variable to store current calldata memory offset at calldata CTX's memory VAR GLOBAL txIndex ; index of the current tx in the block +VAR GLOBAL isL1InfoDataZero; indicates if the l1 info data value to be prove has zero value + VAR CTX txGasLimit ; transaction parameter: 'gas limit' VAR CTX txDestAddr ; transaction parameter: 'to' VAR CTX storageAddr ; address which the storage will be modified diff --git a/package.json b/package.json index 18618387..123cf032 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonhermez/zkevm-rom", - "version": "5.0.0", + "version": "6.0.0", "description": "zkROM source code", "main": "index.js", "scripts": { @@ -43,9 +43,9 @@ "yargs": "^17.5.1" }, "devDependencies": { - "@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v5.0.0-fork.8", - "@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs#493569b08869a496e5de379c83263e4a10d5e585", - "@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#v5.0.0-fork.8", + "@0xpolygonhermez/zkevm-commonjs": "github:0xPolygonHermez/zkevm-commonjs#v6.0.0-fork.9", + "@0xpolygonhermez/zkevm-proverjs": "github:0xPolygonHermez/zkevm-proverjs#39508f69cb191487a065ffbf76c647cd83b59720", + "@0xpolygonhermez/zkevm-testvectors": "github:0xPolygonHermez/zkevm-testvectors#v6.0.1-fork.9", "chai": "^4.3.6", "chalk": "^3.0.0", "eslint": "^8.25.0",