From dd1a23d36474bfcd59de4cf7f3cf79b4a13a971e Mon Sep 17 00:00:00 2001 From: Ignasi Date: Tue, 26 Mar 2024 11:58:23 +0100 Subject: [PATCH] small optimizations --- main/opcodes/flow-control.zkasm | 20 +++++++------------- main/opcodes/stack-operations.zkasm | 5 ++--- main/process-tx.zkasm | 1 - 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/main/opcodes/flow-control.zkasm b/main/opcodes/flow-control.zkasm index 763a0475..283e9ae4 100644 --- a/main/opcodes/flow-control.zkasm +++ b/main/opcodes/flow-control.zkasm @@ -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) diff --git a/main/opcodes/stack-operations.zkasm b/main/opcodes/stack-operations.zkasm index 0c135b12..849ee185 100644 --- a/main/opcodes/stack-operations.zkasm +++ b/main/opcodes/stack-operations.zkasm @@ -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 diff --git a/main/process-tx.zkasm b/main/process-tx.zkasm index c9685d70..eb2cc95d 100644 --- a/main/process-tx.zkasm +++ b/main/process-tx.zkasm @@ -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