Beginner FriendlyFoundryNFT
100 EXP
View results
Submission Details
Severity: high
Valid

Use of a Predictable Randomness Source in `selectWinner`

Vulnerability Details

The contract uses a predictable source of randomness in the selectWinner function. The randomness for selecting the raffle winner is derived from on-chain data, specifically block.timestamp, msg.sender, and block.difficulty:

uint256 winnerIndex =
uint256(keccak256(abi.encodePacked(msg.sender, block.timestamp, block.difficulty))) % players.length;

These parameters, particularly block.timestamp and block.difficulty, can be influenced or predicted to a certain extent. block.timestamp can be manipulated by miners within certain boundaries, and block.difficulty follows a predictable adjustment pattern. Additionally, msg.sender is known to the participant initiating the transaction. This predictability can be exploited by a miner or a participant with the ability to influence transaction order, allowing them to increase their chances of winning the raffle.

Impact

The use of predictable sources of randomness compromises the fairness and security of the raffle process. Miners or participants with advanced knowledge or control over these parameters could manipulate the outcome to their advantage. This undermines the integrity of the raffle, leading to a loss of trust and potential financial loss for other participants.

Recommendations

  • Use of Verifiable Random Function (VRF): Implement a more secure randomness generation mechanism, such as Chainlink's VRF (Verifiable Random Function), which provides provably fair and tamper-proof random numbers.

  • Off-Chain Randomness: Consider generating randomness off-chain using a trusted oracle service and feeding it into the contract securely.

  • Commit-Reveal Scheme: Implement a commit-reveal scheme where participants submit hashes of their secret values in one transaction and reveal them in a subsequent transaction, contributing to the randomness.

  • Enhanced On-Chain Randomness: If on-chain randomness is necessary, combine multiple unpredictable sources and consider adding participant-generated randomness to increase unpredictability.

Updates

Lead Judging Commences

Hamiltonite Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

weak-randomness

Root cause: bad RNG Impact: manipulate winner

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!