The GivingThanks::donate
function uses _mint()
to mint NFTs to donors without ensuring the recipient can handle ERC721 tokens. This can result in NFTs being irreversibly locked if sent to smart contracts that are not designed to receive ERC721 tokens.
In the GivingThanks
contract, the donate
function mints an NFT to the donor using _mint()
:
The _mint()
function does not check whether the recipient (msg.sender
) is a smart contract capable of handling ERC721 tokens. If msg.sender
is a contract that does not implement the IERC721Receiver
interface, the NFT will be permanently locked in that contract, as it cannot respond to the token transfer appropriately.
Using _safeMint()
instead of _mint()
ensures that if the recipient is a contract, it must implement onERC721Received()
. If it doesn't, the minting operation will revert, preventing the NFT from being locked in an incompatible contract.
Permanent Loss of NFTs: NFTs may become inaccessible if minted to contracts that cannot handle them.
User Frustration: Donors using smart contract wallets or interacting through contracts may not receive their NFTs, leading to a poor user experience.
Potential Legal and Financial Implications: Loss of valuable NFTs could have legal or financial repercussions for the platform.
Manual code review
Solidity documentation and ERC721 standard specifications
Replace _mint()
with _safeMint()
:
Modify the donate
function as follows:
Benefit of Using _safeMint()
:
Ensures that if the recipient is a smart contract, it must implement IERC721Receiver
, preventing tokens from being locked.
Provides an additional safety check without significant overhead.
Additional Considerations:
Inform users that they should ensure their wallets or contracts are compatible with ERC721 tokens.
Consider implementing a fallback mechanism or user notification if the minting fails.
By making this change, you enhance the security and reliability of the NFT minting process, safeguarding user assets and improving overall platform trust.
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.