diff --git a/lib/cchain/types.go b/lib/cchain/types.go index c1f69d58e..c36dbba80 100644 --- a/lib/cchain/types.go +++ b/lib/cchain/types.go @@ -8,6 +8,7 @@ import ( "github.com/omni-network/omni/lib/umath" cmtcrypto "github.com/cometbft/cometbft/crypto" + k1 "github.com/cometbft/cometbft/crypto/secp256k1" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -101,6 +102,10 @@ func (v SDKValidator) ConsensusCmtAddr() (cmtcrypto.Address, error) { return nil, errors.Wrap(err, "unmarshal consensus pubkey") } + if len(pk.Bytes()) != k1.PubKeySize { + return nil, errors.New("invalid public key size") + } + return pk.Address(), nil } @@ -112,6 +117,10 @@ func (v SDKValidator) ConsensusPublicKey() (*ecdsa.PublicKey, error) { return nil, errors.Wrap(err, "unmarshal consensus pubkey") } + if len(pk.Bytes()) != k1.PubKeySize { + return nil, errors.New("invalid public key size") + } + pubkey, err := crypto.DecompressPubkey(pk.Bytes()) if err != nil { return nil, errors.Wrap(err, "decompress pubkey")