diff --git a/main/constants.zkasm b/main/constants.zkasm index 544eeb9e..ff9ab7b4 100644 --- a/main/constants.zkasm +++ b/main/constants.zkasm @@ -37,6 +37,6 @@ CONST %MAX_CNT_MEM_ALIGN = %MAX_CNT_STEPS / 32 CONST %MAX_CNT_KECCAK_F = (%MAX_CNT_STEPS / 158418) * 9 CONST %MAX_CNT_PADDING_PG = (%MAX_CNT_STEPS / 56) CONST %MAX_CNT_POSEIDON_G = (%MAX_CNT_STEPS / 30) -CONST %MIN_CNT_KECCAK_BATCH = 2 ; minimum necessary keccaks to compute global hash +CONST %MIN_CNT_KECCAK_BATCH = 1 ; minimum necessary keccaks to compute global hash ; ETHEREUM CONSTANTS CONSTL %MAX_NONCE = 0xffffffffffffffffn \ No newline at end of file diff --git a/main/main.zkasm b/main/main.zkasm index c0e1a441..a3b785ab 100644 --- a/main/main.zkasm +++ b/main/main.zkasm @@ -70,8 +70,6 @@ skipSetGlobalExitRoot: ; Compute necessary keccak counters to finish batch $ => A :MLOAD(batchL2DataLength) - ; batchHashData: batchL2DataLength + 32 (globalExitRoot) + 20 (sequencerAddress) - A + 52 => A ; Divide the total data length by 136 to obtain the keccak counter increment. ; 136 is the value used by the prover to increment keccak counters A :MSTORE(arithA) @@ -79,7 +77,7 @@ skipSetGlobalExitRoot: :CALL(divARITH) $ => B :MLOAD(arithRes1) ; Compute minimum necessary keccaks to finish the batch - B + %MIN_CNT_KECCAK_BATCH :MSTORE(cntKeccakPreProcess) + B + 1 + %MIN_CNT_KECCAK_BATCH :MSTORE(cntKeccakPreProcess) %MAX_CNT_KECCAK_F - CNT_KECCAK_F => A $ :LT, JMPC(outOfCountersKeccak) diff --git a/main/opcodes/block.zkasm b/main/opcodes/block.zkasm index 79fa6185..73bf945a 100644 --- a/main/opcodes/block.zkasm +++ b/main/opcodes/block.zkasm @@ -3,7 +3,7 @@ opBLOCKHASH: %MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 255 :JMPN(outOfCountersPoseidon) $ => A :MLOAD(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 2 :JMPN(outOfCountersKeccak) + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 :JMPN(outOfCountersKeccak) %MAX_CNT_STEPS - STEP - 200 :JMPN(outOfCountersStep) SP - 1 => SP :JMPN(stackUnderflow) @@ -23,7 +23,8 @@ opBLOCKHASH: A :HASHK(E) %STATE_ROOT_STORAGE_POS :HASHK(E) HASHPOS :HASHKLEN(E) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - %MIN_CNT_KECCAK_BATCH - 2:JMPN(outOfCountersKeccak) + $ => A :MLOAD(cntKeccakPreProcess) + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1:JMPN(outOfCountersKeccak) $ => C :HASHKDIGEST(E) %ADDRESS_SYSTEM => A %SMT_KEY_SC_STORAGE => B diff --git a/main/opcodes/crypto.zkasm b/main/opcodes/crypto.zkasm index e93eb59f..b0a9cb4c 100644 --- a/main/opcodes/crypto.zkasm +++ b/main/opcodes/crypto.zkasm @@ -17,7 +17,7 @@ opSHA3: %MAX_CNT_BINARY - CNT_BINARY - 193 :JMPN(outOfCountersBinary) %MAX_CNT_MEM_ALIGN - CNT_MEM_ALIGN - 2 :JMPN(outOfCountersMemalign) $ => A :MLOAD(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 2 :JMPN(outOfCountersKeccak) + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 :JMPN(outOfCountersKeccak) %MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 10 :JMPN(outOfCountersPoseidon) %MAX_CNT_STEPS - STEP - 200 :JMPN(outOfCountersStep) @@ -103,7 +103,7 @@ opSHA3End: $ => B :MLOAD(arithRes1) $ => A :MLOAD(cntKeccakPreProcess) ; checks keccak counters - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A => A + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 => A $ :LT, JMPC(outOfCountersKeccak) ; compute hash $ => A :HASHKDIGEST(E) diff --git a/main/process-tx.zkasm b/main/process-tx.zkasm index 503555cb..cd53eca1 100644 --- a/main/process-tx.zkasm +++ b/main/process-tx.zkasm @@ -41,7 +41,7 @@ processTx: :CALL(divARITH) $ => B :MLOAD(arithRes1) $ => A :MLOAD(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A => A + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 => A $ :LT, JMPC(outOfCountersKeccak) ; Get hash address previously stored in RLP parsing @@ -314,7 +314,7 @@ create2end: :CALL(divARITH) $ => B :MLOAD(arithRes1) $ => A :MLOAD(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A => A + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 => A $ :LT, JMPC(outOfCountersKeccak) $ => C :HASHKDIGEST(E) ; new hash with position 0 is started @@ -341,7 +341,7 @@ endContractAddress: :CALL(divARITH) $ => B :MLOAD(arithRes1) $ => A :MLOAD(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A => A + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 => A $ :LT, JMPC(outOfCountersKeccak) $ => A :HASHKDIGEST(E) diff --git a/main/utils.zkasm b/main/utils.zkasm index b73b71e3..57679776 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -1062,7 +1062,8 @@ updateSystemData: A :HASHK(E) %STATE_ROOT_STORAGE_POS :HASHK(E) HASHPOS :HASHKLEN(E) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - %MIN_CNT_KECCAK_BATCH - 2:JMPN(outOfCountersKeccak) + $ => A :MLOAD(cntKeccakPreProcess) + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1:JMPN(outOfCountersKeccak) $ => C :HASHKDIGEST(E) %ADDRESS_SYSTEM => A SR => D