Skip to main content

miden_lifted_stark/
config.rs

1//! STARK configuration trait and generic implementation.
2//!
3//! [`StarkConfig`] bundles the LMCS, DFT, and challenger as associated types.
4//! The base field `F` and extension field `EF` are generic parameters so that
5//! functions using `SC: StarkConfig<F, EF>` can refer to `F` and `EF` directly
6//! instead of going through `SC::F` / `SC::EF`.
7//!
8//! [`GenericStarkConfig`] provides a ready-made implementation for tests and
9//! examples. Production integrations can implement `StarkConfig` on their own
10//! concrete struct.
11
12use core::marker::PhantomData;
13
14use miden_stark_transcript::TranscriptChallenger;
15use p3_dft::TwoAdicSubgroupDft;
16use p3_field::{ExtensionField, TwoAdicField};
17
18use crate::{lmcs::Lmcs, pcs::params::PcsParams};
19
20/// Lifted STARK configuration.
21///
22/// `F` and `EF` are generic parameters rather than associated types so that
23/// functions bounded by `SC: StarkConfig<F, EF>` can refer to them directly.
24/// Bounds on `F` and `EF` are declared once here and inherited by every user.
25pub trait StarkConfig<F: TwoAdicField, EF: ExtensionField<F>>: Clone {
26    /// LMCS (Merkle commitment scheme).
27    type Lmcs: Lmcs<F = F>;
28    /// DFT for LDE computation.
29    type Dft: TwoAdicSubgroupDft<F>;
30    /// Fiat-Shamir challenger.
31    type Challenger: TranscriptChallenger<F, <Self::Lmcs as Lmcs>::Commitment>;
32
33    /// PCS parameters (DEEP + FRI settings).
34    fn pcs(&self) -> &PcsParams;
35    /// LMCS instance for commitments.
36    fn lmcs(&self) -> &Self::Lmcs;
37    /// DFT implementation for LDE computation.
38    fn dft(&self) -> &Self::Dft;
39    /// Create a fresh challenger for a new proof/verification.
40    fn challenger(&self) -> Self::Challenger;
41}
42
43/// Generic [`StarkConfig`] implementation.
44///
45/// Stores the PCS parameters, LMCS, DFT, and a challenger prototype
46/// (cloned for each proof/verification). Use this for tests and examples;
47/// production code can implement `StarkConfig` on a custom struct.
48pub struct GenericStarkConfig<F, EF, L, Dft, Ch> {
49    pub pcs: PcsParams,
50    pub lmcs: L,
51    pub dft: Dft,
52    pub challenger: Ch,
53    _phantom: PhantomData<fn() -> (F, EF)>,
54}
55
56impl<F, EF, L, Dft, Ch> GenericStarkConfig<F, EF, L, Dft, Ch> {
57    pub fn new(pcs: PcsParams, lmcs: L, dft: Dft, challenger: Ch) -> Self {
58        Self {
59            pcs,
60            lmcs,
61            dft,
62            challenger,
63            _phantom: PhantomData,
64        }
65    }
66}
67
68// Manual Clone: avoids requiring F: Clone, EF: Clone.
69impl<F, EF, L: Clone, Dft: Clone, Ch: Clone> Clone for GenericStarkConfig<F, EF, L, Dft, Ch> {
70    fn clone(&self) -> Self {
71        Self {
72            pcs: self.pcs,
73            lmcs: self.lmcs.clone(),
74            dft: self.dft.clone(),
75            challenger: self.challenger.clone(),
76            _phantom: PhantomData,
77        }
78    }
79}
80
81impl<F, EF, L, Dft, Ch> StarkConfig<F, EF> for GenericStarkConfig<F, EF, L, Dft, Ch>
82where
83    F: TwoAdicField,
84    EF: ExtensionField<F>,
85    L: Lmcs<F = F>,
86    Dft: TwoAdicSubgroupDft<F> + Clone,
87    Ch: TranscriptChallenger<F, L::Commitment>,
88{
89    type Lmcs = L;
90    type Dft = Dft;
91    type Challenger = Ch;
92
93    fn pcs(&self) -> &PcsParams {
94        &self.pcs
95    }
96
97    fn lmcs(&self) -> &L {
98        &self.lmcs
99    }
100
101    fn dft(&self) -> &Dft {
102        &self.dft
103    }
104
105    fn challenger(&self) -> Ch {
106        self.challenger.clone()
107    }
108}