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

The reentrancy vulnerability in refund can allow an attacker to steal all funds

Summary

PuppyRaffle#refund has a sendValue function that calls msg.sender to send back the entry fee and set the player addresses in the player array to zero addresses. However, msg.sender can call the fallback() function to reenter refunds().

Vulnerability Details

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

An attacker can maliciously reenter refund() to steal all the funds.

Tools Used

Manual Review

Recommendations

Consider using ReentrancyGuard or the checks-effects-interactions pattern

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!