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

The refund function is vulnerable to Reentrancy

Summary

The refund function is vulnerable to a reentrancy attack, as it first transfers the entranceFee and updates the state after.

Vulnerability Details

The refund function looks like this:

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

As we can see, it sends the funds back to the msg.sender and updates the state after that, without using a reentrancy guard. This is vulnerable to a reentrancy attack and therefore allows anyone to fully drain the contract.

Impact

Complete loss of all funds

Tools Used

Manual Review

Recommendations

Use a reentrancy guard, or update the state before the transfer call.

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!