diff --git a/CHANGELOG.md b/CHANGELOG.md index 2000262634b..02a9bff1a07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -218,6 +218,7 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf ### Bug Fixes +* (x/bank) [#14538](https://github.com/cosmos/cosmos-sdk/pull/14538) Validate denom in bank balances GRPC queries. * (baseapp) [#14505](https://github.com/cosmos/cosmos-sdk/pull/14505) PrepareProposal and ProcessProposal now use deliverState for the first block in order to access changes made in InitChain. * (x/group) [#14526](https://github.com/cosmos/cosmos-sdk/pull/14526) Fix wrong address set in `EventUpdateGroupPolicy`. * (server) [#14441](https://github.com/cosmos/cosmos-sdk/pull/14441) Fix `--log_format` flag not working. diff --git a/x/bank/keeper/grpc_query.go b/x/bank/keeper/grpc_query.go index ada58b235f0..692c2959b5b 100644 --- a/x/bank/keeper/grpc_query.go +++ b/x/bank/keeper/grpc_query.go @@ -22,8 +22,8 @@ func (k BaseKeeper) Balance(ctx context.Context, req *types.QueryBalanceRequest) return nil, status.Error(codes.InvalidArgument, "empty request") } - if req.Denom == "" { - return nil, status.Error(codes.InvalidArgument, "invalid denom") + if err := sdk.ValidateDenom(req.Denom); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) } sdkCtx := sdk.UnwrapSDKContext(ctx) @@ -117,8 +117,8 @@ func (k BaseKeeper) SpendableBalanceByDenom(ctx context.Context, req *types.Quer return nil, status.Errorf(codes.InvalidArgument, "invalid address: %s", err.Error()) } - if req.Denom == "" { - return nil, status.Error(codes.InvalidArgument, "invalid denom") + if err := sdk.ValidateDenom(req.Denom); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) } sdkCtx := sdk.UnwrapSDKContext(ctx) @@ -145,8 +145,8 @@ func (k BaseKeeper) SupplyOf(c context.Context, req *types.QuerySupplyOfRequest) return nil, status.Error(codes.InvalidArgument, "empty request") } - if req.Denom == "" { - return nil, status.Error(codes.InvalidArgument, "invalid denom") + if err := sdk.ValidateDenom(req.Denom); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) } ctx := sdk.UnwrapSDKContext(c) @@ -200,8 +200,8 @@ func (k BaseKeeper) DenomMetadata(c context.Context, req *types.QueryDenomMetada return nil, status.Errorf(codes.InvalidArgument, "empty request") } - if req.Denom == "" { - return nil, status.Error(codes.InvalidArgument, "invalid denom") + if err := sdk.ValidateDenom(req.Denom); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) } ctx := sdk.UnwrapSDKContext(c) @@ -224,8 +224,8 @@ func (k BaseKeeper) DenomOwners( return nil, status.Errorf(codes.InvalidArgument, "empty request") } - if req.Denom == "" { - return nil, status.Error(codes.InvalidArgument, "empty denom") + if err := sdk.ValidateDenom(req.Denom); err != nil { + return nil, status.Error(codes.InvalidArgument, err.Error()) } ctx := sdk.UnwrapSDKContext(goCtx) diff --git a/x/bank/keeper/grpc_query_test.go b/x/bank/keeper/grpc_query_test.go index 4593aed464c..a0ac3adedcb 100644 --- a/x/bank/keeper/grpc_query_test.go +++ b/x/bank/keeper/grpc_query_test.go @@ -25,7 +25,11 @@ func (suite *KeeperTestSuite) TestQueryBalance() { _, err = queryClient.Balance(gocontext.Background(), &types.QueryBalanceRequest{Address: addr.String()}) suite.Require().Error(err) - req := types.NewQueryBalanceRequest(addr, fooDenom) + req := types.NewQueryBalanceRequest(addr, "0000") + _, err = queryClient.Balance(gocontext.Background(), req) + suite.Require().Error(err) + + req = types.NewQueryBalanceRequest(addr, fooDenom) res, err := queryClient.Balance(gocontext.Background(), req) suite.Require().NoError(err) suite.Require().NotNil(res) diff --git a/x/bank/keeper/view.go b/x/bank/keeper/view.go index c761163beab..b785430292c 100644 --- a/x/bank/keeper/view.go +++ b/x/bank/keeper/view.go @@ -252,6 +252,10 @@ func (k BaseViewKeeper) getDenomAddressPrefixStore(ctx sdk.Context, denom string // UnmarshalBalanceCompat unmarshal balance amount from storage, it's backward-compatible with the legacy format. func UnmarshalBalanceCompat(cdc codec.BinaryCodec, bz []byte, denom string) (sdk.Coin, error) { + if err := sdk.ValidateDenom(denom); err != nil { + return sdk.Coin{}, err + } + amount := math.ZeroInt() if bz == nil { return sdk.NewCoin(denom, amount), nil