Skip to content

Commit

Permalink
Merge pull request #204 from 0xPolygonHermez/feature/return-refactor
Browse files Browse the repository at this point in the history
Feature/return refactor
  • Loading branch information
krlosMata authored Dec 15, 2022
2 parents c30d2dc + 48f78d5 commit 39d12de
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 47 deletions.
6 changes: 2 additions & 4 deletions main/load-tx-rlp-utils.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,5 +24,4 @@ addHashTx:
${getTxs(p,D)} => A
$${p = p + D}
A :HASHK(E)
C + D => C
:RETURN
C + D => C :RETURN
6 changes: 2 additions & 4 deletions main/opcodes/calldata-returndata-code.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 5 additions & 10 deletions main/touched.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -113,5 +109,4 @@ finishColdSlot:
; restore tmp registers
$ => B :MLOAD(tmpB)
$ => D :MLOAD(tmpD)
$ => E :MLOAD(tmpE)
:RETURN
$ => E :MLOAD(tmpE), RETURN
42 changes: 13 additions & 29 deletions main/utils.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -483,7 +473,6 @@ zeroDiv:
divisorSmallerDiv:
0 :MSTORE(arithRes1)
E :MSTORE(arithRes2), CALL(loadTmp)

$ => RR :MLOAD(tmpZkPCArith)
:RETURN

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -957,8 +944,7 @@ maskAddress:
B :MSTORE(tmpVarB)
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFn => B
$ => A :AND
$ => B :MLOAD(tmpVarB)
:RETURN
$ => B :MLOAD(tmpVarB), RETURN

updateSystemData:
; check keccak counters
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 39d12de

Please sign in to comment.