Root cause: PuppyRaffle::refund blanks a slot but never shrinks players, while selectWinner computes the payout from players.length, which still counts the refunded tickets.
Impact: a single refund makes the contract try to pay out more ETH than it holds, so selectWinner reverts on every call and the raffle — together with all remaining stakes — is locked forever.
selectWinner is meant to distribute exactly what the current round collected: 80% to the winner and 20% to the fee address.
refund sends the stake back and writes address(0) into the slot, deliberately leaving a hole (@dev This function will allow there to be blank spots in the array). players.length is unchanged, so totalAmountCollected keeps counting money that has already left the contract. The prize transfer then asks for more than the balance and the require reverts, permanently.
Likelihood:
Occurs whenever any player refunds before the draw, which is a documented, intended feature of the protocol. No attacker and no privilege required — one honest refund is enough.
There is no code path that ever removes the hole or decrements the length, so the condition persists until the contract is redeployed.
Impact:
selectWinner reverts on every call: the prize pool computed from four stakes cannot be paid out of three. All remaining player funds are stuck in the contract.
A second, independent revert path exists: if winnerIndex lands on a blanked slot, winner is address(0) and _safeMint reverts first.
withdrawFees cannot rescue anything either, since it requires address(this).balance == totalFees and the balance still holds the players' stakes.
Four players enter, one refunds. The contract holds 3 ether but selectWinner tries to send a 3.2 ether prize pool:
Control test, showing the draw settles normally when nobody refunds — the revert comes from the stale length, not from the draw itself:
Both tests pass on the audited commit with forge test.
Track the number of live entries instead of trusting the array length, and skip blank slots when picking a winner. Swapping the refunded entry with the last one and popping keeps the array dense:
If the blank-slot design is kept deliberately, then selectWinner must both derive the pot from a separate counter of active entries and re-draw when the selected slot is address(0).
## Description `PuppyRaffle::refund` is supposed to refund a player and remove him from the current players. But instead, it replaces his index value with address(0) which is considered a valid value by solidity. This can cause a lot issues because the players array length is unchanged and address(0) is now considered a player. ## Vulnerability Details ```javascript players[playerIndex] = address(0); @> uint256 totalAmountCollected = players.length * entranceFee; (bool success,) = winner.call{value: prizePool}(""); require(success, "PuppyRaffle: Failed to send prize pool to winner"); _safeMint(winner, tokenId); ``` If a player refunds his position, the function `PuppyRaffle::selectWinner` will always revert. Because more than likely the following call will not work because the `prizePool` is based on a amount calculated by considering that that no player has refunded his position and exit the lottery. And it will try to send more tokens that what the contract has : ```javascript uint256 totalAmountCollected = players.length * entranceFee; uint256 prizePool = (totalAmountCollected * 80) / 100; (bool success,) = winner.call{value: prizePool}(""); require(success, "PuppyRaffle: Failed to send prize pool to winner"); ``` However, even if this calls passes for some reason (maby there are more native tokens that what the players have sent or because of the 80% ...). The call will thankfully still fail because of the following line is minting to the zero address is not allowed. ```javascript _safeMint(winner, tokenId); ``` ## Impact The lottery is stoped, any call to the function `PuppyRaffle::selectWinner`will revert. There is no actual loss of funds for users as they can always refund and get their tokens back. However, the protocol is shut down and will lose all it's customers. A core functionality is exposed. Impact is high ### Proof of concept To execute this test : forge test --mt testWinnerSelectionRevertsAfterExit -vvvv ```javascript function testWinnerSelectionRevertsAfterExit() public playersEntered { vm.warp(block.timestamp + duration + 1); vm.roll(block.number + 1); // There are four winners. Winner is last slot vm.prank(playerFour); puppyRaffle.refund(3); // reverts because out of Funds vm.expectRevert(); puppyRaffle.selectWinner(); vm.deal(address(puppyRaffle), 10 ether); vm.expectRevert("ERC721: mint to the zero address"); puppyRaffle.selectWinner(); } ``` ## Recommendations Delete the player index that has refunded. ```diff - players[playerIndex] = address(0); + players[playerIndex] = players[players.length - 1]; + players.pop() ```
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.