Skip to content

Commit 4ff6e42

Browse files
committed
surjectionproof: add test for existing behavior on input=output proofs
1 parent 71a206f commit 4ff6e42

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/modules/surjection/tests_impl.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,33 @@ void test_bad_parse(void) {
524524
CHECK(secp256k1_surjectionproof_parse(ctx, &proof, serialized_proof2, sizeof(serialized_proof2)) == 0);
525525
}
526526

527+
void test_input_eq_output(void) {
528+
secp256k1_surjectionproof proof;
529+
secp256k1_fixed_asset_tag fixed_tag;
530+
secp256k1_generator ephemeral_tag;
531+
unsigned char blinding_key[32];
532+
unsigned char entropy[32];
533+
size_t input_index;
534+
535+
secp256k1_testrand256(fixed_tag.data);
536+
secp256k1_testrand256(blinding_key);
537+
secp256k1_testrand256(entropy);
538+
539+
CHECK(secp256k1_surjectionproof_initialize(ctx, &proof, &input_index, &fixed_tag, 1, 1, &fixed_tag, 100, entropy) == 1);
540+
CHECK(input_index == 0);
541+
542+
/* Generation should fail */
543+
CHECK(secp256k1_generator_generate_blinded(ctx, &ephemeral_tag, fixed_tag.data, blinding_key));
544+
CHECK(!secp256k1_surjectionproof_generate(ctx, &proof, &ephemeral_tag, 1, &ephemeral_tag, input_index, blinding_key, blinding_key));
545+
546+
/* It succeeds when the blinding factor is 0... (will fix this in the next commit) */
547+
memset(blinding_key, 0, 32);
548+
CHECK(secp256k1_generator_generate_blinded(ctx, &ephemeral_tag, fixed_tag.data, blinding_key));
549+
CHECK(secp256k1_surjectionproof_generate(ctx, &proof, &ephemeral_tag, 1, &ephemeral_tag, input_index, blinding_key, blinding_key));
550+
/* ...but verification doesn't */
551+
CHECK(!secp256k1_surjectionproof_verify(ctx, &proof, &ephemeral_tag, 1, &ephemeral_tag));
552+
}
553+
527554
void test_fixed_vectors(void) {
528555
const unsigned char tag0_ser[] = {
529556
0x0a,
@@ -672,6 +699,7 @@ void test_fixed_vectors(void) {
672699

673700
void run_surjection_tests(void) {
674701
test_surjectionproof_api();
702+
test_input_eq_output();
675703
test_fixed_vectors();
676704

677705
test_input_selection(0);

0 commit comments

Comments
 (0)