A comprehensive toolkit for integrating RISC Zero zero-knowledge proofs with Cartesi's off-chain computation infrastructure. This project demonstrates how to generate zero-knowledge proofs using RISC Zero and verify them within Cartesi's Linux environment through two integration patterns: Cartesi Rollups and Cartesi Coprocessor.
This project combines two powerful technologies:
- RISC Zero: A zero-knowledge virtual machine (zkVM) that enables developers to prove the correctness of computations while keeping input data private.
- Cartesi: A platform providing scalable off-chain computation in a deterministic Linux environment, bridging blockchain smart contracts with powerful off-chain processing.
The toolkit demonstrates two key integration patterns:
-
Cartesi Rollups Integration: Verifies RISC Zero proofs within Cartesi's Linux runtime, enabling privacy-preserving computations in rollups while handling complex verification logic off-chain.
-
Cartesi Coprocessor Integration: Leverages Cartesi Machine for computation-heavy tasks while generating RISC Zero proofs for privacy-sensitive operations, creating hybrid solutions with optimal resource allocation.
The integration consists of three main components:
-
RISC Zero Host Program: Orchestrates the proof generation process, manages the proof generation pipeline, prepares private inputs, and serializes proof data for Cartesi verification.
-
RISC Zero Guest Program: Defines the computation to be proven, optimizes for efficient proving with clear I/O boundaries, and implements selective disclosure and STARK-based proof generation.
-
Cartesi Verifier: Runs inside the Cartesi Machine and validates RISC Zero proofs, managing verification state and reporting results to the rollup or coprocessor.
-
Install Rust & Cargo:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Install Docker Desktop following the Docker Desktop installation guide.
-
Install Foundry:
curl -L https://foundry.paradigm.xyz | bash foundryup
-
Install Cartesi CLI (using Homebrew or NPM):
# Using Homebrew brew install cartesi/tap/cartesi # Or using NPM npm install -g @cartesi/cli
-
Install RISC Zero zkVM:
curl -L https://risczero.com/install | bash rzup install
cartesi-risczero/
├── generate_proof/ # RISC Zero proof generation example
│ ├── host/ # Host program that runs the zkVM
│ └── methods/ # Guest program that runs inside zkVM
├── rollups-verifier/ # Cartesi Rollups verification example
│ └── src/ # Rust application for verifying proofs
├── coprocessor-verifier/ # Cartesi Coprocessor verification example
│ ├── contracts/ # Smart contracts for deployment
│ └── src/ # Rust application for verifying proofs
└── README.md # This file
# Create a new RISC Zero project
cargo risczero new generate_proof --guest-name age_verify
cd generate_proof
# Build and run to generate the proof
RISC0_DEV_MODE=0 cargo run --release
The proof is saved in proof_input.json
and will be used in the next step to verify the proof in the Cartesi Machine.
# Create a new Cartesi Rollups project
cartesi create rollups-verifier --template rust
cd rollups-verifier
# Build and run the application
cartesi build
cartesi run
# Send the proof for verification
cd ../generate_proof
./rollups.sh
# Create a new Cartesi Coprocessor project
cartesi-coprocessor create --dapp-name coprocessor-verifier --template rust
cd coprocessor-verifier
# Start the local development environment
cartesi-coprocessor start-devnet
# Build and publish the application
cartesi-coprocessor build
cartesi-coprocessor publish --network devnet
# Deploy the smart contract
cd contracts
cartesi-coprocessor deploy \
--contract-name MyContract \
--network devnet \
--constructor-args <COPROCESSOR_ADDRESS> <MACHINE_HASH>
# Send the proof for verification
cd ../generate_proof
./coprocessor.sh
RISC Zero supports three types of receipts:
-
Composite Receipt (default): Contains multiple STARK proofs for program segments (>100kb). Best for development and testing.
-
Succinct Receipt: Compressed using STARK recursion with a single unified proof for the entire computation (>100kb). Ideal for production systems with moderate size constraints.
-
Groth16 Receipt: Uses STARK-to-SNARK conversion for maximum compression with trusted setup (less than 1kb). Optimal for on-chain verification and storage-constrained systems.
For on-chain verification and production deployments, Groth16 receipts are recommended due to their minimal size:
let receipt = prover
.prove_with_opts(env, PASSWORD_ELF, &ProverOpts::groth16())
.unwrap()
.receipt;
Important: Groth16 receipt generation requires x86 architecture. If you're on Apple Silicon or another architecture, you'll need to use a remote x86 server, use the Bonsai proving service, or use composite or succinct receipts instead.
For production deployments, we recommend using the Bonsai proving service with Groth16 receipts:
export BONSAI_API_KEY=your_api_key_here
export BONSAI_API_URL=https://api.bonsai.xyz
RISC0_DEV_MODE=0 cargo run --release
- Rust Installation Guide
- Docker Desktop Installation
- Foundry Documentation
- RISC Zero Installation Guide
- Cartesi Documentation
- RISC Zero Documentation
- Cartesi Coprocessor
This project is licensed under the MIT License.