* The `selectWinner()` function calculates `totalAmountCollected` using `players.length * entranceFee`, which includes refunded players (slots set to `address(0)`).
* When players refund, they receive their `entranceFee` back, but their slot remains in the array. The calculation assumes funds exist that were already returned, leading to incorrect prize pool and fee calculations.
```solidity:131:134:src/PuppyRaffle.sol
uint256 totalAmountCollected = players.length * entranceFee;
uint256 prizePool = (totalAmountCollected * 80) / 100;
uint256 fee = (totalAmountCollected * 20) / 100;
totalFees = totalFees + uint64(fee);
```
Likelihood:
* This occurs whenever any player has refunded before `selectWinner()` is called
* Refunds are allowed until the raffle ends, so this is a common scenario
* The calculation uses `players.length` which doesn't decrease when players refund
Impact:
* Prize pool calculation assumes more funds than actually exist in the contract
* Contract may attempt to send more ETH than it has, causing transaction to revert
* Fee calculation is also incorrect, leading to accounting errors
* Potential for contract drain if calculations are off
* Winners may receive incorrect prize amounts
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.