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

fix(ibc-nft): add duplicate token id validation in packet data #325

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading