From 2ee7fcb095117fba444f295a8d415a7034e39142 Mon Sep 17 00:00:00 2001 From: Ignasirv Date: Mon, 28 Nov 2022 17:38:02 +0100 Subject: [PATCH] Fix checking counters after gas at sha3 --- main/opcodes/block.zkasm | 1 - main/opcodes/crypto.zkasm | 20 +++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/main/opcodes/block.zkasm b/main/opcodes/block.zkasm index 5e4e2b6e..9603aabb 100644 --- a/main/opcodes/block.zkasm +++ b/main/opcodes/block.zkasm @@ -23,7 +23,6 @@ opBLOCKHASH: A :HASHK(E) %STATE_ROOT_STORAGE_POS :HASHK(E) HASHPOS :HASHKLEN(E) - $ => A :MLOAD(cntKeccakPreProcess) $ => C :HASHKDIGEST(E) %ADDRESS_SYSTEM => A %SMT_KEY_SC_STORAGE => B diff --git a/main/opcodes/crypto.zkasm b/main/opcodes/crypto.zkasm index c2b06f4b..0048b94d 100644 --- a/main/opcodes/crypto.zkasm +++ b/main/opcodes/crypto.zkasm @@ -27,15 +27,6 @@ opSHA3: SP - 1 => SP $ => E :MLOAD(SP--); [offset => E] $ => C :MLOAD(SP) ; [size => C] - ; check keccak counters - C + 1 :MSTORE(arithA) - 136 :MSTORE(arithB) - :CALL(divARITH); in: [arithA, arithB] out: [arithRes1: arithA/arithB, arithRes2: arithA%arithB] - $ => B :MLOAD(arithRes1) - $ => A :MLOAD(cntKeccakPreProcess) - ; checks keccak counters - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 => A - $ :LT, JMPC(outOfCountersKeccak) ; store lastMemOffset for memory expansion gas cost E :MSTORE(lastMemOffset) @@ -58,6 +49,17 @@ opSHA3: :CALL(mulARITH) $ => A :MLOAD(arithRes1) GAS - A => GAS :JMPN(outOfGas) ; dynamic_gas = 6 * minimum_word_size + memory_expansion_cost + + ; check keccak counters + C + 1 :MSTORE(arithA) + 136 :MSTORE(arithB) + :CALL(divARITH); in: [arithA, arithB] out: [arithRes1: arithA/arithB, arithRes2: arithA%arithB] + $ => B :MLOAD(arithRes1) + $ => A :MLOAD(cntKeccakPreProcess) + ; checks keccak counters + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - A - 1 => A + $ :LT, JMPC(outOfCountersKeccak) + ; new hash id $ => B :MLOAD(lastHashKIdUsed) B + 1 => B :MSTORE(lastHashKIdUsed)