tests: silentpayments: check found outputs are distinct in vector tests #1950

pull ViniciusCestarii wants to merge 1 commits into bitcoin-core:master from ViniciusCestarii:sp-test-vector-distinct-outputs changing 1 files +8 −0
  1. ViniciusCestarii commented at 4:34 PM on September 30, 2026: contributor

    Suggested by theStack: add a new check on silent payments vector tests: if N outputs are found, ensure they all have distinct x-only pubkeys.

    This catches the mutant from #1943 (j_start + i / 2 -> (j_start + i) / 2 in secp256k1_silentpayments_check_label_batch), which maps several matches to the same tx output and previously went undetected.

  2. real-or-random added the label assurance on Oct 1, 2026
  3. real-or-random added the label tweak/refactor on Oct 1, 2026
  4. in src/modules/silentpayments/tests_impl.h:915 in 00a051ac3d
     906 | @@ -907,6 +907,12 @@ void run_silentpayments_test_vector_receive(const struct bip352_test_vector *tes
     907 |          }
     908 |      }
     909 |      CHECK(n_found == subtest->num_found_output_pubkeys);
     910 | +    /* all found outputs must have distinct x-only pubkeys */
     911 | +    for (i = 0; i < n_found; i++) {
     912 | +        for (j = i + 1; j < n_found; j++) {
     913 | +            CHECK(secp256k1_xonly_pubkey_cmp(CTX, &found_outputs[i]->output, &found_outputs[j]->output) != 0);
     914 | +        }
     915 | +    }
    


    theStack commented at 2:48 PM on October 1, 2026:

    nit: could put this into an else-branch for if (subtest->full_check) { ... } above, as for full check test vectors the outputs are already verified in detail


    ViniciusCestarii commented at 4:46 PM on October 1, 2026:

    Makes sense, done on 1c306ddf8a249fc52b9a1ca3eabf9ba88c539e19

  5. theStack approved
  6. theStack commented at 3:27 PM on October 1, 2026: contributor

    ACK 00a051ac3d626a8e5ba32070bd2c084fe2e0fb19

    Nice! We could be even more thorough by checking the set of found outputs must be a subset of the scanned outputs, but for a very simple structural sanity check this seems more than enough, considering it killed a mutant :zombie:. For more detailed checks new test vectors could be introduced that contain the expected outputs.

  7. in src/modules/silentpayments/tests_impl.h:912 in 00a051ac3d
     906 | @@ -907,6 +907,12 @@ void run_silentpayments_test_vector_receive(const struct bip352_test_vector *tes
     907 |          }
     908 |      }
     909 |      CHECK(n_found == subtest->num_found_output_pubkeys);
     910 | +    /* all found outputs must have distinct x-only pubkeys */
     911 | +    for (i = 0; i < n_found; i++) {
     912 | +        for (j = i + 1; j < n_found; j++) {
    


    theStack commented at 3:34 PM on October 1, 2026:

    note for other reviewers: this has quadratic time complexity, but given that n_found is bounded by 2323 ( SECP256K1_SILENTPAYMENTS_RECIPIENT_GROUP_LIMIT) and the loop body is cheap, this seems fine; the run-time of the tests didn't increase noticeably on my machine

  8. ViniciusCestarii force-pushed on Oct 1, 2026
  9. ViniciusCestarii commented at 4:52 PM on October 1, 2026: contributor

    Thanks @theStack for reviewing. Force-pushed 1c306ddf8a249fc52b9a1ca3eabf9ba88c539e19 addressing #1950 (review)

  10. theStack approved
  11. theStack commented at 5:34 PM on October 1, 2026: contributor

    re-ACK 1c306ddf8a249fc52b9a1ca3eabf9ba88c539e19

  12. tests: silentpayments: check found outputs are distinct in vector tests
    Suggested by theStack in #1943.
    1c6f793084
  13. in src/modules/silentpayments/tests_impl.h:909 in 1c306ddf8a
     904 | @@ -905,6 +905,13 @@ void run_silentpayments_test_vector_receive(const struct bip352_test_vector *tes
     905 |                  CHECK(found_label_tweak != NULL);
     906 |              }
     907 |          }
     908 | +    } else {
     909 | +        /* all found outputs must have distinct x-only pubkeys */
    


    real-or-random commented at 7:55 PM on October 1, 2026:

    Now that this comment appears behind the else, it looked to me as if the distinctness property is somehow implied only in the else branch. Something like this would make it clearer:

            /* Not performing a full check, so resort to a structural sanity check: */
            /* All outputs must have distinct x-only pubkeys.  */
    

    ViniciusCestarii commented at 8:01 PM on October 1, 2026:

    I agree, done on 1c6f7930848009281edc468b547dd2056c175901

  14. ViniciusCestarii force-pushed on Oct 1, 2026
  15. real-or-random approved
  16. real-or-random commented at 8:25 PM on October 1, 2026: contributor

    utACK 1c6f7930848009281edc468b547dd2056c175901

  17. theStack approved
  18. theStack commented at 10:18 PM on October 1, 2026: contributor

    re-ACK 1c6f7930848009281edc468b547dd2056c175901

  19. real-or-random merged this on Oct 2, 2026
  20. real-or-random closed this on Oct 2, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-03 03:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me