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

Reentrancy may lead to a drain on contract funds

Summary

Reentrancy can occur in the PuppyRaffle::refund function

Vulnerability Details

External calling happens without following the Check Effect Interaction pattern.

In this way, a raffle participant can call the refund function, and then call it back in its fallbakc function until all funds are drained.

Impact

Contract funds can be completely drained

Tools Used

Foundry

Recommendations

The CEI pattern should always be followed when making external calls.

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!