halo2_solana_verifier/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]
2#![forbid(unsafe_code)]
3
4//! halo2-solana-verifier
5//!
6//! Tight BN254-only KZG/SHPLONK verifier for PSE-Halo2 proofs, designed for
7//! the Solana BPF VM. Inspired by Light Protocol's `groth16-solana` pattern:
8//! no generic Loader/CurveAffine abstraction, no halo2curves dependency —
9//! direct calls to `solana_bn254` syscalls + arkworks types only.
10//!
11//! Architecture (decided in research+pivot phase):
12//! - On-chain: arkworks-bn254 for Fr/Fq arithmetic + alt_bn128 syscalls
13//! for G1/G2/pairing, Keccak transcript via sol_keccak256.
14//! - Off-chain: same code paths with feature `solana-syscalls` off; the
15//! syscalls module falls back to host arkworks ops (used for unit tests
16//! and the prover-side reference verifier).
17//!
18//! v1 targets devnet (SIMD-0284 LE byte order, SIMD-0302 G2 syscalls active).
19//! v1.5 will add a mainnet fallback path that emulates G2 ops in pure BPF.
20//!
21//! See `vendor/snark-verifier/` (gitignored) for the upstream reference
22//! implementation we cross-check against.
23
24extern crate alloc;
25
26pub mod error;
27pub mod gate_compat;
28pub mod syscalls;
29
30pub mod field;
31pub mod curve;
32pub mod pairing;
33pub mod transcript;
34
35pub mod kzg;
36pub mod plonk;
37pub use plonk::proof_reader;
38
39pub mod vk;
40pub mod proof;
41pub mod stage_state;
42
43pub use error::Error;
44
45use crate::kzg::KzgVk;
46
47/// Verify a Halo2-PSE (BN254/KZG/SHPLONK) proof against the flat on-chain VK
48/// bytes and a list of public inputs.
49///
50/// `kzg_vk` is the trimmed KZG verifying SRS (`[1]_1`, `[1]_2`, `[τ]_2`),
51/// embedded as `const` in the calling BPF program's rodata. v1 ships a
52/// StandardPlonk-specialised gate identity; arbitrary halo2 gate AST is v1.5.
53pub fn verify(
54 vk_bytes: &[u8],
55 proof_bytes: &[u8],
56 public_inputs: &[[u8; 32]],
57 kzg_vk: &KzgVk,
58) -> Result<bool, Error> {
59 plonk::verifier::verify(vk_bytes, proof_bytes, public_inputs, kzg_vk)
60}