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

PuppyRaffle::refund does not decrease the players array length after refund

Summary

  • Accounting issue.

  • PuppyRaffle.refund() does not reduce the length of players array after refunding.

Vulnerability Details

  • Since the players length remains same and entry fee is also refunded, when selectWinner is called, it calculates uint256 totalAmountCollected = players.length * entranceFee

  • But, the ether in contract wont be enough because we already refunded to the player before.

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] = players[players.length - 1];
+ players.pop();
+ 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:

refund-doesnt-reduce-players-array-size-causing-protocol-to-freeze

zero address can win the raffle

Funds are locked to no one. If someone gets the refund issue, they also got this issue. IMPACT: High Likelihood: High

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.