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

PuppyRaffle::refund is reentrant and call steal all ether in the contract

Summary

PuppyRaffle.refund() can be reentered with a smart contract as the player.

Vulnerability Details

  • the attack is due to the updating the storage after external call, where it lacks the Checks effects Interaction pattern.

Impact

  • Severity : high

  • Likelihood : high

Tools Used

  • Manual verification

Recommendations

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