New Proposal
Cartesi PRNG
A set of tools to generate random numbers on Cartesi’s convenience layer.
Project Description
The goal of this project is to create a framework for Cartesi that will make it easy for web3 developers to create DApps using Cartesi. The framework will:
- use React and TypeScript to create a modular and reusable component library that will provide a common PRNG (Pseudo-Random Number Generator) algorithm to Cartesi technology;
- use Web3.js and Cartesi’s SDK to connect to the blockchain and the Cartesi Machine;
- be documented with Docusaurus;
- be published on npm and GitHub and maintained with semantic versioning.
Our project will offer three different ways to generate random numbers, each with its own advantages and disadvantages:
- The first type uses block number, clock, and end user ethereum address to make a seed. This is a simple way to generate a seed that depends on some external factors that are hard to predict or manipulate. However, this type of PRNG may not be very secure or random, as it may be vulnerable to attacks or biases.
- The second type uses VDF - Verifiable Delay Function, which will produce an unpredictable result in the future while the blockchain network is making another block. That way, the resulting seed cannot be predicted or biased. Also, the VDF result can be provided by anyone to avoid tampering.
- The third type uses a hash function to commit to a number that will be revealed in the future and generate the seed. This is a more secure and random way to generate a seed, as hash functions are designed to produce outputs that are unpredictable and uniformly distributed. However, this type of PRNG may require more transaction steps and may not be very efficient.
Value proposition
We believe that creating these tools for developers we remove a important entry barrier for them. Random numbers are an essential part of many apps and DApps, specialy games. So, as we add this feature to the convenience layer, we expect to see an increase in Cartesi’s adoption and in our community growth.
Here are some types of games that could benefit from this framework:
- A decentralized soccer game that uses Cartesi’s random algorithm to generate fair and unpredictable moves for both players;
- A decentralized card game that uses Cartesi’s off-chain computation to handle encryption algorithms and game logic to randomize the deck;
- RPG games that use PRNGs to determine loot drops, enemy spawns, critical hits, etc.
How you will use Cartesi, specifically?
This project aims to add tooling to build DApps on Cartesi, and this is why it makes sense to have community’s support. The following sections describe how each of the algorithms will interact with the Cartesi environment.
Simple PRNG
The Simple PRNG scheme is unpredictable and verifiable, but it is biasable because the block proposer for a given slot can directly manipulate the block’s hash by manipulating the block’s body.
VDF PRNG
For this type of PRNG, we will use a VDF - Verifiable Delay Function for cryptography. A VDF is a function that takes a certain amount of time to compute, and cannot be accelerated through parallelization or additional processors. Once computed, the output can be quickly verified by anyone.
- Define a VDF that takes twice as long as the block production time.
- Send an input to initiate the process and obtain the block hash of the transaction block: BlockHash[0].
- Compute
VDF(BlockHash(N))
and send the result to the contract. - Meanwhile, the network will produce the next block hash:
BlockHash(N+1)
. - The contract will combine the VDF results with the block hash and generate a random number.
- Send the number to the target contract.
This algorithm can be exploited by the leader only, if the leader has a sequential processing power more than twice as high as the network’s. To illustrate, let’s imagine a hypothetical scenario: The leader generates the blockhash, calculates the result of the VDF and if it is not favorable, he generates another blockhash.
Hashed Turn Based Seed for PRNG
Based on the commit-reveal but applied to PvP games where the result can be WO.
The commit-reveal is a cryptographic scheme that allows players to hide their choices until they are revealed later. It is used to prevent front-running attacks, where someone can see the transactions in the pool and act before them. The commit-reveal has two phases: a commit phase, where the players send their hashed choices to a smart contract, and a reveal phase, where the players reveal their choices and the contract verifies them. The contract then uses the choices to generate a random outcome for the game.
PvP games are player versus player games, where two players compete against each other. Examples of PvP games are rock-paper-scissors, even or odd, or poker.
The result can be WO means that the result can be a walkover, which is when one player wins by default because the other player does not show up, forfeits, or fails to reveal their choice.
Milestones
Milestone 1: Simple PRNG
-
Duration: 4 weeks
-
Deliverables:
- An automated build and test process of the npm library artifact using Github Actions;
- An automated packaging and release process for the npm library;
- The entire codebase under a permissive MIT open-source license;
- A readme file that explains the project;
- A smart contract with a new attribute in input_metadata to receive blockhash;
- A library for the Cartesi Machine that obtains all the seeds and produces a random number sequence
A simple method to generate random numbers
- Funds request (USD) for milestone 1: $8,000 USD
Milestone 2: VDF PRNG
-
Duration: 6 weeks
-
Deliverables:
- An automated build and test process of the library artifact using Github Actions;
- An automated packaging and release process for the npm library;
- The entire codebase under a permissive MIT open-source license;
- A readme file that provides an overview of the project;
- A smart contract with:
- a new method to verify the VDF result;
- a new method to register the configuration;
- a new attribute in input_metadata to receive the seed;
- A library for the Cartesi Machine that obtains the generated seed and produces a random number sequence
- Funds request (USD) for milestone 2: $12,000 USD
Milestone 3: Hashed Turn Based Seed for PRNG
- Duration: 8 weeks
-
Deliverables:
- An automated build and test process of the library artifact using Github Actions;
- An automated packaging and release process for the npm library;
- The entire codebase under a permissive MIT open-source license;
- A readme file that provides an overview of the project;
- A smart contract with:
- a new method to register the commit hash;
- a new method to check the revealed result;
- a new attribute in input_metadata to receive the seed;
- A library for the Cartesi Machine that obtains the generated seed and produces a random number sequence
-
Funds request (USD) for milestone 3: $16,000 USD
Total funds requested
$36,000 USD
About your Team
Bruno Ochotorena
Web3 Developer
LinkedIn: /in/sandhilt
Fabio Oshiro
Web3 Specialist
LinkedIn: /in/fabiooshiro
Contributions to the Cartesi community:
Links and resources
Website: calindra.tech
LinkedIn: /company/calindra
Github: /Calindra
ERC-20 Payee address
0x7cE0AA3DFbB8abdCD0Ea426769ffD21302DAA8B8