Introducing the Verifiable Random Function (VRF) in Cairo 1

We are thrilled to announce the first phase of Pragma VRF, leveraging verifiable random functions to generate onchain verifiable randomness. Pragma VRF will greatly help numerous smart contracts on Starknet, particularly those that need to prove they use an external, unalterable random source.

The first phase involves publishing the randomness proof as calldata, enabling offchain verification by anyone. Further details on verifying the randomness can be found below.

In the second phase, the proof will be directly verified onchain (to be introduced soon). Users requesting the VRF will need to bear the gas expenses for their callback function and a nominal fee for the randomness request.

1. What is a VRF?

At its core, a VRF is a cryptographic primitive that provides provably fair and verifiable randomness. Unlike traditional random number generators, VRFs are designed to offer a high level of security, ensuring that the outcomes cannot be predicted or manipulated by any party, including those who generate the random number.

1.1. Understanding the Pragma Oracle's VRF

Pragma Oracle uses a specific type of VRF based on elliptic curves, specifically the Curve25519, as recommended by the Internet Engineering Task Force (IETF). This approach is chosen for its security and open-source Python implementation.

When a smart contract needs random numbers, it sends a private seed to Pragma. This seed ensures that the resulting randomness can't be manipulated by Pragma since they don't know the private key needed to calculate it. At the same time, the smart contract and others can't predict the outcome because they don't have access to this private key.

The process works as follows:

  1. A smart contract requests randomness by specifying a random seed.

  2. Offchain, Pragma uses a private key and the seed to generate randomness.

  3. The generated randomness and a proof are sent back to the blockchain.

  4. The smart contract receives this unbiased randomness.

Pragma chose Curve25519 over the more common Bitcoin curve for two main reasons:

  1. Interoperability:

    • Curve25519 is compatible with many other protocols and platforms, improving the ability to work together with different technologies.
  2. Efficiency and Security:

    • A process called "hashing to the curve" is more efficient and secure with Curve25519, using a method called Elligator2.

    • This results in lower costs and safer operations compared to other curves like the Bitcoin curve.

1.2. Pricing

The pricing structure for the randomness function is clear and divided into two components:

  1. Callback Gas Usage: When you request randomness, you specify a callback_fee_limit parameter, which covers the cost in the transaction's fee token. After the randomness is delivered to the consumer contract, any excess fee is refunded.

  2. Premium: This is a decreasing fee paid to the entity fulfilling the randomness request. Currently, it's paid using the transaction's fee token, but in the future, a specialized payment token will be used. Below is the detailed pricing table:

This table outlines the costs associated with different volumes of randomness requests.

2. Use Case: Gaming primitives

The StarkNet ecosystem has successfully attracted a large number of game developers. The implementation of the first VRF in Cairo represents a groundbreaking advancement for onchain games.

Here are a few examples of how games can benefit from this technology:

  • Treasure Hunt: In treasure hunt games, a VRF can be utilized to randomly generate treasure locations on the game map. This ensures each session offers a unique challenge, with treasure placements being unpredictable and non-manipulable.

  • Card Games: VRFs can be applied to shuffle and deal cards, providing a provably fair and random process. This element is vital in games where unpredictability and strategy hinge on the random distribution of cards.

  • Random Quest Generation: VRFs can be used to randomly create quest details such as objectives, locations, and rewards in games featuring quests. This not only boosts replayability but also guarantees a distinctive and impartial experience for every player.

  • Puzzle Games: In puzzle games, VRFs can randomly organize puzzle pieces or generate puzzle patterns. This guarantees that puzzle solving is solely dependent on skill and strategy, free from predictable layouts.

  • Battle Royale Games: VRFs can randomly assign locations for weapons, items, or safe zones in battle royale games. This randomness injects excitement and unpredictability, requiring players to constantly adapt to new game scenarios.

  • Dice Games: In dice-based games, VRFs can be used to simulate dice rolls, ensuring outcomes are truly random and fair. This is especially crucial in games where dice outcomes significantly affect gameplay and final results.

3. Looking Ahead

The introduction of VRF in Cairo 1 is just the beginning. This technology is poised to revolutionize how trust and randomness are perceived in the blockchain space, paving the way for more secure, transparent, and reliable decentralized systems.

Please subscribe and follow us to get the latest updates on the VRF, and more broadly about Pragma.

Subscribe to Pragma
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.