Because of Reentrancy vulnerability, GivingThanks::donate
functions gives an opportunity to malicious actor to manipulate the system to gain an unfair benefit, typically through repeated minting of NFTs.
The attacker calls GivingThanks::donate
function from the malicious contract as the charity address.
The donate
function sends Ether to the MaliciousCharity contract, triggering its receive() function.
In the receive()
function, the malicious contract re-enters the donate function before the original call completes. This happens before the token counter is incremented or the minting logic finishes.
Each time the Ether is sent, the contract keeps re-entering and minting new tokens, leading to multiple tokens being issued without properly tracking donations.
A bad actor could create a contract designed to exploit the vulnerable GivingThanks::donate
function by re-entering it through the call that sends Ether to manipulate the system to gain an unfair benefit, typically through repeated minting of NFTs.
Foundry, Manual
There are a few ways how to mitigate this problem:
Update your state variable tokenCounter
before making the external call to ensure that any attempt to re-enter the function will not allow the attacker to mint extra tokens unfairly.
Use the nonReentrant
modifier from OpenZeppelin
to ensure that no reentrancy is possible. This will block the malicious contract from re-entering the donate function while it is already executing.
Impact: High, one charity can reenter the donate function with the same ETH provided and mint several NFT. Likelyhood: Low, any malicious charity can do it but Admin is trusted and should verify the charity contract before "verifying" it.
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.