-
Notifications
You must be signed in to change notification settings - Fork 9
/
BenchFk.cpp
91 lines (71 loc) · 2.63 KB
/
BenchFk.cpp
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
#include <polycrypto/Configuration.h>
#include <polycrypto/PolyCrypto.h>
#include <polycrypto/PolyOps.h>
#include <polycrypto/Utils.h>
#include <polycrypto/KZG.h>
#include <polycrypto/FFT.h>
#include <polycrypto/KatePublicParameters.h>
#include <cmath>
#include <ctime>
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <vector>
#include <xassert/XAssert.h>
#include <xutils/Log.h>
#include <xutils/Utils.h>
#include <xutils/NotImplementedException.h>
#include <xutils/Timer.h>
using namespace std;
using namespace libfqfft;
using namespace libpolycrypto;
int main(int argc, char *argv[]) {
libpolycrypto::initialize(nullptr, 0);
srand(static_cast<unsigned int>(time(NULL)));
if(argc < 5) {
cout << "Usage: " << argv[0] << "<deg> <n> <r>" << endl;
cout << endl;
cout << "OPTIONS: " << endl;
cout << " <pp-file> the Kate public parameters file" << endl;
cout << " <deg> the degree of the evaluated polynomial (i.e., t-1)" << endl;
cout << " <n> the # of points to construct proofs for" << endl;
cout << " <r> the # of times to repeat the benchmark" << endl;
cout << endl;
return 1;
}
std::string ppFile = argv[1];
size_t deg = static_cast<size_t>(std::stoi(argv[2]));
size_t n = static_cast<size_t>(std::stoi(argv[3]));
size_t r = static_cast<size_t>(std::stoi(argv[4]));
size_t N = Utils::smallestPowerOfTwoAbove(n);
// TODO: what happens if deg > n?
std::unique_ptr<Dkg::KatePublicParameters> kpp(
new Dkg::KatePublicParameters(ppFile, deg));
loginfo << endl;
loginfo << "Degree " << deg << " poly, evaluated at n = " << n << " points, iters = " << r << endl;
std::vector<Fr> f = random_field_elems(deg + 1);
AveragingTimer ht("Computing h[i]'s");
std::chrono::microseconds::rep mus;
std::vector<G1> H;
for(size_t i = 0; i < r; i++) {
ht.startLap();
H = kpp->computeAllHis(f);
mus = ht.endLap();
logperf << " - Computing h[i]'s (iter " << i << "): " << Utils::humanizeMicroseconds(mus, 2) << endl;
}
// resize H to size n, since the degree of f < n
H.resize(N, G1::zero());
AveragingTimer ft("FFT on h[i]'s");
for(size_t i = 0; i < r; i++) {
ft.startLap();
FFT<G1, Fr>(H);
mus = ft.endLap();
logperf << " - FFT on h[i]'s (iter " << i << "): " << Utils::humanizeMicroseconds(mus, 2) << endl;
}
logperf << endl;
logperf << ht << endl;
logperf << ft << endl;
logperf << endl;
loginfo << "Exited successfully!" << endl;
return 0;
}