Skip to content

Commit

Permalink
chore: limit packet data to length of one.
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitrisJim committed Oct 21, 2024
1 parent e77a0f4 commit a3d1f14
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/core/04-channel/v2/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (msg *MsgRecvPacket) ValidateBasic() error {
return errorsmod.Wrap(commitmenttypesv1.ErrInvalidProof, "proof commitment can not be empty")
}

if len(msg.Packet.Data) != 1 {
return errorsmod.Wrapf(ErrInvalidPacketData, "packet data must be of length 1, got %d instead", len(msg.Packet.Data))
}

_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
Expand All @@ -164,6 +168,10 @@ func (msg *MsgAcknowledgement) ValidateBasic() error {
return errorsmod.Wrap(commitmenttypesv1.ErrInvalidProof, "cannot submit an empty acknowledgement proof")
}

if len(msg.Packet.Data) != 1 {
return errorsmod.Wrapf(ErrInvalidPacketData, "packet data must be of length 1, got %d instead", len(msg.Packet.Data))
}

// TODO: Add validation for ack object https://github.com/cosmos/ibc-go/issues/7472

_, err := sdk.AccAddressFromBech32(msg.Signer)
Expand All @@ -190,6 +198,10 @@ func (msg *MsgTimeout) ValidateBasic() error {
return errorsmod.Wrap(commitmenttypesv1.ErrInvalidProof, "proof unreceived can not be empty")
}

if len(msg.Packet.Data) != 1 {
return errorsmod.Wrapf(ErrInvalidPacketData, "packet data must be of length 1, got %d instead", len(msg.Packet.Data))
}

_, err := sdk.AccAddressFromBech32(msg.Signer)
if err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
Expand Down
28 changes: 28 additions & 0 deletions modules/core/04-channel/v2/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ func (s *TypesTestSuite) TestMsgSendPacketValidateBasic() {
},
{
name: "failure: invalid length for packetdata",
malleate: func() {
msg.PacketData = []types.PacketData{{}, {}}
},
expError: types.ErrInvalidPacketData,
},
{
name: "failure: invalid packetdata",
malleate: func() {
msg.PacketData = []types.PacketData{}
},
Expand Down Expand Up @@ -241,6 +248,13 @@ func (s *TypesTestSuite) TestMsgRecvPacketValidateBasic() {
},
expError: commitmenttypes.ErrInvalidProof,
},
{
name: "failure: invalid length for packetdata",
malleate: func() {
msg.Packet.Data = []types.PacketData{{}, {}}
},
expError: types.ErrInvalidPacketData,
},
{
name: "failure: invalid signer",
malleate: func() {
Expand Down Expand Up @@ -288,6 +302,13 @@ func (s *TypesTestSuite) TestMsgAcknowledge_ValidateBasic() {
},
expError: commitmenttypes.ErrInvalidProof,
},
{
name: "failure: invalid length for packetdata",
malleate: func() {
msg.Packet.Data = []types.PacketData{{}, {}}
},
expError: types.ErrInvalidPacketData,
},
{
name: "failure: invalid signer",
malleate: func() {
Expand Down Expand Up @@ -345,6 +366,13 @@ func (s *TypesTestSuite) TestMsgTimeoutValidateBasic() {
},
expError: ibcerrors.ErrInvalidAddress,
},
{
name: "failure: invalid length for packetdata",
malleate: func() {
msg.Packet.Data = []types.PacketData{{}, {}}
},
expError: types.ErrInvalidPacketData,
},
{
name: "failure: invalid packet",
malleate: func() {
Expand Down

0 comments on commit a3d1f14

Please sign in to comment.