Deploy RISC0 Prover
Prerequisites
- Machine with CUDA support
- L1 Accounts with funds (One for the Prover, One for Prover Registry)
- L1 RPC URL
- L1 Account Private Key
Overview
Set up Docker, CUDA, and other dependencies to run Risc0 prover on an x86 machine. Documentation: Risc0 API
Install Docker
Follow the official Docker documentation for installation steps.
Allow Running Docker Without sudo
- Add your user to the
docker
group:sudo usermod -aG docker $USER
- Apply the changes to the user group:
newgrp docker
- Verify that Docker works without sudo:
docker ps
Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
sudo reboot
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
Uninstall Existing CUDA (optional)
Reference: NVIDIA CUDA Installation Guide - Handle Conflicting Installation Methods
Uninstall a Toolkit runfile installation
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 the CUDA installer:
wget https://developer.download.nvidia.com/compute/cuda/12.6.2/local_installers/cuda_12.6.2_560.35.03_linux.run
-
Run the installer:
sudo sh cuda_12.6.2_560.35.03_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_12.6.2_560.35.03_linux.run
-
Verify CUDA installation:
ls /usr/local/ | grep cuda
-
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" -
Apply the changes:
source ~/.bashrc
Pull Raiko
git clone https://github.com/NethermindEth/raiko.git
cd raiko
git checkout risc0-main
cargo --version
Install Raiko with RISC0
- Navigate to the root directory:
cd /
- Create the required directories:
sudo mkdir -p /opt/riscv
sudo chown $USER /opt/riscv - Switch to the Raiko repository directory:
cd ~/raiko
- Install Raiko with the RISC0 target:
Note: If you encounter an error during this step, run the following command to refresh your environment variables and retry the installation:
TARGET=risc0 make install
source ~/.bashrc
TARGET=risc0 make install
Build Risc0 Program
Run the following command:
cargo +nightly-2024-04-18 run --bin risc0-builder -F raiko-tasks/in-memory
You will get the image ID from the output of that call.
Setup Trusted Images for the RISC0 Verifier Contract
Run the following command to set an image as trusted:
cast send <RISC0_VERIFIER> "setImageIdTrusted(bytes32,bool)" <IMAGE_ID> true --rpc-url <L1_RPC_URL> --private-key <PRIVATE_KEY>
Set Chain Spec
Edit the file located at:
raiko/host/config/chain_spec_list_default.json
Set the values according to your chain configuration.
Build Raiko
Run the following command:
cargo build -F cuda --release --features risc0 -F raiko-tasks/in-memory
Run Raiko
Set the required environment variables:
export GROTH16_VERIFIER_ADDRESS=0xA2C4Ef228de6BA701660e75Cb06f1c9b29E53069
export GROTH16_VERIFIER_RPC_URL=http://139.162.249.67:32002
export TASKDB=./raiko-tasks/in-memory
export RISC0_PROVER=local
Run Raiko in the background:
nohup ./target/release/raiko-host --chain-spec-path=</full/path/to/chain_spec_list_default.json> > ~/log/output.log 2>&1 &
Check Logs
View the log output:
cat ~/log/output.log