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

The contract can be drained by reentering refund function

Summary

A user can drain the contract using a malicious contract that reenter refund function.

Vulnerability Details

A malicious contract can re-enter refund function here:

payable(msg.sender).sendValue(entranceFee);

CEI pattern is not followed because players[playerIndex] = address(0) is executed after the external call.

Impact

All ETH in the contract can be drained.

Tools Used

Manual review

Recommendations

Follow CEI pattern:

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

In addition use nonReentrant() modifier by OpenZeppelin ReentrancyGuard contract.

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!