GivingThanks

First Flight #28
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: medium
Invalid

Use of `_mint` instead of `_safeMint` inside the `GivingThanks::donate` function

Description The contract uses the _mint function to create new ERC721 tokens, which does not check if the recipient is capable of receiving these types of tokens.

Impact If tokens are minted to a contract that does not implement the onERC721Received function, they could become permanently locked, leading to loss of tokens.

Proof of Concepts

  1. A smart contract that doesn't support ERC-721 tokens calls the GivingThanks::donate function

  2. The smart contract receives the NFT

  3. The owner of the contract is not allowed to transfer the NFT from the smart contract.

Recommended mitigation

Add the following changes to the GivingThanks::donate function.

function donate(address charity) public payable {
require(registry.isVerified(charity), "Charity not verified");
(bool sent,) = charity.call{value: msg.value}("");
require(sent, "Failed to send Ether");
- _mint(msg.sender, tokenCounter);
+ _safeMint(msg.sender, tokenCounter);
// Create metadata for the tokenURI
string memory uri = _createTokenURI(msg.sender, block.timestamp, msg.value);
_setTokenURI(tokenCounter, uri);
tokenCounter += 1;
}
Updates

Lead Judging Commences

n0kto Lead Judge 8 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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