Checks-effects-interactions pattern is not properly implemented. Because of this, funds can be drained via reentrancy attack.
A malicious user can enter the raffle with an address of a contract. After entering the raffle, this contract would then call the refund
function to get a refund. The contract would have a receive
function that would again call the refund
function. This reentrancy attack is possible because the refund
function only updates the players
array after it sends the funds to the address requesting refund.
src/PuppyRaffle.sol
https://github.com/Cyfrin/2023-10-Puppy-Raffle/blob/07399f4d02520a2abf6f462c024842e495ca82e4/src/PuppyRaffle.sol#L100-L103
Reentrancy attack can drain ether from the contract.
Update the players array before sending ether.
Manual Audit
Foundry
Create a new attacker contract below.
Note: this is just a POC contract. It is beyond scope of this POC to ensure this attack contract is written securely and that funds are handled correctly once the contract has them.
And the test function.
Note: this test function is to be added to the existing test suite as it needs already existing components from there.
reentrancy in refund() function
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.