Somebody can take advantage of the 'selectWinner' function through the way we compute randomness on the chain.
A potential exploit exists where a malicious actor could manipulate outcomes by simulating transactions on a testnet (or through tools like Foundry or Tenderly). By repeatedly calling the function with varying block timestamps and block difficulties, they can identify a successful pattern. Once identified, this pattern could be replicated in a transaction on the mainnet, leading to a compromise.
An attacker can monitor the mempool (the set of unconfirmed transactions) for a transaction that successfully calls the selectWinner function. Upon spotting such a transaction, the attacker can initiate their own transaction with a higher gas fee. This maneuver ensures the attacker's transaction is processed first by the miners, effectively allowing the attacker to manipulate the outcome. This scenario becomes particularly problematic because the inclusion of their transaction changes the state of the contract (such as increasing the size of the players array), potentially causing the original transaction to fail or produce a different outcome. This vulnerability can be exploited to gain an unfair advantage or to disrupt the normal operation of the raffle.
This vulnerability can potentially undermine the integrity of the system, leading to unfair advantages and loss of trust among users.
Manual review
To mitigate this risk, it is advisable to integrate Chainlink's Verifiable Random Function (VRF) for more secure and verifiable on-chain randomness. This approach will greatly enhance the fairness and security of the 'selectWinner' function.
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.