diff --git a/main/opcodes/calldata-returndata-code.zkasm b/main/opcodes/calldata-returndata-code.zkasm index e03cc4b4..d32f4622 100644 --- a/main/opcodes/calldata-returndata-code.zkasm +++ b/main/opcodes/calldata-returndata-code.zkasm @@ -385,12 +385,12 @@ opEXTCODECOPY: $ => D :MLOAD(SP+1); [offset => D] $ => E :MLOAD(SP); [size => E] - ; store lastMemOffset for memory expansion gas cost - C :MSTORE(lastMemOffset) + ; store lastMemOffset for memory expansion gas cost, we store also at B to recover later + C => B :MSTORE(lastMemOffset) - ; store lastMemLength for memory expansion gas cost + ; store lastMemLength for memory expansion gas cost, we store also at RCX to recover later ; compute memory expansion gas cost - E :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength] + E => RCX :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength] ; check out-of-gas ;${3*((E+31)/32)} @@ -401,6 +401,8 @@ opEXTCODECOPY: ; 3*((E+31)/32) ; check out-of-gas GAS - 3 * E => GAS :JMPN(outOfGas) + RCX => E + B => C ; if offset is above data len, length => offset D => A $ => B :MLOAD(tmpContractLength) @@ -504,8 +506,8 @@ opRETURNDATACOPY: $ => C :MLOAD(SP); [size => C] ; store lastMemOffset for memory expansion gas cost D :MSTORE(lastMemOffset) - ; store lastMemLength for memory expansion gas cost - C :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength] + ; store lastMemLength for memory expansion gas cost, we store also at RCX to recover later + C => RCX :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength] ; if retDataCTX is 0, end opcode execution $ => B :MLOAD(retDataCTX), JMPZ(opRETURNDATACOPYEmpty) ; Load ret data length from last ctx @@ -527,6 +529,7 @@ opRETURNDATACOPY: ; C is secured to be less than 32 bits after calling saveMem ;(C+31)/32 C + 31 => A :CALL(offsetUtil); in: [A: offset] out: [E: offset/32, C: offset%32] + RCX => C ; 3*((C+31)/32) ; check out-of-gas GAS - 3 * E => GAS :JMPN(outOfGas) diff --git a/main/opcodes/crypto.zkasm b/main/opcodes/crypto.zkasm index 86d7d2de..579c781b 100644 --- a/main/opcodes/crypto.zkasm +++ b/main/opcodes/crypto.zkasm @@ -17,8 +17,8 @@ opSHA3: ; check out-of-gas GAS - %KECCAK_GAS => GAS :JMPN(outOfGas) SP - 1 => SP - $ => E :MLOAD(SP--); [offset => E] - $ => C :MLOAD(SP) ; [size => C] + $ => E, D :MLOAD(SP--); [offset => E] + $ => C, B :MLOAD(SP) ; [size => C] ; store lastMemOffset for memory expansion gas cost E :MSTORE(lastMemOffset) @@ -34,6 +34,9 @@ opSHA3: ; E is less than 32 bits because C is less than 32 bits and E = C/32 ; 6*((C+31)/32) GAS - 6 * E => GAS :JMPN(outOfGas) ; dynamic_gas = 6 * minimum_word_size + memory_expansion_cost + ; Recover offset and size at E and C + D => E + B => C ; check keccak counters C + 1 :MSTORE(arithA) 136 :MSTORE(arithB), CALL(divARITH); in: [arithA, arithB] out: [arithRes1: arithA/arithB, arithRes2: arithA%arithB] diff --git a/main/precompiled/identity.zkasm b/main/precompiled/identity.zkasm index 420bd502..5349d136 100644 --- a/main/precompiled/identity.zkasm +++ b/main/precompiled/identity.zkasm @@ -17,9 +17,10 @@ IDENTITY: $ :LT, JMPC(moveBalances) GAS - %IDENTITY_GAS => GAS :JMPN(outOfGas) - $ => C :MLOAD(txCalldataLen) + $ => C, D :MLOAD(txCalldataLen) ;(C+31)/32 => A C + 31 => A :CALL(offsetUtil); in: [A: offset] out: [E: offset/32, C: offset%32] + D => C GAS - %IDENTITY_WORD_GAS*E => GAS :JMPN(outOfGas) 0 => E, D :MSTORE(retDataOffset) C :MSTORE(retDataLength) diff --git a/main/precompiled/pre-sha2-256.zkasm b/main/precompiled/pre-sha2-256.zkasm index d5558f0f..41123956 100644 --- a/main/precompiled/pre-sha2-256.zkasm +++ b/main/precompiled/pre-sha2-256.zkasm @@ -25,11 +25,11 @@ funcSHA256: ; GAS - staticGas GAS - %SHA2_256_GAS => GAS :JMPN(outOfGas) - $ => C :MLOAD(txCalldataLen) + $ => C, D :MLOAD(txCalldataLen) ;words => A === (C+31)/32 => A C + 31 => A :CALL(offsetUtil); in: [A: offset] out: [E: offset/32, C: offset%32] - + D => C ; GAS - dynamicGas GAS - %SHA2_256_WORD_GAS*E => GAS :JMPN(outOfGas) diff --git a/main/utils.zkasm b/main/utils.zkasm index ad2c1cf1..922aa23c 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -736,10 +736,10 @@ SHRarithBit: E :MSTORE(tmpVarESHX) SHRarithinit: + A => E :MSTORE(arithA) 0 => B ; if A == 0 --> no shift $ :EQ,JMPC(SHRarithfinal) - A => E :MSTORE(arithA) ; B bits D => B 255 => A