var img = document.createElement('img'); img.src = "https://nethermind.matomo.cloud//piwik.php?idsite=6&rec=1&url=https://www.surge.wtf" + location.pathname; img.style = "border:0"; img.alt = "tracker"; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(img,s);
Skip to main content

SP1 & RISC Zero Provers

This guide provides step-by-step instructions to set up SP1 and RISC Zero provers. Due to the compatible nature of SP1 and RISC Zero, they can be run on the same machine, so the instructions for both provers are combined in this guide.

Prerequisites

  • Machine with CUDA support
  • Docker
  • L1 accounts with funds (one for the prover, one for prover registry)
  • L1 RPC URL

Overview

This guide covers setting up CUDA, CUDA Container Toolkit, and other dependencies required to run SP1 and RISC Zero provers on an x86 machine.

For detailed information, refer to:


Uninstall Existing CUDA (optional)

Reference: NVIDIA CUDA Installation Guide - Handle Conflicting Installation Methods

Use the following command to uninstall a Toolkit runfile installation:
sudo /usr/local/cuda-X.Y/bin/cuda-uninstaller

Steps to Uninstall CUDA

  1. Stop NVIDIA Persistenced Service (if running):
    sudo service nvidia-persistenced stop
  2. Remove CUDA Toolkit:
    sudo apt-get --purge remove "*cublas*" "cuda*" "nsight*"
  3. Remove NVIDIA Drivers:
    sudo apt-get --purge remove "*nvidia*"
  4. Remove Source File Installations (if applicable): Assuming the default installation location is /usr/local, remove it using:
    sudo rm -rf /usr/local/cuda*

Install CUDA

Refer to the CUDA Quick Start Guide for more information.

  1. Download and run the CUDA installer:

    Download the runfile CUDA installer from here for your OS. The website will provide commands similar to:

    wget https://developer.download.nvidia.com/compute/cuda/13.0.1/local_installers/cuda_13.0.1_580.82.07_linux.run
    sudo sh cuda_13.0.1_580.82.07_linux.run
  2. If you encounter an error, the installer will create a file at:

    /etc/modprobe.d/nvidia-installer-disable-nouveau.conf
  3. Reboot the system:

    sudo reboot
  4. After rebooting, rerun the installer:

    sudo sh cuda_13.0.1_580.82.07_linux.run
  5. Verify CUDA installation:

    ls /usr/local/ | grep cuda
  6. Add environment variables:

    Open the .bashrc file:

    nano ~/.bashrc

    Append the following lines to the end of the file:

    export PATH="/usr/local/cuda/bin:$PATH"
    export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"
  7. Apply the changes:

    source ~/.bashrc

Installing the NVIDIA Container Toolkit

Refer to the NVIDIA Documentation

Installing with Apt

  1. Configure the production repository:

    curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg    && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list |      sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' |      sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
  2. Optionally, configure the repository to use experimental packages:

    sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-container-toolkit.list
  3. Update the packages list from the repository:

    sudo apt-get update
  4. Install the NVIDIA Container Toolkit packages:

    sudo apt-get install -y nvidia-container-toolkit

Configuring Docker

  1. Configure the container runtime by using the nvidia-ctk command:

    sudo nvidia-ctk runtime configure --runtime=docker

    The nvidia-ctk command modifies the /etc/docker/daemon.json file on the host. The file is updated so that Docker can use the NVIDIA Container Runtime.

  2. Restart the Docker daemon:

    sudo systemctl restart docker

RISC Zero Specific Setup

If you intend to run the RISC Zero prover, you need to set up Bonsai (Bento):

git clone https://github.com/NethermindEth/risc0-bento.git
cd risc0-bento
cp bento/dockerfiles/sample.env ./sample.env
docker compose --file compose.yml --env-file sample.env up -d --build

Running Raiko in Docker

1. Clone Raiko Repository

git clone https://github.com/NethermindEth/raiko.git
cd raiko

2. Setup Chain Spec and Config

Both chain_spec_list.json and config.json files are placed in raiko/host/config/devnet for devnet and raiko/host/config/testnet for testnet. You can edit existing configs or create new ones based on your chain configuration.

tip

In Simple Surge Node, the surge-protocol-deployer.sh deployment script will generate chain_spec_list.json for you after the Running provers? (true/false) [default: false] prompt.

You just need to copy it from simple-surge-node/configs/chain_spec_list_default.json into your prover config folder (e.g., raiko/host/config/devnet/chain_spec_list.json).

Here are the most important parameters to check in config.json:

  • address: The address of the prover server
  • network: The network name of the L2
  • concurrency_limit: The number of concurrent proving tasks the prover can handle. Note that this value should be set to the number of GPUs available on the prover machine.
  • l1_network: The network name of the L1
  • ballot_zk: Configuration for zk_any request
  • ballot_sgx: Configuration for sgx_any request

This config.json file is used as the default proof request config, but clients can override it with specific values.

note

The chain_spec_list.json file is generated when deploying the protocol. You should copy it as-is. Don't change anything in this file unless you know what you're doing.

3. Configure Environment Variables

Copy the sample .env file:

cd raiko/docker
cp .env.sample.zk .env

Edit the .env file and configure the following important variables:

  • RAIKO_CONF_DIR - Directory where your Raiko configuration files are stored
  • BASE_CONFIG_FILE - Base configuration file for Raiko inside $RAIKO_CONF_DIR
  • BASE_CHAINSPEC_FILE - Base chainspec file for Raiko inside $RAIKO_CONF_DIR
  • SP1_PROVER - Set to local to use local SP1 prover
  • SP1_VERIFIER_RPC_URL - RPC URL of the L1 network where the SP1 verifier contract is deployed
  • SP1_VERIFIER_ADDRESS - Address of the deployed SP1 verifier contract
  • GROTH16_VERIFIER_RPC_URL - RPC URL of the L1 network
  • GROTH16_VERIFIER_ADDRESS - Address of the deployed Groth16 verifier contract
  • BONSAI_API_URL - URL of the Bonsai API server
  • RUST_LOG - Log level for Rust (info, debug, warn, error, or trace)
tip

You can leave RAIKO_CONF_DIR, BASE_CONFIG_FILE, and BASE_CHAINSPEC_FILE as default if you have placed your config files in raiko/host/config/devnet.

Some SP1 and GROTH16 environment variables will be generated for you in Simple Surge Node surge-protocol-deployer.sh deployment script after the Running provers? (true/false) [default: false] prompt. Just use them.

BONSAI_API_URL should be set to http://0.0.0.0:8081 by default if you didn't change the Bonsai configuration.

4. Build and Run the Prover

You have two options to run the prover:

  • Use a pre-built image from Docker Hub
  • Build the image yourself

Using Pre-built Image from Docker Hub

The docker-compose-zk.yml file uses the latest Raiko ZK image from Docker Hub by default. Run the following commands:

cd docker 
docker compose -f docker-compose-zk.yml up -d --force-recreate # Run the prover in detached mode

To use a specific version, update the image tag in the docker-compose-zk.yml file. Check the Raiko repository for available releases. Update the image field in docker/docker-compose-zk.yml for the raiko service.

For example, if the latest release is v1.8.5-surge:

services:
raiko:
image: nethermind.jfrog.io/core-oci-local-prod/raiko-zk:v1.8.5-surge
...

Build the Image Yourself

You may want to build the image yourself if you have made local changes to the Raiko codebase or want to use a specific commit.

To build the image from the raiko directory:

cd docker # Navigate to the docker directory inside raiko
docker compose -f docker-compose-zk.yml up -d --force-recreate --build # Build and Run the prover

5. Verify the Prover is Running

Your SP1/RISC Zero prover should now be operational. To verify it's running correctly, check the container logs:

docker logs -f raiko

6. Next Steps

Next you can set up an SGX prover by following the instructions in the SGX Prover guide.

If you have already done it, the next step is to register your provers in the protocol. Follow the instructions in the Register Provers guide.

Non-Docker Setup Instructions

If you need to run the prover without Docker, follow these instructions. Note that this is not the preferred method for running the prover.

1. Install Dependencies

For running without Docker (not preferred), you first need to install dependencies. See the details below:

Install Dependencies

Install Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Install openssl

sudo apt-get install libssl-dev

Install package-config

sudo apt-get update
sudo apt-get install pkg-config

Install sccache

cargo install sccache

Install gcc-12

sudo apt install gcc-12
cd /usr/bin
sudo rm gcc
sudo ln -s gcc-12 gcc
gcc --version

Install g++-12

sudo apt install g++-12
sudo rm g++
sudo ln -s g++-12 g++
g++ --version

Install clang

sudo apt install clang

2. Build SP1 and RISC Zero Provers

Install SP1 and RISC Zero dependencies:

TARGET=sp1 make install
TARGET=risc0 make install

Build guest files:

cargo run --release --bin sp1-builder
cargo run --release --bin risc0-builder

Build the prover with both SP1 and RISC Zero features (you can also build them separately if needed):

cargo build --release --features sp1,risc0

3. Run SP1 and RISC Zero Provers

Set up environment variables:

export SP1_PROVER=local
export SP1_VERIFIER_ADDRESS=<SP1_VERIFIER_ADDRESS>
export SP1_VERIFIER_RPC_URL=<SP1_VERIFIER_RPC_URL>
export GROTH16_VERIFIER_RPC_URL=<GROTH16_VERIFIER_RPC_URL>
export GROTH16_VERIFIER_ADDRESS=<GROTH16_VERIFIER_ADDRESS>
export BONSAI_API_URL=http://0.0.0.0:8081
tip

Check the 3. Configure Environment Variables section above for more details on how to get these values.

Run the provers:

./target/release/raiko-host --chain-spec-path=host/config/devnet/chain_spec_list.json --config-path=host/config/devnet/config.json
note

If you compiled Raiko with both SP1 and RISC Zero features, both provers will be available in the same binary.

4. Next Steps

Next you can set up an SGX prover by following the instructions in the SGX Prover guide.

If you have already done it, the next step is to register your provers in the protocol. Follow the instructions in the Register Provers guide.