When pseudo-random numbers are used for critical decisions in smart contracts, their predictability can create security vulnerabilities. Such attacks typically occur in two main ways:
- Predictability of Values: Attackers may anticipate certain pseudo-random values in advance. For instance, in a lottery contract, an attacker could calculate the winning result beforehand and place bets accordingly.
- Manipulation of External Inputs: If a contract relies on external data as a randomness source, attackers may exploit their ability to influence these inputs. For example, by manipulating block timestamps or transaction ordering, they can skew the outcome of the pseudo-random number generation.
Security Measures Against Pseudo-Random Number Attacks
- Off-Chain Random Number Services
Use trusted third-party services or off-chain computation to generate random numbers, which are then submitted on-chain. While not entirely attack-proof, this greatly increases the difficulty and cost of manipulation. - Combining Multiple Random Sources
Mix different sources of entropy—such as timestamps, block hashes, and external API data—to make prediction significantly harder for attackers. - Commit-Reveal Schemes
Introduce a commit-reveal process within the contract. Users first submit a cryptographic commitment (e.g., a hash of their chosen number) and reveal the actual value later, after sufficient blocks have passed. This prevents attackers from reverse-engineering future randomness from current states. - Verifiable Random Functions (VRF)
VRFs are cryptographic primitives that produce random values with a proof of correctness. They guarantee unpredictability, uniform distribution, and verifiability by any third party—making them ideal for high-security applications. - Social Randomness
Gather randomness collaboratively, for example, by having multiple participants contribute entropy and using voting or consensus mechanisms to determine the final value. This distributes risk and reduces the likelihood of manipulation by a single entity.



