Skip to content

Commit

Permalink
signature haskdigest at rlp parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Nov 29, 2022
1 parent 6d8d1a5 commit c4ab415
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
13 changes: 9 additions & 4 deletions main/load-tx-rlp.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

;;;;;;;;;
Expand Down
20 changes: 2 additions & 18 deletions main/process-tx.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

;;;;;;;;;;;;;;;;;;
Expand Down
2 changes: 0 additions & 2 deletions main/vars.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

0 comments on commit c4ab415

Please sign in to comment.