Skip to content

Commit 90f8bd3

Browse files
committed
verify for list of random challenges
1 parent 851ba8c commit 90f8bd3

File tree

3 files changed

+40
-20
lines changed

3 files changed

+40
-20
lines changed

Ecc.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ public:
7171
_curve{Secp256k1}
7272
{ }
7373

74-
Point(int1024_t const & x, int1024_t const & y) :
74+
Point(uint256_t const & x, uint256_t const & y) :
7575
_x{x}, _y{y}, _curve{Secp256k1}
7676
{ }
7777

78-
Point(Curve curve, int1024_t const & x, int1024_t const & y) :
78+
Point(Curve curve, uint256_t const & x, uint256_t const & y) :
7979
_x{x}, _y{y}, _curve{std::move(curve)}
8080
{ }
8181

@@ -159,7 +159,7 @@ private:
159159
auto v = ((int1024_t)y() + curve().p - (m * (int1024_t)x()) % curve().p) % curve().p;
160160
auto x = (m * m + curve().p - (int1024_t)this->x() + curve().p - (int1024_t)point.x()) % curve().p;
161161
auto y = (curve().p - (m * x) % curve().p + curve().p - v) % curve().p;
162-
return {curve(), x, y};
162+
return {curve(), (uint256_t)x, (uint256_t)y};
163163
}
164164

165165
private:

Proof.hh

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <array>
99
#include <cstring>
10+
#include <vector>
1011
#include "Ecc.hh"
1112

1213

@@ -17,7 +18,7 @@ struct Proof {
1718
Point h, z;
1819
Point a, b;
1920

20-
uint256_t r, c;
21+
std::vector<std::pair<uint256_t, uint256_t>> cr;
2122

2223
bool verify() {
2324
if (!h.isOnCurve() || !g.isOnCurve())
@@ -26,28 +27,34 @@ struct Proof {
2627
if (!z.isOnCurve() || !m.isOnCurve())
2728
return false;
2829

29-
auto ch = h.scalarMult(c);
30-
auto rg = g.scalarMult(r);
31-
auto aa = rg.add(ch);
30+
for (auto pair: cr) {
31+
auto ch = h.scalarMult(pair.first);
32+
auto rg = g.scalarMult(pair.second);
33+
auto aa = rg.add(ch);
3234

33-
auto cz = z.scalarMult(c);
34-
auto rm = m.scalarMult(r);
35-
auto bb = rm.add(cz);
35+
auto cz = z.scalarMult(pair.first);
36+
auto rm = m.scalarMult(pair.second);
37+
auto bb = rm.add(cz);
3638

37-
return a == aa && b == bb;
38-
}
39+
if (a != aa || b != bb)
40+
return false;
41+
}
3942

40-
static Proof generate(Point g, Point m, uint256_t x) {
41-
uint256_t c = rand();
43+
return true;
44+
}
4245

46+
static Proof generate(Point g, Point m, uint256_t x, std::vector<uint256_t> const & cList) {
4347
// s must be large then Curve.N
4448
uint256_t s = Secp256k1.n;
4549
s += rand();
4650

47-
uint256_t r{};
48-
49-
c = c % Secp256k1.n;
50-
r = (s - c * x) % Secp256k1.n;
51+
std::vector<std::pair<uint256_t, uint256_t>> cr;
52+
uint256_t cc, rr;
53+
for (auto c: cList) {
54+
cc = c % Secp256k1.n;
55+
rr = (s - cc * x) % Secp256k1.n;
56+
cr.push_back(std::make_pair(cc, rr));
57+
}
5158

5259
auto a = g.scalarMult(s);
5360
auto b = m.scalarMult(s);
@@ -56,7 +63,7 @@ struct Proof {
5663
g, m,
5764
g.scalarMult(x), m.scalarMult(x),
5865
a, b,
59-
r, c
66+
std::move(cr)
6067
};
6168
}
6269
};

main.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,22 @@ void proofTest() {
4747
// Init generators (public keys)
4848
Point g = curve.scalarMult(rand1);
4949
Point m = curve.scalarMult(rand2);
50+
std::coud << "g: " << g.x() << " " < g.y() << "\n";
51+
std::coud << "m: " << m.x() << " " < m.y() << "\n";
52+
53+
54+
// Prepare list of random tests
55+
std::vector<uint256_t> cList;
56+
for (auto k = 0; k < 5; ++k)
57+
cList.push_back((uint256_t)rand());
5058

5159
// Proof
52-
auto proof = Proof::generate(g, m, x);
60+
auto proof = Proof::generate(g, m, x, cList);
61+
62+
// Print a, b
63+
std::cout << "Proof generated\n";
64+
std::cout << "a: " << proof.a.x() << " " << proof.a.y() << "\n";
65+
std::cout << "b: " << proof.b.x() << " " << proof.b.y() << "\n";
5366

5467
// Validate
5568
std::cout << "valid for x: " << proof.verify() << "\n";

0 commit comments

Comments
 (0)