-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathio.i
82 lines (69 loc) · 2.29 KB
/
io.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
%{
#include <iostream>
#include <fstream>
template<mp_size_t n, const bigint<n>& modulus>
void prettywrite(std::ostream &strm, const Fp_model<n, modulus> &val) {
mpz_t t;
mpz_init(t);
val.as_bigint().to_mpz(t);
strm << t;
mpz_clear(t);
}
template<mp_size_t n, const bigint<n>& modulus>
void prettywrite(std::ostream &strm, const Fp2_model<n, modulus> &el)
{
prettywrite(strm, el.c0);
strm << " ";
prettywrite(strm, el.c1);
}
// formatting by https://github.com/christianlundkvist/libsnark-tutorial/blob/master/src/util.hpp
void prettywrite(ostream& strm, const libff::G1<libff::alt_bn128_pp>& pt) {
libff::G1<libff::alt_bn128_pp> pp(pt);
pp.to_affine_coordinates();
prettywrite(strm, pp.X); strm << endl;
prettywrite(strm, pp.Y); strm << endl;
prettywrite(strm, pp.Z); strm << endl;
}
void prettywrite(ostream& strm, const libff::G2<libff::alt_bn128_pp>& pt) {
libff::G2<libff::alt_bn128_pp> pp(pt);
pp.to_affine_coordinates();
prettywrite(strm, pp.X); strm << endl;
prettywrite(strm, pp.Y); strm << endl;
prettywrite(strm, pp.Z); strm << endl;
}
template<typename T>
void prettywrite(std::ostream& out, const sparse_vector<T> &v)
{
for (int i = 0; i < v.indices.size(); i++) {
prettywrite(out, v.values[i]);
}
}
template<typename T>
void prettywrite(std::ostream& out, const accumulation_vector<T> &v)
{
out << (v.rest.indices.size()+1) << endl;
prettywrite(out, v.first);
prettywrite(out, v.rest);
}
bool cseq(
const libsnark::r1cs_constraint_system<Ft>& cs1,
const libsnark::r1cs_constraint_system<Ft>& cs2) {
if (cs1.constraints.size() != cs2.constraints.size()) return false;
if (cs1.primary_input_size != cs2.primary_input_size) return false;
if (cs1.auxiliary_input_size != cs2.auxiliary_input_size) return false;
auto it1 = cs1.constraints.begin();
auto it2 = cs2.constraints.begin();
// libsnark may swap a and b so this is a bit involved
while (it1!=cs1.constraints.end()) {
if (!(it1->c==it2->c)) return false;
if (it1->a==it2->a) {
if (!(it1->b==it2->b)) return false;
} else {
if (!(it1->a==it2->b && it1->b==it2->a)) return false;
}
it1++;
it2++;
}
return true;
}
%}