Git Product home page Git Product logo

randomina's Introduction

๐ŸŽฒ RandoMina - Provable Random Numbers on Mina Blockchain ๐Ÿ”

RandoMina enables verifiable random number generation on the Mina blockchain. ๐Ÿ”ข It utilizes Zero-Knowledge (ZK) proofs to ensure the randomness is provable, secure, and trustless. ๐Ÿ”

This protocol has been developed as a part of zkLocus, which enables for authenticated, private and programmable geolocation sharing off & on-chain.

You can learn more about zkLocus at the following links:

๐ŸŒŸ Features

  • ๐Ÿ”€ Provable pseudo-random number generation using ZK proofs
  • ๐Ÿ”’ Secure and tamper-proof, leveraging Mina's decentralized ledger
  • โšก Efficient and scalable, supporting infinite random numbers per block
  • ๐ŸŒ Decentralized and trustless, no need for centralized oracles
  • ๐Ÿ”ญ Transparent and auditable, with open-source code

๐Ÿ“š Overview

RandoMina is a protocol designed to generate pseudorandom numbers on the Mina blockchain. It is implemented as a SmartContract in o1js, and can be either deployed and used individually, or as a part of a customized solution. By leveraging recursive zkSNARKs, RandoMina ensures that the generated random numbers are provably random, fresh and tamper-proof. These properties make RandoMina suitable for a wide range of applications, such as gaming, lotteries, and decentralized finance (DeFi).

How It Works ๐Ÿ”

RandoMina employs a combination of on-chain data and user-specific details to generate pseudorandom numbers:

  • Network State: Utilizes the current network state, including block attributes and timestamps, to maintain freshness and prevent precomputation or prediction of future values.
  • Sender-Specific Nonce: Incorporates a user-specific nonce, derived from the sender's public key, to ensure that each participant generates unique random numbers.
  • Local Seed/Nonce: Allows each user to generate multiple pseudorandom numbers within a single block by varying their own private nonce.

Integration with zkApps and Smart Contracts ๐Ÿงฉ

The RandoMinaContract smart contract facilitates the generation and the verification of pseudorandom numbers by users. It ensures that the numbers are produced using the correct network state and sender information. This contract can be integrated with or serve as a foundation for other smart contracts requiring random number generation. It can be natively used on the Mina blockchain

๐Ÿš€ Getting Started

๐Ÿ’ป Example Usage

// 1. Geneerate random number. This is done off-chain.
const senderPublicKey: PublicKey = getSenderPublicKey(); // set the public key of the sender. this is the account that generates the random number

const networkState: NetworkValue = Mina.activeInstance.getNetworkState();
const currentState: Field = networkState.stakingEpochData.ledger.hash;
const sender: Field = Poseidon.hash(senderPublicKey.toFields());

const randomNumberProof: RandomNumberObservationCircuitProof = await RandomNumberObservationCircuit.generateRandomNumber(
    { networkState: currentState, sender: sender }, // public PRNG params
    randomNonce, // private PRNG param
);

// 1.1 The random number can be extracted from the public output
const randomNumber: Field = randomNumberProof.publicOutput;

// 2. Verify random number. This is done on-chain. Once the proof is verified, the random number can be used in other smart conracts.
// This is achieved by leveraging recursive zkSNARKs.
const txn: Mina.Transaction = await Mina.transaction({ sender: feePayerPublicKey, fee: transactionFee }, () => {
    zkAppInstance.verifyRandomNumber(randomNumberProof);
});

๐Ÿ› ๏ธ How to build

npm run build

๐Ÿงช How to run tests

npm run test
npm run testw # watch mode

๐Ÿ“Š How to run coverage

npm run coverage

Made with ๐Ÿ’œ by the zkLocus Team | Illya Gerasymchuk

randomina's People

Contributors

iluxonchik avatar

Stargazers

 avatar Nguyen Duc Dung avatar Karol  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.