Skip to content

Commit d25ea67

Browse files
committed
add memo length validation
1 parent 17b6cda commit d25ea67

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

modules/apps/27-interchain-accounts/types/packet.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ import (
66
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
77
)
88

9+
const MaxMemoCharLength = 256
10+
911
// ValidateBasic performs basic validation of the interchain account packet data.
1012
// The memo may be empty.
1113
func (iapd InterchainAccountPacketData) ValidateBasic() error {
1214
if iapd.Data == nil {
1315
return sdkerrors.Wrap(ErrInvalidOutgoingData, "packet data cannot be empty")
1416
}
17+
18+
if len(iapd.Memo) > MaxMemoCharLength {
19+
return sdkerrors.Wrapf(ErrInvalidOutgoingData, "packet data memo cannot be greater than %d characters", MaxMemoCharLength)
20+
}
1521
// TODO: add type validation when data type enum supports unspecified type
1622

1723
return nil

modules/apps/27-interchain-accounts/types/packet_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
55
)
66

7+
var largeMemo = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum"
8+
79
func (suite *TypesTestSuite) TestValidateBasic() {
810
testCases := []struct {
911
name string
@@ -36,6 +38,15 @@ func (suite *TypesTestSuite) TestValidateBasic() {
3638
},
3739
false,
3840
},
41+
{
42+
"memo too large",
43+
types.InterchainAccountPacketData{
44+
Type: types.EXECUTE_TX,
45+
Data: []byte("data"),
46+
Memo: largeMemo,
47+
},
48+
false,
49+
},
3950
}
4051

4152
for _, tc := range testCases {

0 commit comments

Comments
 (0)