The selectWinner
function has an issue related to its random number generation mechanism. This vulnerability could potentially be exploited by a malicious actor to predict or influence the outcome, thereby compromising the fairness of the winner selection process.
The randomness in the selectWinner
function is derived from on-chain data using the expression:
This method of generating random numbers is considered weak and predictable because it relies on variables that can be influenced or anticipated by a participant or miner. Specifically:
msg.sender
: This is the address of the caller. A malicious actor could potentially manipulate this by using different addresses.
block.timestamp
: This is predictable and can be slightly manipulated by miners.
block.difficulty
: Although less predictable, it can still potentially be influenced.
Using these variables in combination does not sufficiently obscure the outcome, making it possible for someone to influence the winner selection process.
If exploited, this vulnerability could lead to a situation where a malicious actor consistently influences the outcome of the winner selection, thus compromising the fairness of the game and potentially causing financial loss to other participants.
Manual code review
To mitigate this issue, consider the following recommendations:
Use an External Oracle for Randomness: Integrate a reliable and secure external oracle to provide random numbers. Services like Chainlink VRF (Verifiable Random Function) are specifically designed for this purpose.
Commit-Reveal Scheme: Implement a commit-reveal scheme where participants submit hashes of their chosen numbers, and the actual numbers are revealed later. This makes it difficult for anyone to predict or influence the outcome.
On-Chain Randomness with Delay: If using on-chain data, introduce significant delays and combine multiple unpredictable block variables to increase randomness. However, this is generally less secure than using external oracles.
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.