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

Malicious user can exploit the contract by reenter the refund

Summary

Malicious user can exploit the contract by reenter the refund

Vulnerability Details

refund will send entranceFee to msg.sender and players[playerIndex] is not updated. Attacker can reenter the refund and drain the contract.

/// @param playerIndex the index of the player to refund. You can find it externally by calling `getActivePlayerIndex`
/// @dev This function will allow there to be blank spots in the array
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");
payable(msg.sender).sendValue(entranceFee);
players[playerIndex] = address(0);
emit RaffleRefunded(playerAddress);
}

Impact

The attacker can drain the contract of its funds.

Tools Used

Manual review.

Recommendations

Add reentrancy protection.

Updates

Lead Judging Commences

Hamiltonite Lead Judge over 1 year 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.