GivingThanks

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

Safe mint is not implemented for ERC721 token receipt

Summary

Donors will be minted an ERC721 token to confirm the receipt of their donations in GivingThanks:donate function. However, _mint function is used instead of _safeMint function. If donors are smart contract that do not implement the onERC721Received function, they wouldn't be able to receive their tokens.

https://github.com/Cyfrin/2024-11-giving-thanks/blob/304812abfc16df934249ecd4cd8dea38568a625d/src/GivingThanks.sol#L26

Vulnerability Details

The minting of ERC721 token receipt to donors was found done via the _mint function in GivingThanks:donate. If donors are smart contract that do not implement the onERC721Received function, they wouldn't be able to receive their token receipt.

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);
// Create metadata for the tokenURI
string memory uri = _createTokenURI(msg.sender, block.timestamp, msg.value);
_setTokenURI(tokenCounter, uri);
tokenCounter += 1;
}

Impact

Donors that are smart contracts which do not implement the onERC721Received function wouldn't be able to receive their token receipts.

Tools Used

Manual review

Recommendations

Replace the _mint to safeMint in GivingThanks:donate

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 12 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.