Randomness is an instrument for fun and fairness on the web3. We need it to assign random traits to NFTs during the minting process, to ensure that each token is unique and is distributed unpredictably.
From selecting winners in decentralised lotteries and raffles, to selecting leaders/assign roles in DAOs, and to maximise the entertainment on blockchain gaming — in all things, randomness is indispensable.
Traditionally, randomisation was exercised through straightforward random number generators (RNGs) or off-chain randomness sources.
There’s a reason why both of these methods were not ideal for blockchain applications:
Offchain randomness defeats the purpose of utilising randomisation in any blockchain application, because it involves depending on external source or oracle. This undermines the integrity and trustless nature of blockchain apps because randomness is acquired upon trust that is not absolutely verifiable.
Meanwhile, RNGs are an incomplete process; They lack a deterministic factor upon which all validators can agree on the state of the blockchain. This means that the same random number should be reproducible under the same conditions (The nature of blockchain is such that same input = same output, and the ideal randomisation protocol should match this), but this would not be possible with RNGs.
As viable alternatives, there have been protocols ensuring that randomness is achieved entirely onchain, to achieve verifiability and tamper-proofing:
The blockhash method: Using the hash of a future block to generate random numbers (but this can be manipulated by validators/miners by reordering or withholding transactions).
Verifiable Random Functions (VRFs): To combine on-chain data with cryptographic techniques to generate random numbers that come with a cryptographic proof, making the latter impenetrable.
Randomness beacons: It generates random values independently of the block's core operations to avoid biases and manipulations by validators.
While VRFs provide cryptographic proofs that ensure the randomness has not been tampered with, they can still suffer from liveness and bias issues. A malicious user can preemptively compute the output and decide to abort the protocol if the output is unfavourable, thus biasing the result.
On the other hand, randomness beacons generate random values independently of the block's core operations. While they help avoid biases and manipulations, they often rely on a centralised source or a small set of nodes, introducing trust issues.
Oh! The bane in creating a trusted setup that generates true randomness 😩😔
Fortunately, after examining prior setbacks in establishing onchain randomness, Pyth network recently introduced a breakthrough solution 😎
In the commitment phase, both the requester and the provider prepare their random numbers:
The requester writes a secret number on paper and seals it in an envelope (hashes it). The contents are private.
The provider generates a sequence of random numbers, sealing each in an envelope (producing hashes).
These sealed envelopes are then presented to the network, ensuring the contents remain confidential.
The requester submits their seal (hash of their random number) to the Pyth’s Entropy contract. Entropy assigns a specific number from the provider's sequence based on the requester’s seal.
E.g you give Pyth the seal “h(u)” → Entropy assigns you seal “h(i)” after running it through its function. So, the number that Entropy assigns you is “i”.
Instead of committing your true random number, you give the provider the number that Entropy had assigned you (“i”), in return for a random number.
By revealing the number ‘i’ to them, the true committed number (“u”) is still withheld effectively, maximising security.
At this juncture, the provider will have to verify you: they do so by checking their on-chain sequence number to ensure it is greater than “i” and then reveals a number, Xi.
The requester submits both numbers (theirs and the provider’s) to Entropy. Entropy verifies these numbers using the respective hash functions.
X(u) → concealed and yours
X(i) → from provider
Entropy verifies Xi by checking that h(i) = Xi-1 (provider’s function), and Xu, through h(u) = h(Xu) (contract’s function).
Once both inputs are verified, Entropy combines them to produce the final random number.
Converse to the blockhash method, Entropy reduces the risk of manipulation, since it requires collusion between multiple parties to influence the outcome;
Unlike VRFs, Pyth Entropy enhances the commit-reveal protocol by allowing a single party to commit to multiple random numbers upfront, reducing the number of transactions required and mitigating the liveness issue. This ensures that the protocol proceeds to completion once initiated, providing a more reliable and unbiased source of randomness;
In contrast to randomness beacons, Entropy operates in a decentralised manner, leveraging a commit-reveal protocol that minimises trust between participants. This decentralised approach ensures that the randomness is not controlled by a single entity, enhancing security and trustworthiness.
By pre-committing to random numbers, Pyth Entropy minimises on-chain transactions, leading to faster and cheaper operations (lower gas fee + latency😎).
Pyth Entropy is designed to be easy to integrate into existing blockchain applications. It requires minimal code changes and can be implemented permissionlessly, making it accessible to a wide range of developers
By incorporating the blockhash into the final random number, it adds an additional layer of randomness and security, making it difficult for any single party to predict or manipulate the outcome. As long as one party is honest, the resulting number is guaranteed to be random.
Every step is verifiable on-chain, ensuring the integrity of the random numbers generated.
Optimised randomness ensures genuinely fair and unbiased outcomes in applications like lotteries, games, and NFTs. This fairness is critical for user trust and engagement, particularly in high-stakes scenarios like decentralised finance (DeFi) protocols or NFT auctions.
DeFi protocols often require randomness for tasks like selecting validators, distributing rewards, and managing pools. Using entropy to generate randomness could ensure these processes are conducted fairly and securely, reducing the risk of exploits and increasing overall protocol stability.
Efficient randomness protocols reduce the computational resources and gas fees required to generate and verify random numbers on-chain, making a wide range of applications more economically viable on the blockchain,
Randomness enhances high-frequency and high-throughput applications, like real-time gaming and trading platforms, without compromising security or fairness.
Users can independently verify the randomness used in their interactions with blockchain applications, building confidence and allowing broader participation in Web3 activities.
Perhaps, DAOs can utilise optimised randomness for decision-making processes, member selection, and distribution of roles and responsibilities, ensuring unbiased and fair governance mechanisms.
References:
BitKan. "What Is Pyth Entropy? How Does Pyth Entropy Work?" Accessed June 17, 2024. https://bitkan.com/learn/what-is-pyth-entropy-how-does-pyth-entropy-work-24764.
IETF. "Verifiable Random Functions (VRFs)." Accessed June 17, 2024. https://www.ietf.org/archive/id/draft-irtf-cfrg-vrf-13.html.
Pyth Network. "Pyth Entropy: Random Number Generation for Blockchain Apps." Accessed June 17, 2024. https://pyth.network/blog/pyth-entropy-random-number-generation-for-blockchain-apps.
Pyth Network. "Secure Random Numbers for Blockchains." Accessed June 17, 2024. https://pyth.network/blog/secure-random-numbers-for-blockchains.
Supra. "An Analysis of Verifiable Randomness in Web3." Accessed June 17, 2024. https://supra.com/academy/an-analysis-of-verifiable-randomness-in-web3.
a16z Crypto. "Public Randomness and Randomness Beacons." Accessed June 17, 2024. https://a16zcrypto.com/posts/article/public-randomness-and-randomness-beacons.
ResearchGate. "Entropy as a New Entrant for On-chain Randomness." Accessed June 17, 2024. https://www.researchgate.net/publication/381352758_Entropy_as_a_New_Entrant_for_On-chain_Randomness/download.
MonoSwap. "Pyth Entropy." Accessed June 17, 2024. https://docs.monoswap.io/protocol/or-pyth-entropy.
GitHub. "Randomness Beacon." Accessed June 17, 2024. https://github.com/hmason/randomness_beacon.
MPost. "Pyth Network's On-Chain Random Number Generator Pyth Entropy Launches on Mainnet." Accessed June 17, 2024. https://mpost.io/pyth-networks-on-chain-random-number-generator-pyth-entropy-launches-on-mainnet.
NCC Group. "Exploring Verifiable Random Functions in Code." Accessed June 17, 2024. https://research.nccgroup.com/2020/04/03/exploring-verifiable-random-functions-in-code.
Hackaday. "NIST Randomness Beacon." Accessed June 17, 2024. https://hackaday.com/2014/12/19/nist-randomness-beacon.
HackRead. "Blockchain Randomness: Eliminate Trust Issues." Accessed June 17, 2024. https://hackread.com/blockchain-randomness-eliminate-trust-issues.
Supra. "On-Chain Randomness Fulfillment via Verifiable Random Functions." Accessed June 17, 2024. https://supra.com/academy/on-chain-randomness-fulfillment-via-verifiable-random-functions.
Reddit. "NIST Randomness Beacon: Actual Random Numbers and Their Uses." Accessed June 17, 2024. https://www.reddit.com/r/programming/comments/1q6m5d/nist_randomness_beacon_actual_random_numbers_and/?rdt=42200.
Pyth Network. "Protocol Design - Entropy." Accessed June 17, 2024. https://docs.pyth.network/entropy/protocol-design.
NCC Group. "Rigging the Vote: Uniqueness in Verifiable Random Functions." Accessed June 17, 2024. https://research.nccgroup.com/2023/05/18/rigging-the-vote-uniqueness-in-verifiable-random-functions.
Lee, Charles J. "Bitcoin Beacon." Accessed June 17, 2024. https://charlesjlee.com/post/20170716-bitcoin-beacon.
Twitter. "Pyth Network on Twitter." Accessed June 17, 2024. https://twitter.com/PythNetwork/status/1745853276539507105.
Ethereum Stack Exchange. "Can Matic (Polygon) Block Producers Easily Manipulate Block Hash?" Accessed June 17, 2024. https://ethereum.stackexchange.com/questions/112997/can-matic-polygon-block-producers-easily-manipulate-block-hash.
"Commitment Scheme." n.d. Wikipedia. Accessed June 17, 2024. https://en.wikipedia.org/wiki/Commitment_scheme.
Pyth Network. n.d. Pyth Network Official Website. Accessed June 17, 2024. https://pyth.network.
"Python — EntropyHub 2.0 Documentation." n.d. EntropyHub. Accessed June 17, 2024. https://entropyhub.com/documentation.
"Entropy." n.d. Pyth Network Documentation. Accessed June 17, 2024. https://docs.pyth.network/entropy.
"Timed Commitments Revisited." n.d. Cryptology ePrint Archive. Accessed June 17, 2024. https://eprint.iacr.org/2024/000.
"Protocol Design - Entropy." n.d. Pyth Network Documentation. Accessed June 17, 2024. https://docs.pyth.network/protocol-design-entropy.
"Safety." n.d. Ethereum Wiki. Accessed June 17, 2024. https://wiki.ethereum.org/safety.
"Introduction – Pyth Network Documentation." n.d. Pyth Network Documentation. Accessed June 17, 2024. https://docs.pyth.network/introduction.
"Example Applications – Pyth Network Documentation." n.d. Pyth Network Documentation. Accessed June 17, 2024. https://docs.pyth.network/example-applications.
"Best Practices – Pyth Network Documentation." n.d. Pyth Network Documentation. Accessed June 17, 2024. https://docs.pyth.network/best-practices.
"Pyth Entropy." n.d. Pyth Entropy Documentation. Accessed June 17, 2024. https://docs.pyth.network/entropy.
"Cryptographic Commit-Reveal Scheme." n.d. Ethereum Wiki. Accessed June 17, 2024. https://wiki.ethereum.org/cryptographic-commit-reveal-scheme.
"DeFi and Web3 Applications." n.d. DeFi Pulse. Accessed June 17, 2024. https://defipulse.com/defi-and-web3-applications.