Skip to content

Commit

Permalink
Fix checking counters after gas at sha3
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Nov 28, 2022
1 parent ac287c4 commit 2ee7fcb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 0 additions & 1 deletion main/opcodes/block.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions main/opcodes/crypto.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 2ee7fcb

Please sign in to comment.