Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rangeproof: add unit test for malleating single-value proofs #295

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/modules/rangeproof/tests_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ static void test_single_value_proof(uint64_t val) {

uint64_t val_out = 0;
size_t m_len_out = 0;
size_t i;

secp256k1_testrand256(blind);
secp256k1_testrand256(nonce);
Expand Down Expand Up @@ -463,6 +464,30 @@ static void test_single_value_proof(uint64_t val) {
CHECK(plen == 73);
}

/* Test if trailing bytes are rejected. */
proof[plen] = 0;
CHECK(secp256k1_rangeproof_verify(
CTX,
&min_val_out, &max_val_out,
&commit,
proof, plen + 1,
real-or-random marked this conversation as resolved.
Show resolved Hide resolved
NULL, 0,
secp256k1_generator_h
) == 0);
/* Test if single-bit malleation is caught */
for (i = 0; i < plen*8; i++) {
proof[i >> 3] ^= 1 << (i & 7);
CHECK(secp256k1_rangeproof_verify(
CTX,
&min_val_out, &max_val_out,
&commit,
proof, plen,
NULL, 0,
secp256k1_generator_h
) == 0);
proof[i >> 3] ^= 1 << (i & 7);
}
/* Test if unchanged proof is accepted. */
CHECK(secp256k1_rangeproof_verify(
CTX,
&min_val_out, &max_val_out,
Expand Down
Loading