diff --git a/protocol/x/affiliates/keeper/grpc_query.go b/protocol/x/affiliates/keeper/grpc_query.go index 63b10dca48..84185382a8 100644 --- a/protocol/x/affiliates/keeper/grpc_query.go +++ b/protocol/x/affiliates/keeper/grpc_query.go @@ -59,6 +59,13 @@ func (k Keeper) ReferredBy(ctx context.Context, req *types.ReferredByRequest) (*types.ReferredByResponse, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) + // Check req.Address is a valid bech32 address + _, err := sdk.AccAddressFromBech32(req.GetAddress()) + if err != nil { + return nil, errorsmod.Wrapf(types.ErrInvalidAddress, "address: %s, error: %s", + req.GetAddress(), err.Error()) + } + affiliateAddr, exists := k.GetReferredBy(sdkCtx, req.GetAddress()) if !exists { return &types.ReferredByResponse{}, nil diff --git a/protocol/x/affiliates/keeper/grpc_query_test.go b/protocol/x/affiliates/keeper/grpc_query_test.go index a19d76c3a9..23f0e35c93 100644 --- a/protocol/x/affiliates/keeper/grpc_query_test.go +++ b/protocol/x/affiliates/keeper/grpc_query_test.go @@ -190,6 +190,14 @@ func TestReferredBy(t *testing.T) { expected: nil, expectError: nil, }, + "Invalid bech32 address": { + req: &types.ReferredByRequest{ + Address: "Foo", + }, + setup: func(ctx sdk.Context, k keeper.Keeper) {}, + expected: nil, + expectError: types.ErrInvalidAddress, + }, } for name, tc := range testCases {