Skip to main content

sp1_verifier/
lib.rs

1//! This crate provides verifiers for SP1 Groth16 and Plonk BN254 proofs in a no-std environment.
2//! It is patched for efficient verification within the SP1 zkVM context.
3
4#![cfg_attr(not(any(feature = "std", test)), no_std)]
5extern crate alloc;
6
7use lazy_static::lazy_static;
8use slop_algebra::PrimeField;
9use sp1_hypercube::koalabears_to_bn254;
10
11lazy_static! {
12    /// The PLONK verifying key for this SP1 version.
13    pub static ref PLONK_VK_BYTES: &'static [u8] = include_bytes!("../vk-artifacts/plonk_vk.bin");
14}
15
16lazy_static! {
17    /// The Groth16 verifying key for this SP1 version.
18    pub static ref GROTH16_VK_BYTES: &'static [u8] = include_bytes!("../vk-artifacts/groth16_vk.bin");
19}
20
21lazy_static! {
22    /// The VK merkle tree root as 32 bytes (big-endian bn254 representation).
23    /// Derived from the recursion verifying key data.
24    pub static ref VK_ROOT_BYTES: [u8; 32] = {
25        let vks = recursion_vks::VerifierRecursionVks::default();
26        let bn254 = koalabears_to_bn254(&vks.root());
27        let bigint = bn254.as_canonical_biguint();
28        let be_bytes = bigint.to_bytes_be();
29        let mut result = [0u8; 32];
30        let start = 32 - be_bytes.len();
31        result[start..].copy_from_slice(&be_bytes);
32        result
33    };
34}
35
36mod recursion_vks;
37pub use recursion_vks::VerifierRecursionVks;
38
39pub mod compressed;
40
41mod constants;
42pub mod converter;
43mod error;
44mod proof;
45
46mod utils;
47pub use utils::*;
48
49pub use groth16::{error::Groth16Error, Groth16Verifier};
50pub use proof::*;
51mod groth16;
52
53#[cfg(feature = "ark")]
54pub use groth16::ark_converter::*;
55
56pub use plonk::{error::PlonkError, PlonkVerifier};
57mod plonk;
58
59#[cfg(test)]
60mod tests;