Optimized SP1 Verifier for ckb-vm

An optimized port of the SP1 verifier (Plonk proof) targeting ckb-vm, based on SP1 6.0.2.

The original SP1 verifier lacks `no_std` support and has high cycle counts (~6000M cycles), making it unusable for on-chain scripts on ckb-vm. This fork addresses both limitations.

## Changes

The code lives on this [branch]( GitHub - XuJiandong/sp1: SP1 is a zero‑knowledge virtual machine that proves the correct execution of programs compiled for the RISC-V architecture. · GitHub ), primarily in the `crates/verifier` folder.

Key modifications from the original:

1. Replaced the bn254 (alt\_bn128) elliptic curve implementation with the highly optimized [ckb-alt-bn128]( crates.io: Rust Package Registry )

2. Ported to `no_std` Rust

3. Only the Plonk verifier has been updated; Groth16 is not optimized

As a result, cycle count for a single verification is reduced from ~6000M to ~63M, with a binary size of 246 KB — viable for on-chain use on ckb-vm.

## Usage

Add the dependency to your `Cargo.toml`:

sp1-verifier = { git = “https://github.com/XuJiandong/sp1.git”, default-features = false, rev = “0cc2b42” }

Example:

use sp1_verifier::PlonkVerifier;

pub fn main() → Result<(), Error> {

let vk_hash = “0x00e5c18e0c045a455db8eb2bee09cb2db3c87129e0972cc1562ce3c13d6c9c10”;

let proof = \[\]; // fill proof here

let public_values = \[\]; // fill public values here

PlonkVerifier::verify(&proof, &public_values, &vk_hash, sp1_verifier::PLONK_VK_BYTES).expect("plonk verify failed");
}

For more usage examples, see the [official SP1 documentation]( Offchain Verification | Succinct Docs ).

A full benchmark is available [here](ckb-rust-algorithm-benchmarks/contracts/sp1-test at master · XuJiandong/ckb-rust-algorithm-benchmarks · GitHub).

3 Likes

How can I use this with sp1 version 5.2.4?

I’m using sp1 to generate proofs from TEE attestation but that uses sp1 v5.2.4 and when i try to verify the proofs generated, i get an error that the proof verification failed.

We strongly recommend using SP1 v6.0 or above (Hypercube), as it offers significantly improved proof generation performance. Versions prior to 6.0 are considerably more expensive to operate, resulting in higher gas costs. And their architectures are different (rv32 vs rv64)

3 Likes

Okay, thanks.

I had two options, to make the onchain use v5.2.4 verifier or to write a custom dcap-attestation crate with SP1 v6, I took the latter route and it works fine.

Thanks for your contribution.

2 Likes