From 48f78d559e07623af47de212b1b7b2c4a2ca8f12 Mon Sep 17 00:00:00 2001 From: Ignasirv Date: Wed, 14 Dec 2022 19:04:55 +0100 Subject: [PATCH] Refactor return statement --- main/load-tx-rlp-utils.zkasm | 6 +-- main/opcodes/calldata-returndata-code.zkasm | 6 +-- main/touched.zkasm | 15 +++----- main/utils.zkasm | 42 +++++++-------------- 4 files changed, 22 insertions(+), 47 deletions(-) diff --git a/main/load-tx-rlp-utils.zkasm b/main/load-tx-rlp-utils.zkasm index 43811309..064a554f 100644 --- a/main/load-tx-rlp-utils.zkasm +++ b/main/load-tx-rlp-utils.zkasm @@ -5,8 +5,7 @@ addBatchHashData: A :HASHK(E) HASHPOS :MSTORE(batchHashPos) C => HASHPOS - $ => E :MLOAD(lastHashKIdUsed) - :RETURN + $ => E :MLOAD(lastHashKIdUsed), RETURN ;; get D bytes from transaction bytes getTxBytes: @@ -25,5 +24,4 @@ addHashTx: ${getTxs(p,D)} => A $${p = p + D} A :HASHK(E) - C + D => C - :RETURN \ No newline at end of file + C + D => C :RETURN diff --git a/main/opcodes/calldata-returndata-code.zkasm b/main/opcodes/calldata-returndata-code.zkasm index 604d4b23..66bad485 100644 --- a/main/opcodes/calldata-returndata-code.zkasm +++ b/main/opcodes/calldata-returndata-code.zkasm @@ -373,13 +373,11 @@ opCODECOPYLoadBytes: HASHPOS => A $ :LT, JMPC(readValueBytecode) readZero: - 0 => B - :RETURN + 0 => B :RETURN readValueBytecode: $ => E :MLOAD(codecopyHashId) ; read value to write in memory - $ => B :HASHP1(E) - :RETURN + $ => B :HASHP1(E), RETURN /** * @link [https://www.evm.codes/#3B?fork=berlin] diff --git a/main/touched.zkasm b/main/touched.zkasm index 51c87e61..ff223abe 100644 --- a/main/touched.zkasm +++ b/main/touched.zkasm @@ -5,14 +5,12 @@ VAR GLOBAL tmpE VAR GLOBAL tmpStateRoot initTouchedTree: - 0 :MSTORE(touchedSR) - :RETURN + 0 :MSTORE(touchedSR), RETURN ; @info Save touched root when a new context is created checkpointTouched: $ => A :MLOAD(touchedSR) - A :MSTORE(initTouchedSR) - :RETURN + A :MSTORE(initTouchedSR), RETURN ; @info Back to initial touched root revertTouched: @@ -64,16 +62,14 @@ finishColdAddress: ; restore tmp registers $ => B :MLOAD(tmpB) $ => C :MLOAD(tmpC) - $ => E :MLOAD(tmpE) - :RETURN + $ => E :MLOAD(tmpE), RETURN finishColdPrecompiled: 0 => D ; restore tmp registers $ => B :MLOAD(tmpB) $ => C :MLOAD(tmpC) - $ => E :MLOAD(tmpE) - :RETURN + $ => E :MLOAD(tmpE), RETURN ; @info Check if storage slot is cold. If it is, add it to the touched tree ; @in A => address @@ -113,5 +109,4 @@ finishColdSlot: ; restore tmp registers $ => B :MLOAD(tmpB) $ => D :MLOAD(tmpD) - $ => E :MLOAD(tmpE) - :RETURN \ No newline at end of file + $ => E :MLOAD(tmpE), RETURN diff --git a/main/utils.zkasm b/main/utils.zkasm index e15269c3..28609740 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -34,8 +34,7 @@ absIsNeg: A => B 0 => A $ => A :SUB - 1 => B - :RETURN + 1 => B :RETURN ; @info copy calldata A to ctxB SP = %CALLDATA_OFFSET copySP: @@ -64,9 +63,8 @@ copyFinal: $ => CTX :MLOAD(originCTX) copyEnd: - $ => CTX :MLOAD(currentCTX) $ => RR :MLOAD(tmpZkPC2) - :RETURN + $ => CTX :MLOAD(currentCTX), RETURN ; @info byte length of B ; @in B => number @@ -93,9 +91,8 @@ getLenEnd: C => A $ => B :MLOAD(tmpVarB) $ => C :MLOAD(tmpVarC) - $ => D :MLOAD(tmpVarD) $ => RR :MLOAD(tmpZkPC) - :RETURN + $ => D :MLOAD(tmpVarD), RETURN ; @info bits length of B ; @in B => number @@ -125,9 +122,8 @@ getLenBitsEnd: C => A $ => B :MLOAD(tmpVarB) $ => C :MLOAD(tmpVarC) - $ => D :MLOAD(tmpVarD) $ => RR :MLOAD(tmpZkPC) - :RETURN + $ => D :MLOAD(tmpVarD), RETURN VAR GLOBAL bytesToStore VAR GLOBAL isMSTOREX @@ -231,10 +227,8 @@ endMSTORE: $ => A :MLOAD(tmpVarA) $ => B :MLOAD(tmpVarB) $ => C :MLOAD(tmpVarC) - $ => D :MLOAD(tmpVarD) $ => RR :MLOAD(tmpZkPC) - :RETURN - + $ => D :MLOAD(tmpVarD), RETURN VAR GLOBAL isMLOADX ; @info get value from memory (< 32 bytes) @@ -290,9 +284,8 @@ offsetMLOAD32: endMLOAD: $ => B :MLOAD(tmpVarB) $ => C :MLOAD(tmpVarC) - $ => D :MLOAD(tmpVarD) $ => RR :MLOAD(tmpZkPC) - :RETURN + $ => D :MLOAD(tmpVarD), RETURN errorMLOADMSTORE: :JMP(handleError) @@ -336,8 +329,7 @@ ISEMPTYEnd: $ => A :MLOAD(tmpVarA) $ => B :MLOAD(tmpVarB) $ => C :MLOAD(tmpVarC) - $ => D :MLOAD(tmpVarD) - :RETURN + $ => D :MLOAD(tmpVarD), RETURN ; @out A => min( requested_gas , all_but_one_64th(63/64) ) computeGasSendCall: @@ -359,8 +351,7 @@ computeGasSendCallEnd: $ => B :MLOAD(tmpVarB) $ => C :MLOAD(tmpVarC) $ => D :MLOAD(tmpVarD) - $ => E :MLOAD(tmpVarE) - :RETURN + $ => E :MLOAD(tmpVarE), RETURN ; lastMemOffset: offset to copy bytes ; lastMemLength: size of the bytes to copy saveMem: @@ -396,8 +387,7 @@ saveMemEnd: $ => A :MLOAD(tmpVarA) $ => B :MLOAD(tmpVarB) $ => C :MLOAD(tmpVarC) - $ => E :MLOAD(tmpVarE) - :RETURN + $ => E :MLOAD(tmpVarE), RETURN VAR GLOBAL tmpVarAArith VAR GLOBAL tmpVarBArith @@ -483,7 +473,6 @@ zeroDiv: divisorSmallerDiv: 0 :MSTORE(arithRes1) E :MSTORE(arithRes2), CALL(loadTmp) - $ => RR :MLOAD(tmpZkPCArith) :RETURN @@ -627,9 +616,8 @@ SHLarithfinal: $ => B :MLOAD(tmpVarB2) $ => C :MLOAD(tmpVarC2) $ => D :MLOAD(tmpVarD2) - $ => E :MLOAD(tmpVarE2) $ => RR :MLOAD(tmpSHXZkPC2) - :RETURN + $ => E :MLOAD(tmpVarE2), RETURN outOfCountersStep: $${eventLog(onError, OOCS)} :JMP(handleBatchError) @@ -946,8 +934,7 @@ hashPoseidonReturn: $ => A :MLOAD(tmpVarA) $ => B :MLOAD(tmpVarB) $ => C :MLOAD(tmpVarC) - $ => E :MLOAD(tmpVarE) - :RETURN + $ => E :MLOAD(tmpVarE), RETURN ; @info Mask address to 20 bytes @@ -957,8 +944,7 @@ maskAddress: B :MSTORE(tmpVarB) 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn => B $ => A :AND - $ => B :MLOAD(tmpVarB) - :RETURN + $ => B :MLOAD(tmpVarB), RETURN updateSystemData: ; check keccak counters @@ -986,9 +972,7 @@ updateSystemData: $ => C :HASHKDIGEST(E) %ADDRESS_SYSTEM => A SR => D - $ => SR :SSTORE - :RETURN - + $ => SR :SSTORE, RETURN ; @info (A*B)%C => C ; @in A