From 5b9e0254ce8fca8e1fbc241f1d82f31a47879f7d Mon Sep 17 00:00:00 2001 From: Philip Su Date: Mon, 29 Apr 2024 10:53:40 -0700 Subject: [PATCH] Disallow using sr25519 addresses for evm send and other funcs (#1605) * debug * debug * debug * goimport --- evmrpc/utils.go | 6 ++++++ x/evm/client/cli/tx.go | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/evmrpc/utils.go b/evmrpc/utils.go index 0e7a974129..f39bf9b3c5 100644 --- a/evmrpc/utils.go +++ b/evmrpc/utils.go @@ -8,6 +8,8 @@ import ( "math/big" "time" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/config" "github.com/cosmos/cosmos-sdk/codec/legacy" @@ -197,6 +199,10 @@ func getAddressPrivKeyMap(kb keyring.Keyring) map[string]*ecdsa.PrivateKey { // will only show local key continue } + if localInfo.GetAlgo() != hd.Secp256k1Type { + fmt.Printf("Skipping address %s because it isn't signed with secp256k1\n", localInfo.Name) + continue + } priv, err := legacy.PrivKeyFromBytes([]byte(localInfo.PrivKeyArmor)) if err != nil { continue diff --git a/x/evm/client/cli/tx.go b/x/evm/client/cli/tx.go index 37844437c8..93e52710de 100644 --- a/x/evm/client/cli/tx.go +++ b/x/evm/client/cli/tx.go @@ -14,6 +14,8 @@ import ( "strconv" "strings" + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" @@ -95,6 +97,9 @@ func CmdAssociateAddress() *cobra.Command { if !ok { return errors.New("can only associate address for local keys") } + if localInfo.GetAlgo() != hd.Secp256k1Type { + return errors.New("can only use addresses using secp256k1") + } priv, err := legacy.PrivKeyFromBytes([]byte(localInfo.PrivKeyArmor)) if err != nil { return err @@ -585,6 +590,9 @@ func getPrivateKey(cmd *cobra.Command) (*ecdsa.PrivateKey, error) { if !ok { return nil, errors.New("can only associate address for local keys") } + if localInfo.GetAlgo() != hd.Secp256k1Type { + return nil, errors.New("can only use addresses using secp256k1") + } priv, err := legacy.PrivKeyFromBytes([]byte(localInfo.PrivKeyArmor)) if err != nil { return nil, err