Reentrancy bug allows the receiver contract to execute code which can then execute a function inside the puppyRaffle.sol. In this particular issue, The receiver contract can reenter the refund function before it has executed completely. The receiver function can drain more than the allocated funds of the refund.
In the above code reentrancy issue is present in:
sendValue transfers control to the receiving address, if its a contract it can execute its fallback function which can contain code that executes the refund function again. This will allow the receiver to reenter the function before their index is set to address(0)
An attacker can retrieve more than their allocated amount by reentering in to this function. They can drain the contract of its funds and retrieve them on their contract. Loss of funds can occur and if the contract loses too many funds then the selectWinner function will also not execute due to the strict equality not fulfilling.
Manual Review and Slither
Change the code in the following way
This will first set the index to 0 and then give the control to the receiver. If the receiver tries to reenter then the require will result in a false and not allow further execution.
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.