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
- Stop NVIDIA Persistenced Service (if running):
sudo service nvidia-persistenced stop - Remove CUDA Toolkit:
sudo apt-get --purge remove "*cublas*" "cuda*" "nsight*" - Remove NVIDIA Drivers:
sudo apt-get --purge remove "*nvidia*" - 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.
-
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 -
If you encounter an error, the installer will create a file at:
/etc/modprobe.d/nvidia-installer-disable-nouveau.conf -
Reboot the system:
sudo reboot -
After rebooting, rerun the installer:
sudo sh cuda_13.0.1_580.82.07_linux.run -
Verify CUDA installation:
ls /usr/local/ | grep cuda -
Add environment variables:
Open the
.bashrcfile:nano ~/.bashrcAppend 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" -
Apply the changes:
source ~/.bashrc
Installing the NVIDIA Container Toolkit
Refer to the NVIDIA Documentation
Installing with Apt
-
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 -
Optionally, configure the repository to use experimental packages:
sed -i -e '/experimental/ s/^#//g' /etc/apt/sources.list.d/nvidia-container-toolkit.list -
Update the packages list from the repository:
sudo apt-get update -
Install the NVIDIA Container Toolkit packages:
sudo apt-get install -y nvidia-container-toolkit
Configuring Docker
-
Configure the container runtime by using the
nvidia-ctkcommand:sudo nvidia-ctk runtime configure --runtime=dockerThe
nvidia-ctkcommand modifies the/etc/docker/daemon.jsonfile on the host. The file is updated so that Docker can use the NVIDIA Container Runtime. -
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.
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 servernetwork: The network name of the L2concurrency_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 L1ballot_zk: Configuration forzk_anyrequestballot_sgx: Configuration forsgx_anyrequest
This config.json file is used as the default proof request config, but clients can override it with specific values.
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 storedBASE_CONFIG_FILE- Base configuration file for Raiko inside$RAIKO_CONF_DIRBASE_CHAINSPEC_FILE- Base chainspec file for Raiko inside$RAIKO_CONF_DIRSP1_PROVER- Set tolocalto use local SP1 proverSP1_VERIFIER_RPC_URL- RPC URL of the L1 network where the SP1 verifier contract is deployedSP1_VERIFIER_ADDRESS- Address of the deployed SP1 verifier contractGROTH16_VERIFIER_RPC_URL- RPC URL of the L1 networkGROTH16_VERIFIER_ADDRESS- Address of the deployed Groth16 verifier contractBONSAI_API_URL- URL of the Bonsai API serverRUST_LOG- Log level for Rust (info,debug,warn,error, ortrace)
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
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
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.