Skip to content

Commit

Permalink
address some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed May 6, 2024
1 parent 66f9df5 commit 90aa6ba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
4 changes: 1 addition & 3 deletions crypto/bn254/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
36 changes: 14 additions & 22 deletions signerv2/remote_signer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ 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 {
SignTransaction(from common.Address, tx *types.Transaction) (*types.Transaction, error)
}

// 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
Expand All @@ -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(),
Expand All @@ -54,7 +57,7 @@ func (r RemoteSigner) SignTransaction(
},
}

request := RpcRequest{
request := JsonRpcRequest{
JsonRPC: "2.0",
Method: method,
Params: params,
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion signerv2/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 90aa6ba

Please sign in to comment.