Introducing Harmony Verifiable Random Function (VRF)

Rongjian Lan
Harmony
Published in
4 min readJul 8, 2021

--

A fair and provably secure random source on blockchain is the prerequisite for building trust-worthy decentralized applications. A good source of on-chain randomness needs to be unpredictable, unbiasable, verifiable and immediately available. It’s unpredictable when no one can predict the output before it’s generated; unbiasable when no one can influence the output of the random source; verifiable when the random output can be cryptographically proved to be valid; and immediately available when a new randomness is produced for every block and can be directly utilized by any smart contract without extra fees.

Blockchain developers have been struggling to find a secure source of randomness so they fall back to secondary solutions such as the block hash. Block hash is not secure randomness since the block miners have the ability to bias the output to their favor by grinding on the block hash. A better solution than block hash is to rely on blockchain oracle to provide a secure randomness when requested. However, oracle-based randomness is not immediately available since there will be a delay of a few blocks before the randomness is fed back to the requesting smart contract and such request is not free.

Secure On-chain Randomness using VRF

Harmony brings the technology of VRF (Verifiable Random Function) natively on chain to create an optimal solution for randomness that is unpredictable, unbiasable, verifiable and immediately available. Harmony VRF is a unique construction based on our existing cryptographic primitive of BLS signatures which makes the computation efficient without extra burden to our network validators. Harmony VRF is available for every single block and any smart contract can access the random output through a precompiled contract without paying additional fees.

Harmony supports the on-chain verifiable random source based on VRF. Specifically, for every new block, the block producer uses its BLS private key with the last block hash to produce a 32-bytes VRF output and 96-bytes proof. The VRF output and proof are concatenated as a 128-bytes data and put in the VRF field of the newly proposed block. The VRF is available to be consumed by any chain clients by querying the block header. We also exposed the VRF data in the smart contract level via a new EVM precompiled contract at address 0xff which any smart contract on Harmony can access through StaticCall (see code example).

How Harmony VRF is Constructed

Harmony builds on the existing cryptographic primitive of BLS signatures which are currently used for block signing and consensus to create an efficient and secure VRF construction. The BLS-based VRF works as follows. Given a VRF input M, a BLS private key SK is first used to sign on M to produce a signature S=sign(SK, M). Then the signature is hashed with sha256 to produce the VRF random output R=hash(S), and the signature itself becomes the VRF proof P=S. The VRF output R can be verified with the proof P by checking that P is the correct signature from PK on message M and that hash(P)=R. More formally, the BLS-based VRF construction (Keygen, Compute, Verify) can be specified as follows:

  • Keygen(r) → (PK, SK). The BLS key generation algorithm produces a pair of public key PK and private key SK.
  • Compute(SK, M): Hash(Sign(SK, M)) → (R, P). The computation of VRF output R is the hashing of the signature signed with the private key SK on message M. The VRF proof P equals the signature from Sign(SK, M).
  • Verify(PK, M, R, P): SigVerify(PK, P, M)=True & Hash(P)=R. The verification of the VRF works by checking 1) the VRF proof P is the correct signature from public key PK and message M; 2) the VRF output R equals the hash of P.

What Harmony VRF Brings to your Dapps

Harmony VRF brings the opportunity for developers to build trust-worthy and fair Dapps and protocols on chain. To name a few potential applications using VRF:

  1. Make blockchain games provably fair and entertaining by using VRF to generate random game scenarios, distribute loot fairly and shuffle players unpredictably.
  2. Randomly and fairly assign tasks or assets to participants of DAO, DeFi or NFT.
  3. Select a random sample of protocol validators or governance voters from all participants for consensus or decentralized governance.

With Harmony VRF, a new realm of randomness-based trust-worthy applications can be built natively on Harmony blockchain. Developers with a security-focused mindset can feel safe to build applications using Harmony’s secure on-chain randomness. It’s guaranteed by cryptography with verifiable proof that no malicious participants are able to predict or influence the random outcome and make unfair profits. Additionally, Harmony VRF is available on every block of all 4 shards in Harmony and is easily accessible through a simple smart contract call without extra fee.

Harmony VRF extends the functionalities of Harmony blockchain further to allow the building of secure and fair Dapps using on-chain randomness. We welcome all developers to try out Harmony VRF and build interesting Dapps with it.

About Harmony

Build on Harmony, run on all chains.

Harmony is your open platform for assets, collectibles, identity, governance. Be the ONE to bridge to all blockchains.

Harmony is an open and fast blockchain. Our mainnet runs Ethereum applications with 2-second transaction finality and 100 times lower fees. Harmony’s secure bridges offer cross-chain asset transfers with Ethereum, Binance and other chains. https://www.harmony.one/

We ❤️ Developers.

Got an idea? Build it on Harmony and Apply for a Grant.

Telegram | Twitter | Discord | Youtube | Medium | Facebook | LinkedIn | Reddit | Instagram

--

--