Skip to main content

openvm_stark_sdk/config/
log_up_params.rs

1use openvm_stark_backend::{
2    interaction::LogUpSecurityParameters, p3_field::PrimeField32, soundness::SoundnessCalculator,
3};
4use p3_baby_bear::BabyBear;
5
6use crate::config::challenge_field_bits;
7
8const TARGET_LOGUP_SECURITY_BITS: f64 = 100.0;
9const MIN_BABY_BEAR_LOGUP_POW_BITS: usize = 18;
10
11/// Returns BabyBear LogUp parameters with at least 100 bits after the PCS list-size union bound.
12///
13/// `log2_pcs_list_size` is `log2(L_PCS)` for the initial WHIR proximity regime. It is zero for
14/// unique decoding.
15pub fn log_up_security_params_baby_bear_100_bits(
16    log2_pcs_list_size: f64,
17) -> LogUpSecurityParameters {
18    assert!(
19        log2_pcs_list_size.is_finite() && log2_pcs_list_size >= 0.0,
20        "log2_pcs_list_size must be finite and nonnegative"
21    );
22
23    let challenge_field_bits = challenge_field_bits();
24    let max_interaction_count = BabyBear::ORDER_U32;
25    let log_max_message_length = 7;
26
27    // Pre-grinding LogUp security via the backend (the single source of truth). Security is linear
28    // in `pow_bits` with unit slope, so the grinding needed to reach the target is exactly the
29    // remaining gap. Floor at `MIN_BABY_BEAR_LOGUP_POW_BITS` to keep the historical baseline margin
30    // for the unique-decoding configs. The authoritative check that the resulting params clear the
31    // target is `test_all_production_configs` in the backend's soundness tests.
32    let security_without_pow = SoundnessCalculator::logup_soundness(
33        max_interaction_count,
34        log_max_message_length,
35        challenge_field_bits,
36        log2_pcs_list_size,
37    );
38    let pow_bits = ((TARGET_LOGUP_SECURITY_BITS - security_without_pow)
39        .ceil()
40        .max(0.0) as usize)
41        .max(MIN_BABY_BEAR_LOGUP_POW_BITS);
42
43    LogUpSecurityParameters {
44        max_interaction_count,
45        log_max_message_length,
46        pow_bits,
47    }
48}