p3_uni_stark/
config.rs

1use core::marker::PhantomData;
2
3use p3_challenger::{CanObserve, CanSample, FieldChallenger};
4use p3_commit::{Pcs, PolynomialSpace};
5use p3_field::{ExtensionField, Field};
6
7pub type PcsError<SC> = <<SC as StarkGenericConfig>::Pcs as Pcs<
8    <SC as StarkGenericConfig>::Challenge,
9    <SC as StarkGenericConfig>::Challenger,
10>>::Error;
11
12pub type Domain<SC> = <<SC as StarkGenericConfig>::Pcs as Pcs<
13    <SC as StarkGenericConfig>::Challenge,
14    <SC as StarkGenericConfig>::Challenger,
15>>::Domain;
16
17pub type Val<SC> = <Domain<SC> as PolynomialSpace>::Val;
18
19pub type PackedVal<SC> = <Val<SC> as Field>::Packing;
20
21pub type PackedChallenge<SC> =
22    <<SC as StarkGenericConfig>::Challenge as ExtensionField<Val<SC>>>::ExtensionPacking;
23
24pub trait StarkGenericConfig {
25    /// The PCS used to commit to trace polynomials.
26    type Pcs: Pcs<Self::Challenge, Self::Challenger>;
27
28    /// The field from which most random challenges are drawn.
29    type Challenge: ExtensionField<Val<Self>>;
30
31    /// The challenger (Fiat-Shamir) implementation used.
32    type Challenger: FieldChallenger<Val<Self>>
33        + CanObserve<<Self::Pcs as Pcs<Self::Challenge, Self::Challenger>>::Commitment>
34        + CanSample<Self::Challenge>;
35
36    /// Get a reference to the PCS used by this proof configuration.
37    fn pcs(&self) -> &Self::Pcs;
38
39    /// Get an initialisation of the challenger used by this proof configuration.
40    fn initialise_challenger(&self) -> Self::Challenger;
41
42    /// Returns 1 if the PCS is zero-knowledge, 0 otherwise.
43    fn is_zk(&self) -> usize {
44        Self::Pcs::ZK as usize
45    }
46}
47
48#[derive(Debug)]
49pub struct StarkConfig<Pcs, Challenge, Challenger> {
50    /// The PCS used to commit polynomials and prove opening proofs.
51    pcs: Pcs,
52    /// An initialised instance of the challenger.
53    challenger: Challenger,
54    _phantom: PhantomData<Challenge>,
55}
56
57impl<Pcs, Challenge, Challenger> StarkConfig<Pcs, Challenge, Challenger> {
58    pub const fn new(pcs: Pcs, challenger: Challenger) -> Self {
59        Self {
60            pcs,
61            challenger,
62            _phantom: PhantomData,
63        }
64    }
65}
66
67impl<Pcs, Challenge, Challenger> StarkGenericConfig for StarkConfig<Pcs, Challenge, Challenger>
68where
69    Challenge: ExtensionField<<Pcs::Domain as PolynomialSpace>::Val>,
70    Pcs: p3_commit::Pcs<Challenge, Challenger>,
71    Challenger: FieldChallenger<<Pcs::Domain as PolynomialSpace>::Val>
72        + CanObserve<Pcs::Commitment>
73        + CanSample<Challenge>
74        + Clone,
75{
76    type Pcs = Pcs;
77    type Challenge = Challenge;
78    type Challenger = Challenger;
79
80    fn pcs(&self) -> &Self::Pcs {
81        &self.pcs
82    }
83
84    fn initialise_challenger(&self) -> Self::Challenger {
85        self.challenger.clone()
86    }
87}