Both PuppyRaffle::selectWinner()::winnerIndex and PuppyRaffle::selectWinner()::rarity use deterministic randomness.
The code generates randomness based on the sender's address (msg.sender), the block's difficulty (block.difficulty), and in the case of winnerIndex the current block's timestamp (block.timestamp).
However, this approach is deterministic, meaning that the same input parameters will always produce the same result. This can potentially be exploited by malicious users who might try to predict or influence the outcome by timing their transactions.
Miner Manipulation: Miners have control over the order in which transactions are included in a block, and they can choose to include or exclude transactions. This means they can manipulate the block.timestamp and block.difficulty to some extent, which could further undermine the randomness of this approach.
Predictability: If participants can anticipate the result, they might game the system by submitting transactions at specific times to increase their chances of winning. Block-related pseudo-random properties like block.coinbase, block.difficulty, block.gaslimit, block.number and block.timestamp are available to any attacker if their transaction is in the same block information as the victim's transaction. In the case of PuppyRaffle contract this in easy to achieve since PuppyRaffle::selectWinner() is public and anyone can call it even the attacker.
Solidity
To enhance the security and fairness of random number generation in smart contracts, it's generally advisable to use an external source of randomness, such as Chainlink VRF (Verifiable Random Function) or another decentralized oracle service. These services provide a more tamper-resistant source of randomness, making it much more difficult for anyone, including miners, to predict or manipulate the outcome.
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.