Trick or Treat

First Flight #27
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

NFT tokens can have the same token URI

Summary

ERC-721 specifically requires that each token has a unique URI associated with it , but this contract does not follow the rules.

Vulnerability Details

When a user calls trickOrTreatfunction he/she provides name of the treat which is needed to find a struct in

the mapping treatList.

function trickOrTreat(
string memory _treatName
) public payable nonReentrant {
Treat memory treat = treatList[_treatName];

During the process of minting an NFT, the internal function _setTokenUri is called. This function receives two parameters: the token ID and the token URI data. The token URI data is obtained from the struct associated with the treat name.

function mintTreat(address recipient, Treat memory treat) internal {
uint256 tokenId = nextTokenId;
_mint(recipient, tokenId);
- _setTokenURI(tokenId, treat.metadataURI);
nextTokenId += 1;
emit Swapped(recipient, treat.name, tokenId);
}

However, after minting, the mapping is not updated correctly. Specifically, the line delete treatList[_treatName] is not executed. As a result, another user can provide the same treat name and receive an NFT with the same URI metadata. The only difference between the two NFTs will be their token IDs.

Impact

This is a deviation from ERC721 NFT standards, each token should have a unique URI. The purpose of the URI is to provide clear, distinguishable metadata for each token. Sharing URIs defeats this purpose.

Recommendations

To fix this issue, the contract should ensure that the treatList mapping is updated appropriately after each successful mint operation. Without this update, the contract fails to maintain the uniqueness of NFTs based on treat names, potentially leading to unintended duplicates.

Maybe that is not a bug but a feature, but if you want to have multiple NFTs with the same URI better consider to use
ERC1155 standart.

Updates

Appeal created

bube Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.