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

imp: check order in validate basic of MsgRegisterInterchainAccount #5671

Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package types

import (
"slices"
"strings"

errorsmod "cosmossdk.io/errors"
Expand Down Expand Up @@ -41,6 +42,10 @@ func (msg MsgRegisterInterchainAccount) ValidateBasic() error {
return errorsmod.Wrap(err, "invalid connection ID")
}

if !slices.Contains([]channeltypes.Order{channeltypes.ORDERED, channeltypes.UNORDERED}, msg.Order) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked about this in security audit and though it does indeed get handled later on I do think having explicit ordering check here also makes sense. Only worry is something like #5668 occurring again, maybe we can add these checks in spec too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to include it in the spec as well. I have this PR with ICS 27 updates, so I can include it there.

return errorsmod.Wrap(channeltypes.ErrInvalidChannelOrdering, msg.Order.String())
}

if strings.TrimSpace(msg.Owner) == "" {
return errorsmod.Wrap(ibcerrors.ErrInvalidAddress, "owner address cannot be empty")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func TestMsgRegisterInterchainAccountValidateBasic(t *testing.T) {
},
false,
},
{
"order is not valid",
func() {
msg.Order = channeltypes.NONE
Copy link
Contributor Author

@crodriguezvega crodriguezvega Jan 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit I just realised: in the protos we called this field order for MsgRegisterInterchainAccount, while in MsgChannelOpenInit is called ordering. Should we rename order to ordering for consistency?

Copy link
Contributor

@DimitrisJim DimitrisJim Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, think we should! can push directly here if you want me to.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, go for it!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, would be nice to backport that change and just saw about BP this PR. can open as separate instead to have it backport cleanly

},
false,
},
}

for i, tc := range testCases {
Expand Down
4 changes: 3 additions & 1 deletion modules/core/04-channel/types/channel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package types

import (
"slices"

errorsmod "cosmossdk.io/errors"

host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
Expand Down Expand Up @@ -68,7 +70,7 @@ func (ch Channel) ValidateBasic() error {
if ch.State == UNINITIALIZED {
return ErrInvalidChannelState
}
if !(ch.Ordering == ORDERED || ch.Ordering == UNORDERED) {
if !slices.Contains([]Order{ORDERED, UNORDERED}, ch.Ordering) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty to make this small improvement.

return errorsmod.Wrap(ErrInvalidChannelOrdering, ch.Ordering.String())
}
if len(ch.ConnectionHops) != 1 {
Expand Down
Loading