DittoETH

Ditto
DeFiFoundryOracle
55,000 USDC
View results
Submission Details
Severity: low
Invalid

tokenId is not unique

Summary

tokenId is not unique

Vulnerability Details

The vulnerability in lines 195 to 211 is related to the minting of NFTs. The function mintNFT allows a user to mint an NFT for an active shortRecord. However, there is no check to ensure that the tokenId generated is unique. This could potentially allow a user to mint multiple NFTs with the same tokenId, leading to a collision in the tokenId space. This could result in unexpected behavior in the contract's functions that rely on tokenId for identifying and manipulating NFTs. This vulnerability could be exploited by an attacker to disrupt the normal functioning of the contract or to gain an unfair advantage.

Tools Used

vscode

Recommendations

To resolve this issue, you should add a check to ensure that the tokenId generated is unique. This can be done by maintaining a mapping of used tokenIds and checking against this mapping whenever a new tokenId is generated. If a collision is detected, the contract should revert the transaction and prevent the minting of the NFT. Here is a sample implementation:

mapping(uint256 => bool) usedTokenIds;
function mintNFT(address asset, uint8 shortRecordId)
external
isNotFrozen(asset)
nonReentrant
onlyValidShortRecord(asset, msg.sender, shortRecordId)
{
if (shortRecordId == Constants.SHORT_MAX_ID) {
revert Errors.CannotMintLastShortRecord();
}
STypes.ShortRecord storage short =
s.shortRecords[asset][msg.sender][shortRecordId];
if (short.tokenId != 0) revert Errors.AlreadyMinted();
if (usedTokenIds[s.tokenIdCounter]) {
revert Errors.TokenIdAlreadyUsed();
}
s.nftMapping[s.tokenIdCounter] = STypes.NFT({
owner: msg.sender,
assetId: s.asset[asset].assetId,
shortRecordId: shortRecordId
});
short.tokenId = s.tokenIdCounter;
usedTokenIds[s.tokenIdCounter] = true;
//@dev never decreases
s.tokenIdCounter += 1;
}

In this code, usedTokenIds is a mapping that keeps track of all tokenIds that have been used. Before a new NFT is minted, the contract checks if the tokenId has been used before. If it has, the contract reverts the transaction with an error message. This ensures that all tokenIds are unique and prevents any potential collisions.

Updates

Lead Judging Commences

0xnevi Lead Judge
over 1 year ago
0xnevi Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Other

Support

FAQs

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