Skip to content

Commit

Permalink
Disallow using sr25519 addresses for evm send and other funcs (#1605)
Browse files Browse the repository at this point in the history
* debug

* debug

* debug

* goimport
  • Loading branch information
philipsu522 authored Apr 29, 2024
1 parent 9df725e commit 5b9e025
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions evmrpc/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions x/evm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5b9e025

Please sign in to comment.