Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

refund function vulnerable to reentrancy attack

Summary

The refund function is vulnerable to a reentrancy attack.

Vulnerability Details

The refund function is vulnerable to a reentrancy attack because it doesn't update all the logic before sending the users funds back to them.

Impact

allows the attacker to drain the entire contracts funds.

Tools Used

Manual Review, Slither

Recommendations

use CEI (Checks, Effects, Interactions). only send ether once you have finished updating all the logic.

function refund(uint256 playerIndex) public {
address playerAddress = players[playerIndex];
require(playerAddress == msg.sender, "PuppyRaffle: Only the player can refund");
require(playerAddress != address(0), "PuppyRaffle: Player already refunded, or is not active");
+ players[playerIndex] = address(0);
payable(msg.sender).sendValue(entranceFee);
- players[playerIndex] = address(0);
emit RaffleRefunded(playerAddress);
}
Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

reentrancy-in-refund

reentrancy in refund() function

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!