The EggstravaganzaNFT::mintEgg function calls the _mint() function rather than the more robust _safeMint() function to mint the egg NFT to the destination players. The _safeMint() function includes an essential safety mechanism that verifies a recipient contract’s capability to receive and manage ERC-721 tokens by calling the onERC721Received method. This check ensures the recipient implements the ERC721Receiver interface, reducing the risk of tokens being sent to incompatible contracts.
The mintEgg function uses _mint instead of _safeMint and returns true, even if the minting fails.
Using ERC721::_mint() can mint ERC721 tokens to addresses which don't support ERC721 tokens, while ERC721::_safeMint() ensures that ERC721 tokens are only minted to addresses which support them. OpenZeppelin discourages the use of _mint().
Furthermore, the function returns true even when the minting process fails which can lead to incorrect event data being emitted.
Add the below BadRecipient.sol contract to the src folder. This is an example contract that cannot properly receive or transfer NFTs:
Import the contract inside the EggHuntGameTest.t.sol file:
Add the following test and run forge test --mt testMintEggToBadRecipient
Manual review, Foundry for tests
Use the _safeMint function instead of _mint. Additionally, add logic to check if minting succeeded instead of returning the hardcoded value of true.
Protocol doesn't check if recipient contracts can handle ERC721 tokens
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.