PuppyRaffle::selectWinner can be called even if we don't have 4 or more players, if protocol have enough balance. Because of PuppyRaffle::refund function implementation and wrong counting of players length.
Let's take an example there are 4 players entered the raffle with 0.01 eth as fee(total 0.04 eth). Now 1 of them refunded, so ideally PuppyRaffle::selectWinner should not work because there are only 3 players, but it will work if we have extra eth in the contract balance to cover the fee of that left player. All this is happening because when we are refunding, we are only making refunder address(0) that is not decreasing the length of players array because address(0) is also counting as we can't remove a particular index element from an array.
How will protocol have extra eth to cover the fee of left player so protocol is collecting fee from every raffle round and if owner don't withdraw its eth then a point will come when there will be enough eth to cover the fee of that left player.
There will be two thing while selecting winner
if left player address got selected(it will because address(0) is still there and we are counting winnerIndex using players.length) then tx. will revert because you can't mint nft on zero address.
if a real player got selected(from those 3 players) then winner will be able to mint nft and it will get reward based on 4 players not on 3 players and that will leads to loss of funds to owner because it was his funds.
Loss of funds and wrong winner calculation.
//Here is Proof of concept
For extra eth I've made a deposit function in PuppyRaffle because if not then I've to run so many raffle to get enough eth as fee to cover the fee of left player.
Manual Review, Foundry
Use a counter to count the number of players instead of using players.length and that will help you to reduce the counter when player is getting refund because you can't remove a particular index element from array.
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.