From 16fcac6ce651493798769fa7f1a1ac2be2e7744a Mon Sep 17 00:00:00 2001 From: laisolizq Date: Fri, 3 Jun 2022 11:52:47 +0200 Subject: [PATCH] Update ecrecover --- main/precompiled/ecrecover.zkasm | 5 ++++- main/process_tx.zkasm | 6 +++++- package.json | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/main/precompiled/ecrecover.zkasm b/main/precompiled/ecrecover.zkasm index eb429cf2..53e20995 100644 --- a/main/precompiled/ecrecover.zkasm +++ b/main/precompiled/ecrecover.zkasm @@ -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] @@ -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) diff --git a/main/process_tx.zkasm b/main/process_tx.zkasm index 21dabefa..70536238 100644 --- a/main/process_tx.zkasm +++ b/main/process_tx.zkasm @@ -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) @@ -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) diff --git a/package.json b/package.json index ff937c7e..301de523 100644 --- a/package.json +++ b/package.json @@ -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" } }