Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_bilinearity.cpp
Go to the documentation of this file.
1
9#ifdef CURVE_BN128
11#endif
15
16using namespace libff;
17
18#ifndef NDEBUG
19template<typename ppT>
21{
22 GT<ppT> GT_one = GT<ppT>::one();
23
24 printf("Running bilinearity tests:\n");
26 //G1<ppT> P = Fr<ppT>("2") * G1<ppT>::one();
28 //G2<ppT> Q = Fr<ppT>("3") * G2<ppT>::one();
29
30 printf("P:\n");
31 P.print();
32 P.print_coordinates();
33 printf("Q:\n");
34 Q.print();
35 Q.print_coordinates();
36 printf("\n\n");
37
39 //Fr<ppT> s = Fr<ppT>("2");
40 G1<ppT> sP = s * P;
41 G2<ppT> sQ = s * Q;
42
43 printf("Pairing bilinearity tests (three must match):\n");
44 GT<ppT> ans1 = ppT::reduced_pairing(sP, Q);
45 GT<ppT> ans2 = ppT::reduced_pairing(P, sQ);
46 GT<ppT> ans3 = ppT::reduced_pairing(P, Q)^s;
47 ans1.print();
48 ans2.print();
49 ans3.print();
50 assert(ans1 == ans2);
51 assert(ans2 == ans3);
52
53 assert(ans1 != GT_one);
54 assert((ans1^Fr<ppT>::field_char()) == GT_one);
55 printf("\n\n");
56}
57
58template<typename ppT>
60{
65
66 const G1_precomp<ppT> prec_P1 = ppT::precompute_G1(P1);
67 const G1_precomp<ppT> prec_P2 = ppT::precompute_G1(P2);
68 const G2_precomp<ppT> prec_Q1 = ppT::precompute_G2(Q1);
69 const G2_precomp<ppT> prec_Q2 = ppT::precompute_G2(Q2);
70
71 const Fqk<ppT> ans_1 = ppT::miller_loop(prec_P1, prec_Q1);
72 const Fqk<ppT> ans_2 = ppT::miller_loop(prec_P2, prec_Q2);
73 const Fqk<ppT> ans_12 = ppT::double_miller_loop(prec_P1, prec_Q1, prec_P2, prec_Q2);
74 assert(ans_1 * ans_2 == ans_12);
75}
76
77template<typename ppT>
79{
80 GT<ppT> GT_one = GT<ppT>::one();
81
82 printf("Running bilinearity tests:\n");
85
86 printf("P:\n");
87 P.print();
88 printf("Q:\n");
89 Q.print();
90 printf("\n\n");
91
93 G1<ppT> sP = s * P;
94 G2<ppT> sQ = s * Q;
95
96 printf("Pairing bilinearity tests (three must match):\n");
97 GT<ppT> ans1 = ppT::affine_reduced_pairing(sP, Q);
98 GT<ppT> ans2 = ppT::affine_reduced_pairing(P, sQ);
99 GT<ppT> ans3 = ppT::affine_reduced_pairing(P, Q)^s;
100 ans1.print();
101 ans2.print();
102 ans3.print();
103 assert(ans1 == ans2);
104 assert(ans2 == ans3);
105
106 assert(ans1 != GT_one);
107 assert((ans1^Fr<ppT>::field_char()) == GT_one);
108 printf("\n\n");
109}
110
138
139#else // NDEBUG
140
141int main()
142{
143 printf("All tests here depend on assert() which is disabled by -DNDEBUG. Please recompile and run again.\n");
144}
145#endif // NDEBUG
static void init_public_params()
static void init_public_params()
Definition bn128_pp.cpp:13
static void init_public_params()
static void init_public_params()
Definition mnt4_pp.cpp:18
static void init_public_params()
Definition mnt6_pp.cpp:18
#define P
Definition dtoa.c:437
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
typename EC_ppT::Fqk_type Fqk
typename EC_ppT::G1_precomp_type G1_precomp
typename EC_ppT::G1_type G1
void start_profiling()
Definition profiling.cpp:56
typename EC_ppT::Fp_type Fr
typename EC_ppT::GT_type GT
typename EC_ppT::G2_precomp_type G2_precomp
void affine_pairing_test()
int main(void)
void pairing_test()
void double_miller_loop_test()
char * s