sp1_stark/
config.rs

1#![allow(missing_docs)]
2
3use p3_challenger::{CanObserve, CanSample, FieldChallenger};
4use p3_commit::{Pcs, PolynomialSpace};
5use p3_field::{ExtensionField, Field, PrimeField32, TwoAdicField};
6use serde::{de::DeserializeOwned, Serialize};
7
8pub type Domain<SC> = <<SC as StarkGenericConfig>::Pcs as Pcs<
9    <SC as StarkGenericConfig>::Challenge,
10    <SC as StarkGenericConfig>::Challenger,
11>>::Domain;
12
13pub type Val<SC> = <<<SC as StarkGenericConfig>::Pcs as Pcs<
14    <SC as StarkGenericConfig>::Challenge,
15    <SC as StarkGenericConfig>::Challenger,
16>>::Domain as PolynomialSpace>::Val;
17
18pub type Dom<SC> = <<SC as StarkGenericConfig>::Pcs as Pcs<
19    <SC as StarkGenericConfig>::Challenge,
20    <SC as StarkGenericConfig>::Challenger,
21>>::Domain;
22
23pub type PackedVal<SC> = <Val<SC> as Field>::Packing;
24
25pub type PackedChallenge<SC> =
26    <<SC as StarkGenericConfig>::Challenge as ExtensionField<Val<SC>>>::ExtensionPacking;
27
28pub type Com<SC> = <<SC as StarkGenericConfig>::Pcs as Pcs<
29    <SC as StarkGenericConfig>::Challenge,
30    <SC as StarkGenericConfig>::Challenger,
31>>::Commitment;
32
33pub type OpeningProof<SC> = <<SC as StarkGenericConfig>::Pcs as Pcs<
34    <SC as StarkGenericConfig>::Challenge,
35    <SC as StarkGenericConfig>::Challenger,
36>>::Proof;
37
38pub type OpeningError<SC> = <<SC as StarkGenericConfig>::Pcs as Pcs<
39    <SC as StarkGenericConfig>::Challenge,
40    <SC as StarkGenericConfig>::Challenger,
41>>::Error;
42
43pub type PcsProverData<SC> = <<SC as StarkGenericConfig>::Pcs as Pcs<
44    <SC as StarkGenericConfig>::Challenge,
45    <SC as StarkGenericConfig>::Challenger,
46>>::ProverData;
47
48pub type Challenge<SC> = <SC as StarkGenericConfig>::Challenge;
49pub type Challenger<SC> = <SC as StarkGenericConfig>::Challenger;
50
51pub trait StarkGenericConfig: 'static + Send + Sync + Serialize + DeserializeOwned + Clone {
52    type Val: PrimeField32 + TwoAdicField;
53
54    type Domain: PolynomialSpace<Val = Self::Val> + Sync;
55
56    /// The PCS used to commit to trace polynomials.
57    type Pcs: Pcs<Self::Challenge, Self::Challenger, Domain = Self::Domain>
58        + Sync
59        + ZeroCommitment<Self>;
60
61    /// The field from which most random challenges are drawn.
62    type Challenge: ExtensionField<Self::Val>;
63
64    /// The challenger (Fiat-Shamir) implementation used.
65    type Challenger: FieldChallenger<Val<Self>>
66        + CanObserve<<Self::Pcs as Pcs<Self::Challenge, Self::Challenger>>::Commitment>
67        + CanSample<Self::Challenge>
68        + Serialize
69        + DeserializeOwned;
70
71    /// Get the PCS used by this configuration.
72    fn pcs(&self) -> &Self::Pcs;
73
74    /// Initialize a new challenger.
75    fn challenger(&self) -> Self::Challenger;
76}
77
78pub trait ZeroCommitment<SC: StarkGenericConfig> {
79    fn zero_commitment(&self) -> Com<SC>;
80}
81
82pub struct UniConfig<SC>(pub SC);
83
84impl<SC: StarkGenericConfig> p3_uni_stark::StarkGenericConfig for UniConfig<SC> {
85    type Pcs = SC::Pcs;
86
87    type Challenge = SC::Challenge;
88
89    type Challenger = SC::Challenger;
90
91    fn pcs(&self) -> &Self::Pcs {
92        self.0.pcs()
93    }
94}