VRF and Lamas Finance’s On-Chain Random Solution on Solana
Introduction
In our pursuit of fairness within our gaming ecosystem, Lamas Finance has adopted the Verifiable Random Function (VRF), an innovative approach to generating unpredictable and unbiased random numbers on the blockchain. Notably, our commitment has not only earned accolades but also the prestigious distinction of being among the initial grant recipients officially approved by the Solana Foundation. In this article, we embark on a detailed exploration of VRF, shedding light on how we meticulously construct our on-chain random solution.
Why Randomness is Challenging on the Blockchain?
Understanding True Random Numbers
A genuine random number is one that is both unbiased and unpredictable. Achieving this in the context of blockchain poses several challenges.
The General Approach
In generating random numbers, a prevalent technique involves a nonlinear recursive expression:
Specifically: The Lehmer Algorithm
In many computer systems, the Lehmer algorithm is employed:
Here, z₀ and a represent the seed numbers. The algorithm ensures an unbiased outcome, but a critical concern arises — the need to guarantee that the seed number itself is unpredictable.
Achieving genuine unpredictability in the seed number becomes a pivotal consideration, and this complexity is heightened in the context of a decentralized blockchain network. In a standard computer, diverse and hard-to-predict elements like CPU temperature, disk activities, and time-based seeds contribute to seed unpredictability. However, the distributed nature of blockchain, with various nodes contributing seed values, necessitates a meticulous approach to ensure the overall unpredictability of the generated random numbers. This intricacy underscores the unique challenges of achieving true randomness within the blockchain environment.
What is VRF?
VRF, short for Verifiable Random Function, stands as a cryptographic cornerstone within blockchain systems. Its primary role is to generate random numbers that are both unpredictable and unbiased. The unique characteristic of VRF lies in its ability to generate these random numbers off-chain while providing a means to verify them on-chain.
The versatility of VRF extends its application across a myriad of scenarios, particularly within the realm of smart contracts. Here are several instances where VRF proves invaluable:
- Building Blockchain Games: VRF plays a pivotal role in creating fair and unpredictable outcomes in various blockchain games such as lotteries, spinners, and the enhancement of in-game items.
- NFT Minting and Distribution: For projects involving non-fungible tokens (NFTs), VRF ensures the random rarity of these digital assets during the minting or distribution processes.
- Consensus Mechanisms (POS): Shuffling the validator set in consensus mechanisms like Proof of Stake (POS) benefits from the use of VRF, introducing an element of randomness in selecting validators.
- Decentralized Network or DAO: The selection of random committee members within a decentralized network or a Decentralized Autonomous Organization (DAO) leverages VRF to maintain a fair and unbiased process.
In essence, VRF serves as a crucial tool for blockchain-based applications that require genuine randomness, offering a secure and verifiable way to introduce unpredictability into various processes.
Chainlink VRF
Chainlink VRF stands out as a provably fair and verifiable random number generator (RNG) designed to empower smart contracts with secure and accessible random values. Serving as an implementation of the VRF algorithm, Chainlink VRF follows a meticulous process to ensure the integrity and reliability of random outcomes.
Here’s a breakdown of how Chainlink VRF operates:
- Request Generation: Whenever a smart contract makes a request for a random value, Chainlink VRF generates one or more random values.
- Cryptographic Proof: Alongside the random values, Chainlink VRF produces cryptographic proof detailing how these values were determined. This proof serves as a transparent and verifiable record of the randomness generation.
- Publication and Verification: The generated random values and their cryptographic proof are published on-chain. This on-chain publication initiates a verification process, ensuring that the information is authentic and has not been tampered with.
- Pre-Usage Verification: Before any consuming applications or smart contracts can utilize the generated random values, the on-chain proof undergoes thorough verification. This step is pivotal in preventing manipulation or tampering by any single entity, including oracle operators, miners, users, or smart contract developers.
Lamas Finance Open-Source VRF
Why do we need this?
While Chainlink VRF stands out as a leading implementation of Verifiable Random Function (VRF), its integration with Solana is yet to be realized. In the Solana ecosystem, alternatives like Switchboard, though available, present certain challenges:
- Cost Concerns: Switchboard can be expensive for extensive random requests, potentially impacting the feasibility of large-scale applications.
- Limited Customization: Switchboard may pose challenges in terms of adaptability for specific use cases due to its structure.
This highlights the need for tailored solutions when implementing VRF in Solana-based projects, taking into account factors like cost-effectiveness and flexibility to meet unique project requirements.
Lamas Finance Open-Source VRF for Solana
Our commitment to innovation extends to providing an open-source VRF tool tailored for Solana builders. This tool empowers developers to deploy their random number generators on Solana-based projects, offering a customizable and cost-effective solution. It’s important to note that this tool serves as a foundational resource and not a fully-fledged oracle. This initiative aims to contribute to the accessibility and adaptability of VRF solutions in the vibrant Solana ecosystem.
Using Lamas Finance VRF in your project
Source code and example can be found here: VRF Github
If you’re eager to harness the power of Lamas Finance VRF for your Solana-based project, here’s a simple guide:
Overall process
On the Contract Side:
- Add the vrf-sdk dependency.
- Utilize the available API to request random numbers and handle callbacks.
On the Server Side:
- Deploy your servers (via Docker, etc.) using the source in vrf-server.
- Add necessary configurations (pubkey, private key, signer key).
- The server will listen to on-chain requests and provide random numbers to the contract.
How it works?
Refer to this chart:
Why no on-chain verification
On-chain verification is omitted due to several factors:
- Limited compute budget for a single transaction.
- Increased cost and time per request.
- Lack of an open-source VRF library suitable for on-chain verification.
Using VRF in your project — Contract side
- Add vrf-sdk as a dependency in your contract:
[dependencies]
vrf-sdk = { git = “https://github.com/Lamas-Finance-Official/solana-vrf" }
2. Request randomness using vrf-sdk:
With the callback instruction as:
fn on_coin_flipped(ctx: Context<CoinFlipResult>,vrf_result:vrf_sdk::VrfResult,bet_amount: u64)
3. Get a random value from the invoked callback:
Using VRF in your project — Server side
- Add the program pubkey to the vrf-server config file, along with signer private key and vrf private key
2. Deploy a single or multiple instance of the server as a Docker container.
Conclusion
Navigating the intricacies of randomness in decentralized applications is no longer a challenge with Lamas Finance VRF. Our open-source solution empowers Solana projects to seamlessly integrate and leverage unpredictable randomness securely. By choosing our VRF, developers gain a reliable and efficient tool, driving fairness and unpredictability in their projects.
Explore the potential, contribute to our open-source initiative, and embark on a journey where your projects meet the dynamic demands of the decentralized future. With Lamas Finance VRF, innovation knows no bounds on the Solana blockchain.