snark_verifier/
pcs.rs
1use crate::{
4 loader::{native::NativeLoader, Loader},
5 util::{
6 arithmetic::{CurveAffine, Rotation},
7 msm::Msm,
8 transcript::{TranscriptRead, TranscriptWrite},
9 },
10 Error,
11};
12use rand::Rng;
13use std::{fmt::Debug, marker::PhantomData};
14
15pub mod ipa;
16pub mod kzg;
17
18#[derive(Clone, Debug)]
21pub struct Query<S, T = ()> {
22 pub poly: usize,
24 pub shift: S,
26 pub loaded_shift: T,
28 pub eval: T,
30}
31
32impl<S> Query<S> {
33 pub fn new(poly: usize, shift: S) -> Self {
35 Self { poly, shift, loaded_shift: (), eval: () }
36 }
37
38 pub fn with_evaluation<T>(self, loaded_shift: T, eval: T) -> Query<S, T> {
40 Query { poly: self.poly, shift: self.shift, loaded_shift, eval }
41 }
42}
43
44pub trait PolynomialCommitmentScheme<C, L>: Clone + Debug
46where
47 C: CurveAffine,
48 L: Loader<C>,
49{
50 type VerifyingKey: Clone + Debug;
52 type Proof: Clone + Debug;
54 type Output: Clone + Debug;
56
57 fn read_proof<T>(
59 vk: &Self::VerifyingKey,
60 queries: &[Query<Rotation>],
61 transcript: &mut T,
62 ) -> Result<Self::Proof, Error>
63 where
64 T: TranscriptRead<C, L>;
65
66 fn verify(
68 vk: &Self::VerifyingKey,
69 commitments: &[Msm<C, L>],
70 point: &L::LoadedScalar,
71 queries: &[Query<Rotation, L::LoadedScalar>],
72 proof: &Self::Proof,
73 ) -> Result<Self::Output, Error>;
74}
75
76pub trait AccumulationScheme<C, L>
78where
79 C: CurveAffine,
80 L: Loader<C>,
81{
82 type Accumulator: Clone + Debug;
84 type VerifyingKey: Clone + Debug;
86 type Proof: Clone + Debug;
88
89 fn read_proof<T>(
91 vk: &Self::VerifyingKey,
92 instances: &[Self::Accumulator],
93 transcript: &mut T,
94 ) -> Result<Self::Proof, Error>
95 where
96 T: TranscriptRead<C, L>;
97
98 fn verify(
102 vk: &Self::VerifyingKey,
103 instances: &[Self::Accumulator],
104 proof: &Self::Proof,
105 ) -> Result<Self::Accumulator, Error>;
106}
107
108pub trait AccumulationDecider<C, L>: AccumulationScheme<C, L>
113where
114 C: CurveAffine,
115 L: Loader<C>,
116{
117 type DecidingKey: Clone + Debug;
120
121 fn decide(dk: &Self::DecidingKey, accumulator: Self::Accumulator) -> Result<(), Error>;
123
124 fn decide_all(
126 dk: &Self::DecidingKey,
127 accumulators: Vec<Self::Accumulator>,
128 ) -> Result<(), Error>;
129}
130
131pub trait AccumulationSchemeProver<C>: AccumulationScheme<C, NativeLoader>
133where
134 C: CurveAffine,
135{
136 type ProvingKey: Clone + Debug;
138
139 fn create_proof<T, R>(
143 pk: &Self::ProvingKey,
144 instances: &[Self::Accumulator],
145 transcript: &mut T,
146 rng: R,
147 ) -> Result<Self::Accumulator, Error>
148 where
149 T: TranscriptWrite<C>,
150 R: Rng;
151}
152
153pub trait AccumulatorEncoding<C, L>: Clone + Debug
155where
156 C: CurveAffine,
157 L: Loader<C>,
158{
159 type Accumulator: Clone + Debug;
161
162 fn from_repr(repr: &[&L::LoadedScalar]) -> Result<Self::Accumulator, Error>;
165}
166
167impl<C, L, PCS> AccumulatorEncoding<C, L> for PhantomData<PCS>
168where
169 C: CurveAffine,
170 L: Loader<C>,
171 PCS: PolynomialCommitmentScheme<C, L>,
172{
173 type Accumulator = PCS::Output;
174
175 fn from_repr(_: &[&L::LoadedScalar]) -> Result<Self::Accumulator, Error> {
176 unimplemented!()
177 }
178}