justinfrevert / risc-roll

Substrate RISC Zero for rollups hackathon project
The Unlicense
3 stars 1 forks source link

Risc-roll

Update

This project is often referenced in conversations on examples of RISC Zero usage with Substrate. If you are looking for such examples, please see:

This repository serves as a Proof of Concept (POC) for a prover which can serve as a zkrollup of a Substrate-based chain. Our goal is to explore the possibilities of enabling Substrate/rust developers to leverage zk proofs generally, and not necessarily within the context of rollups, without the difficulty of circuit design, and at any level throughout the Substrate stack.

We try to exemplify this through a zk-prover of an extrinsic: balance transfers, for use in a zkrollup. Substrate developers are in a unique position to selectively roll up parts of their chain and enshrine the rollup results simply and in pasteable code similar to the pallet that we show due to Substrate's modularity. In the future, it may be possible to rollup any substrate pallet through some process that generates the appropriate guest code for it. In lieau of such a process, we show that this is a simple process to perform manually.

In other words, this is like a simplified version of the R1CS payment tutorial, which instead uses Risc0 and is also enshrined on-chain.

This project was developed over the course of one month at the 2023 Consensus Web3athon

Technology and Terms

Risc0

Risc0 is a general purpose STARK-based zero-knowledge virtual machine(ZKVM). Developers can write programs in languages such as Rust and C++ using Risc0, and produce a proof based on the program's execution which allows a separate party to verify that program's execution without access to the inputs that were given to it. For a more technically accurate and detailed explanation, see the Risc0 docs. In this project's documentation, we make claims about ease and accessibility around zk proofs and developer's ability to generate them from pure rust - that is all enabled by Risc0's technology.

Substrate

Substrate is a blockchain development framework written in Rust. Substrate provides out-of-the box client modules for networking, database, consensus, and a WASM runtime which boasts more modularity in the form of a concept of "pallets". Pallets are a notable feature because they give the blockchain developer a different mindset around deploying onchain logic compared to smart contracts due to the level of control and access they have over the blockchain. You can find the Substrate documentation website here.

This level of control is demonstrated in this project, as we demonstrate giving trust to the verified proofs generated by the known prover + known program to execute large state changes onchain, in a way we would not be able to on other blockchains. This is somewhat of a Substrate analogue to enshrined rollups, given in a few lines of code.

Goals

Our project has the following objectives:

Scope

To maintain focus and deliver a meaningful POC, our project(for the initial hackathon) has the following scope:

Project Overview

Our project comprises the following components:

The typical Substrate structure of ./node, ./runtime, and ./pallets exists in this project. The custom pallet can be found in ./pallets/template

architecture

Performance

Some initial testing(not actual benchmarks) Macbook i7 16GB RAM(without metal feature)

Development

Local development is based around the main workflow of sending proofs to the locally running Substrate node.

Pre-requisites

Install Rust Substrate

Start local node

  1. In the root of the directory:
    cargo build --release
  2. Start the node with local dev options:
    ./target/release/node-template --dev

Run Prover

  1. Navigate to prover directory
    cd ./provers/transfer
  2. Build:
    cargo build --release
  3. Run prover
    ../../target/release/prover-host

The prover will prove the transactions in ./provers/transfer/transactions.json, send the proofs to the chain, which will verify and change the balances state, if the proof is verified.

When making changes: ensure you keep the image id and subxt metadata up-to-date to avoid errors. See provers/transfer/README.md