When a player calls refund(), their slot in the players array is set to address(0). selectWinner() can pick this zeroed slot as the winner. The subsequent _safeMint(winner, tokenId) call reverts because ERC721 forbids minting to address(0). The entire transaction reverts, meaning the raffle cannot be resolved for that particular msg.sender/block combination.
Since the winner index depends on msg.sender, different callers produce different indices. Some callers will hit non-zero slots and succeed. But depending on how many refunds occurred, a large fraction of the array may be zeroed, making most callers unable to resolve the raffle.
Additionally, the prize calculation at line 131 uses players.length * entranceFee, which includes refunded slots. This means the math assumes ETH that was already returned, so the .call{value: prizePool} would also fail if the contract balance doesn't cover the inflated prize pool.
Likelihood:
Triggered whenever at least one player refunds before selectWinner() is called. Refunds are a core feature of the protocol (the README explicitly supports them), so this scenario is common.
Impact:
The raffle may be unresolvable for many callers. In the worst case (many refunds), nearly every possible winnerIndex maps to address(0), effectively deadlocking the raffle. The remaining players' entrance fees are stuck until a caller happens to produce a valid index.
No separate PoC. The vulnerability is visible from reading the code path: refund() sets address(0) → selectWinner() picks any index → _safeMint(address(0)) reverts per ERC721 spec.
Skip address(0) entries when selecting the winner:
Also fix the prize pool calculation to subtract refunded players, or track active player count separately.
## 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.