Skip to content

Commit 71890d5

Browse files
committed
Merge #426: update secp256k1-zkp b2dca3ae19dbe47ba978a79a5022a289efbdc846
f3a424f update secp256k1-zkp 2318f18a909dffa1f962e681db7ff62cdc0f8e1c (Gregory Sanders)
2 parents 138d55a + f3a424f commit 71890d5

File tree

7 files changed

+182
-40
lines changed

7 files changed

+182
-40
lines changed

src/secp256k1/include/secp256k1_generator.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ extern "C" {
1313
*
1414
* The exact representation of data inside is implementation defined and not
1515
* guaranteed to be portable between different platforms or versions. It is
16-
* however guaranteed to be 33 bytes in size, and can be safely copied/moved.
17-
* If you need to convert to a format suitable for storage or transmission, use
18-
* the secp256k1_generator_serialize_*.
19-
*
20-
* Furthermore, it is guaranteed to identical points will have identical
21-
* representation, so they can be memcmp'ed.
16+
* however guaranteed to be 64 bytes in size, and can be safely copied/moved.
17+
* If you need to convert to a format suitable for storage, transmission, or
18+
* comparison, use secp256k1_generator_serialize and secp256k1_generator_parse.
2219
*/
2320
typedef struct {
24-
unsigned char data[33];
21+
unsigned char data[64];
2522
} secp256k1_generator;
2623

2724
/** Parse a 33-byte generator byte sequence into a generator object.
@@ -58,9 +55,9 @@ SECP256K1_API int secp256k1_generator_serialize(
5855
* Out: gen: a generator object
5956
* In: seed32: a 32-byte seed
6057
*
61-
* If succesful, a valid generator will be placed in gen. The produced
58+
* If successful a valid generator will be placed in gen. The produced
6259
* generators are distributed uniformly over the curve, and will not have a
63-
* known dicrete logarithm with respect to any other generator produced,
60+
* known discrete logarithm with respect to any other generator produced,
6461
* or to the base generator G.
6562
*/
6663
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_generator_generate(

src/secp256k1/include/secp256k1_rangeproof.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,19 @@ extern "C" {
1414
*
1515
* The exact representation of data inside is implementation defined and not
1616
* guaranteed to be portable between different platforms or versions. It is
17-
* however guaranteed to be 33 bytes in size, and can be safely copied/moved.
18-
* If you need to convert to a format suitable for storage or transmission, use
19-
* secp256k1_pedersen_commitment_serialize and secp256k1_pedersen_commitment_parse.
20-
*
21-
* Furthermore, it is guaranteed to identical signatures will have identical
22-
* representation, so they can be memcmp'ed.
17+
* however guaranteed to be 64 bytes in size, and can be safely copied/moved.
18+
* If you need to convert to a format suitable for storage, transmission, or
19+
* comparison, use secp256k1_pedersen_commitment_serialize and
20+
* secp256k1_pedersen_commitment_parse.
2321
*/
2422
typedef struct {
25-
unsigned char data[33];
23+
unsigned char data[64];
2624
} secp256k1_pedersen_commitment;
2725

2826
/**
2927
* Static constant generator 'h' maintained for historical reasons.
3028
*/
31-
extern const secp256k1_generator *secp256k1_generator_h;
29+
SECP256K1_API extern const secp256k1_generator *secp256k1_generator_h;
3230

3331
/** Parse a 33-byte commitment into a commitment object.
3432
*

src/secp256k1/src/modules/generator/main_impl.h

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,55 @@
1515
#include "scalar.h"
1616

1717
static void secp256k1_generator_load(secp256k1_ge* ge, const secp256k1_generator* gen) {
18-
secp256k1_fe fe;
19-
secp256k1_fe_set_b32(&fe, &gen->data[1]);
20-
secp256k1_ge_set_xquad(ge, &fe);
21-
if (gen->data[0] & 1) {
22-
secp256k1_ge_neg(ge, ge);
23-
}
18+
int succeed;
19+
succeed = secp256k1_fe_set_b32(&ge->x, &gen->data[0]);
20+
VERIFY_CHECK(succeed != 0);
21+
succeed = secp256k1_fe_set_b32(&ge->y, &gen->data[32]);
22+
VERIFY_CHECK(succeed != 0);
23+
ge->infinity = 0;
24+
(void) succeed;
2425
}
2526

26-
static void secp256k1_generator_save(secp256k1_generator* commit, secp256k1_ge* ge) {
27-
secp256k1_fe_normalize(&ge->x);
28-
secp256k1_fe_get_b32(&commit->data[1], &ge->x);
29-
commit->data[0] = 11 ^ secp256k1_fe_is_quad_var(&ge->y);
27+
static void secp256k1_generator_save(secp256k1_generator *gen, secp256k1_ge* ge) {
28+
VERIFY_CHECK(!secp256k1_ge_is_infinity(ge));
29+
secp256k1_fe_normalize_var(&ge->x);
30+
secp256k1_fe_normalize_var(&ge->y);
31+
secp256k1_fe_get_b32(&gen->data[0], &ge->x);
32+
secp256k1_fe_get_b32(&gen->data[32], &ge->y);
3033
}
3134

3235
int secp256k1_generator_parse(const secp256k1_context* ctx, secp256k1_generator* gen, const unsigned char *input) {
36+
secp256k1_fe x;
37+
secp256k1_ge ge;
38+
3339
VERIFY_CHECK(ctx != NULL);
3440
ARG_CHECK(gen != NULL);
3541
ARG_CHECK(input != NULL);
36-
if ((input[0] & 0xFE) != 10) {
42+
43+
if ((input[0] & 0xFE) != 10 ||
44+
!secp256k1_fe_set_b32(&x, &input[1]) ||
45+
!secp256k1_ge_set_xquad(&ge, &x)) {
3746
return 0;
3847
}
39-
memcpy(gen->data, input, sizeof(gen->data));
48+
if (input[0] & 1) {
49+
secp256k1_ge_neg(&ge, &ge);
50+
}
51+
secp256k1_generator_save(gen, &ge);
4052
return 1;
4153
}
4254

4355
int secp256k1_generator_serialize(const secp256k1_context* ctx, unsigned char *output, const secp256k1_generator* gen) {
56+
secp256k1_ge ge;
57+
4458
VERIFY_CHECK(ctx != NULL);
4559
ARG_CHECK(output != NULL);
4660
ARG_CHECK(gen != NULL);
47-
memcpy(output, gen->data, sizeof(gen->data));
61+
62+
secp256k1_generator_load(&ge, gen);
63+
64+
output[0] = 11 ^ secp256k1_fe_is_quad_var(&ge.y);
65+
secp256k1_fe_normalize_var(&ge.x);
66+
secp256k1_fe_get_b32(&output[1], &ge.x);
4867
return 1;
4968
}
5069

src/secp256k1/src/modules/generator/tests_impl.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,28 @@ void test_generator_generate(void) {
190190
}
191191
}
192192

193+
void test_generator_fixed_vector(void) {
194+
const unsigned char two_g[33] = {
195+
0x0b,
196+
0xc6, 0x04, 0x7f, 0x94, 0x41, 0xed, 0x7d, 0x6d, 0x30, 0x45, 0x40, 0x6e, 0x95, 0xc0, 0x7c, 0xd8,
197+
0x5c, 0x77, 0x8e, 0x4b, 0x8c, 0xef, 0x3c, 0xa7, 0xab, 0xac, 0x09, 0xb9, 0x5c, 0x70, 0x9e, 0xe5
198+
};
199+
unsigned char result[33];
200+
secp256k1_generator parse;
201+
202+
CHECK(secp256k1_generator_parse(ctx, &parse, two_g));
203+
CHECK(secp256k1_generator_serialize(ctx, result, &parse));
204+
CHECK(memcmp(two_g, result, 33) == 0);
205+
206+
result[0] = 0x0a;
207+
CHECK(secp256k1_generator_parse(ctx, &parse, result));
208+
result[0] = 0x08;
209+
CHECK(!secp256k1_generator_parse(ctx, &parse, result));
210+
}
211+
193212
void run_generator_tests(void) {
194213
test_shallue_van_de_woestijne();
214+
test_generator_fixed_vector();
195215
test_generator_api();
196216
test_generator_generate();
197217
}

src/secp256k1/src/modules/rangeproof/main_impl.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
/** Alternative generator for secp256k1.
1717
* This is the sha256 of 'g' after DER encoding (without compression),
1818
* which happens to be a point on the curve.
19-
* sage: G2 = EllipticCurve ([F (0), F (7)]).lift_x(int(hashlib.sha256('0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'.decode('hex')).hexdigest(),16))
20-
* sage: '%x %x' % (11 - G2.xy()[1].is_square(), G2.xy()[0])
19+
* sage: G2 = EllipticCurve ([F (0), F (7)]).lift_x(F(int(hashlib.sha256('0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'.decode('hex')).hexdigest(),16)))
20+
* sage: '%x %x' % G2.xy()
2121
*/
2222
static const secp256k1_generator secp256k1_generator_h_internal = {{
23-
0x11,
2423
0x50, 0x92, 0x9b, 0x74, 0xc1, 0xa0, 0x49, 0x54, 0xb7, 0x8b, 0x4b, 0x60, 0x35, 0xe9, 0x7a, 0x5e,
25-
0x07, 0x8a, 0x5a, 0x0f, 0x28, 0xec, 0x96, 0xd5, 0x47, 0xbf, 0xee, 0x9a, 0xce, 0x80, 0x3a, 0xc0
24+
0x07, 0x8a, 0x5a, 0x0f, 0x28, 0xec, 0x96, 0xd5, 0x47, 0xbf, 0xee, 0x9a, 0xce, 0x80, 0x3a, 0xc0,
25+
0x31, 0xd3, 0xc6, 0x86, 0x39, 0x73, 0x92, 0x6e, 0x04, 0x9e, 0x63, 0x7c, 0xb1, 0xb5, 0xf4, 0x0a,
26+
0x36, 0xda, 0xc2, 0x8a, 0xf1, 0x76, 0x69, 0x68, 0xc3, 0x0c, 0x23, 0x13, 0xf3, 0xa3, 0x89, 0x04
2627
}};
2728

2829
const secp256k1_generator *secp256k1_generator_h = &secp256k1_generator_h_internal;
@@ -43,22 +44,38 @@ static void secp256k1_pedersen_commitment_save(secp256k1_pedersen_commitment* co
4344
}
4445

4546
int secp256k1_pedersen_commitment_parse(const secp256k1_context* ctx, secp256k1_pedersen_commitment* commit, const unsigned char *input) {
47+
secp256k1_fe x;
48+
secp256k1_ge ge;
49+
4650
VERIFY_CHECK(ctx != NULL);
4751
ARG_CHECK(commit != NULL);
4852
ARG_CHECK(input != NULL);
4953
(void) ctx;
50-
if ((input[0] & 0xFE) != 8) {
54+
55+
if ((input[0] & 0xFE) != 8 ||
56+
!secp256k1_fe_set_b32(&x, &input[1]) ||
57+
!secp256k1_ge_set_xquad(&ge, &x)) {
5158
return 0;
5259
}
53-
memcpy(commit->data, input, sizeof(commit->data));
60+
if (input[0] & 1) {
61+
secp256k1_ge_neg(&ge, &ge);
62+
}
63+
secp256k1_pedersen_commitment_save(commit, &ge);
5464
return 1;
5565
}
5666

5767
int secp256k1_pedersen_commitment_serialize(const secp256k1_context* ctx, unsigned char *output, const secp256k1_pedersen_commitment* commit) {
68+
secp256k1_ge ge;
69+
5870
VERIFY_CHECK(ctx != NULL);
5971
ARG_CHECK(output != NULL);
6072
ARG_CHECK(commit != NULL);
61-
memcpy(output, commit->data, sizeof(commit->data));
73+
74+
secp256k1_pedersen_commitment_load(&ge, commit);
75+
76+
output[0] = 9 ^ secp256k1_fe_is_quad_var(&ge.y);
77+
secp256k1_fe_normalize_var(&ge.x);
78+
secp256k1_fe_get_b32(&output[1], &ge.x);
6279
return 1;
6380
}
6481

src/secp256k1/src/modules/rangeproof/rangeproof_impl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,10 @@ SECP256K1_INLINE static int secp256k1_rangeproof_verify_impl(const secp256k1_ecm
609609
}
610610
for(i = 0; i < rings - 1; i++) {
611611
secp256k1_fe fe;
612-
secp256k1_fe_set_b32(&fe, &proof[offset]);
613-
secp256k1_ge_set_xquad(&c, &fe);
612+
if (!secp256k1_fe_set_b32(&fe, &proof[offset]) ||
613+
!secp256k1_ge_set_xquad(&c, &fe)) {
614+
return 0;
615+
}
614616
if (signs[i]) {
615617
secp256k1_ge_neg(&c, &c);
616618
}

src/secp256k1/src/modules/rangeproof/tests_impl.h

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static void test_rangeproof(void) {
385385
const uint64_t testvs[11] = {0, 1, 5, 11, 65535, 65537, INT32_MAX, UINT32_MAX, INT64_MAX - 1, INT64_MAX, UINT64_MAX};
386386
secp256k1_pedersen_commitment commit;
387387
secp256k1_pedersen_commitment commit2;
388-
unsigned char proof[5134];
388+
unsigned char proof[5134 + 1]; /* One additional byte to test if trailing bytes are rejected */
389389
unsigned char blind[32];
390390
unsigned char blindout[32];
391391
unsigned char message[4096];
@@ -485,6 +485,9 @@ static void test_rangeproof(void) {
485485
len = 5134;
486486
CHECK(secp256k1_rangeproof_sign(ctx, proof, &len, 0, &commit, blind, commit.data, 0, 3, v, NULL, 0, NULL, 0, secp256k1_generator_h));
487487
CHECK(len <= 5134);
488+
/* Test if trailing bytes are rejected. */
489+
proof[len] = v;
490+
CHECK(!secp256k1_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len + 1, NULL, 0, secp256k1_generator_h));
488491
for (i = 0; i < len*8; i++) {
489492
proof[i >> 3] ^= 1 << (i & 7);
490493
CHECK(!secp256k1_rangeproof_verify(ctx, &minv, &maxv, &commit, proof, len, NULL, 0, secp256k1_generator_h));
@@ -604,9 +607,95 @@ void test_multiple_generators(void) {
604607
}
605608
}
606609

610+
void test_rangeproof_fixed_vectors(void) {
611+
const unsigned char vector_1[] = {
612+
0x62, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x56, 0x02, 0x2a, 0x5c, 0x42, 0x0e, 0x1d,
613+
0x51, 0xe1, 0xb7, 0xf3, 0x69, 0x04, 0xb5, 0xbb, 0x9b, 0x41, 0x66, 0x14, 0xf3, 0x64, 0x42, 0x26,
614+
0xe3, 0xa7, 0x6a, 0x06, 0xbb, 0xa8, 0x5a, 0x49, 0x6f, 0x19, 0x76, 0xfb, 0xe5, 0x75, 0x77, 0x88,
615+
0xab, 0xa9, 0x66, 0x44, 0x80, 0xea, 0x29, 0x95, 0x7f, 0xdf, 0x72, 0x4a, 0xaf, 0x02, 0xbe, 0xdd,
616+
0x5d, 0x15, 0xd8, 0xae, 0xff, 0x74, 0xc9, 0x8c, 0x1a, 0x67, 0x0e, 0xb2, 0x57, 0x22, 0x99, 0xc3,
617+
0x21, 0x46, 0x6f, 0x15, 0x58, 0x0e, 0xdb, 0xe6, 0x6e, 0xc4, 0x0d, 0xfe, 0x6f, 0x04, 0x6b, 0x0d,
618+
0x18, 0x3d, 0x78, 0x40, 0x98, 0x56, 0x4e, 0xe4, 0x4a, 0x74, 0x90, 0xa7, 0xac, 0x9c, 0x16, 0xe0,
619+
0x3e, 0x81, 0xaf, 0x0f, 0xe3, 0x4f, 0x34, 0x99, 0x52, 0xf7, 0xa7, 0xf6, 0xd3, 0x83, 0xa0, 0x17,
620+
0x4b, 0x2d, 0xa7, 0xd4, 0xfd, 0xf7, 0x84, 0x45, 0xc4, 0x11, 0x71, 0x3d, 0x4a, 0x22, 0x34, 0x09,
621+
0x9c, 0xa7, 0xe5, 0xc8, 0xba, 0x04, 0xbf, 0xfd, 0x25, 0x11, 0x7d, 0xa4, 0x43, 0x45, 0xc7, 0x62,
622+
0x9e, 0x7b, 0x80, 0xf6, 0x09, 0xbb, 0x1b, 0x2e, 0xf3, 0xcd, 0x23, 0xe0, 0xed, 0x81, 0x43, 0x42,
623+
0xbe, 0xc4, 0x9f, 0x58, 0x8a, 0x0d, 0x66, 0x79, 0x09, 0x70, 0x11, 0x68, 0x3d, 0x87, 0x38, 0x1c,
624+
0x3c, 0x85, 0x52, 0x5b, 0x62, 0xf7, 0x3e, 0x7e, 0x87, 0xa2, 0x99, 0x24, 0xd0, 0x7d, 0x18, 0x63,
625+
0x56, 0x48, 0xa4, 0x3a, 0xfe, 0x65, 0xfa, 0xa4, 0xd0, 0x67, 0xaa, 0x98, 0x65, 0x4d, 0xe4, 0x22,
626+
0x75, 0x45, 0x52, 0xe8, 0x41, 0xc7, 0xed, 0x38, 0xeb, 0xf5, 0x02, 0x90, 0xc9, 0x45, 0xa3, 0xb0,
627+
0x4d, 0x03, 0xd7, 0xab, 0x43, 0xe4, 0x21, 0xfc, 0x83, 0xd6, 0x12, 0x1d, 0x76, 0xb1, 0x3c, 0x67,
628+
0x63, 0x1f, 0x52, 0x9d, 0xc3, 0x23, 0x5c, 0x4e, 0xa6, 0x8d, 0x01, 0x4a, 0xba, 0x9a, 0xf4, 0x16,
629+
0x5b, 0x67, 0xc8, 0xe1, 0xd2, 0x42, 0x6d, 0xdf, 0xcd, 0x08, 0x6a, 0x73, 0x41, 0x6a, 0xc2, 0x84,
630+
0xc6, 0x31, 0xbe, 0x57, 0xcb, 0x0e, 0xde, 0xbf, 0x71, 0xd5, 0x8a, 0xf7, 0x24, 0xb2, 0xa7, 0x89,
631+
0x96, 0x62, 0x4f, 0xd9, 0xf7, 0xc3, 0xde, 0x4c, 0xab, 0x13, 0x72, 0xb4, 0xb3, 0x35, 0x04, 0x82,
632+
0xa8, 0x75, 0x1d, 0xde, 0x46, 0xa8, 0x0d, 0xb8, 0x23, 0x44, 0x00, 0x44, 0xfa, 0x53, 0x6c, 0x2d,
633+
0xce, 0xd3, 0xa6, 0x80, 0xa1, 0x20, 0xca, 0xd1, 0x63, 0xbb, 0xbe, 0x39, 0x5f, 0x9d, 0x27, 0x69,
634+
0xb3, 0x33, 0x1f, 0xdb, 0xda, 0x67, 0x05, 0x37, 0xbe, 0x65, 0xe9, 0x7e, 0xa9, 0xc3, 0xff, 0x37,
635+
0x8a, 0xb4, 0x2d, 0xfe, 0xf2, 0x16, 0x85, 0xc7, 0x0f, 0xd9, 0xbe, 0x14, 0xd1, 0x80, 0x14, 0x9f,
636+
0x58, 0x56, 0x98, 0x41, 0xf6, 0x26, 0xf7, 0xa2, 0x71, 0x66, 0xb4, 0x7a, 0x9c, 0x12, 0x73, 0xd3,
637+
0xdf, 0x77, 0x2b, 0x49, 0xe5, 0xca, 0x50, 0x57, 0x44, 0x6e, 0x3f, 0x58, 0x56, 0xbc, 0x21, 0x70,
638+
0x4f, 0xc6, 0xaa, 0x12, 0xff, 0x7c, 0xa7, 0x3d, 0xed, 0x46, 0xc1, 0x40, 0xe6, 0x58, 0x09, 0x2a,
639+
0xda, 0xb3, 0x76, 0xab, 0x44, 0xb5, 0x4e, 0xb3, 0x12, 0xe0, 0x26, 0x8a, 0x52, 0xac, 0x49, 0x1d,
640+
0xe7, 0x06, 0x53, 0x3a, 0x01, 0x35, 0x21, 0x2e, 0x86, 0x48, 0xc5, 0x75, 0xc1, 0xa2, 0x7d, 0x22,
641+
0x53, 0xf6, 0x3f, 0x41, 0xc5, 0xb3, 0x08, 0x7d, 0xa3, 0x67, 0xc0, 0xbb, 0xb6, 0x8d, 0xf0, 0xd3,
642+
0x01, 0x72, 0xd3, 0x63, 0x82, 0x01, 0x1a, 0xe7, 0x1d, 0x22, 0xfa, 0x95, 0x33, 0xf6, 0xf2, 0xde,
643+
0xa2, 0x53, 0x86, 0x55, 0x5a, 0xb4, 0x2e, 0x75, 0x75, 0xc6, 0xd5, 0x93, 0x9c, 0x57, 0xa9, 0x1f,
644+
0xb9, 0x3e, 0xe8, 0x1c, 0xbf, 0xac, 0x1c, 0x54, 0x6f, 0xf5, 0xab, 0x41, 0xee, 0xb3, 0x0e, 0xd0,
645+
0x76, 0xc4, 0x1a, 0x45, 0xcd, 0xf1, 0xd6, 0xcc, 0xb0, 0x83, 0x70, 0x73, 0xbc, 0x88, 0x74, 0xa0,
646+
0x5b, 0xe7, 0x98, 0x10, 0x36, 0xbf, 0xec, 0x23, 0x1c, 0xc2, 0xb5, 0xba, 0x4b, 0x9d, 0x7f, 0x8c,
647+
0x8a, 0xe2, 0xda, 0x18, 0xdd, 0xab, 0x27, 0x8a, 0x15, 0xeb, 0xb0, 0xd4, 0x3a, 0x8b, 0x77, 0x00,
648+
0xc7, 0xbb, 0xcc, 0xfa, 0xba, 0xa4, 0x6a, 0x17, 0x5c, 0xf8, 0x51, 0x5d, 0x8d, 0x16, 0xcd, 0xa7,
649+
0x0e, 0x71, 0x97, 0x98, 0x78, 0x5a, 0x41, 0xb3, 0xf0, 0x1f, 0x87, 0x2d, 0x65, 0xcd, 0x29, 0x49,
650+
0xd2, 0x87, 0x2c, 0x91, 0xa9, 0x5f, 0xcc, 0xa9, 0xd8, 0xbb, 0x53, 0x18, 0xe7, 0xd6, 0xec, 0x65,
651+
0xa6, 0x45, 0xf6, 0xce, 0xcf, 0x48, 0xf6, 0x1e, 0x3d, 0xd2, 0xcf, 0xcb, 0x3a, 0xcd, 0xbb, 0x92,
652+
0x29, 0x24, 0x16, 0x7f, 0x8a, 0xa8, 0x5c, 0x0c, 0x45, 0x71, 0x33
653+
};
654+
const unsigned char commit_1[] = {
655+
0x08,
656+
0xf5, 0x1e, 0x0d, 0xc5, 0x86, 0x78, 0x51, 0xa9, 0x00, 0x00, 0xef, 0x4d, 0xe2, 0x94, 0x60, 0x89,
657+
0x83, 0x04, 0xb4, 0x0e, 0x90, 0x10, 0x05, 0x1c, 0x7f, 0xd7, 0x33, 0x92, 0x1f, 0xe7, 0x74, 0x59
658+
};
659+
size_t min_value_1;
660+
size_t max_value_1;
661+
secp256k1_pedersen_commitment pc;
662+
663+
CHECK(secp256k1_pedersen_commitment_parse(ctx, &pc, commit_1));
664+
665+
CHECK(secp256k1_rangeproof_verify(
666+
ctx,
667+
&min_value_1, &max_value_1,
668+
&pc,
669+
vector_1, sizeof(vector_1),
670+
NULL, 0,
671+
secp256k1_generator_h
672+
));
673+
}
674+
675+
void test_pedersen_commitment_fixed_vector(void) {
676+
const unsigned char two_g[33] = {
677+
0x09,
678+
0xc6, 0x04, 0x7f, 0x94, 0x41, 0xed, 0x7d, 0x6d, 0x30, 0x45, 0x40, 0x6e, 0x95, 0xc0, 0x7c, 0xd8,
679+
0x5c, 0x77, 0x8e, 0x4b, 0x8c, 0xef, 0x3c, 0xa7, 0xab, 0xac, 0x09, 0xb9, 0x5c, 0x70, 0x9e, 0xe5
680+
};
681+
unsigned char result[33];
682+
secp256k1_pedersen_commitment parse;
683+
684+
CHECK(secp256k1_pedersen_commitment_parse(ctx, &parse, two_g));
685+
CHECK(secp256k1_pedersen_commitment_serialize(ctx, result, &parse));
686+
CHECK(memcmp(two_g, result, 33) == 0);
687+
688+
result[0] = 0x08;
689+
CHECK(secp256k1_pedersen_commitment_parse(ctx, &parse, result));
690+
result[0] = 0x0c;
691+
CHECK(!secp256k1_pedersen_commitment_parse(ctx, &parse, result));
692+
}
693+
607694
void run_rangeproof_tests(void) {
608695
int i;
609696
test_api();
697+
test_rangeproof_fixed_vectors();
698+
test_pedersen_commitment_fixed_vector();
610699
for (i = 0; i < 10*count; i++) {
611700
test_pedersen();
612701
}

0 commit comments

Comments
 (0)