diff --git a/main/opcodes/calldata-returndata-code.zkasm b/main/opcodes/calldata-returndata-code.zkasm index daa93a68..7d664a87 100644 --- a/main/opcodes/calldata-returndata-code.zkasm +++ b/main/opcodes/calldata-returndata-code.zkasm @@ -407,10 +407,9 @@ readZero: 0 => B :RETURN readValueBytecode: - 1 => D $ => E :MLOAD(codecopyHashId) ; read value to write in memory - $ => B :HASHP(E) + $ => B :HASHP1(E) :RETURN /** @@ -543,14 +542,12 @@ opEXTCODECOPYCheckHash: :JMP(opEXTCODECOPYCheckHashLoop) ; @info bytes are inserted byte by byte -; TODO: it could be improved by computing how many 32 bytes slots are needed opEXTCODECOPYCheckHashLoop: %MAX_CNT_STEPS - STEP - 20 :JMPN(outOfCountersStep) ; finish reading bytecode B - 1 :JMPN(opEXTCODECOPYCheckHashLoopEnd) - 1 => D ; add bytes to hash contract bytecode - ${getBytecode(A, HASHPOS, 1)} :HASHP(E) + ${getBytecode(A, HASHPOS, 1)} :HASHP1(E) B - 1 => B :JMP(opEXTCODECOPYCheckHashLoop) diff --git a/main/opcodes/flow-control.zkasm b/main/opcodes/flow-control.zkasm index 84f7bb87..3a022d53 100644 --- a/main/opcodes/flow-control.zkasm +++ b/main/opcodes/flow-control.zkasm @@ -56,11 +56,9 @@ checkJumpDest: $ :LT,JMPC(invalidJump) B => PC B => HASHPOS - ; set number of bytes to hashP at D - 1 => D ; get hashP address pointer where contract bytecode is stored $ => E :MLOAD(contractHashId) - $ => A :HASHP(E) + $ => A :HASHP1(E) ; check if is a jumpDest (0x5B) 0x5B => B $ :EQ, JMPC(readCode) @@ -71,14 +69,13 @@ checkJumpDestDeployment: -A :JMPN(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 push + ; add PC to data starts to point the bytes to read for the push B => PC HASHPOS + PC => HASHPOS ; get memory pointer for hashing $ => E :MLOAD(batchHashDataId) ; set number of bytes to hashK at D - 1 => D - $ => A :HASHK(E) + $ => A :HASHK1(E) ; check if is a jumpDest (0x5B) 0x5B => B $ :EQ, JMPC(readCode) diff --git a/main/opcodes/stack-operations.zkasm b/main/opcodes/stack-operations.zkasm index 4734e820..c4f1caaf 100644 --- a/main/opcodes/stack-operations.zkasm +++ b/main/opcodes/stack-operations.zkasm @@ -245,13 +245,13 @@ opAuxPUSHBloop: %MAX_CNT_BINARY - CNT_BINARY - 4 :JMPN(outOfCountersBinary) %MAX_CNT_ARITH - CNT_ARITH - 4 :JMPN(outOfCountersArith) - 1 => D ; get position where data starts in the tx $ => HASHPOS :MLOAD(dataStarts) - ; add PC to data starts to point the bytes to read for the push + ; add PC to data starts to point the bytes to read for the push HASHPOS + PC => HASHPOS PC + 1 => PC ; get memory pointer for hashing + 1 => D $ => E :MLOAD(batchHashDataId) $ => B :HASHK(E) ; accumulate hash value diff --git a/main/process-tx.zkasm b/main/process-tx.zkasm index 74ef6656..4187c9e7 100644 --- a/main/process-tx.zkasm +++ b/main/process-tx.zkasm @@ -127,9 +127,8 @@ loopBytes: %MAX_CNT_STEPS - STEP - 10 :JMPN(outOfCountersStep) A - C - 1 :JMPN(endCalldataIntrinsicGas) E => B - 1 => D $ => E :MLOAD(batchHashDataId) - $ => D :HASHK(E) + $ => D :HASHK1(E) B => E C + 1 => C D - 1 :JMPN(add4Gas) @@ -232,15 +231,13 @@ getContractAddress: 0x80 => B $ :LT,JMPC(nonce1byte) $ => C :MLOAD(lengthNonce) - 1 => D ; 1 byte length address + 20 bytes address + 1 byte length nonce + C bytes nonce - 0xc0 + 22 + C :HASHK(E) - 0x94 :HASHK(E) + 0xc0 + 22 + C :HASHK1(E) + 0x94 :HASHK1(E) 20 => D $ => B :MLOAD(txSrcAddr) B :HASHK(E) - 1 => D - 0x80 + C :HASHK(E) + 0x80 + C :HASHK1(E) C => D A :HASHK(E) :JMP(endContractAddress) @@ -248,18 +245,16 @@ getContractAddress: nonce1byte: $ => A :MLOAD(txSrcAddr) $ => B :MLOAD(txNonce) - 1 => D - 0xc0 + 22 :HASHK(E) - 0x94 :HASHK(E) + 0xc0 + 22 :HASHK1(E) + 0x94 :HASHK1(E) 20 => D A :HASHK(E) - 1 => D B - 1 :JMPN(nonceIs0) - B :HASHK(E) + B :HASHK1(E) :JMP(endContractAddress) nonceIs0: - 0x80 :HASHK(E) + 0x80 :HASHK1(E) :JMP(endContractAddress) ;; compute new contract address as CREATE2 spec: keccak256(0xff ++ address ++ salt ++ keccak256(init_code))[12:] (https://eips.ethereum.org/EIPS/eip-1014) @@ -312,8 +307,7 @@ create2end: 0 => HASHPOS $ => E :MLOAD(lastHashKIdUsed) E+1 => E :MSTORE(lastHashKIdUsed) - 1 => D - 0xff :HASHK(E) + 0xff :HASHK1(E) 20 => D $ => A :MLOAD(txSrcAddr) A :HASHK(E) @@ -376,8 +370,7 @@ readDeployBytecode: $ => HASHPOS :MLOAD(dataStarts) HASHPOS + PC => HASHPOS $ => E :MLOAD(batchHashDataId) - 1 => D - $ => RR :HASHK(E) + $ => RR :HASHK1(E) ${eventLog(onOpcode(RR))} PC + 1 => PC :JMP(@mapping_opcodes + RR) @@ -446,7 +439,6 @@ callContract: $ => A :SLOAD A :MSTORE(hashContractTxDestAddr) 0 => HASHPOS - 1 => D $ => B :MLOAD(bytecodeLength) ; get a new hashPId @@ -459,7 +451,7 @@ callContract: ; set repeat itarations: RCX register + 1 B - 1 => RCX :JMPN(checkHashBytecodeEnd) - ${getBytecode(A, HASHPOS, 1)} :HASHP(E), REPEAT(RCX) ; hash contract bytecode + ${getBytecode(A, HASHPOS, 1)} :HASHP1(E), REPEAT(RCX) ; hash contract bytecode checkHashBytecodeEnd: HASHPOS :HASHPLEN(E) @@ -476,8 +468,7 @@ readByteCode: $ => B :MLOAD(bytecodeLength) B - PC - 1 :JMPN(defaultOpCode) ; no bytecode treated as 0x00 PC => HASHPOS - 1 => D - $ => RR :HASHP(E) + $ => RR :HASHP1(E) ${eventLog(onOpcode(RR))} PC + 1 => PC :JMP(@mapping_opcodes + RR) diff --git a/main/utils.zkasm b/main/utils.zkasm index 0507baaf..9bc6d846 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -854,19 +854,18 @@ readPushBlock: E :MLOAD(contractHashId) ; load hash contract identifier ; read bytes - 1 => D - $ => C :HASHP(E) + $ => C :HASHP1(E) HASHPOS - 2 => HASHPOS - $ => A :HASHP(E) + $ => A :HASHP1(E) HASHPOS - 2 => HASHPOS A*256 + C => C - $ => A :HASHP(E) + $ => A :HASHP1(E) HASHPOS - 2 => HASHPOS A*65536 + C => C - $ => A :HASHP(E) + $ => A :HASHP1(E) HASHPOS - 2 => HASHPOS A*16777216 + C => C @@ -906,8 +905,7 @@ endPushLoop: $ => A :MLOAD(leftBytes) $ :EQ, JMPC(endPushFinal) - 1 => D - $ => D :HASHP(E) + $ => D :HASHP1(E) HASHPOS - 2 => HASHPOS B - 1 => A :JMP(computeFactorLoop)