The GivingThanks::donate
function transfers Ether to the charity address before minting and setting the token URI. This sequence introduces a potential reentrancy vulnerability where a malicious charity contract could re-enter the donate function and manipulate the state.
If GivingThanks::donate
exploited, this vulnerability could lead to inconsistencies in the contract’s state, such as token counter manipulation or unauthorized access.
This test involves deploying a malicious Attacker contract that re-enters the donate function during the Ether transfer.
First, we define an Attacker contract that will exploit the reentrancy vulnerability by calling donate again within its fallback function.
Now, we create a test function to deploy the Attacker, set up the scenario, and execute the attack.
After running this test, the test case will FAIL
which shows that reentrancy can manipulate the GivingThanks::donate
flow, causing unintended reverts. In practice, this means an attacker could exploit this vulnerability to interfere with the contract’s operations or even drain funds in real deployments.
Foundry
Implement the Checks-Effects-Interactions Pattern: Ensure that all state updates occur before any external calls to prevent reentrancy.
Add a Reentrancy Guard: Apply the nonReentrant
modifier ReentrancyGuard
to prevent multiple simultaneous calls to donate.
The event gets emitted when a user calls the donate function.
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.