Block Hash Prediction (On-Chain)
CVSS 9.5 CriticalThe most common on-chain RNG exploit. Smart contracts that derive game outcomes directly from `block.hash`, `block.timestamp`, or `block.prevrandao` are vulnerable to miner/validator manipulation and contract-to-contract prediction attacks.
Attack Mechanic
A malicious smart contract can call the gambling contract and read the same block hash that the RNG function will use. If the computed outcome is unfavorable, the attacker can revert their transaction — effectively getting unlimited free rolls until they win. Validators can also withhold blocks or orphan blocks to influence outcomes in high-value games.
Real-World Example
In 2019, the Fomo3D-style contract "LastWinner" was drained by an attacker who deployed a prediction contract that only executed bets when the computed block hash yielded a jackpot outcome. The attacker won the jackpot in under 50 attempts, bypassing the intended 1-in-1000 odds.
Defenses
- 01Never use block.hash, block.timestamp, or block.prevrandao alone as entropy
- 02Use Chainlink VRF v2+ for tamper-proof on-chain randomness with cryptographic proofs
- 03Implement a two-transaction commit-reveal with multi-party entropy contributions
- 04Add a minimum block delay between bet placement and outcome resolution