Puppy Raffle

AI First Flight #1
Beginner FriendlyFoundrySolidityNFT
EXP
View results
Submission Details
Impact: medium
Likelihood: medium
Invalid

MED-01: Unchecked Return Value of ERC721 _mint()

MED-01: Unchecked Return Value of ERC721 _mint()

Description

The _mint() function from ERC721 returns a uint256 token ID, but the return value is not checked. While OpenZeppelin's _mint() reverts on failure, explicitly checking the return value is a best practice for clarity and defense-in-depth.

// Root cause in the codebase with @> marks to highlight the relevant section
function selectWinner() external {
// ...
@> _mint(winner, tokenId);
// No check of return value
}

Risk

Likelihood:

  • Low - OpenZeppelin's _mint() reverts on failure

  • But silent failures possible if implementation changes

Impact:

  • Token ID tracking could be incorrect

  • tokenIdToRarity mapping might not match actual minted token

Proof of Concept

// If _mint() ever returned 0 or failed silently:
// tokenIdToRarity[tokenId] = rarity; // Would use wrong tokenId
// tokenId++; // Would increment incorrectly

Recommended Mitigation

function selectWinner() external {
// ...
- _mint(winner, tokenId);
+ uint256 mintedTokenId = _mint(winner, tokenId);
+ require(mintedTokenId == tokenId, "PuppyRaffle: Mint failed or returned unexpected tokenId");
tokenIdToRarity[tokenId] = rarity;
tokenId++;
}
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 7 hours ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!