From far off, blockchain can seem a simple distributed ledger technology that ensures the utmost security of data stored in it. But if one observes closely, there are various minuscule but acutely important aspects of blockchain that are usually not discussed in general conversations about the technology. One such aspect is the importance of attaining random numbers for various applications built over a blockchain.

 

While blockchain technology is itself deterministic, randomness generators are required for the security of decentralised applications such as lottery games that rely on the production of random numbers.

 

But why must these applications generate random numbers and why must they be foolproof to the maximum extent?

 

Decentralised applications strategically use randomness to ensure fair and unpredictable play on the ledger. They are decentralised and fully rely on smart contracts for automated processes and transactions. Thus, if a person can predict the outcomes of a random number generator beforehand, they can manipulate the applications in their favour. 

 

This brings us to the three important features of the randomness algorithm:

 

  1. Unpredictable: No one should be able to predict in advance as to what numbers the function will generate next.
  2. Unbiasable: It should be almost impossible to manipulate or influence the numbers produced by the randomness function.
  3. Tamper-proof: The protocol should still work properly in case some nodes go offline or try to manipulate the results.

How to Achieve Randomness?

Developers who build blockchain applications that rely on random numbers must ensure that the randomness generator they choose closely meets the above three conditions. For that matter, developers have the option to rely on either off-chain or on-chain solutions.

 

For one, we have an on-chain solution RANDAO where network participants randomly choose a number and submit a commitment to the privately chosen number. Following this, they use a consensus algorithm to agree on some commitments and reveal all the numbers, where the XOR of the revealed numbers gives the random number.

Another on-chain solution is the Chainlink VRF that generates random numbers using on-chain verifiable random functions. Another on-chain solution is where smart contracts rely on the block hash generated for new blocks. It is an efficient way for random number generation as the hash values of new blocks are highly unpredictable.

 

The common off-chain solution is to source a random number generator through a blockchain oracle. Many consider relying on off-chain solutions risky as it means that the authenticity of the smart contract depends on a third party, which indirectly makes it centralised. In the case of Alacrity, however, developers can depend on its oracle as it is integrated directly to the blockchain and reduces the risk of third party manipulations.

 

There are also other approaches to achieve randomness such as RandShare, threshold signature, RANDAO + verifiable delay function (VDF), NEAR approach, etc.

Conclusion

The lack of an effective function for generating random numbers in a blockchain application may create an opportunity for ill actors to create a bias in the application. Hence, developers must carefully choose what process they use for random number generation. This will play an important role in how trustworthy a blockchain-based application is.