Some things are best left to chance.
In fact, quality randomness is highly sought-after. Game economies use randomness as a part of their system to reward players. DeFi pools use RNGs (random number generators) to pick and disburse pool yields to the winning user.
But how do you create “good” randomness and chance?
Introducing on-chain VRFs.
A Verifiable Random Function (VRF) is a cryptographic function that produces unpredictable, publicly verifiable random values. Many chains use VRFs to randomly select proposals for block nodes in their consensus protocol, while other on-chain services use it to generate random numbers with on-chain proofs.
But isn’t it super-easy to generate random values? Why would I need to resort to an on-chain solution?
One word. Trust.
Trust forms the foundation of all blockchain activities; GameFi, DeFi, or otherwise.
A trustworthy, fair and just randomness is:
- Tamper-proof, and
- Provably random
The biggest advantage of on-chain VRF is not the randomness it generates, but the validity of the randomness generated.
Consider the immensely popular mobile game Clash Royale. Players fight P2P battles to win gold and Chests of varying rarity. The probability of whether you’d receive a Legendary chest or the low-tier Silver Chest feels random — but a lot of players use third-party apps to check their chest cycles and “predict” what their next chest rewards will be.
Similarly, there are many games — both online and on-chain — where players take advantage of the lack of good randomness.
The algorithms generating randomness are opaque and not complex enough, hence people are able to exploit the system — leading to an unfair distribution of rewards.
A good VRF can provide good, unpredictable randomness. But why does it need to be on-chain?
Take, for example, a generative NFT which is a part of a GameFi project. The smart contract that generates random properties for the NFT requires variables as input for the RNG (random number generator).
But RNG solutions for smart contracts are prone to tampering. Using on-chain data like block hash, wallet addresses leaves the data susceptible to hackers; while off-chain solutions are opaque and are not verifiably random.