diff --git a/x/gov/keeper/crosschain.go b/x/gov/keeper/crosschain.go index f82f8e45ea..21bbfdad70 100644 --- a/x/gov/keeper/crosschain.go +++ b/x/gov/keeper/crosschain.go @@ -66,13 +66,16 @@ func (k Keeper) SyncParams(ctx sdk.Context, destChainId sdk.ChainID, cpc govv1.C Target: addresses, } - encodedPackage := pack.MustSerialize() + encodedPackage, err := pack.Serialize() + if err != nil { + return sdkerrors.Wrapf(types.ErrInvalidSyncParamPackage, "fail to serialize, err: %s", err.Error()) + } if !k.crossChainKeeper.IsDestChainSupported(destChainId) { return sdkerrors.Wrapf(types.ErrChainNotSupported, "destination chain (%d) is not supported", destChainId) } - _, err := k.crossChainKeeper.CreateRawIBCPackageWithFee( + _, err = k.crossChainKeeper.CreateRawIBCPackageWithFee( ctx, destChainId, types.SyncParamsChannelID, diff --git a/x/gov/types/crosschain.go b/x/gov/types/crosschain.go index 259c0a2e0e..ac63a5c371 100644 --- a/x/gov/types/crosschain.go +++ b/x/gov/types/crosschain.go @@ -35,10 +35,10 @@ var ( } ) -func (p SyncParamsPackage) MustSerialize() []byte { +func (p SyncParamsPackage) Serialize() ([]byte, error) { encodedBytes, err := syncParamsPackageArgs.Pack(&p) if err != nil { - panic("encode params change sync package error") + return nil, err } - return encodedBytes + return encodedBytes, nil } diff --git a/x/gov/types/errors.go b/x/gov/types/errors.go index 71c4ac98b9..248a918d2f 100644 --- a/x/gov/types/errors.go +++ b/x/gov/types/errors.go @@ -33,7 +33,7 @@ var ( ErrAddressSizeNotMatch = errors.Register(ModuleName, 25, "number of old address not equal to new addresses") ErrAddressNotValid = errors.Register(ModuleName, 26, "address format is not valid") ErrExceedParamsChangeLimit = errors.Register(ModuleName, 27, "exceed params change limit") - ErrInvalidUpgradeProposal = errors.Register(ModuleName, 28, "invalid sync params package") + ErrInvalidSyncParamPackage = errors.Register(ModuleName, 28, "invalid sync params package") ErrInvalidValue = errors.Register(ModuleName, 29, "decode hex value failed") ErrChainNotSupported = errors.Register(ModuleName, 30, "crosschain: chain is not supported") diff --git a/x/gov/types/v1/crosschain.go b/x/gov/types/v1/crosschain.go index 2974c89631..000094576d 100644 --- a/x/gov/types/v1/crosschain.go +++ b/x/gov/types/v1/crosschain.go @@ -1,8 +1,10 @@ package v1 import ( + "encoding/hex" "strings" + sdkerrors "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/gov/types" ) @@ -36,6 +38,11 @@ func (m *CrossChainParamsChange) ValidateBasic() error { if err != nil { return types.ErrAddressNotValid } + } else { + _, err := hex.DecodeString(value) + if err != nil { + return sdkerrors.Wrapf(types.ErrInvalidValue, "value is not valid %s", value) + } } _, err := sdk.AccAddressFromHexUnsafe(target) if err != nil {