-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
78 lines (54 loc) · 1.8 KB
/
main.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
#include <iostream>
#include "Proof.hh"
// Simple scalar multiplication test
void multTest() {
auto curve = Point(Secp256k1, Secp256k1.G.x, Secp256k1.G.y);
auto q = curve;
std::cout << "Curve point: " << q.x() << " " << q.y() << "\n";
std::cout << "Is on curve ? " << q.isOnCurve() << "\n";
for (auto i = 2; i < 10; ++i) {
q = q.add(curve);
std::cout << "Curve point: " << q.x() << " " << q.y() << "\n";
auto g = curve.scalarMult(i);
if (q != g)
std::cout << "Fail " << i << "\n";
else
std::cout << "Success " << i << "\n";
}
}
// NIZK proof test
void proofTest() {
srand(static_cast<unsigned int>(time(nullptr)));
// ECC curve secp256k1
auto curve = Point(Secp256k1.G.x, Secp256k1.G.y);
// Secret value
uint256_t x = rand();
std::cout << "x: " << x << "\n";
// Random private keys
uint256_t rand1 = rand();
uint256_t rand2 = rand();
std::cout << "rand1: " << rand1 << "\n";
std::cout << "rand2: " << rand2 << "\n";
// Init generators (public keys)
Point g = curve.scalarMult(rand1);
Point m = curve.scalarMult(rand2);
std::coud << "g: " << g.x() << " " < g.y() << "\n";
std::coud << "m: " << m.x() << " " < m.y() << "\n";
// Prepare list of random tests
std::vector<uint256_t> cList;
for (auto k = 0; k < 5; ++k)
cList.push_back((uint256_t)rand());
// Proof
auto proof = Proof::generate(g, m, x, cList);
// Print a, b
std::cout << "Proof generated\n";
std::cout << "a: " << proof.a.x() << " " << proof.a.y() << "\n";
std::cout << "b: " << proof.b.x() << " " << proof.b.y() << "\n";
// Validate
std::cout << "valid for x: " << proof.verify() << "\n";
}
int main() {
multTest();
proofTest();
return 0;
}