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

Reentrancy in refund()

Summary

refund() does not follow CEI pattern therefore it is vulnerable to reentrancy attack.

Vulnerability Details

players[playerIndex] = address(0); is updated after payable(msg.sender).sendValue(entranceFee);, so attacker can do reentrancy attack during the callback to drain the contract.

Impact

The contract's balance will be drained.

Tools Used

Manual review

Recommendations

Rewrite the function:

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);
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!