If a player wants to refund their entry, the refund function returns their funds and then changes their address in the players array to 0 but does not remove them from the array. This creates problems in the selectWinner function because it depends on players.length in multiple ways. selectWinner picks a winner using a modulo of players.length which means that a refunded player could be selected. Also, a selection could be made with less than 4 players even though selectWinner intends for there to be at least 4 players. Also selectWinner will incorrectly calculate the winnings as players.length * entranceFee which doesn't account for refunds.
refund does not remove refunded players from the array:
selectWinner picks a winner using a modulo of players.length (which means that a refunded player could be selected or that a selection could be made with less than 4 players and also select Winner incorrectly calculates the winnings as players.length * entranceFee which doesn't account for refunds.
The protocol could send more money than it intends to the winner if someone had requested a refund during that lottery. They could also select the index of a player who got a refund and then send the winnings to a 0 address (since that is what the refund function set their address too). This is effectively burning the funds. Also, they could run the lottery with less than 4 players even though that is not what they intend.
Manual review
Instead of just zeroing out the address of someone who wants a refund, instead move the last player in the array to the spot of the person who asked for a refund and then use .pop to remove the last item in the array. This will shorten the length of the array to only the active players and fix all these problems.
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.