The selectWinner
function is vulnerable to front-running attacks. Specifically, by observing a legitimate transaction that invokes this function in the mempool, an attacker can preemptively send their own transaction with a higher gas fee to manipulate the outcome of the winner selection and possibly profit from the subsequent prize distribution.
The function uses msg.sender, block.timestamp, and block.difficulty as seed values for the keccak256 hash function to generate "randomness". However, two of these values (msg.sender and block.timestamp) can be controlled or influenced by the attacker, especially when they are front-running.
Since Ethereum miners prioritize transactions offering higher gas fees, an attacker can observe the selectWinner transaction in the mempool and send a similar transaction with a higher gas price. By doing so, the attacker ensures that their transaction is mined before the original one.
By preempting the original transaction, the attacker's transaction becomes the one to set the block.timestamp and uses the attacker's address for msg.sender, which in turn influences the outcome of the winner selection.
Unfair Winner Selection
Employ services like Chainlink VRF (Verifiable Random Function) which provide on-chain verifiable randomness that is hard to manipulate.
Commit-Reveal techniques
zk-solutions
Batching providers like Flashbots, etc.
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.