Players that got refunds are not considered when calculating prize pool and fee pools. This leads those calculations to be bloated and when the contract tries to send out the funds, the transaction will fail as not enough funds are available.
When selecting a winner, in selectWinner
function, the code does not take into consideration users that might of got a refund. totalAmountCollected
is calculated by multiplying the players
array length and the entranceFee
$$ totalAmountCollected = players.length * entranceFee $$
When a player gets a refund, their address in the players
array gets changed to the zero address and their entrance fee gets returned to them. This is not taken into consideration in the selectWinner
function.
src/PuppyRaffle.sol
https://github.com/Cyfrin/2023-10-Puppy-Raffle/blob/07399f4d02520a2abf6f462c024842e495ca82e4/src/PuppyRaffle.sol#L131-L133
Wrong calculations for:
totalAmountCollected
prizePool
fee
and totalFees
Contract will try to send more funds that it has and those transactions will fail.
In addition to checking that there is at least 4 players for the raffle, It is also recommended to make sure that the total players does not include any zero addresses which represents players that got refunds. A new array could be created with this count and only the non zero addresses should be populated to the new array. Then safely loop over that array.
Instead of using players.length
to get total valid players use something similar to below. Which only counts the non-zero-address players.
Manual Audit
Foundry
Funds are locked to no one. If someone gets the refund issue, they also got this issue. IMPACT: High Likelihood: High
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.