The PuppyRaffle::refund function is vulnerable to reentrancy attack. An attacker can empty the smart contract balance.
The refund function is vulnerable to reentrancy attack.
The function sends the eth to the user and then changes the value of players[playerIndex] that is used before sending the eth to check whether or not to send it.
This means that if a call is made to the same function refund, before the status is changed, the eth will be sent again. Exploiting this vulnerability can empty the smart contract balance.
I create an attacker contract and a test to verify the vulnerability, follow these steps to test it:
Put this file inside src folder, and rename it with Attacker.sol
Put this file inside test folder, and rename it with ReEntrancyTest.t.sol
and run the command
This vulnerability permits to an attacker to empty the balance of the smart contract.
Foundry
Manual review
It is necessary to move the line that updates the status before making the sendValue call.
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.