Skip to content

Commit 43877df

Browse files
imp: check length tokens array against maximum allowed (#6349)
* check length of tokens array against maximum allowed * chore: add note on arbitrary selection --------- Co-authored-by: Colin Axnér <25233464+colin-axner@users.noreply.github.com>
1 parent a84b0e7 commit 43877df

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

modules/apps/transfer/types/msgs.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
const (
1616
MaximumReceiverLength = 2048 // maximum length of the receiver address in bytes (value chosen arbitrarily)
1717
MaximumMemoLength = 32768 // maximum length of the memo in bytes (value chosen arbitrarily)
18+
MaximumTokensLength = 100 // maximum number of tokens that can be transferred in a single message (value chosen arbitrarily)
1819
)
1920

2021
var (
@@ -81,6 +82,10 @@ func (msg MsgTransfer) ValidateBasic() error {
8182
return errorsmod.Wrap(ErrInvalidAmount, "cannot fill both token and token array")
8283
}
8384

85+
if len(msg.Tokens) > MaximumTokensLength {
86+
return errorsmod.Wrapf(ibcerrors.ErrInvalidCoins, "number of tokens must not exceed %d", MaximumTokensLength)
87+
}
88+
8489
_, err := sdk.AccAddressFromBech32(msg.Sender)
8590
if err != nil {
8691
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)

modules/apps/transfer/types/msgs_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func TestMsgTransferValidation(t *testing.T) {
7474
{"multidenom: invalid denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidDenomCoins...), sender, receiver, timeoutHeight, 0, ""), false},
7575
{"multidenom: invalid ibc denom", types.NewMsgTransfer(validPort, validChannel, coins.Add(invalidIBCCoins...), sender, receiver, timeoutHeight, 0, ""), false},
7676
{"multidenom: zero coins", types.NewMsgTransfer(validPort, validChannel, zeroCoins, sender, receiver, timeoutHeight, 0, ""), false},
77+
{"multidenom: too many coins", types.NewMsgTransfer(validPort, validChannel, make([]sdk.Coin, types.MaximumTokensLength+1), sender, receiver, timeoutHeight, 0, ""), false},
7778
}
7879

7980
for i, tc := range testCases {

0 commit comments

Comments
 (0)