GivingThanks

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

Unsafe Use of _mint(), Should use _safeMint() Instead

Summary

The GivingThanks contract uses "_mint()" in the donate() function when creating a donor's token NFT. Since it does not use_ "__safeMint()", this can result in the tokens being sent to addresses that do not support ERC721 tokens which would cause them to not be retrievable. Utilizing "_safeMint()" from the Openzeppelin library will be able to prevent this.

Vulnerability Details

"_mint()" is used in the donate() function within the GivingThanks contract:

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;
}

The use of "_mint()" sends the token NFT to the donor address without verifying whether the donor can receive ERC721 tokens. If the donor is a contract that does not implement the IERC721Receiver interface, the NFT will be locked in that contract, leading to asset loss for donors.

Utilizing "_safeMint()" guarantees that the recipient address can receive the token NFT without running into this issue.

Impact

  1. Permanent loss of token NFT if the receiving address is a contract that does not have a proper implementation of the IERC721Receiver interface.

  2. Aversion to using the contract as users may be nervous they may not receive their donation token NFT if they donate.

Tools Used

Manual analysis and Foundry

Recommendations

Replace "_mint()" with Openzeppelin's "_safeMint()" to ensure donors are able to receive their token NFT:

- _mint(msg.sender, tokenCounter);
+ _safeMint(msg.sender, tokenCounter); // Ensures recipient can handle ERC721 tokens
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.