The selectWinner() function uses insufficient methods to calculate the random winner of the raffle, leading to an attacker being able to predict the winner of the raffle.
The winner's index is calculated based upon non-random values, which can be calculated and predicted by an attacker:
uint256 winnerIndex = uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp, block.difficulty))) % players.length
Since the raffle duration is a known value, the block.timestamp at the time of selectWinner() can be calculated.
Run the test with forge test -f $LOCAL_RPC_URL --mt testWalleWinnerIsRandom -vv.
An attacker could arbitrarily join raffles, check if they win and refund, if they don't, basically leading to winning every raffle. Adding arbitrarily new players to the raffle even changes the outcome of the raffle, so that an attacker could change the outcome to his own advantage (=win).
Root cause: bad RNG Impact: manipulate winner
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.