Primitives / On-Chain Randomness
Cryptography Blockchain Primitive

On-Chain Randomness

Verifiable random number generation for fair selection, gaming, and unpredictable outcomes on blockchain

What is On-Chain Randomness?

Generating random numbers on blockchain networks presents a fundamental paradox: blockchains are designed to be deterministic systems where every node must arrive at exactly the same result when executing the same transactions. This determinism is essential for consensus, but it directly conflicts with the unpredictability required for true randomness. If randomness could be predicted, malicious actors would exploit it for profit, undermining the fairness that random selection is meant to provide.

The challenge extends beyond mere unpredictability. On-chain randomness must also be verifiable, meaning anyone can confirm that the random value was generated correctly without manipulation. Traditional random number generators rely on entropy sources like hardware noise or user input timing, but these approaches fail in blockchain environments where all inputs must be publicly visible and reproducible. Smart contracts cannot access external entropy sources directly, and any value available on-chain is visible to all participants before a transaction is finalized.

This visibility creates opportunities for manipulation. Miners and validators who propose blocks can potentially influence or selectively include transactions based on random outcomes they can preview. Users can simulate transaction outcomes and only submit when randomness favors them. These attack vectors have led to significant losses in early blockchain applications that relied on naive randomness implementations, driving the development of more sophisticated approaches that provide both unpredictability and verifiability.

Randomness Sources

Block hashes were among the first sources of on-chain randomness, using the hash of a future block as an unpredictable value. The idea seems sound: nobody can predict what transactions will be included in a future block or exactly when it will be mined, making the resulting hash appear random. However, block proposers have some influence over the hash through transaction ordering and timing, and they can choose not to publish a block if the resulting randomness is unfavorable. This manipulation is profitable when the value at stake exceeds the block reward the proposer would forfeit.

RANDAO represents an improvement used in proof-of-stake systems like Ethereum. Each validator contributes a pre-committed random value when proposing a block, and these contributions are combined to produce the final random output. The mixing function ensures that as long as at least one participant is honest and their contribution remains secret until reveal time, the output is unpredictable. However, the last revealer still has one bit of influence: they can choose whether to reveal their value or accept a penalty, effectively having veto power over unfavorable outcomes.

Commit-reveal schemes provide a more robust pattern where participants first commit to a hash of their secret value, then reveal the actual value after all commitments are collected. The random output combines all revealed values, preventing any single party from influencing the result after seeing others’ contributions. This approach works well for applications where all participants have stake in the outcome, but it requires multiple rounds of interaction and can fail if participants refuse to reveal. Many blockchain lotteries and games use commit-reveal, often with timeout mechanisms and stake slashing to ensure participants follow through with reveals.

Verifiable Random Functions

Verifiable Random Functions provide a cryptographic solution that generates provably random outputs tied to specific inputs. A VRF uses a private key to deterministically produce a random-looking output along with a proof that anyone can verify using the corresponding public key. This proof demonstrates that the output was correctly computed from the input without revealing the private key, making it impossible for the key holder to manipulate results by trying different inputs until finding a favorable outcome.

Chainlink VRF has become the dominant solution for dApp developers needing secure randomness. When a smart contract requests randomness, Chainlink oracles generate a VRF output using the request parameters and a block hash as inputs. The oracle submits both the random value and its proof on-chain, where the smart contract verifies the proof before using the value. This architecture ensures that neither the oracle nor the requesting contract can manipulate the outcome: the oracle cannot predict future block hashes, and the contract cannot influence the oracle’s private key operations.

The economic security of VRF systems depends on the oracle’s stake and reputation. Chainlink nodes must stake LINK tokens that can be slashed for misbehavior, and their historical performance affects future job assignments. Alternative VRF implementations exist across different networks, with some chains building VRF directly into their consensus mechanism. Drand, for example, provides a distributed randomness beacon where multiple parties collaborate to generate unpredictable values, offering an alternative trust model that doesn’t rely on a single oracle network.

Use Cases

Validator selection in proof-of-stake networks relies heavily on randomness to determine which validator proposes the next block and which validators form attestation committees. Without unpredictable selection, attackers could predict future proposers and target them with denial-of-service attacks, or colluding validators could coordinate to manipulate the chain. Ethereum’s beacon chain uses RANDAO mixed with validator shuffling to make selection unpredictable while remaining verifiable, ensuring that the consensus mechanism resists manipulation even from well-resourced adversaries.

NFT mints and gaming applications represent the largest consumer-facing use of on-chain randomness. Fair NFT reveals require that neither the project team nor early minters can predict which token IDs correspond to rare traits, preventing insider trading and sniper bots. Blockchain games use randomness for loot drops, combat outcomes, and procedural generation, with players trusting that results are genuinely random rather than manipulated by game operators. The transparency of on-chain randomness actually becomes a feature, as players can verify that games are fair by examining the randomness source.

Lotteries and prize distributions showcase randomness at its most direct. Traditional lotteries require trust in the operating organization, but blockchain lotteries can prove their fairness through verifiable randomness. PoolTogether pioneered no-loss lotteries where deposited funds earn yield and the accumulated interest is randomly awarded to winners, with Chainlink VRF ensuring unpredictable selection. Similar mechanisms power airdrops, raffle systems, and any application where fair random selection from a participant pool is required. The key advantage is that losers can verify they genuinely lost to chance rather than manipulation.

Randomness Attacks

Manipulation attacks exploit the influence that block proposers have over randomness sources. When using block hashes, a miner can compute the randomness outcome before publishing a block and choose to orphan blocks with unfavorable results. This attack becomes profitable when the expected value from manipulation exceeds the orphaned block reward. RANDAO suffers from last-revealer attacks where the final validator to reveal their contribution can compute both possible outcomes and strategically withhold their reveal, accepting a slashing penalty if the favorable outcome justifies the cost.

Biasability refers to the subtle influence attackers can exert even without full control over random outcomes. In commit-reveal schemes, participants who submit their commitments last can bias results by choosing not to participate if early commitments suggest unfavorable outcomes. Front-running attacks allow observers of pending randomness requests to submit their own transactions that depend on the same random value, knowing the outcome before honest participants. These attacks don’t require breaking cryptography but exploit the temporal gaps between randomness generation and consumption.

Solutions combine multiple approaches to minimize attack surfaces. Time-delayed revelation ensures randomness consumers cannot act on values until after a commitment period closes. Threshold cryptography distributes VRF key shares among multiple parties, requiring a quorum to generate random values and preventing any single party from manipulation. Economic penalties make attacks unprofitable by slashing stakes when misbehavior is detected. Chainlink VRF’s architecture, which uses future block hashes as inputs to oracle-generated randomness, eliminates most manipulation vectors by separating the parties who influence different components. Despite these advances, the fundamental tension between determinism and randomness means that on-chain randomness always involves tradeoffs between security, cost, and latency.

Related Primitives