1
- use super :: * ;
1
+ use std:: rc:: Rc ;
2
+
2
3
use snark_verifier:: {
3
4
loader:: halo2:: EccInstructions ,
4
5
pcs:: { kzg:: KzgAccumulator , MultiOpenScheme , PolynomialCommitmentScheme } ,
@@ -8,225 +9,8 @@ use snark_verifier_sdk::{
8
9
types:: { BaseFieldEccChip , Halo2Loader , Plonk } ,
9
10
SnarkWitness ,
10
11
} ;
11
- use std:: rc:: Rc ;
12
-
13
- // pub const LIMBS: usize = 3;
14
- // pub const BITS: usize = 88;
15
- // pub const T: usize = 5;
16
- // pub const RATE: usize = 4;
17
- // pub const R_F: usize = 8;
18
- // pub const R_P: usize = 60;
19
-
20
- // pub type Svk = KzgSuccinctVerifyingKey<G1Affine>;
21
- // pub type As = KzgAs<Pcs>;
22
- // pub use snark_verifier_sdk::types::{Plonk, Halo2Loader, BaseFieldEccChip};
23
- // pub type Poseidon<L> = hash::Poseidon<Fr, L, T, RATE>;
24
- // // TODO: replace with POSEIDON_SPEC
25
- // pub type PoseidonTranscript<L, S> =
26
- // halo2::transcript::halo2::PoseidonTranscript<G1Affine, L, S, T, RATE, R_F, R_P>;
27
-
28
- // pub struct Snark {
29
- // pub protocol: Protocol<G1Affine>,
30
- // pub instances: Vec<Vec<Fr>>,
31
- // pub proof: Vec<u8>,
32
- // }
33
-
34
- // impl Snark {
35
- // pub fn new(protocol: Protocol<G1Affine>, instances: Vec<Vec<Fr>>, proof: Vec<u8>) -> Self {
36
- // Self { protocol, instances, proof }
37
- // }
38
- // }
39
-
40
- // impl From<Snark> for SnarkWitness {
41
- // fn from(snark: Snark) -> Self {
42
- // Self {
43
- // protocol: snark.protocol,
44
- // instances: snark
45
- // .instances
46
- // .into_iter()
47
- // .map(|instances| instances.into_iter().map(Value::known).collect_vec())
48
- // .collect(),
49
- // proof: Value::known(snark.proof),
50
- // }
51
- // }
52
- // }
53
-
54
- // #[derive(Clone)]
55
- // pub struct SnarkWitness {
56
- // pub protocol: Protocol<G1Affine>,
57
- // pub instances: Vec<Vec<Value<Fr>>>,
58
- // pub proof: Value<Vec<u8>>,
59
- // }
60
-
61
- // impl SnarkWitness {
62
- // pub fn without_witnesses(&self) -> Self {
63
- // SnarkWitness {
64
- // protocol: self.protocol.clone(),
65
- // instances: self
66
- // .instances
67
- // .iter()
68
- // .map(|instances| vec![Value::unknown(); instances.len()])
69
- // .collect(),
70
- // proof: Value::unknown(),
71
- // }
72
- // }
73
-
74
- // pub fn proof(&self) -> Value<&[u8]> {
75
- // self.proof.as_ref().map(Vec::as_slice)
76
- // }
77
- // }
78
-
79
- // pub fn gen_pk<C: Circuit<Fr>>(params: &ParamsKZG<Bn256>, circuit: &C) -> ProvingKey<G1Affine> {
80
- // let vk = keygen_vk(params, circuit).unwrap();
81
- // keygen_pk(params, vk, circuit).unwrap()
82
- // }
83
-
84
- // pub fn gen_proof<C: Circuit<Fr>>(
85
- // params: &ParamsKZG<Bn256>,
86
- // pk: &ProvingKey<G1Affine>,
87
- // circuit: C,
88
- // rng: impl Rng + Send,
89
- // instances: Vec<Vec<Fr>>,
90
- // ) -> Vec<u8> {
91
- // if params.k() > 3 {
92
- // let mock = start_timer!(|| "Mock prover");
93
- // MockProver::run(params.k(), &circuit, instances.clone())
94
- // .unwrap()
95
- // .assert_satisfied_par();
96
- // end_timer!(mock);
97
- // }
98
12
99
- // let instances = instances.iter().map(Vec::as_slice).collect_vec();
100
- // let proof = {
101
- // let mut transcript = PoseidonTranscript::<NativeLoader, _>::new(Vec::new());
102
- // create_proof::<_, ProverGWC<_>, _, _, _, _>(
103
- // params,
104
- // pk,
105
- // &[circuit],
106
- // &[instances.as_slice()],
107
- // rng,
108
- // &mut transcript,
109
- // )
110
- // .unwrap();
111
- // transcript.finalize()
112
- // };
113
-
114
- // let accept = {
115
- // let mut transcript = PoseidonTranscript::<NativeLoader, _>::new(proof.as_slice());
116
- // VerificationStrategy::<_, VerifierGWC<_>>::finalize(
117
- // verify_proof::<_, VerifierGWC<_>, _, _, _>(
118
- // params.verifier_params(),
119
- // pk.get_vk(),
120
- // AccumulatorStrategy::new(params.verifier_params()),
121
- // &[instances.as_slice()],
122
- // &mut transcript,
123
- // )
124
- // .unwrap(),
125
- // )
126
- // };
127
- // assert!(accept);
128
-
129
- // proof
130
- // }
131
-
132
- // pub fn gen_snark<ConcreteCircuit: CircuitExt<Fr>>(
133
- // params: &ParamsKZG<Bn256>,
134
- // pk: &ProvingKey<G1Affine>,
135
- // circuit: ConcreteCircuit,
136
- // rng: impl Rng + Send,
137
- // ) -> Snark {
138
- // let protocol = compile(
139
- // params,
140
- // pk.get_vk(),
141
- // Config::kzg()
142
- // .with_num_instance(ConcreteCircuit::num_instance())
143
- // .with_accumulator_indices(ConcreteCircuit::accumulator_indices()),
144
- // );
145
-
146
- // let instances = circuit.instances();
147
- // let proof = gen_proof(params, pk, circuit, rng, instances.clone());
148
-
149
- // Snark::new(protocol, instances, proof)
150
- // }
151
-
152
- // pub fn gen_dummy_snark<ConcreteCircuit: CircuitExt<Fr>>(
153
- // params: &ParamsKZG<Bn256>,
154
- // vk: Option<&VerifyingKey<G1Affine>>,
155
- // rng: impl Rng + Send,
156
- // ) -> Snark {
157
- // use std::{iter, marker::PhantomData};
158
- // struct CsProxy<F, C>(PhantomData<(F, C)>);
159
-
160
- // impl<F: Field, C: CircuitExt<F>> Circuit<F> for CsProxy<F, C> {
161
- // type Config = C::Config;
162
- // type FloorPlanner = C::FloorPlanner;
163
- // #[cfg(feature = "circuit-params")]
164
- // type Params = ();
165
-
166
- // fn without_witnesses(&self) -> Self {
167
- // CsProxy(PhantomData)
168
- // }
169
-
170
- // fn configure(meta: &mut ConstraintSystem<F>) -> Self::Config {
171
- // C::configure(meta)
172
- // }
173
-
174
- // fn synthesize(
175
- // &self,
176
- // config: Self::Config,
177
- // mut layouter: impl Layouter<F>,
178
- // ) -> Result<(), Error> {
179
- // // when `C` has simple selectors, we tell `CsProxy` not to over-optimize the selectors (e.g., compressing them all into one) by turning all selectors on in the first row
180
- // // currently this only works if all simple selector columns are used in the actual circuit and there are overlaps amongst all enabled selectors (i.e., the actual circuit will not optimize constraint system further)
181
- // layouter.assign_region(
182
- // || "",
183
- // |mut region| {
184
- // for q in C::selectors(&config).iter() {
185
- // q.enable(&mut region, 0)?;
186
- // }
187
- // Ok(())
188
- // },
189
- // )?;
190
- // Ok(())
191
- // }
192
- // }
193
-
194
- // let dummy_vk = vk
195
- // .is_none()
196
- // .then(|| keygen_vk(params, &CsProxy::<Fr, ConcreteCircuit>(PhantomData)).unwrap());
197
- // let protocol = compile(
198
- // params,
199
- // vk.or(dummy_vk.as_ref()).unwrap(),
200
- // Config::kzg()
201
- // .with_num_instance(ConcreteCircuit::num_instance())
202
- // .with_accumulator_indices(ConcreteCircuit::accumulator_indices()),
203
- // );
204
- // let instances = ConcreteCircuit::num_instance()
205
- // .into_iter()
206
- // .map(|n| iter::repeat_with(|| Fr::random(rng)).take(n).collect())
207
- // .collect();
208
- // let proof = {
209
- // let mut transcript = PoseidonTranscript::<NativeLoader, _>::new(Vec::new());
210
- // for _ in 0..protocol
211
- // .num_witness
212
- // .iter()
213
- // .chain(Some(&protocol.quotient.num_chunk()))
214
- // .sum::<usize>()
215
- // {
216
- // transcript.write_ec_point(G1Affine::random(rng)).unwrap();
217
- // }
218
- // for _ in 0..protocol.evaluations.len() {
219
- // transcript.write_scalar(Fr::random(rng)).unwrap();
220
- // }
221
- // let queries = PlonkProof::<G1Affine, NativeLoader, Pcs>::empty_queries(&protocol);
222
- // for _ in 0..Pcs::estimate_cost(&queries).num_commitment {
223
- // transcript.write_ec_point(G1Affine::random(rng)).unwrap();
224
- // }
225
- // transcript.finalize()
226
- // };
227
-
228
- // Snark::new(protocol, instances, proof)
229
- // }
13
+ use super :: * ;
230
14
231
15
type AssignedScalar < ' a > = <BaseFieldEccChip as EccInstructions < ' a , G1Affine > >:: AssignedScalar ;
232
16
@@ -236,17 +20,9 @@ fn poseidon<L: Loader<G1Affine>>(loader: &L, inputs: &[L::LoadedScalar]) -> L::L
236
20
hasher. squeeze ( )
237
21
}
238
22
239
- // TODO: maybe it can be added into snark-verifier sdk later?
240
- // Now it is still a version specified for Kzg since the only
241
- // type support AccumulatorEncoding trait in verifier::Plonk
242
- // is LimbsEncoding, which only be generic with PCS whose Accmulator
243
- // is KzgAccmulator ...
244
-
245
23
/// It is similar to `succinct_verify` method inside of snark-verifier
246
24
/// but allow it allow loader to load preprocessed part as witness (so ANY circuit)
247
- /// can be verified
248
- ///
249
- ///
25
+ /// can be verified.
250
26
pub fn dynamic_verify < ' a , PCS > (
251
27
svk : & PCS :: SuccinctVerifyingKey ,
252
28
loader : & Rc < Halo2Loader < ' a > > ,
0 commit comments