Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: check recipient address length #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (k *Keeper) ExecuteForwards(ctx context.Context) {
}

timeout := uint64(k.headerService.GetHeaderInfo(ctx).Time.UnixNano()) + transfertypes.DefaultRelativePacketTimeoutTimestamp
_, err := k.transferKeeper.Transfer(ctx, &transfertypes.MsgTransfer{
msg := &transfertypes.MsgTransfer{
SourcePort: transfertypes.PortID,
SourceChannel: forward.Channel,
Token: balance,
Expand All @@ -138,7 +138,12 @@ func (k *Keeper) ExecuteForwards(ctx context.Context) {
TimeoutHeight: clienttypes.ZeroHeight(),
TimeoutTimestamp: timeout,
Memo: "",
})
}
if err := msg.ValidateBasic(); err != nil {
k.Logger().Error("message validation failed", "channel", forward.Channel, "address", forward.GetAddress().String(), "amount", balance.String(), "err", err)
twothirtyfive marked this conversation as resolved.
Show resolved Hide resolved
continue
}
_, err := k.transferKeeper.Transfer(ctx, msg)
if err != nil {
// TODO: Consider moving to persistent store in order to retry in future blocks?
k.Logger().Error("unable to execute automatic forward", "channel", forward.Channel, "address", forward.GetAddress().String(), "amount", balance.String(), "err", err)
Expand Down
4 changes: 4 additions & 0 deletions keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func (k *Keeper) RegisterAccount(ctx context.Context, msg *types.MsgRegisterAcco
return nil, errors.New("invalid channel")
}

if len(msg.Recipient) > transfertypes.MaximumReceiverLength {
return nil, fmt.Errorf("recipient address must not exceed %d bytes", transfertypes.MaximumReceiverLength)
}

if msg.Fallback != "" {
if _, err := k.accountKeeper.AddressCodec().StringToBytes(msg.Fallback); err != nil {
return nil, errors.New("invalid fallback address")
Expand Down
5 changes: 5 additions & 0 deletions keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"

"cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -27,6 +28,10 @@ func (k *Keeper) Address(ctx context.Context, req *types.QueryAddress) (*types.Q
return nil, errorstypes.ErrInvalidRequest
}

if len(req.Recipient) > transfertypes.MaximumReceiverLength {
return nil, fmt.Errorf("recipient address must not exceed %d bytes", transfertypes.MaximumReceiverLength)
}

if req.Fallback != "" {
_, err := k.accountKeeper.AddressCodec().StringToBytes(req.Fallback)
if err != nil {
Expand Down