From 7a6df19465ed37185f3719c841bd4ec3d2e9ddaf Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Mon, 6 May 2024 14:21:34 -0700 Subject: [PATCH] address some comments --- crypto/bn254/utils.go | 4 +--- signerv2/remote_signer_client.go | 36 +++++++++++++------------------- signerv2/signer.go | 2 +- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/crypto/bn254/utils.go b/crypto/bn254/utils.go index 9ee90734..bd350523 100644 --- a/crypto/bn254/utils.go +++ b/crypto/bn254/utils.go @@ -31,9 +31,7 @@ func VerifySig(sig *bn254.G1Affine, pubkey *bn254.G2Affine, msgBytes [32]byte) ( // MapToCurve implements the simple hash-and-check (also sometimes try-and-increment) algorithm // see https://hackmd.io/@benjaminion/bls12-381#Hash-and-check // Note that this function needs to be the same as the one used in the contract: -// -// https://github.com/Layr-Labs/eigenlayer-middleware/blob/1feb6ae7e12f33ce8eefb361edb69ee26c118b5d/src/libraries/BN254.sol#L292 -// +// https://github.com/Layr-Labs/eigenlayer-middleware/blob/1feb6ae7e12f33ce8eefb361edb69ee26c118b5d/src/libraries/BN254.sol#L292 // we don't use the newer constant time hash-to-curve algorithms as they are gas-expensive to compute onchain func MapToCurve(digest [32]byte) *bn254.G1Affine { diff --git a/signerv2/remote_signer_client.go b/signerv2/remote_signer_client.go index ce0cb652..941ccb26 100644 --- a/signerv2/remote_signer_client.go +++ b/signerv2/remote_signer_client.go @@ -11,13 +11,16 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/rlp" + "github.com/google/uuid" ) -type RpcRequest struct { +// JsonRpcRequest is a struct for JSON RPC 2.0 request +// See: https://www.jsonrpc.org/specification +type JsonRpcRequest struct { JsonRPC string `json:"jsonrpc"` Method string `json:"method"` Params interface{} `json:"params"` - ID int `json:"id"` + ID string `json:"id"` } type RemoteSignerClient interface { @@ -25,8 +28,8 @@ type RemoteSignerClient interface { } // RemoteSigner is a client for a remote signer -// It implements Consensys Web3 Signer -// Reference: https://docs.web3signer.consensys.io/reference/api/json-rpc +// It currently implements `eth_signTransaction` method of Consensys Web3 Signer +// Reference: https://docs.web3signer.consensys.io/reference/api/json-rpc#eth_signtransaction type RemoteSigner struct { url string client http.Client @@ -42,7 +45,7 @@ func (r RemoteSigner) SignTransaction( tx *types.Transaction, ) (*types.Transaction, error) { method := "eth_signTransaction" - id := 1 + id := uuid.New().String() params := []map[string]string{ { "from": from.Hex(), @@ -54,7 +57,7 @@ func (r RemoteSigner) SignTransaction( }, } - request := RpcRequest{ + request := JsonRpcRequest{ JsonRPC: "2.0", Method: method, Params: params, @@ -63,33 +66,22 @@ func (r RemoteSigner) SignTransaction( jsonData, err := json.Marshal(request) if err != nil { - fmt.Println("Error marshalling request:", err) - return nil, err - } - - req, err := http.NewRequest("POST", r.url, bytes.NewBuffer(jsonData)) - if err != nil { - fmt.Println("Error creating request:", err) - return nil, err + return nil, utils.WrapError("error marshalling request", err) } - req.Header.Set("Content-Type", "application/json") - resp, err := r.client.Do(req) + resp, err := r.client.Post(r.url, "application/json", bytes.NewBuffer(jsonData)) if err != nil { - fmt.Println("Error sending request:", err) return nil, err } defer resp.Body.Close() var result map[string]interface{} - if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { - fmt.Println("Error decoding response:", err) - return nil, err + if err = json.NewDecoder(resp.Body).Decode(&result); err != nil { + return nil, utils.WrapError("error decoding response", err) } if result["error"] != nil { - fmt.Println("Error in response:", result["error"]) - return nil, fmt.Errorf("error in response") + return nil, utils.WrapError("error in response", fmt.Errorf("%v", result["error"])) } rlpEncodedSignedTx := result["result"].(string) diff --git a/signerv2/signer.go b/signerv2/signer.go index 9b9a9b17..ce2b35f0 100644 --- a/signerv2/signer.go +++ b/signerv2/signer.go @@ -40,7 +40,7 @@ func KeyStoreSignerFn(path string, password string, chainID *big.Int) (bind.Sign } // RemoteSignerFn creates a signer function that uses a remote signer -// It should expose `eth_SignTransaction` endpoint which return rlp +// It exposes `eth_SignTransaction` endpoint which return rlp // encoded signed tx func RemoteSignerFn(remoteSignerUrl string) (bind.SignerFn, error) { client := NewRemoteSignerClient(remoteSignerUrl)