The refund() function in the PuppyRaffle contract is vulnerable to a reentrancy attack. This vulnerability could be exploited to steal all of the funds in the contract.
The refund() function works as follows:
The player's address is retrieved from the players array at the specified index.
A require statement checks that the player address is equal to the caller's address.
Another require statement checks that the player address is not already refunded or is not active.
The player's entrance fee is sent back to them using the sendValue() function.
The player's address is set to address(0) in the players array.
A RaffleRefunded event is emitted.
The vulnerability is that the players array is updated after the sendValue() call is made. This means that if the attacker is able to reenter the refund function before the update to players mapping has completed, the attacker can steal all of the funds in the contract.
If this vulnerability is exploited, the attacker could steal all of the funds in the PuppyRaffle contract.
Foundry
Follows the CEI pattern and update the players mapping before the external call is being made
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.