From c274c0a73e1a0615103702e475b7c6b0c9e98b85 Mon Sep 17 00:00:00 2001 From: krlosMata Date: Fri, 5 Aug 2022 11:42:26 +0200 Subject: [PATCH 1/2] fix precompiled ecrecover --- main/precompiled/pre-ecrecover.zkasm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/precompiled/pre-ecrecover.zkasm b/main/precompiled/pre-ecrecover.zkasm index 12e3a90b..2475f1d5 100644 --- a/main/precompiled/pre-ecrecover.zkasm +++ b/main/precompiled/pre-ecrecover.zkasm @@ -30,8 +30,8 @@ funcECRECOVER: ; prepare return data $ => E :MLOAD(retCallOffset) ; $ => C :MLOAD(retCallLength) ; always 32 - $ => A :MLOAD(originCTX) - A - 1 :JMPN(handleGas) + $ => C :MLOAD(originCTX) + C - 1 :JMPN(handleGas) $ => CTX :MLOAD(originCTX) A :MSTORE(bytesToStore) :CALL(MSTORE32) From 4be64788577159881bef7323999ba464b9f1313a Mon Sep 17 00:00:00 2001 From: krlosMata Date: Fri, 5 Aug 2022 15:35:10 +0200 Subject: [PATCH 2/2] review changes --- main/opcodes.zkasm | 22 +++++++++++----------- main/precompiled/pre-ecrecover.zkasm | 4 ++-- main/process-tx.zkasm | 8 ++++---- main/utils.zkasm | 10 +++++++++- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/main/opcodes.zkasm b/main/opcodes.zkasm index 7e384d9a..08f59f26 100644 --- a/main/opcodes.zkasm +++ b/main/opcodes.zkasm @@ -5,7 +5,7 @@ opSTOP: B - 1 :JMPN(handleGas) $ => A :MLOAD(gasRefund) $ => C :MLOAD(isCreate) - 1 => D + 1 => D C - 1 :JMPN(opSTOPend) $ => D :MLOAD(createContractAddress) @@ -1023,11 +1023,11 @@ opRETURNDATASIZE: $ => B :MLOAD(retDataCTX) 0 => A $ :EQ, JMPC(endOpRETURNDATASIZE) - B => CTX + B => CTX $ => A :MLOAD(retDataLength) ; Restore current context $ => CTX :MLOAD(currentCTX) - + endOpRETURNDATASIZE: A :MSTORE(SP++) 1024 - SP :JMPN(stackOverflow) @@ -1255,7 +1255,7 @@ opCHAINID: :JMP(readCode) opSELFBALANCE: - + %MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 255 :JMPN(outOfCounters) $ => A :MLOAD(storageAddr) @@ -1290,7 +1290,7 @@ opMLOAD: :JMP(readCode) ;MSTORE 32 bytes -opMSTORE: +opMSTORE: %MAX_CNT_ARITH - CNT_ARITH - 32 :JMPN(outOfCounters) %MAX_CNT_BINARY - CNT_BINARY - 32 :JMPN(outOfCounters) @@ -2532,7 +2532,7 @@ opCALLCODE2: C :MSTORE(lastMemLength) ; Mem expansion gas cost call args :CALL(saveMem) - + ; Store byte offset in the memory in bytes, where to store the return data of the sub context. $ => B :MLOAD(SP--) B :MSTORE(lastMemOffset) @@ -2780,7 +2780,7 @@ opDELEGATECALL: SR :MSTORE(initSR) $ => A :MLOAD(addrCall) A :MSTORE(txDestAddr) - + B :MSTORE(retCallOffset) D :MSTORE(retCallLength) @@ -2889,7 +2889,7 @@ opSTATICCALL: A :MSTORE(lastMemOffset) $ => B :MLOAD(SP--) - B :MSTORE(argsLengthCall) + B :MSTORE(argsLengthCall) B :MSTORE(lastMemLength) ;Check counters @@ -3017,7 +3017,7 @@ opREVERTend: opSELFDESTRUCT: ;Check counters - %MAX_CNT_BINARY - CNT_BINARY - 10 :JMPN(outOfCounters) + %MAX_CNT_BINARY - CNT_BINARY - 10 :JMPN(outOfCounters) %MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 2040 :JMPN(outOfCounters) $ => A :MLOAD(isStaticCall) @@ -3084,7 +3084,7 @@ opSELFDESTRUCT2: $ :EQ,JMPC(handleGas) $ => B :MLOAD(gasRefund) $ => C :MLOAD(isCreate) - 1 => D + 1 => D C - 1 :JMPN(opSELFDESTRUCTCend) $ => D :MLOAD(createContractAddress) @@ -3107,5 +3107,5 @@ opINVALID: ; Remaining gas is consumed 0 => GAS ; if main context, halt execution - $ => B :MLOAD(originCTX) + $ => B :MLOAD(originCTX) :JMP(invalidProcess) diff --git a/main/precompiled/pre-ecrecover.zkasm b/main/precompiled/pre-ecrecover.zkasm index 2475f1d5..b134e263 100644 --- a/main/precompiled/pre-ecrecover.zkasm +++ b/main/precompiled/pre-ecrecover.zkasm @@ -32,7 +32,7 @@ funcECRECOVER: ; $ => C :MLOAD(retCallLength) ; always 32 $ => C :MLOAD(originCTX) C - 1 :JMPN(handleGas) - $ => CTX :MLOAD(originCTX) + C => CTX A :MSTORE(bytesToStore) :CALL(MSTORE32) :JMP(preEnd) @@ -40,5 +40,5 @@ funcECRECOVER: endECRECOVER: $ => A :MLOAD(originCTX) A - 1 :JMPN(handleGas) - $ => CTX :MLOAD(originCTX) + A => CTX :JMP(preEnd) \ No newline at end of file diff --git a/main/process-tx.zkasm b/main/process-tx.zkasm index 438f054b..5b5ddb2c 100644 --- a/main/process-tx.zkasm +++ b/main/process-tx.zkasm @@ -325,7 +325,7 @@ readDeployBytecode: $ => B :MLOAD(isCreate) 0 - B :JMPN(readDeployBytecodeCreate) $ => B :MLOAD(txCalldataLen) - B - PC - 1 :JMPN(defaultOpCode) + B - PC - 1 :JMPN(defaultOpCode) $ => HASHPOS :MLOAD(dataStarts) HASHPOS + PC => HASHPOS $ => E :MLOAD(batchHashDataId) @@ -337,8 +337,8 @@ readDeployBytecode: readDeployBytecodeCreate: $ => CTX :MLOAD(originCTX) $ => E :MLOAD(argsLengthCall) - E - PC - 1 :JMPN(readDeployBytecodeCreateDefault) - + E - PC - 1 :JMPN(readDeployBytecodeCreateDefault) + $ => E :MLOAD(argsOffsetCall) E + PC => E 1 => C @@ -517,4 +517,4 @@ invalidTx: defaultOpCode: ${eventLog(onOpcode(0))} - :JMP(opSTOP) \ No newline at end of file + :JMP(opSTOP) \ No newline at end of file diff --git a/main/utils.zkasm b/main/utils.zkasm index 3ebe1b1b..df7ec267 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -458,7 +458,7 @@ zeroDiv: zkPC+1 => RR :JMP(loadTmp) $ => RR :MLOAD(tmpZkPC) :JMP(RR) - + divisorSmallerDiv: 0 :MSTORE(arithRes1) E :MSTORE(arithRes2) @@ -621,11 +621,19 @@ stackOverflow: ${eventLog(onError, overflow)} :JMP(handleError) invalidDeploy: +<<<<<<< HEAD ${eventLog(onError, invalid)} :JMP(handleError) invalidStaticTx: ${eventLog(onError, invalid)} :JMP(handleInvalidStatic) +======= +${eventLog(onError, invalid)} + :JMP(handleError) +invalidStaticTx: +${eventLog(onError, invalid)} + :JMP(handleInvalidStatic) +>>>>>>> review changes handleError: ;revert all state changes ;initSR --> balance = balance - gas, nonce + 1