Skip to content

Commit

Permalink
ecrecover at process tx
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Nov 29, 2022
1 parent 3eac6cb commit 4e5f9c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
13 changes: 6 additions & 7 deletions main/load-tx-rlp.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ endList:
:CALL(divARITH)
$ => B :MLOAD(arithRes1)
$ => D :MLOAD(cntKeccakPreProcess)
%MAX_CNT_KECCAK_F - CNT_KECCAK_F - B - D - 1:JMPN(outOfCountersKeccak)
%MAX_CNT_KECCAK_F - CNT_KECCAK_F - B - D - 1:JMPN(handleOOCatRLP)

;; Read RLP 'nonce'
; 64 bits max
Expand Down Expand Up @@ -322,18 +322,17 @@ vREADTx:
;; increase number of transaction to process
$ => A :MLOAD(pendingTxs)
A + 1 => A :MSTORE(pendingTxs)
;; check signature
;; compute signature
$ => A :HASHKDIGEST(E)
$ => B :MLOAD(txR)
$ => C :MLOAD(txS)
$ => D :MLOAD(txV)
:CALL(ecrecover)
A :MSTORE(txSrcAddr)
A :MSTORE(txHash)
:JMP(txLoopRLP)

;;;;;;;;;
;; E - Handler error RLP fields
;;;;;;;;;
handleOOCatRLP:
${eventLog(onError, OOCK)}
$ => SR :MLOAD(batchSR)

invalidTxRLP:
;; Append all missing 'batchL2Data' to 'batchDataHash' bytes
Expand Down
11 changes: 9 additions & 2 deletions main/process-tx.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ processTx:

; Minimum of 100000 steps left to process a tx
%MAX_CNT_STEPS - STEP - 100000 :JMPN(outOfCountersStep)
; check from address
$ => A :MLOAD(txHash)
; Check the signature
$ => B :MLOAD(txR)
$ => C :MLOAD(txS)
$ => D :MLOAD(txV)
:CALL(ecrecover)
; Check result is non-zero
checkAndSaveFrom:
0 => B
$ => A :MLOAD(txSrcAddr)
A :MSTORE(txSrcAddr)
A :MSTORE(txSrcOriginAddr)
$ :EQ,JMPC(invalidIntrinsicTxSignature)

Expand Down
1 change: 1 addition & 0 deletions main/vars.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ VAR CTX txS ; transaction parameter: ecdsa signature S
VAR CTX txR ; transaction parameter: ecdsa signature R
VAR CTX txV ; transaction parameter: ecdsa signature V
VAR CTX txSrcAddr ; address that sends a transaction 'message.sender'
VAR CTX txHash ; signed tx hash
VAR CTX txCalldataLen ; calldata length
VAR CTX isCreateContract ; flag to determine if a transaction will create a new contract
VAR CTX createContractAddress ; address computed of a new contract
Expand Down

0 comments on commit 4e5f9c5

Please sign in to comment.