-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathr1cs_gg_ppzksnark.i
472 lines (472 loc) · 18.4 KB
/
r1cs_gg_ppzksnark.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
///** @file
//*****************************************************************************
//
//Declaration of interfaces for a ppzkSNARK for R1CS with a security proof
//in the generic group (GG) model.
//
//This includes:
//- class for proving key
//- class for verification key
//- class for processed verification key
//- class for key pair (proving key & verification key)
//- class for proof
//- generator algorithm
//- prover algorithm
//- verifier algorithm (with strong or weak input consistency)
//- online verifier algorithm (with strong or weak input consistency)
//
//The implementation instantiates the protocol of \[Gro16].
//
//
//Acronyms:
//
//- R1CS = "Rank-1 Constraint Systems"
//- ppzkSNARK = "PreProcessing Zero-Knowledge Succinct Non-interactive ARgument of Knowledge"
//
//References:
//
//\[Gro16]:
// "On the Size of Pairing-based Non-interactive Arguments",
// Jens Groth,
// EUROCRYPT 2016,
// <https://eprint.iacr.org/2016/260>
//
//
//*****************************************************************************
//* @author This file is part of libsnark, developed by SCIPR Lab
//* and contributors (see AUTHORS).
//* @copyright MIT license (see LICENSE file)
//*****************************************************************************/
//
//#ifndef R1CS_GG_PPZKSNARK_HPP_
//#define R1CS_GG_PPZKSNARK_HPP_
//
//#include <memory>
//
//#include <libff/algebra/curves/public_params.hpp>
//
//#include <libsnark/common/data_structures/accumulation_vector.hpp>
//#include <libsnark/knowledge_commitment/knowledge_commitment.hpp>
//#include <libsnark/relations/constraint_satisfaction_problems/r1cs/r1cs.hpp>
//#include <libsnark/zk_proof_systems/ppzksnark/r1cs_gg_ppzksnark/r1cs_gg_ppzksnark_params.hpp>
//
//namespace libsnark {
//
///******************************** Proving key ********************************/
//
//template<typename ppT>
//class r1cs_gg_ppzksnark_proving_key;
//
//template<typename ppT>
//std::ostream& operator<<(std::ostream &out, const r1cs_gg_ppzksnark_proving_key<ppT> &pk);
//
//template<typename ppT>
//std::istream& operator>>(std::istream &in, r1cs_gg_ppzksnark_proving_key<ppT> &pk);
//
///**
// * A proving key for the R1CS GG-ppzkSNARK.
// */
template<typename ppT>
class r1cs_gg_ppzksnark_proving_key {
//public:
// libff::G1<ppT> alpha_g1;
// libff::G1<ppT> beta_g1;
// libff::G2<ppT> beta_g2;
// libff::G1<ppT> delta_g1;
// libff::G2<ppT> delta_g2;
//
// libff::G1_vector<ppT> A_query; // this could be a sparse vector if we had multiexp for those
// knowledge_commitment_vector<libff::G2<ppT>, libff::G1<ppT> > B_query;
// libff::G1_vector<ppT> H_query;
// libff::G1_vector<ppT> L_query;
//
// r1cs_gg_ppzksnark_constraint_system<ppT> constraint_system;
//
// r1cs_gg_ppzksnark_proving_key() {};
// r1cs_gg_ppzksnark_proving_key<ppT>& operator=(const r1cs_gg_ppzksnark_proving_key<ppT> &other) = default;
// r1cs_gg_ppzksnark_proving_key(const r1cs_gg_ppzksnark_proving_key<ppT> &other) = default;
// r1cs_gg_ppzksnark_proving_key(r1cs_gg_ppzksnark_proving_key<ppT> &&other) = default;
// r1cs_gg_ppzksnark_proving_key(libff::G1<ppT> &&alpha_g1,
// libff::G1<ppT> &&beta_g1,
// libff::G2<ppT> &&beta_g2,
// libff::G1<ppT> &&delta_g1,
// libff::G2<ppT> &&delta_g2,
// libff::G1_vector<ppT> &&A_query,
// knowledge_commitment_vector<libff::G2<ppT>, libff::G1<ppT> > &&B_query,
// libff::G1_vector<ppT> &&H_query,
// libff::G1_vector<ppT> &&L_query,
// r1cs_gg_ppzksnark_constraint_system<ppT> &&constraint_system) :
// alpha_g1(std::move(alpha_g1)),
// beta_g1(std::move(beta_g1)),
// beta_g2(std::move(beta_g2)),
// delta_g1(std::move(delta_g1)),
// delta_g2(std::move(delta_g2)),
// A_query(std::move(A_query)),
// B_query(std::move(B_query)),
// H_query(std::move(H_query)),
// L_query(std::move(L_query)),
// constraint_system(std::move(constraint_system))
// {};
//
// size_t G1_size() const
// {
// return 1 + A_query.size() + B_query.domain_size() + H_query.size() + L_query.size();
// }
//
// size_t G2_size() const
// {
// return 1 + B_query.domain_size();
// }
//
// size_t G1_sparse_size() const
// {
// return 1 + A_query.size() + B_query.size() + H_query.size() + L_query.size();
// }
//
// size_t G2_sparse_size() const
// {
// return 1 + B_query.size();
// }
//
// size_t size_in_bits() const
// {
// return (libff::size_in_bits(A_query) + B_query.size_in_bits() +
// libff::size_in_bits(H_query) + libff::size_in_bits(L_query) +
// 1 * libff::G1<ppT>::size_in_bits() + 1 * libff::G2<ppT>::size_in_bits());
// }
//
// void print_size() const
// {
// libff::print_indent(); printf("* G1 elements in PK: %zu\n", this->G1_size());
// libff::print_indent(); printf("* Non-zero G1 elements in PK: %zu\n", this->G1_sparse_size());
// libff::print_indent(); printf("* G2 elements in PK: %zu\n", this->G2_size());
// libff::print_indent(); printf("* Non-zero G2 elements in PK: %zu\n", this->G2_sparse_size());
// libff::print_indent(); printf("* PK size in bits: %zu\n", this->size_in_bits());
// }
//
// bool operator==(const r1cs_gg_ppzksnark_proving_key<ppT> &other) const;
// friend std::ostream& operator<< <ppT>(std::ostream &out, const r1cs_gg_ppzksnark_proving_key<ppT> &pk);
// friend std::istream& operator>> <ppT>(std::istream &in, r1cs_gg_ppzksnark_proving_key<ppT> &pk);
};
//
//
///******************************* Verification key ****************************/
//
//template<typename ppT>
//class r1cs_gg_ppzksnark_verification_key;
//
//template<typename ppT>
//std::ostream& operator<<(std::ostream &out, const r1cs_gg_ppzksnark_verification_key<ppT> &vk);
//
//template<typename ppT>
//std::istream& operator>>(std::istream &in, r1cs_gg_ppzksnark_verification_key<ppT> &vk);
//
///**
// * A verification key for the R1CS GG-ppzkSNARK.
// */
template<typename ppT>
class r1cs_gg_ppzksnark_verification_key {
//public:
// libff::GT<ppT> alpha_g1_beta_g2;
// libff::G2<ppT> gamma_g2;
// libff::G2<ppT> delta_g2;
//
// accumulation_vector<libff::G1<ppT> > gamma_ABC_g1;
//
// r1cs_gg_ppzksnark_verification_key() = default;
// r1cs_gg_ppzksnark_verification_key(const libff::GT<ppT> &alpha_g1_beta_g2,
// const libff::G2<ppT> &gamma_g2,
// const libff::G2<ppT> &delta_g2,
// const accumulation_vector<libff::G1<ppT> > &gamma_ABC_g1) :
// alpha_g1_beta_g2(alpha_g1_beta_g2),
// gamma_g2(gamma_g2),
// delta_g2(delta_g2),
// gamma_ABC_g1(gamma_ABC_g1)
// {};
//
// size_t G1_size() const
// {
// return gamma_ABC_g1.size();
// }
//
// size_t G2_size() const
// {
// return 2;
// }
//
// size_t GT_size() const
// {
// return 1;
// }
//
// size_t size_in_bits() const
// {
// // TODO: include GT size
// return (gamma_ABC_g1.size_in_bits() + 2 * libff::G2<ppT>::size_in_bits());
// }
//
// void print_size() const
// {
// libff::print_indent(); printf("* G1 elements in VK: %zu\n", this->G1_size());
// libff::print_indent(); printf("* G2 elements in VK: %zu\n", this->G2_size());
// libff::print_indent(); printf("* GT elements in VK: %zu\n", this->GT_size());
// libff::print_indent(); printf("* VK size in bits: %zu\n", this->size_in_bits());
// }
//
// bool operator==(const r1cs_gg_ppzksnark_verification_key<ppT> &other) const;
// friend std::ostream& operator<< <ppT>(std::ostream &out, const r1cs_gg_ppzksnark_verification_key<ppT> &vk);
// friend std::istream& operator>> <ppT>(std::istream &in, r1cs_gg_ppzksnark_verification_key<ppT> &vk);
//
// static r1cs_gg_ppzksnark_verification_key<ppT> dummy_verification_key(const size_t input_size);
};
//
//
///************************ Processed verification key *************************/
//
//template<typename ppT>
//class r1cs_gg_ppzksnark_processed_verification_key;
//
//template<typename ppT>
//std::ostream& operator<<(std::ostream &out, const r1cs_gg_ppzksnark_processed_verification_key<ppT> &pvk);
//
//template<typename ppT>
//std::istream& operator>>(std::istream &in, r1cs_gg_ppzksnark_processed_verification_key<ppT> &pvk);
//
///**
// * A processed verification key for the R1CS GG-ppzkSNARK.
// *
// * Compared to a (non-processed) verification key, a processed verification key
// * contains a small constant amount of additional pre-computed information that
// * enables a faster verification time.
// */
//template<typename ppT>
//class r1cs_gg_ppzksnark_processed_verification_key {
//public:
// libff::GT<ppT> vk_alpha_g1_beta_g2;
// libff::G2_precomp<ppT> vk_gamma_g2_precomp;
// libff::G2_precomp<ppT> vk_delta_g2_precomp;
//
// accumulation_vector<libff::G1<ppT> > gamma_ABC_g1;
//
// bool operator==(const r1cs_gg_ppzksnark_processed_verification_key &other) const;
// friend std::ostream& operator<< <ppT>(std::ostream &out, const r1cs_gg_ppzksnark_processed_verification_key<ppT> &pvk);
// friend std::istream& operator>> <ppT>(std::istream &in, r1cs_gg_ppzksnark_processed_verification_key<ppT> &pvk);
//};
//
//
///********************************** Key pair *********************************/
//
///**
// * A key pair for the R1CS GG-ppzkSNARK, which consists of a proving key and a verification key.
// */
template<typename ppT>
class r1cs_gg_ppzksnark_keypair {
public:
r1cs_gg_ppzksnark_proving_key<ppT> pk;
r1cs_gg_ppzksnark_verification_key<ppT> vk;
//
// r1cs_gg_ppzksnark_keypair() = default;
// r1cs_gg_ppzksnark_keypair(const r1cs_gg_ppzksnark_keypair<ppT> &other) = default;
// r1cs_gg_ppzksnark_keypair(r1cs_gg_ppzksnark_proving_key<ppT> &&pk,
// r1cs_gg_ppzksnark_verification_key<ppT> &&vk) :
// pk(std::move(pk)),
// vk(std::move(vk))
// {}
//
r1cs_gg_ppzksnark_keypair(r1cs_gg_ppzksnark_keypair<ppT> &&other) = default;
};
//
//
///*********************************** Proof ***********************************/
//
//template<typename ppT>
//class r1cs_gg_ppzksnark_proof;
//
//template<typename ppT>
//std::ostream& operator<<(std::ostream &out, const r1cs_gg_ppzksnark_proof<ppT> &proof);
//
//template<typename ppT>
//std::istream& operator>>(std::istream &in, r1cs_gg_ppzksnark_proof<ppT> &proof);
//
///**
// * A proof for the R1CS GG-ppzkSNARK.
// *
// * While the proof has a structure, externally one merely opaquely produces,
// * serializes/deserializes, and verifies proofs. We only expose some information
// * about the structure for statistics purposes.
// */
template<typename ppT>
class r1cs_gg_ppzksnark_proof {
public:
// libff::G1<ppT> g_A;
// libff::G2<ppT> g_B;
// libff::G1<ppT> g_C;
//
// r1cs_gg_ppzksnark_proof()
// {
// // invalid proof with valid curve points
// this->g_A = libff::G1<ppT>::one();
// this->g_B = libff::G2<ppT>::one();
// this->g_C = libff::G1<ppT>::one();
// }
// r1cs_gg_ppzksnark_proof(libff::G1<ppT> &&g_A,
// libff::G2<ppT> &&g_B,
// libff::G1<ppT> &&g_C) :
// g_A(std::move(g_A)),
// g_B(std::move(g_B)),
// g_C(std::move(g_C))
// {};
//
// size_t G1_size() const
// {
// return 2;
// }
//
// size_t G2_size() const
// {
// return 1;
// }
//
// size_t size_in_bits() const
// {
// return G1_size() * libff::G1<ppT>::size_in_bits() + G2_size() * libff::G2<ppT>::size_in_bits();
// }
//
// void print_size() const
// {
// libff::print_indent(); printf("* G1 elements in proof: %zu\n", this->G1_size());
// libff::print_indent(); printf("* G2 elements in proof: %zu\n", this->G2_size());
// libff::print_indent(); printf("* Proof size in bits: %zu\n", this->size_in_bits());
// }
//
// bool is_well_formed() const
// {
// return (g_A.is_well_formed() &&
// g_B.is_well_formed() &&
// g_C.is_well_formed());
// }
//
// bool operator==(const r1cs_gg_ppzksnark_proof<ppT> &other) const;
// friend std::ostream& operator<< <ppT>(std::ostream &out, const r1cs_gg_ppzksnark_proof<ppT> &proof);
// friend std::istream& operator>> <ppT>(std::istream &in, r1cs_gg_ppzksnark_proof<ppT> &proof);
};
//
//
///***************************** Main algorithms *******************************/
//
///**
// * A generator algorithm for the R1CS GG-ppzkSNARK.
// *
// * Given a R1CS constraint system CS, this algorithm produces proving and verification keys for CS.
// */
//template<typename ppT>
//r1cs_gg_ppzksnark_keypair<ppT> r1cs_gg_ppzksnark_generator(const r1cs_gg_ppzksnark_constraint_system<ppT> &cs);
template<typename ppT>
r1cs_gg_ppzksnark_keypair<ppT> r1cs_gg_ppzksnark_generator(const r1cs_constraint_system<Ft> &cs);
//
///**
// * A prover algorithm for the R1CS GG-ppzkSNARK.
// *
// * Given a R1CS primary input X and a R1CS auxiliary input Y, this algorithm
// * produces a proof (of knowledge) that attests to the following statement:
// * ``there exists Y such that CS(X,Y)=0''.
// * Above, CS is the R1CS constraint system that was given as input to the generator algorithm.
// */
//template<typename ppT>
//r1cs_gg_ppzksnark_proof<ppT> r1cs_gg_ppzksnark_prover(const r1cs_gg_ppzksnark_proving_key<ppT> &pk,
// const r1cs_gg_ppzksnark_primary_input<ppT> &primary_input,
// const r1cs_gg_ppzksnark_auxiliary_input<ppT> &auxiliary_input);
template<typename ppT>
r1cs_gg_ppzksnark_proof<ppT> r1cs_gg_ppzksnark_prover(const r1cs_gg_ppzksnark_proving_key<ppT> &pk,
const r1cs_primary_input<Ft> &primary_input,
const r1cs_auxiliary_input<Ft> &auxiliary_input);
//
///*
// Below are four variants of verifier algorithm for the R1CS GG-ppzkSNARK.
//
// These are the four cases that arise from the following two choices:
//
// (1) The verifier accepts a (non-processed) verification key or, instead, a processed verification key.
// In the latter case, we call the algorithm an "online verifier".
//
// (2) The verifier checks for "weak" input consistency or, instead, "strong" input consistency.
// Strong input consistency requires that |primary_input| = CS.num_inputs, whereas
// weak input consistency requires that |primary_input| <= CS.num_inputs (and
// the primary input is implicitly padded with zeros up to length CS.num_inputs).
//*/
//
///**
// * A verifier algorithm for the R1CS GG-ppzkSNARK that:
// * (1) accepts a non-processed verification key, and
// * (2) has weak input consistency.
// */
//template<typename ppT>
//bool r1cs_gg_ppzksnark_verifier_weak_IC(const r1cs_gg_ppzksnark_verification_key<ppT> &vk,
// const r1cs_gg_ppzksnark_primary_input<ppT> &primary_input,
// const r1cs_gg_ppzksnark_proof<ppT> &proof);
template<typename ppT>
bool r1cs_gg_ppzksnark_verifier_weak_IC(const r1cs_gg_ppzksnark_verification_key<ppT> &vk,
const r1cs_primary_input<Ft> &primary_input,
const r1cs_gg_ppzksnark_proof<ppT> &proof);
//
///**
// * A verifier algorithm for the R1CS GG-ppzkSNARK that:
// * (1) accepts a non-processed verification key, and
// * (2) has strong input consistency.
// */
//template<typename ppT>
//bool r1cs_gg_ppzksnark_verifier_strong_IC(const r1cs_gg_ppzksnark_verification_key<ppT> &vk,
// const r1cs_gg_ppzksnark_primary_input<ppT> &primary_input,
// const r1cs_gg_ppzksnark_proof<ppT> &proof);
template<typename ppT>
bool r1cs_gg_ppzksnark_verifier_strong_IC(const r1cs_gg_ppzksnark_verification_key<ppT> &vk,
const r1cs_primary_input<Ft> &primary_input,
const r1cs_gg_ppzksnark_proof<ppT> &proof);
//
///**
// * Convert a (non-processed) verification key into a processed verification key.
// */
//template<typename ppT>
//r1cs_gg_ppzksnark_processed_verification_key<ppT> r1cs_gg_ppzksnark_verifier_process_vk(const r1cs_gg_ppzksnark_verification_key<ppT> &vk);
//
///**
// * A verifier algorithm for the R1CS GG-ppzkSNARK that:
// * (1) accepts a processed verification key, and
// * (2) has weak input consistency.
// */
//template<typename ppT>
//bool r1cs_gg_ppzksnark_online_verifier_weak_IC(const r1cs_gg_ppzksnark_processed_verification_key<ppT> &pvk,
// const r1cs_gg_ppzksnark_primary_input<ppT> &input,
// const r1cs_gg_ppzksnark_proof<ppT> &proof);
//
///**
// * A verifier algorithm for the R1CS GG-ppzkSNARK that:
// * (1) accepts a processed verification key, and
// * (2) has strong input consistency.
// */
//template<typename ppT>
//bool r1cs_gg_ppzksnark_online_verifier_strong_IC(const r1cs_gg_ppzksnark_processed_verification_key<ppT> &pvk,
// const r1cs_gg_ppzksnark_primary_input<ppT> &primary_input,
// const r1cs_gg_ppzksnark_proof<ppT> &proof);
//
///****************************** Miscellaneous ********************************/
//
///**
// * For debugging purposes (of r1cs_gg_ppzksnark_r1cs_gg_ppzksnark_verifier_gadget):
// *
// * A verifier algorithm for the R1CS GG-ppzkSNARK that:
// * (1) accepts a non-processed verification key,
// * (2) has weak input consistency, and
// * (3) uses affine coordinates for elliptic-curve computations.
// */
//template<typename ppT>
//bool r1cs_gg_ppzksnark_affine_verifier_weak_IC(const r1cs_gg_ppzksnark_verification_key<ppT> &vk,
// const r1cs_gg_ppzksnark_primary_input<ppT> &primary_input,
// const r1cs_gg_ppzksnark_proof<ppT> &proof);
//
//
//} // libsnark
//
//#include <libsnark/zk_proof_systems/ppzksnark/r1cs_gg_ppzksnark/r1cs_gg_ppzksnark.tcc>
//
//#endif // R1CS_GG_PPZKSNARK_HPP_