openvm_stark_backend/lib.rs
1//! Backend for proving and verifying mixed-matrix STARKs.
2//! The backend is designed to be modular and compatible with different hardware implementations.
3//! The backend provides prover and verifier implementations of the SWIRL proof system.
4//!
5//! The aim is to support different circuit representations and permutation/lookup arguments.
6
7// Re-export all Plonky3 crates
8pub use p3_air;
9pub use p3_challenger;
10pub use p3_field;
11pub use p3_matrix;
12pub use p3_maybe_rayon;
13pub use p3_symmetric;
14pub use p3_util;
15use p3_util::log2_ceil_u64;
16
17/// AIR builders for prover and verifier, including support for cross-matrix permutation arguments.
18pub mod air_builders;
19pub mod codec;
20/// Copy of Plonky3's DFT module without parallelism (Rayon) for faster single-threaded execution.
21/// Used by the prover **only**.
22pub mod dft;
23/// Protocol hasher trait definition.
24pub mod hasher;
25/// Log-up permutation argument implementation as RAP.
26pub mod interaction;
27/// Proving and verifying key generation
28pub mod keygen;
29/// Memory estimates for segmented proving.
30pub mod memory_metering;
31/// Common polynomial utilities shared by prover and verifier
32pub mod poly_common;
33/// Definition of the STARK proof struct.
34pub mod proof;
35pub mod prover;
36pub mod soundness;
37pub mod utils;
38pub mod verifier;
39
40#[cfg(feature = "lean")]
41pub mod lean;
42
43#[cfg(any(test, feature = "test-utils"))]
44pub mod test_utils;
45// #[cfg(test)]
46// pub mod tests;
47
48/// Fiat-Shamir transcript trait and implementations (duplex sponge, multi-field).
49pub mod transcript;
50
51mod any_air;
52/// STARK Protocol configuration trait
53mod config;
54/// Trait for STARK backend engine proving keygen, proviing, verifying API functions.
55mod engine;
56#[cfg(feature = "multi-field-transcript")]
57pub mod multi_field_packing;
58pub use any_air::*;
59pub use config::*;
60pub use engine::*;
61pub use transcript::*;
62
63// Use jemalloc as global allocator for performance
64#[cfg(all(feature = "jemalloc", unix, not(test)))]
65#[global_allocator]
66static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
67
68// Use mimalloc as global allocator
69#[cfg(all(feature = "mimalloc", not(test)))]
70#[global_allocator]
71static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
72
73/// Common utility function for computing `n_logup` parameter in terms of `total_interactions`,
74/// which is the sum of interaction message counts across all traces, using the lifted trace
75/// heights.
76///
77/// This calculation must be consistent between the prover and verifier and is enforced by
78/// the verifier.
79// NOTE: we could use a more strict calculation of `n_logup = log2_ceil(total_interactions >>
80// l_skip)` but the `leading_zeros` calculation below is easier to check in the recursion
81// circuit. The formula below is equivalent to `log2_ceil(total_interactions + 1) - l_skip`.
82pub fn calculate_n_logup(l_skip: usize, total_interactions: u64) -> usize {
83 if total_interactions != 0 {
84 let n_logup = (u64::BITS - total_interactions.leading_zeros()) as usize - l_skip;
85 debug_assert_eq!(
86 n_logup + l_skip,
87 log2_ceil_u64(total_interactions + 1) as usize
88 );
89 n_logup
90 } else {
91 0
92 }
93}