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

Predictable randomness in `selectWinner`

Summary

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.

Vulnerability Details

The randomness in the selectWinner function is derived from on-chain data using the expression:

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

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:

  1. msg.sender: This is the address of the caller. A malicious actor could potentially manipulate this by using different addresses.

  2. block.timestamp: This is predictable and can be slightly manipulated by miners.

  3. 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.

Impact

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.

Tools Used

Manual code review

Recommendations

To mitigate this issue, consider the following recommendations:

  1. 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.

  2. 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.

  3. 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.

Updates

Lead Judging Commences

Hamiltonite Lead Judge almost 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.