The TwentyOne contract's randomness mechanism relies on block.timestamp and block.prevrandao, which are predictable values. This enables malicious players to front-run transactions by calculating cards and outcomes in advance, giving them an unfair advantage in the game. The vulnerability affects multiple key functions including startGame(), hit(), and call(), potentially compromising the entire game's integrity.
Vulnerability stems from using predictable blockchain parameters for randomness:
This affects three main functions:
startGame() function:
hit() function:
call() function:
Scenario of the attack can be as follows:
Attacker monitors the mempool for pending game transactions. For each transaction, attacker can:
Calculate the exact cards that will be drawn using the same inputs
Determine if the outcome will be favorable
Front-run the transaction with their own if favorable
Wait for next block if unfavorable
Attackers can exploit it to predict the cards and outcomes, and subsequently front-run transactions to secure favorable outcomes for themselves. This undermines the integrity of the game, leading to unfair advantages and potential financial loss for other players.
Manual Code Review
Foundry
Use an off-chain randomness source provided by trusted third parties, such as Chainlink’s VRF oracles, that ensure fairness and randomness. This prevents the exploitation of blockchain parameters, and improves security by moving the randomness process off-chain.
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.
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.