Eggstravaganza

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

Unsafe Minting in EggstravaganzaNFT::mintEgg function

Summary

The smart contract exposes a vulnerability by using the _mint function directly instead of the safeMint function in the mintEgg method. This issue can result in unsafe minting, potentially causing problems such as tokens being minted to invalid addresses or incompatible contracts.

Vulnerability Details

The mintEgg function allows only the approved game contract to mint NFTs. However, it uses the _mint function directly, which does not check for the safety of minting tokens to arbitrary addresses or addresses that may not be able to handle the NFT. The proper function to use in this context is safeMint, which ensures that tokens are minted safely to addresses that can accept them.

Code Snippet:

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

Impact

  • Token Loss: If an NFT is minted to a contract address that cannot handle the token (e.g., a contract that does not implement the IERC721Receiver interface), the minted token may be lost.

  • Security Risks: The direct use of _mint exposes the contract to potential issues with minting to malicious or invalid addresses, which could have unforeseen consequences.

  • Reduced Interoperability: The absence of safe checks limits the contract's compatibility with other applications or contracts that expect NFTs to be safely transferable.

Tools Used

  1. Foundry.

  2. Manual Review.

Recommendations

Always use safeMint.

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

Lead Judging Commences

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

Unsafe ERC721 Minting

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

Appeal created

mishoko Auditor
2 months ago
m3dython Lead Judge
about 2 months ago
mishoko Auditor
about 2 months ago
m3dython Lead Judge about 2 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.