From c4ab415608078e4697cb800b2c0a1bbd879e0cc4 Mon Sep 17 00:00:00 2001 From: Ignasirv Date: Tue, 29 Nov 2022 15:58:25 +0100 Subject: [PATCH] signature haskdigest at rlp parsing --- main/load-tx-rlp.zkasm | 13 +++++++++---- main/process-tx.zkasm | 20 ++------------------ main/vars.zkasm | 2 -- 3 files changed, 11 insertions(+), 24 deletions(-) diff --git a/main/load-tx-rlp.zkasm b/main/load-tx-rlp.zkasm index a70f5cbe..9183947e 100644 --- a/main/load-tx-rlp.zkasm +++ b/main/load-tx-rlp.zkasm @@ -51,10 +51,8 @@ endList: 136 :MSTORE(arithB) :CALL(divARITH) $ => B :MLOAD(arithRes1) - $ => D :MLOAD(txHashAccKeccacks) - D + B + 1 => B :MSTORE(txHashAccKeccacks) $ => D :MLOAD(cntKeccakPreProcess) - %MAX_CNT_KECCAK_F - CNT_KECCAK_F - B - D :JMPN(outOfCountersKeccak) + %MAX_CNT_KECCAK_F - CNT_KECCAK_F - B - D - 1:JMPN(outOfCountersKeccak) ;; Read RLP 'nonce' ; 64 bits max @@ -324,7 +322,14 @@ vREADTx: ;; increase number of transaction to process $ => A :MLOAD(pendingTxs) A + 1 => A :MSTORE(pendingTxs) - HASHPOS :MSTORE(sigDataSize) ; save bytes length added to ethereum transaction hash +;; check signature + $ => A :HASHKDIGEST(E) + $ => B :MLOAD(txR) + $ => C :MLOAD(txS) + $ => D :MLOAD(txV) + :CALL(ecrecover) + A :MSTORE(txSrcAddr) + A :MSTORE(txSrcOriginAddr) :JMP(txLoopRLP) ;;;;;;;;; diff --git a/main/process-tx.zkasm b/main/process-tx.zkasm index aa2859a7..5b811782 100644 --- a/main/process-tx.zkasm +++ b/main/process-tx.zkasm @@ -32,25 +32,9 @@ processTx: ; Minimum of 100000 steps left to process a tx %MAX_CNT_STEPS - STEP - 100000 :JMPN(outOfCountersStep) - - ; Get sigDataSize - $ => HASHPOS :MLOAD(sigDataSize) - - ; Get hash address previously stored in RLP parsing - $ => E :MLOAD(lastTxHashId) - E+1 => E :MSTORE(lastTxHashId) - - ; Check the signature - $ => A :HASHKDIGEST(E) - $ => B :MLOAD(txR) - $ => C :MLOAD(txS) - $ => D :MLOAD(txV) - :CALL(ecrecover) - ; Check result is non-zero -checkAndSaveFrom: + ; check from address 0 => B - A :MSTORE(txSrcAddr) - A :MSTORE(txSrcOriginAddr) + $ => A :MLOAD(txSrcOriginAddr) $ :EQ,JMPC(invalidIntrinsicTxSignature) ;;;;;;;;;;;;;;;;;; diff --git a/main/vars.zkasm b/main/vars.zkasm index 27760eb1..2740d28c 100644 --- a/main/vars.zkasm +++ b/main/vars.zkasm @@ -49,7 +49,6 @@ VAR GLOBAL hashContractTxDestAddr ; state-tree hash bytecode leaf value of the ' VAR GLOBAL auxSR ; auxiliaty variable. Temporary state root VAR GLOBAL txRLPLength ; transaction RLP list length VAR GLOBAL txDataRead ; aux varible to check transaction 'data' left that needs to be read -VAR GLOBAL txHashAccKeccacks ; aux var to accumulate the blocked keccacks for tx hashing at rlp parsing VAR CTX txGasLimit ; transaction parameter: 'gas limit' VAR CTX txDestAddr ; transaction parameter: 'to' @@ -88,7 +87,6 @@ VAR CTX isDelegateCall ; flag to determine if a new context comes from a DELEGAT VAR CTX isCreate2 ; flag to determine if a new context comes from a CREATE2 opcode VAR CTX salt ; CREATE2 parameter 'salt' used to compute new contract address VAR CTX gasCTX ; remaining gas in the origin CTX when a new context is created -VAR CTX sigDataSize ; hash position for the ethereum transaction hash VAR CTX dataStarts; hash position where de transaction 'data' starts in the batchHashData VAR CTX isPreEIP155 ; flag to check if the current tx is legacy, previous to Spurious Dragon (EIP-155) VAR CTX initTouchedSR ; touched root once a new context begins \ No newline at end of file