New Proposal
Cartesi PRNG
This project is a component of a larger set of tools for generating 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 a easy and affordable way to generate random numbers.
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, specially 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 this algorithm will interact with the Cartesi environment to generate a trustless random number.
Drand PRNG
Bob initiates a new random number process by sending an input to the Cartesi Rollups. The frontend is unaware of whether the DApp backend inside the Cartesi Machine will require a random number. As needed, the DApp backend will request a random number from the Random Server. The Random Server will then signal the Convenience Middleware to hold all subsequent inputs until the beacon arrives.
The Convenience API will periodically inspect the Cartesi Machine to check if there are any inputs awaiting a beacon. When the Convenience API detects an input waiting for a random number, it will request the latest beacon from the Drand network and send it to the Cartesi Rollups.
The Random Server will calculate the creation time of the beacon by subtracting a safe number of seconds to prevent any prior knowledge of the beacon by the user. Within this safe time, it will load the pending random requests sent before that timestamp and respond with a generated seed. Finally, the DApp will receive that seed to generate a random number.
When an input backend execution requesting a random number arrives, it will force any subsequent inputs (whether they require a random number or not) to be stored until the next Drand beacon arrives. This rule ensures the correct sequence of input execution.
We know that the user’s DApp calls the rollup server, we change the arrow direction to make the problem easier to think about. In reality, DApps will call our middleware and our middleware will call the rollup server.
The DApp’s owner can run an instance of the Convenience API to provide this random number functionality.
Milestones
Milestone 1: Convenience POC
POC to demonstrate the use case of generating a random number with the Convenience tools.
-
Duration: 8 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 Convenience Middleware with a new attribute in input_metadata to receive the generated seed;
-
A library for the Cartesi Machine that obtains all the seeds and produces a random number sequence;
-
A Convenience API (web2 application) that reads the drand’s beacon and sends it to Cartesi Rollups as needed;
-
An example of a simple game project that can help new developers learn how to use the solution;
- Funds request (USD) for milestone 1: $10,500 USD
Milestone 2: Convenience Edge Cases
-
Duration: 5 weeks
-
Deliverables:
-
A list of edge cases (Drand signature error, drand timeout);
-
An method to update the Drand’s public key;
-
An automated tests to cover edge cases;
- Funds request (USD) for milestone 2: $6,563 USD
Milestone 3: Convenience Web3 Client
- Duration: 3 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;
- Funds request (USD) for milestone 3: $3,937 USD
Total funds requested
$21,000 USD
About your Team
Calindra
Calindra helps our partners to execute their digital strategy through a experienced and talented team.
Contributions to the Cartesi community:
Links and resources
Website: calindra.tech
LinkedIn: /company/calindra
Github: /Calindra
ERC-20 Payee address
0x7cE0AA3DFbB8abdCD0Ea426769ffD21302DAA8B8