Skip to content

Commit

Permalink
Merge pull request #76 from hermeznetwork/feature/update-ecrecover
Browse files Browse the repository at this point in the history
Update ecrecover
  • Loading branch information
krlosMata authored Jun 8, 2022
2 parents 0a39dc2 + 16fcac6 commit e8b1d3d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion main/precompiled/ecrecover.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ funcECRECOVER:
; read data stored in SP + 1024
; hash [32 bytes], v [32 bytes], r [32 bytes], s [32 bytes]
1024 => SP
$ => A :MLOAD(lastHashIdUsed)
A + 1 :MSTORE(lastHashIdUsed)
A + 1 :MSTORE(ecrecover_lastHashIdUsed)
$ => E :MLOAD(SP++) ; hash
$ => A :MLOAD(SP++) ; v
; check v range [27, 28]
Expand All @@ -20,7 +23,7 @@ funcECRECOVER:
; check s range [0, secp256k1n/2 + 1]
;0 - ${comp_gt(C, 57896044618658097711785492504343953926418782139537452191302581570759080747169)} :JMPN(endECRECOVER)
; compute ecrecover
$ => A :ECRECOVER
:CALL(ecrecover)
0 => B
$ => B :EQ
0 - B :JMPN(endECRECOVER)
Expand Down
6 changes: 5 additions & 1 deletion main/process_tx.zkasm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
INCLUDE "map-opcodes.zkasm"
INCLUDE "precompiled/selector.zkasm"
INCLUDE "../node_modules/@polygon-hermez/zk_ecrecover/src/ecrecover.zkasm"

processTx:
; Get sigDataSize (VAR CTX)
Expand All @@ -13,11 +14,14 @@ processTx:
;;;;;;;;;

; Check the signature
$ => A :MLOAD(lastHashIdUsed)
A + 1 :MSTORE(lastHashIdUsed)
A + 1 :MSTORE(ecrecover_lastHashIdUsed)
$ => A :HASHKDIGEST(E)
$ => B :MLOAD(txR)
$ => C :MLOAD(txS)
$ => D :MLOAD(txV)
$ => A :ECRECOVER
:CALL(ecrecover)
; Check result is non-zero
0 => B
$ :EQ,JMPC(invalidTx)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"dependencies": {
"@polygon-hermez/zkasm": "git+ssh://git@github.com/hermeznetwork/zkasm.git",
"ffjavascript": "^0.2.46"
"ffjavascript": "^0.2.46",
"@polygon-hermez/zk_ecrecover": "git+ssh://git@github.com/hermeznetwork/zk_ecrecover.git"
}
}

0 comments on commit e8b1d3d

Please sign in to comment.