TwentyOne

First Flight #29
Beginner FriendlyGameFiFoundrySolidity
100 EXP
View results
Submission Details
Severity: low
Invalid

Weak randomness in `TwentyOne::call()` function allows dealer's threshold to be predicted or influenced by an attacker

Summary

The call() function in the TwentyOne smart contract uses a weak pseudorandom number generator (PRNG) to determine the dealer's threshold. This randomness is derived from a combination of block.timestamp, msg.sender, and block.prevrandao. Due to the predictability and manipulability of these inputs, the randomness used to calculate the dealer’s stand threshold can be influenced or predicted by an attacker, potentially compromising the fairness of the game.

Vulnerability Details

The dealer’s threshold is determined using the following line of code:

// Calculate the dealer's threshold for stopping (between 17 and 21)
uint256 standThreshold =
(uint256(keccak256(abi.encodePacked(block.timestamp, msg.sender, block.prevrandao))) % 5) + 17;

This calculation combines block.timestamp (which can be manipulated by miners within a small range), msg.sender (the address of the player, which is easily known and predictable), and block.prevrandao (the hash of the previous block’s randomness, which miners can influence). As a result, an attacker could potentially predict or control the outcome of the threshold value, influencing when the dealer will stop drawing cards.

Impact

The impact of this vulnerability is significant because it directly affects the dealer’s decision-making process in the game. The dealer’s threshold determines when they stop drawing cards, which is a key factor in determining the game’s outcome. If an attacker can predict this threshold, they could adjust their strategy to exploit it, giving them an unfair advantage. For example, the attacker could decide when to stand based on the dealer's likely actions, significantly skewing the game in their favor.

Tools Used

  • Slither

Recommendations

Use Chainlink VRF to handle random number generation

Updates

Lead Judging Commences

inallhonesty Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Known issue
Assigned finding tags:

[INVALID] Known - Randomness

Randomness Manipulation: The randomness mechanism relies on block.timestamp, msg.sender, and block.prevrandao, which may be predictable in certain scenarios. Consider using Chainlink VRF or another oracle for more secure randomness.

Support

FAQs

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