Skip to main content

openvm_stark_sdk/config/
mod.rs

1use openvm_stark_backend::{
2    interaction::LogUpSecurityParameters, soundness, soundness::SoundnessCalculator, SystemParams,
3    WhirProximityStrategy,
4};
5
6use crate::config::{
7    baby_bear_poseidon2::BabyBearPoseidon2Config,
8    log_up_params::log_up_security_params_baby_bear_100_bits,
9};
10
11/// STARK config where the base field is BabyBear, extension field is BabyBear^4, and the hasher is
12/// `Poseidon2<Bn254>`.
13#[cfg(feature = "baby-bear-bn254-poseidon2")]
14pub mod baby_bear_bn254_poseidon2;
15/// STARK config where the base field is BabyBear, extension field is BabyBear^4, and the hasher is
16/// `Poseidon2<BabyBear>`.
17pub mod baby_bear_poseidon2;
18/// BN254 Poseidon2 permutations used by the BabyBear + BN254 configuration.
19#[cfg(feature = "baby-bear-bn254-poseidon2")]
20pub mod bn254_poseidon2;
21pub mod log_up_params;
22
23// ==========================================================================
24// Production configurations
25// ==========================================================================
26// These configurations target 100-bits of proven round-by-round (RBR) security with BabyBear as the
27// base field and BabyBear^4 as the extension field.
28
29pub const DEFAULT_K_WHIR: usize = 4;
30pub const DEFAULT_WHIR_QUERY_PHASE_POW_BITS: usize = 20;
31pub const WHIR_MAX_LOG_FINAL_POLY_LEN: usize = 10;
32pub const SECURITY_BITS_TARGET: usize = 100;
33
34pub const DEFAULT_APP_L_SKIP: usize = 4;
35pub const DEFAULT_APP_LOG_BLOWUP: usize = 1;
36pub const DEFAULT_LEAF_LOG_BLOWUP: usize = 2;
37pub const DEFAULT_INTERNAL_LOG_BLOWUP: usize = 3;
38pub const DEFAULT_ROOT_LOG_BLOWUP: usize = 4;
39pub const DEFAULT_HOOK_LOG_BLOWUP: usize = 2;
40
41pub const APP_MAX_CONSTRAINT_DEGREE: usize = 3;
42pub const RECURSION_MAX_CONSTRAINT_DEGREE: usize = 4;
43
44pub const MAX_APP_LOG_STACKED_HEIGHT: usize = 24;
45
46/// Order `p` of the base field for the production [`BabyBearPoseidon2Config`].
47pub fn base_field_order() -> f64 {
48    soundness::base_field_order::<BabyBearPoseidon2Config>()
49}
50
51/// Number of bits in the challenge field for the production [`BabyBearPoseidon2Config`].
52pub fn challenge_field_bits() -> f64 {
53    soundness::challenge_field_bits::<BabyBearPoseidon2Config>()
54}
55
56/// LogUp grinding sufficient for 100-bit security, accounting for the PCS list-size union bound of
57/// the initial WHIR proximity regime (`log2_pcs_list_size` is 0 for unique decoding).
58fn log_up_params_for_whir(
59    proximity: WhirProximityStrategy,
60    log_stacked_height: usize,
61    log_blowup: usize,
62    w_stack: usize,
63) -> LogUpSecurityParameters {
64    let log2_pcs_list_size = SoundnessCalculator::whir_proximity_gap_security(
65        proximity.initial_round(),
66        challenge_field_bits(),
67        log_stacked_height,
68        log_blowup,
69        w_stack,
70    )
71    .log2_list_size;
72    log_up_security_params_baby_bear_100_bits(log2_pcs_list_size)
73}
74
75/// Builds production `SystemParams` for 100-bit security, calibrating LogUp grinding to the WHIR
76/// proximity regime's PCS list size. The LogUp params are derived up front (from the same inputs
77/// `SystemParams::new` uses to build the WHIR config) so they can be passed straight in.
78#[allow(clippy::too_many_arguments)]
79pub fn params_with_100_bits_security(
80    log_blowup: usize,
81    l_skip: usize,
82    n_stack: usize,
83    w_stack: usize,
84    folding_pow_bits: usize,
85    mu_pow_bits: usize,
86    proximity: WhirProximityStrategy,
87    max_constraint_degree: usize,
88    whir_query_phase_pow_bits: usize,
89    k_whir: usize,
90) -> SystemParams {
91    let logup = log_up_params_for_whir(proximity, l_skip + n_stack, log_blowup, w_stack);
92    SystemParams::new(
93        log_blowup,
94        l_skip,
95        n_stack,
96        w_stack,
97        WHIR_MAX_LOG_FINAL_POLY_LEN,
98        folding_pow_bits,
99        mu_pow_bits,
100        proximity,
101        SECURITY_BITS_TARGET,
102        logup,
103        max_constraint_degree,
104        whir_query_phase_pow_bits,
105        k_whir,
106    )
107}
108
109/// Returns `SystemParams` targeting 100 bits of proven RBR security for App VM circuits.
110///
111/// # Assumptions for 100-bit security
112/// - **Max trace height**: `log_stacked_height` ≤ [`MAX_APP_LOG_STACKED_HEIGHT`] (24)
113/// - **Max constraints per AIR**: ≤ 5,000
114/// - **Num AIRs**: ≤ 100
115/// - **Max interactions per AIR**: ≤ 1,000
116/// - **Num trace columns** (unstacked, total across all AIRs): ≤ 30,000
117/// - **`w_stack`** = 2,048, bounding total stacked cells to `w_stack × 2^(n_stack + l_skip)`
118//
119// See `test_all_production_configs` in `crates/stark-backend/tests/soundness.rs` for the
120// full soundness analysis.
121pub fn app_params_with_100_bits_security(log_stacked_height: usize) -> SystemParams {
122    assert!(
123        log_stacked_height <= MAX_APP_LOG_STACKED_HEIGHT,
124        "log_stacked_height must be <= {MAX_APP_LOG_STACKED_HEIGHT}",
125    );
126    params_with_100_bits_security(
127        DEFAULT_APP_LOG_BLOWUP,
128        DEFAULT_APP_L_SKIP,
129        log_stacked_height.saturating_sub(DEFAULT_APP_L_SKIP), // n_stack
130        2048,                                                  // w_stack
131        5,                                                     // folding pow
132        15,                                                    // mu pow
133        WhirProximityStrategy::UniqueDecoding,
134        APP_MAX_CONSTRAINT_DEGREE,
135        DEFAULT_WHIR_QUERY_PHASE_POW_BITS,
136        DEFAULT_K_WHIR,
137    )
138}
139
140/// Returns `SystemParams` targeting 100 bits of proven RBR security for leaf aggregation circuits.
141///
142/// # Assumptions for 100-bit security
143/// - **Max trace height**: ≤ 2^21
144/// - **Max constraints per AIR**: ≤ 1,000
145/// - **Num AIRs**: ≤ 50
146/// - **Max interactions per AIR**: ≤ 100 (maximum number of interactions in a single AIR for a
147///   single row)
148/// - **Num trace columns** (unstacked, total across all AIRs): ≤ 2,000
149/// - **`w_stack`** = 2,048, bounding total stacked cells to `w_stack × 2^(n_stack + l_skip)`
150///
151/// Config: `l_skip=4, n_stack=17, log_blowup=2`.
152//
153// See `test_all_production_configs` in `crates/stark-backend/tests/soundness.rs` for the
154// full soundness analysis.
155pub fn leaf_params_with_100_bits_security() -> SystemParams {
156    params_with_100_bits_security(
157        DEFAULT_LEAF_LOG_BLOWUP,
158        4,    // l_skip
159        17,   // n_stack
160        2048, // w_stack
161        4,    // folding pow
162        13,   // mu pow
163        WhirProximityStrategy::UniqueDecoding,
164        RECURSION_MAX_CONSTRAINT_DEGREE,
165        DEFAULT_WHIR_QUERY_PHASE_POW_BITS,
166        DEFAULT_K_WHIR,
167    )
168}
169
170/// Returns `SystemParams` targeting 100 bits of proven RBR security for internal aggregation
171/// circuits.
172///
173/// # Assumptions for 100-bit security
174/// - **Max trace height**: ≤ 2^19
175/// - **Max constraints per AIR**: ≤ 1,000
176/// - **Num AIRs**: ≤ 50
177/// - **Max interactions per AIR**: ≤ 100
178/// - **Num trace columns** (unstacked, total across all AIRs): ≤ 2,000
179/// - **`w_stack`** = 512, bounding total stacked cells to `w_stack × 2^(n_stack + l_skip)`
180///
181/// Config: `l_skip=2, n_stack=17, log_blowup=3`.
182//
183// See `test_all_production_configs` in `crates/stark-backend/tests/soundness.rs` for the
184// full soundness analysis.
185pub fn internal_params_with_100_bits_security() -> SystemParams {
186    params_with_100_bits_security(
187        DEFAULT_INTERNAL_LOG_BLOWUP,
188        2,   // l_skip
189        17,  // n_stack
190        512, // w_stack
191        18,  // folding pow
192        20,  // mu pow
193        WhirProximityStrategy::ListDecoding { m: 2 },
194        RECURSION_MAX_CONSTRAINT_DEGREE,
195        DEFAULT_WHIR_QUERY_PHASE_POW_BITS,
196        DEFAULT_K_WHIR,
197    )
198}
199
200/// Returns `SystemParams` targeting 100 bits of proven RBR security for root circuits.
201///
202/// # Assumptions for 100-bit security
203/// - **Max trace height**: ≤ 2^20
204/// - **Max constraints per AIR**: ≤ 1,000
205/// - **Num AIRs**: ≤ 50
206/// - **Max interactions per AIR**: ≤ 100
207/// - **Num trace columns** (unstacked, total across all AIRs): ≤ 2,000
208/// - **`w_stack`** = 18, bounding total stacked cells to `w_stack × 2^(n_stack + l_skip)`
209///
210/// Config: `l_skip=2, n_stack=18, log_blowup=4`.
211//
212// See `test_all_production_configs` in `crates/stark-backend/tests/soundness.rs` for the
213// full soundness analysis.
214pub fn root_params_with_100_bits_security() -> SystemParams {
215    params_with_100_bits_security(
216        DEFAULT_ROOT_LOG_BLOWUP,
217        2,  // l_skip
218        18, // n_stack
219        18, // w_stack
220        15, // folding pow
221        15, // mu pow
222        WhirProximityStrategy::ListDecoding { m: 1 },
223        RECURSION_MAX_CONSTRAINT_DEGREE,
224        15, // whir_query_pow
225        DEFAULT_K_WHIR,
226    )
227}
228
229/// Returns `SystemParams` targeting 100 bits of proven RBR security for deferral hook circuits.
230///
231/// # Assumptions for 100-bit security
232/// - **Max trace height**: ≤ 2^20
233/// - **Max constraints per AIR**: ≤ 1,000
234/// - **Num AIRs**: ≤ 50
235/// - **Max interactions per AIR**: ≤ 100
236/// - **Num trace columns** (unstacked, total across all AIRs): ≤ 2,000
237/// - **`w_stack`** = 80, bounding total stacked cells to `w_stack × 2^(n_stack + l_skip)`
238///
239/// Config: `l_skip=2, n_stack=18, log_blowup=2`.
240//
241// See `test_all_production_configs` in `crates/stark-backend/tests/soundness.rs` for the
242// full soundness analysis.
243pub fn hook_params_with_100_bits_security() -> SystemParams {
244    params_with_100_bits_security(
245        DEFAULT_HOOK_LOG_BLOWUP,
246        2,  // l_skip
247        18, // n_stack
248        80, // w_stack
249        12, // folding pow
250        11, // mu pow
251        WhirProximityStrategy::ListDecoding { m: 1 },
252        RECURSION_MAX_CONSTRAINT_DEGREE,
253        DEFAULT_WHIR_QUERY_PHASE_POW_BITS,
254        DEFAULT_K_WHIR,
255    )
256}