TwentyOne

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

*Couldnt find a way to delete! Just notice in known Issues* Weak Randomness In `drawCard` and `call` Functions Cause Manipulable Data for `RandomIndex` and `standThreshold`

Summary

The drawCard function chooses a random card out of the available cards in the deck. A random card is important to the game as it represents a shuffled card deck.

The call function compares the hands of the player and the dealer. It chooses a threshold randomly.

Vulnerability Details

https://github.com/Cyfrin/2024-11-TwentyOne/blob/a4429168302722d14a5e5996d25d6fc5be22a899/src/TwentyOne.sol#L75

https://github.com/Cyfrin/2024-11-TwentyOne/blob/a4429168302722d14a5e5996d25d6fc5be22a899/src/TwentyOne.sol#L128

Using onchain data to generate a random number is considered a bad practice. On chain information is shared to all users. This allows nodes that can see the meme pool to manipulate the data for their service.

Impact

Let's consider the following scenario:

  1. Bob has started a game.

  2. Bob is a bad actor and can manipulate on chain data for their benefit.

  3. Bob manipulates the timestamp for the transaction so the hash will end up with a random number that will let them win.

  4. Bob steals 2 ETH from the protocol. Not winning by playing the game as it is supposed to be.

Tools Used

Slither

Recommendations

Consider using Oracles to generate a pure random number. Chainlink VRF oracles allow using their off chain capabilities to generate a true random number that cannot be manipulated.

Updates

Lead Judging Commences

inallhonesty Lead Judge
11 months ago
inallhonesty Lead Judge 11 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.