Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Mar 26, 2024
1 parent cfc28cf commit dd1a23d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
20 changes: 7 additions & 13 deletions main/opcodes/flow-control.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,39 @@ opJUMPI:

checkJumpDest:
; if it is a deploy we have to check the data from the calldata (not the bytecode)
$ => B :MLOAD(isCreateContract), JMPNZ(checkJumpDestDeployment)
$ :MLOAD(isCreateContract), JMPNZ(checkJumpDestDeployment)
$ => B :MLOAD(bytecodeLength)
$ :LT,JMPNC(invalidJump)
A => B
B => PC
B => HASHPOS
A => B, PC, HASHPOS
; get hashP address pointer where contract bytecode is stored
$ => E :MLOAD(contractHashId)
$ => A :HASHP1(E)
; check if is a jumpDest (0x5B)
A - 0x5B :JMPZ(readCode, invalidJump)
$ - 0x5B :F_HASHP1(E), JMPZ(readCode, invalidJump)

checkJumpDestDeployment:
; check enough bytes to read in calldata
$ => B :MLOAD(txCalldataLen)
$ :LT,JMPNC(invalidJump)
; check jumpDest from calldata
$ => B :MLOAD(isCreate), JMPNZ(checkJumpDestDeploymentCreate)
$ :MLOAD(isCreate), JMPNZ(checkJumpDestDeploymentCreate)
; get position where data starts in the tx
$ => HASHPOS :MLOAD(dataStarts)
; add PC to data starts to point the bytes to read for the jumpdest
A => PC
HASHPOS + PC => HASHPOS
$ + PC => HASHPOS :F_MLOAD(dataStarts)
; get memory pointer for hashing
$ => E :MLOAD(batchHashDataPointer)
; set number of bytes to hashK
$ => A :HASHP1(E)
; check if is a jumpDest (0x5B)
A - 0x5B :JMPZ(readCode, invalidJump)
$ - 0x5B :F_HASHP1(E), JMPZ(readCode, invalidJump)


checkJumpDestDeploymentCreate:
; get bytes from previous context memory
$ => CTX :MLOAD(originCTX)
; get offset call position
$ => E :MLOAD(argsOffsetCall)
; increase current program counter (PC) to offset for getting pushed bytes to read
A => PC
E + PC => E
$ + PC => E :F_MLOAD(argsOffsetCall)
; set bytes to read from memory at C
1 => C :CALL(MLOADX); in: [E: offset, C: length] out: [A: value, E: new offset]
$ => CTX :MLOAD(currentCTX)
Expand Down
5 changes: 2 additions & 3 deletions main/opcodes/stack-operations.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@ opAuxPUSHA:
; checks zk-counters
%MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)

$ => B :MLOAD(bytecodeLength)
PC + D - B :JMPN(opAuxPUSHA2)
B - PC => D
PC + D - $ :F_MLOAD(bytecodeLength), JMPN(opAuxPUSHA2)
$ - PC => D :F_MLOAD(bytecodeLength)

opAuxPUSHA2:
; check out-of-gas
Expand Down
1 change: 0 additions & 1 deletion main/process-tx.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ readByteCode:
PC + 1 => PC :JMP(@mapping_opcodes + RR)

readCode:
%MAX_CNT_STEPS - STEP - 500 :JMPN(outOfCountersStep)
$ => A :MLOAD(isCreateContract), JMPNZ(readDeployBytecode, readByteCode)

;; Compute and save hash bytecode and bytecode length in the state-tree
Expand Down

0 comments on commit dd1a23d

Please sign in to comment.