Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
Free 30-min Web3 Consultation
Book Now
Smart Contract Security Audits
Learn More
Custom DeFi Protocol Development
Explore
Full-Stack Web3 dApp Development
View Services
LABS
Guides

How to Review Cryptographic Randomness Sources

A technical guide for developers and auditors on evaluating the security and correctness of cryptographic randomness sources used in smart contracts, ZK-SNARKs, and blockchain protocols.
Chainscore © 2026
introduction
SECURITY PRIMER

How to Review Cryptographic Randomness Sources

A guide to evaluating the security and reliability of randomness generation in blockchain applications.

Cryptographic randomness is the foundation of security for many Web3 applications, from generating private keys and nonces to selecting validators in proof-of-stake networks. A failure in this core component can lead to catastrophic outcomes, including stolen funds or compromised consensus. Unlike pseudo-random number generators (PRNGs) used in general computing, blockchain systems require cryptographically secure pseudo-random number generators (CSPRNGs). These must be unpredictable, non-reproducible by an observer, and resistant to manipulation, even if their internal state is partially revealed.

When reviewing a randomness source, you must first identify its entropy source—the origin of initial unpredictability. Common sources include system entropy pools (like /dev/urandom), hardware random number generators (HRNGs), or verifiable delay functions (VDFs). For on-chain applications, be wary of using past block hashes (e.g., blockhash(block.number - 1)) as a sole source, as they can be manipulated by miners or validators. A robust system often combines multiple entropy sources, a process known as entropy pooling, to mitigate the weakness of any single source.

The next critical review step is analyzing the randomness generation algorithm. Widely vetted algorithms like ChaCha20, AES in Counter Mode, or the NIST-approved DRBG are considered secure. You should verify the implementation uses a properly seeded, well-maintained library, such as crypto.getRandomValues() in Web environments or the secrets module in Python. Avoid custom-built RNGs and deprecated algorithms like Dual_EC_DRBG. Check for common pitfalls like insufficient entropy during seeding, which can lead to predictable outputs.

For decentralized applications, consider the trust model. Verifiable Random Functions (VRFs), like those used by Chainlink VRF or Algorand's consensus, provide cryptographic proof that the randomness was generated correctly and was not manipulated. Alternatively, commit-reveal schemes can mitigate front-running by having participants submit a commitment to a random value before revealing it. Review who controls the randomness oracle or beacon and what economic incentives or slashing conditions ensure its honest behavior.

Finally, integrate continuous monitoring and testing. Use statistical test suites like the NIST Statistical Test Suite or dieharder to analyze output for biases. For smart contracts, implement emergency pauses or fallback oracle mechanisms in case the primary randomness source fails. Always document the assumptions and attack vectors considered, such as long-range attacks, validator collusion, or transaction reordering. A thorough review treats randomness not as a simple utility but as a critical security subsystem requiring defense-in-depth.

prerequisites
PREREQUISITES

How to Review Cryptographic Randomness Sources

Understanding the security and reliability of randomness sources is fundamental for building secure blockchain applications, from NFT minting to consensus mechanisms.

Cryptographic randomness, or cryptographically secure pseudo-randomness (CSPRNG), is a cornerstone of Web3 security. Unlike simple Math.random() in JavaScript, a CSPRNG must be unpredictable and non-reproducible by an adversary, even if they know the algorithm and previous outputs. In blockchain, weak randomness can lead to catastrophic failures: predictable NFT reveals, exploitable gaming outcomes, or vulnerable validator selection in Proof-of-Stake networks. Your first task is to identify where and how randomness is generated in the system you're reviewing.

Common sources in Web3 include on-chain verifiable random functions (VRFs), oracle-delivered randomness, and commit-reveal schemes. Chainlink VRF is a prominent example, providing cryptographically proven random numbers on-chain. Other sources might be block hashes (which are manipulable by miners/validators), pre-commitments from multiple parties, or external entropy from oracles like API3 or Witnet. You must map the data flow: where is the seed generated, how is it transmitted, and who can potentially influence it at each stage?

To evaluate a source, ask specific questions. Is the entropy sufficiently high? A seed should have at least 128 bits of entropy. Is the process verifiable and auditable? Solutions like VRF provide cryptographic proofs. Is it bias-resistant? Be wary of sources like future block hashes, which miners can discard to influence outcomes. Is it unpredictable? Even if you know all public inputs, you should not be able to guess the output. Finally, document the failure modes: what happens if the oracle goes offline or the commit-reveal scheme has a non-participant?

For a technical review, you'll need to examine the code. Look for the randomness generation function and trace its inputs. In Solidity, scrutinize the use of blockhash, block.timestamp, and block.difficulty. Review any integration with external randomness providers, checking for proper verification of proofs, as shown in this simplified check for a Chainlink VRF response:

solidity
function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override {
    // Ensure the callback is from the verified VRF coordinator
    // Store or use the `randomWords` array for your application
}

Your review should produce a clear assessment of the attack surface. Consider front-running, where an attacker sees a transaction and races to submit their own, or validator manipulation in schemes relying on the next block's producer. The assessment must conclude with a risk rating and, if flaws are found, recommend mitigations. These could include switching to a verifiable source, using a multi-source randomness beacon, or implementing a commit-reveal scheme with a delay to prevent last-revealer advantage.

key-concepts-text
SECURITY AUDIT

Key Concepts for Cryptographic Randomness Review

A guide to evaluating the security and reliability of randomness sources in blockchain protocols and smart contracts.

Cryptographic randomness is a foundational security primitive for blockchain applications, powering everything from NFT minting and gaming to validator selection and zero-knowledge proofs. Unlike pseudo-random number generators (PRNGs) used in traditional software, which are deterministic, on-chain applications require verifiable, unpredictable, and bias-resistant randomness. A flawed source can lead to catastrophic failures: predictable NFT traits devalue collections, exploitable game mechanics ruin economies, and biased validator selection compromises network security. Reviewing these systems requires analyzing their entropy source, distribution mechanism, and resistance to manipulation.

The core challenge is the blockchain's deterministic environment. A smart contract cannot natively access a random number without external input. Common solutions include oracles (like Chainlink VRF), commit-reveal schemes, and verifiable random functions (VRFs). Each has distinct security models. For example, an oracle-based solution introduces trust in the provider and secure off-chain computation, while a commit-reveal scheme depends on game-theoretic incentives and a sufficiently large, uncolluding participant pool. The reviewer must map the threat model, identifying who can influence the outcome (users, validators, the protocol itself) and under what conditions.

A critical review examines the source of entropy. Is it derived from a future, unpredictable on-chain property like blockhash? Using blockhash of a future block is insecure, as validators can influence it. Using the blockhash of a past block (e.g., blockhash(block.number - 1)) is publicly known and exploitable by front-running bots. Better entropy mixes multiple sources: block hashes, timestamps, and user-provided data, often through a random beacon like the RANDAO on Ethereum. The delay between randomness generation and its usage is also crucial; a sufficient delay prevents the "last-revealer" from manipulating the result in commit-reveal schemes.

Next, analyze the randomness distribution and consumption. How is the raw entropy processed? It should be fed into a cryptographically secure hash function (like Keccak256) to produce a uniformly distributed number. The contract must ensure the final output is used only once to prevent replay attacks. For example, a common pattern is to hash the entropy with a user-specific nonce or request ID. Review code for common pitfalls: using % (modulo) on the output can introduce bias if the range isn't a power of two; using block.timestamp or block.difficulty alone provides low, miner-influenceable entropy.

Finally, consider economic and systemic risks. Does the system assume rational, non-colluding participants? In a commit-reveal scheme, what prevents a validator from withholding their reveal to block the process? Is there a slashing mechanism or alternative source (like a fallback oracle) for liveness? For high-value applications, a multi-party computation (MPC) or threshold signature scheme (TSS) among a decentralized set of nodes provides stronger guarantees than a single oracle. The review concludes by stress-testing the system against identified threat actors, verifying that the cost of attack vastly outweighs any potential profit, ensuring the randomness remains provably fair and unpredictable.

COMPARISON

Common Cryptographic Randomness Sources

A comparison of on-chain and off-chain sources for generating verifiable random numbers in blockchain applications.

Source / MetricChainlink VRFRANDAO (Ethereum)Commit-Reveal SchemesVerifiable Delay Functions (VDFs)

Randomness Type

Verifiable Random Function (VRF)

Biasable Randomness

Commit-Reveal Randomness

Unbiasable Randomness

On-Chain Verifiability

Provable Unpredictability

Resistance to Miner/Validator Manipulation

Typical Latency

2-5 blocks

1 block

2+ rounds

1-10 minutes

Primary Use Case

Smart contract lotteries, gaming

In-protocol randomness (e.g., PoS)

Multi-party random beacons

Leader election, consensus

Gas Cost (Approx.)

$2-10 per request

~21k gas

Varies by participants

High (computationally intensive)

Decentralization

Decentralized oracle network

Decentralized (validator set)

Requires honest majority

Centralized prover, decentralized verifier

review-steps
CRYPTOGRAPHIC RANDOMNESS

Step-by-Step Review Process

A systematic approach to evaluating the security and reliability of randomness sources used in blockchain protocols, from smart contracts to consensus mechanisms.

02

Analyze the Trust Model

Evaluate who or what you must trust for the randomness to be secure. Key questions:

  • Is it cryptoeconomic (e.g., staked validators in RANDAO)?
  • Is it committee-based (e.g., a drand network of nodes)?
  • Is it oracle-dependent (e.g., Chainlink VRF)?
  • Is it client-side (e.g., a local seed)?

Assess the adversarial model: Can a single entity or a colluding minority bias the output? For example, in early RANDAO, the last revealer could withhold.

04

Verify Liveness and Availability

Ensure the randomness source is reliable and unstoppable. A halted source can paralyze dependent applications.

  • What is the update frequency (e.g., every block, every epoch)?
  • What are the failure modes? If a drand node goes offline, does the network halt?
  • Is there a liveness-assuring mechanism like a fallback RNG or slashing for non-participation?

Examine historical uptime data for oracle-based solutions and the incentive structure for decentralized beacons.

05

Check for Verifiability and Audit Trails

True cryptographic randomness must be verifiably random. Anyone should be able to prove the output was generated correctly.

  • Does the system provide a cryptographic proof? (e.g., a VRF proof + public key).
  • Can the entropy source be audited on-chain? Look for emitted events or precompile outputs.
  • Is there a public audit trail of all contributions? For example, each RANDAO reveal is a transaction.

This step is critical for applications like NFT minting or gaming where users may dispute fairness.

code-patterns
CODE REVIEW PATTERNS

How to Review Cryptographic Randomness Sources

A guide to auditing the security of on-chain and off-chain random number generation, a critical component for applications like gaming, lotteries, and NFT minting.

Cryptographic randomness is a foundational security requirement for many Web3 applications. A predictable random number generator (RNG) can be exploited, leading to financial loss or broken game mechanics. When reviewing code, you must first identify the source of entropy. Common sources include on-chain data like blockhash, block.timestamp, and block.difficulty, or off-chain inputs from oracles like Chainlink VRF. The primary anti-pattern is using a single, manipulable on-chain variable as the sole source of randomness, as miners or validators can influence these values.

For on-chain RNG, scrutinize the combination of entropy sources. A common pattern is to hash multiple unpredictable inputs together: keccak256(abi.encodePacked(blockhash(block.number - 1), block.timestamp, msg.sender)). While better than a single source, this is still weak pseudo-randomness vulnerable to MEV bots who can discard unfavorable transactions. Reviewers should flag any use of block.timestamp or block.number alone. A stronger pattern involves committing to a seed in one transaction and revealing it in a later one, using a commit-reveal scheme to prevent front-running.

The gold standard for production applications is using a verified Verifiable Random Function (VRF). When reviewing code that uses an oracle like Chainlink VRF, check for correct implementation of the request-and-fulfill pattern. Key items to verify include: the presence of a requestRandomWords callback, proper management of the requestId, validation of the VRF coordinator's response using the fulfillRandomWords function, and secure handling of the callback's msg.sender. A critical anti-pattern is failing to check that the callback originates from the legitimate VRF coordinator contract.

Always assess the randomness for bias and distribution. For example, using % (modulo) to reduce a 256-bit random number to a small range can introduce bias if the range isn't a power of two. The secure pattern is to use a library function for unbiased range reduction or to reject numbers that would cause bias. Furthermore, ensure the application logic does not expose the random number before its intended use. A common flaw is emitting it in an event before a critical state change, allowing other contracts to react.

Finally, document the trust model of the RNG. On-chain solutions trust the validator set. Oracle solutions trust the oracle network's cryptography and decentralization. Understand and clearly state these assumptions in your review. For high-value applications, recommend a defense-in-depth approach, such as combining a delayed blockhash with a VRF to mitigate the failure of a single source. The goal is to make the cost of manipulating the randomness exceed the potential profit from an attack.

testing-tools
CRYPTOGRAPHIC RANDOMNESS

Testing Tools and Libraries

Reviewing the security of on-chain randomness sources is critical for fair and unpredictable outcomes in applications like gaming, lotteries, and NFT minting. This guide covers essential tools and methodologies for analyzing and verifying the integrity of these systems.

SECURITY ANALYSIS

Randomness Source Risk Assessment Matrix

Comparative risk assessment of common on-chain randomness generation methods.

Risk FactorBlock Hash (Past)Block Hash (Future)Commit-Reveal SchemeVerifiable Random Function (VRF)

Predictability Risk

Extremely High

High

Low

Negligible

Bias/Manipulation Risk

High

High

Medium

Low

Liveness Dependency

Cryptographic Proof

On-Chain Verifiability

Latency to Result

1 block

1-5 blocks

2+ rounds

1-2 blocks

Gas Cost

Low (<50k)

Low (<50k)

High (>200k)

Medium (100-150k)

Example Protocols

Early NFT mints

Chainlink V1

RANDAO

Chainlink VRF, Witnet

zk-randomness
CRYPTOGRAPHIC REVIEW

Randomness in ZK-SNARKs and ZK-STARKs

A guide to auditing the critical randomness sources that underpin the security of zero-knowledge proof systems.

Randomness is a foundational component of ZK-SNARKs and ZK-STARKs, serving distinct but critical roles in their security. In ZK-SNARKs, a trusted setup ceremony generates a Common Reference String (CRS) using random parameters. If this randomness is compromised or predictable, the entire proof system's security collapses, allowing false proofs. In contrast, ZK-STARKs are transparent and do not require a trusted setup; their security relies on collision-resistant hash functions and public randomness for the FRI (Fast Reed-Solomon IOPP) protocol. The primary audit focus for ZK-SNARKs is the setup ceremony's integrity, while for ZK-STARKs, it's the soundness of the hash-based random oracle and the FRI low-degree testing.

When reviewing a ZK-SNARK implementation, your first task is to audit the trusted setup ceremony. You must verify that the toxic waste—the secret random parameters used to generate the CRS—was securely generated and provably destroyed. Examine the Multi-Party Computation (MPC) protocol used, such as the Powers of Tau ceremony. Key questions include: How many independent participants contributed? Were their contributions verifiably random (e.g., using hardware entropy or public randomness beacons)? Is there a publicly verifiable transcript and final output? A ceremony with a single, non-verifiable participant is a critical vulnerability. Tools like the snarkjs powersoftau challenge provide a framework for verifiable ceremonies.

For ZK-STARKs, the audit shifts to the hash function and randomness generation within the FRI protocol. The prover's commitments and the verifier's challenges are derived from a random oracle model, typically instantiated with a hash like SHA-3 or Rescue. You must ensure the hash function is used correctly as a source of public, verifiable randomness. Review the code that samples random field elements for FRI query positions. These must be derived deterministically from the Merkle root of the execution trace, ensuring the verifier can replicate the process. A common flaw is using a weak pseudorandom number generator (PRNG) or a seed with insufficient entropy for these challenges, which could allow a malicious prover to predict and cheat the low-degree test.

Practical code review involves examining specific modules. For a SNARK library like arkworks or libsnark, look for the setup function and trace the source of randomness for parameter generation. In a STARK library such as Winterfell or starknet, inspect the Prover and Verifier traits for how challenge values are produced. Here's a simplified check for a STARK verifier's challenge generation in a Rust-like pseudocode:

rust
// Audit: Is the challenge derived securely from the transcript?
let mut transcript = Transcript::new(b"stark_proof");
transcript.append(b"commitment", &merkle_root);
// The challenge must be a field element derived from the hash.
let challenge: F = transcript.challenge_scalar(b"fri_query");

Ensure the transcript is a robust hash-based construction and that no external, non-deterministic randomness influences the challenge.

Beyond the core protocols, review the integration layer. Many applications use zero-knowledge proofs within larger systems like rollups or privacy protocols. Verify that any randomness used for nullifier generation (in privacy applications) or rollup batch ordering is also cryptographically secure. A vulnerability in the application's PRNG can leak information or create front-running opportunities, even if the underlying proof system is sound. Always map out all entropy sources in the system diagram, from trusted setup and FRI queries to application-level salts and nonces. Documenting this entropy flow is a crucial part of a comprehensive audit report.

Finally, your review should produce a clear report categorizing findings. Critical risks include a broken trusted setup or predictable FRI challenges. High risks might involve using a non-standard hash function for the random oracle or insufficient MPC ceremony participants. Recommend concrete mitigations: using audited libraries, implementing verifiable delay functions (VDFs) for setup randomness, or adopting public randomness beacons like drand. The security of a zero-knowledge system is only as strong as its most predictable random bit.

CRYPTOGRAPHIC RANDOMNESS

Frequently Asked Questions

Common questions and troubleshooting for developers implementing verifiable randomness in Web3 applications.

Verifiable Random Functions (VRFs) and Verifiable Delay Functions (VDFs) serve different purposes in generating cryptographic randomness.

VRFs (e.g., Chainlink VRF) produce a random number and a cryptographic proof that it was generated correctly from a seed and a secret key. They are fast, on-demand, and ideal for applications like NFT minting or gaming where a single, provably fair random output is needed.

VDFs (e.g., used by Ethereum's RANDAO) introduce a mandatory time delay to compute the result, making them manipulation-resistant for randomness that must be finalized at a specific future time. They are slower and better suited for protocol-level randomness, like selecting validators in a proof-of-stake system.

Key distinction: Use a VRF for immediate, application-specific randomness. Use a VDF for slow, unbiasable randomness that becomes public at a predictable future point.

conclusion
SECURITY REVIEW

Conclusion and Next Steps

This guide has covered the critical components of reviewing cryptographic randomness sources. The next steps involve applying this knowledge to real-world systems.

A thorough review of a cryptographic randomness source requires a systematic approach. Start by categorizing the source (e.g., VRF, RANDAO, commit-reveal). Map the entire data flow from entropy generation to final consumption by the application. For each component, assess its threat model: who are the potential adversaries, and what are their capabilities (e.g., controlling a subset of validators, influencing external APIs)? Document assumptions about trust, such as the honesty of a threshold of participants or the security of an underlying blockchain.

Next, conduct a technical deep dive. For on-chain sources like Chainlink VRF, verify the correct integration of the consumer contract, checking the callback function and fulfillment logic. For beacon chain RANDAO, analyze the influence of proposers and the impact of MEV on randomness manipulation. Review any commit-reveal schemes for proper timing constraints and penalties for non-revealing participants. Scrutinize all external dependencies, such as oracles or trusted execution environments (TEEs), as they often become single points of failure.

Finally, test and simulate the system's behavior under adversarial conditions. Use tools like Foundry or Hardhat to write property-based tests that simulate malicious actors. For example, test if the randomness remains unpredictable even if a validator withholds their reveal. For economic systems, model the cost of attack versus the potential profit. The review is complete only when you can confidently articulate the system's security guarantees and its breaking points. Your final report should provide clear, actionable recommendations for mitigation, such as implementing delay mechanisms or using multiple randomness sources.