The donate
function in GivingThanks.sol
allows a zero-Ether donation, which mints an NFT for the donor without requiring any actual funds to be contributed. This could enable abuse by allowing malicious actors to mint unlimited NFTs at no cost, undermining the donation platform’s integrity.
The donate
function currently lacks a check to ensure that msg.value
(the donated amount) is greater than zero. Without this check, a user can call donate
with zero Ether, allowing them to mint NFTs without making any actual donation. This issue opens the platform to exploitation, allowing unauthorized and unlimited NFT minting.
Here is a proof of code that shows a test case in which a donor makes a contribution with a value of Zero, but is still minted the NFT correctly, also correctly updating the tokenCounter, and giving ownership of that NFT to the donor.
Here are the result and the logs from that test:
By allowing zero-Ether donations, the platform is open to abuse, where attackers can mint unlimited NFTs at no cost. This can flood the platform with free NFTs, diminish the perceived value of genuine donations, and undermine the trust and integrity of the system.
Manual code review.
Test case testDonateZeroAmount
to confirm vulnerability using Foundry.
To prevent this vulnerability, add a check in the donate
function to ensure that msg.value
is greater than zero:
This simple check will prevent the function from minting NFTs without an actual donation, safeguarding the platform’s integrity. And also, the test from earlier also fails accordingly.
Likelyhood: Low, anyone can mint an NFT with 0 amount. No reason to do it. Impact: Informational/Very Low, NFT are minted to a false donator. An NFT with 0 in the amount section would be useless. Since that's a bad design and not expected, I'll consider it Low but in a real contest, it could be informational because there is no real impact.
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.