Verifiable Random Function (VRF)

Definition
DEFINITION

A verifiable random function (VRF) is a cryptographic function that takes a series of inputs, computes them, and produces a pseudorandom output and proof of authenticity that can be verified by anyone.

In cryptography, a verifiable random function (VRF) is a random number generator (RNG) that generates an output that can be cryptographically verified as random. Verifiable randomness is essential to many blockchain applications because its tamper-proof unpredictability enables exciting gameplay, rare NFTs, and unbiased outcomes.

In this article, we examine what verifiable random functions are, explore how randomness is used in blockchains, and see how smart contract developers can leverage a secure source of randomness in their own dApps using Chainlink Verifiable Random Function (VRF).

What Is a Verifiable Random Function (VRF)?

A verifiable random function is a cryptographic function that takes a series of inputs, computes them, and produces a pseudorandom output, along with a proof of authenticity that can be verified by anyone.

Inputs for a VRF typically include a public/private key pair (also known as a verification key and secret key) and a seed. A public/private key pair is created and a seed is selected. Those values are passed into the VRF, where the private key and seed are used to generate a random number. The VRF then outputs a random number along with a proof. Critically, the generation of a proof makes the function verifiable, while keeping the private key hidden ensures the number is unpredictable.

As the name suggests, a verifiable random function is defined by its core features:

  • Verifiable—Anyone can verify that the random number generated by a VRF is valid. All they need to do is inspect the proof and verify the correctness of the hash output. While only the holder of the VRF secret key can compute the hash, anyone with the public key can verify the correctness of the hash.
  • Random—The output of a VRF is entirely unpredictable (uniformly distributed) to anyone who doesn’t know the seed or private key and follows no pattern. In a VRF, every possible output is equally likely. The randomness is generated by combining the seed and private key in a unique manner.
  • Function—VRFs rely on a mathematical algorithm to produce both the random number and a proof that verifies its authenticity. For a function to be considered a VRF, the RNG must keep the seed hidden (implicit) to preserve its unpredictability, while the proof must be explicit and calculable by everyone (explicit) to ensure its verifiability.

History of VRF

The concept of verifiable random functions was introduced in a paper published by acclaimed computer scientists and mathematicians Silvio Micali, Michael Rabin, and Salil Vadhan in 1999. Notably, Silvio Micali went on to launch the Algorand blockchain, which uses a VRF in its consensus mechanism.

There have since been a number of key breakthroughs in the development of VRFs. The technology was improved in 2005 when Yevgeniy Dodis and Aleksandr Yampolskiy enhanced its efficiency by utilizing a collision-resistant hash function that enabled shorter proofs and keys. Then in 2015, Dennis Hofheinz and Tibor Jager created a provably secure VRF using elliptic curve cryptography. And in 2019, Nir Bitansky showed that VRFs can be constructed with general primitives rather than simply algebraic constructions. Many VRF implementations today rely on these innovations.

Interestingly, in 2020 researchers proposed a VRF that uses lattice-based cryptography that’s secure enough to protect against attacks from a quantum computer, suggesting that VRF can remain an important technology long into the future.

VRF Use Cases

Most RNGs don’t produce a random number that can be cryptographically verified, leaving them vulnerable to manipulation and thereby limiting their use cases. By guaranteeing the security of a random number, VRFs unlock a number of important use cases such as:

  • Internet security—VRF is used to help secure domain name system (DNS) messages.
  • Zero-knowledge technology—VRF is used in the protocol design for zero-knowledge proofs and zero-knowledge databases.
  • Non-interactive lottery systems—VRF enables provably fair and efficient outcomes for lotteries.
  • Verifiable transaction escrow schemes—VRF can help support automated escrow services that preserve user anonymity.
  • Blockchains and smart contracts—VRF has become an important part of decentralized protocols and applications.

VRF in Blockchain

A number of layer-1 blockchains, including Algorand, Cardano, Internet Computer, and Polkadot, use VRF in their consensus mechanisms to randomly select block producers.

Elsewhere in the blockchain technology ecosystem, smart contract developers also require a source of randomness for their applications. However, on-chain applications do not have access to a secure RNG due to the deterministic nature of blockchain networks. Using on-chain blockhashes as a source of randomness can result in manipulation by blockchain miners/validators who discard blocks with unfavorable hashes and can “re-roll the dice,” changing the RNG value. Naive off-chain solutions are opaque and provide no proof that the RNG value produced is legitimate and has not been manipulated by either the data source or oracle node.

Blockchain miners/validators can exploit blockchain-based RNG solutions.
Blockchain miners/validators can exploit blockchain-based RNG solutions.

Well-designed systems relying on randomness would ideally want it to be provably fair and equally uncertain to all contract participants and also reduce the risk that an adversary could exploit contracts by predicting its outcomes.

Conclusion

In the blockchain space, Chainlink VRF is the industry-leading secure random number generator (RNG), enabling smart contracts and off-chain systems to access a verifiably tamper-proof source of randomness.

Providing a source of randomness that is both cryptography secure and verifiable enables developers to build systems that are more open, accessible, and tamper-proof than the current alternatives. Ultimately, Chainlink VRF and smart contracts help fulfill the blockchain vision of moving society away from weak trust-based systems and toward stronger math-based systems built on cryptographic truth.

If you’re a developer and want to quickly get your application connected to Chainlink VRF, visit the developer documentation and join the technical discussion on Discord. If you want to schedule a call to discuss the integration more in-depth, reach out here.

Learn more about blockchain technology

Get the latest Chainlink content straight to your inbox.