Skip to content

Commit

Permalink
fix(ibc-nft): add duplicate token id validation in packet data (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukema95 authored Dec 24, 2024
1 parent c91bff8 commit 10dcf14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions x/ibc/nft-transfer/types/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,16 @@ func (nftpd NonFungibleTokenPacketData) ValidateBasic() error {
if len(nftpd.TokenIds) != len(nftpd.TokenData) || len(nftpd.TokenIds) != len(nftpd.TokenUris) {
return errors.Wrap(ErrInvalidPacket, "all token infos should have same length")
}
seenTokens := make(map[string]struct{})
for _, tokenId := range nftpd.TokenIds {
if len(tokenId) == 0 {
return errors.Wrap(ErrInvalidTokenIds, "invalid zero length token id")
}
if len(tokenId) == 0 {
return errors.Wrap(ErrInvalidTokenIds, "invalid zero length token id")
}
// check duplicate
if _, exists := seenTokens[tokenId]; exists {
return errors.Wrapf(ErrInvalidTokenIds, "duplicate token id: %s", tokenId)
}
seenTokens[tokenId] = struct{}{}
}
return ValidatePrefixedClassId(nftpd.ClassId)
}
Expand Down
1 change: 1 addition & 0 deletions x/ibc/nft-transfer/types/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestNonFungibleTokenPacketDataValidateBasic(t *testing.T) {
{"invalid token uris", NewNonFungibleTokenPacketData(classId, "", "", []string{"1", "2"}, []string{""}, []string{"", ""}, addr1, addr2, ""), false},
{"missing sender address", NewNonFungibleTokenPacketData(classId, "", "", []string{"1", "2", "3"}, []string{"", "", ""}, []string{"", "", ""}, emptyAddr, addr2, ""), false},
{"missing recipient address", NewNonFungibleTokenPacketData(classId, "", "", []string{"1", "2", "3"}, []string{"", "", ""}, []string{"", "", ""}, addr1, emptyAddr, ""), false},
{"duplicate token ids", NewNonFungibleTokenPacketData(classId, "", "", []string{"1", "2", "3", "1"}, []string{"", "", "", ""}, []string{"", "", "", ""}, addr1, addr2, ""), false},
}

for i, tc := range testCases {
Expand Down

0 comments on commit 10dcf14

Please sign in to comment.