Eggstravaganza

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

Use of `_mint` Instead of `_safeMint` in `EggstravaganzaNFT` May Lead to Irretrievable NFTs

Summary

The mintEgg function in the EggstravaganzaNFT contract utilizes the _mint method to create new NFTs. This approach does not verify whether the recipient address can handle ERC721 tokens, potentially leading to tokens being irretrievably locked in contracts incapable of processing them.

Vulnerability Details

In the current implementation, the mintEgg function is defined as follows:

function mintEgg(address to, uint256 tokenId) external returns (bool) {
require(msg.sender == gameContract, "Unauthorized minter");
_mint(to, tokenId);
totalSupply += 1;
return true;
}

The _mint function from the ERC721 standard directly assigns ownership of a new token to the specified address without performing checks to confirm if the recipient is a contract capable of handling ERC721 tokens. If to is a contract that does not implement the onERC721Received function, the minted NFT could become permanently inaccessible. This scenario is particularly problematic if the recipient contract is not designed to manage ERC721 tokens, leading to a loss of access to the NFT.

Impact

Minting NFTs to contracts that are not ERC721-aware can result in tokens being locked and inaccessible, effectively removing them from circulation and causing potential loss of value for users.

Tools Used

  • Manual code analysis

Recommendations

To prevent the risk of NFTs being locked in non-ERC721-aware contracts, it is advisable to use the _safeMint function instead of _mint. The _safeMint function performs additional checks to ensure that if the recipient is a contract, it implements the onERC721Received function, thereby confirming its ability to handle ERC721 tokens.

The revised mintEgg function would be:

function mintEgg(address to, uint256 tokenId) external returns (bool) {
require(msg.sender == gameContract, "Unauthorized minter");
_safeMint(to, tokenId);
totalSupply += 1;
return true;
}

Updates

Lead Judging Commences

m3dython Lead Judge 3 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.