Skip to content

Commit 6152622

Browse files
committed
Merge #295: rangeproof: add unit test for malleating single-value proofs
3a1c396 rangeproof: add unit test for malleating single-value proofs (Andrew Poelstra) Pull request description: I was a bit confused reading `secp256k1_rangeproof_getheader_impl` because in the case of single-value proofs (`has_nz_range == 0`) some bits of the header are unconstrained. At first I thought this was a malleability vector. And I think I've had this same confusion in the past. But in fact it is not a malleability vector because the whole header gets hashed into the proof. Add a unit test to confirm this to reduce future confusion. ACKs for top commit: real-or-random: utACK 3a1c396 Tree-SHA512: 9670cd04fcc0bb322d89c2c86ef863e13c29e4477dc6fecdda16b9a745e42a84f237a7ec387b3291f334e2a5c5806a8cc7cc00e40246ad5b36366be841195b4b
2 parents 1683772 + 3a1c396 commit 6152622

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/modules/rangeproof/tests_impl.h

+25
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ static void test_single_value_proof(uint64_t val) {
422422

423423
uint64_t val_out = 0;
424424
size_t m_len_out = 0;
425+
size_t i;
425426

426427
secp256k1_testrand256(blind);
427428
secp256k1_testrand256(nonce);
@@ -463,6 +464,30 @@ static void test_single_value_proof(uint64_t val) {
463464
CHECK(plen == 73);
464465
}
465466

467+
/* Test if trailing bytes are rejected. */
468+
proof[plen] = 0;
469+
CHECK(secp256k1_rangeproof_verify(
470+
CTX,
471+
&min_val_out, &max_val_out,
472+
&commit,
473+
proof, plen + 1,
474+
NULL, 0,
475+
secp256k1_generator_h
476+
) == 0);
477+
/* Test if single-bit malleation is caught */
478+
for (i = 0; i < plen*8; i++) {
479+
proof[i >> 3] ^= 1 << (i & 7);
480+
CHECK(secp256k1_rangeproof_verify(
481+
CTX,
482+
&min_val_out, &max_val_out,
483+
&commit,
484+
proof, plen,
485+
NULL, 0,
486+
secp256k1_generator_h
487+
) == 0);
488+
proof[i >> 3] ^= 1 << (i & 7);
489+
}
490+
/* Test if unchanged proof is accepted. */
466491
CHECK(secp256k1_rangeproof_verify(
467492
CTX,
468493
&min_val_out, &max_val_out,

0 commit comments

Comments
 (0)