Eggstravaganza

First Flight #37
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: medium
Valid

Unsafe `ERC721::_mint()` Usage

Summary

Unsafe ERC721::_mint() Usage

Vulnerability Details

The EggstravaganzaNFT contract uses ERC721::_mint() to mint NFTs, which does not check if the recipient address can safely receive ERC721 tokens. This can lead to tokens being minted to incompatible addresses, such as contracts that do not implement the ERC721 receiver interface (IERC721Receiver), potentially locking the tokens.

/// @notice Public function to mint a new Eggstravaganza NFT.
/// Only the approved game contract can mint eggs.
function mintEgg(address to, uint256 tokenId) external returns (bool) {
require(msg.sender == gameContract, "Unauthorized minter");
@> _mint(to, tokenId); // Unsafe minting
totalSupply += 1;
return true;
}

Impact

If an NFT is minted to an address (e.g., a smart contract) that does not support ERC721 tokens, the token could become permanently inaccessible, as the recipient cannot interact with it. This could result in lost assets for players in the EggHuntGame.

Proof of Concepts

  1. Deploy EggstravaganzaNFT and set a valid gameContract.

  2. Call mintEgg with to set to a contract address that does not implement IERC721Receiver.onERC721Received.

  3. The NFT is minted and transferred, but the recipient contract cannot manage it, effectively locking the token.

Tools Used

  • Manual review

  • Aderyn static analyzer

Recommendations

Replace _mint(to, tokenId) with _safeMint(to, tokenId) from OpenZeppelin’s ERC721 implementation. _safeMint ensures the recipient is either an externally owned account (EOA) or a contract that implements IERC721Receiver, preventing tokens from being sent to incompatible addresses.

Updates

Lead Judging Commences

m3dython Lead Judge 4 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Unsafe ERC721 Minting

Protocol doesn't check if recipient contracts can handle ERC721 tokens

Support

FAQs

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