silentpayments: add hash ctx (SHA256 compression override) test #1940

pull theStack wants to merge 1 commits into bitcoin-core:master from theStack:sp-add-hash_ctx-tests changing 1 files +86 −0
  1. theStack commented at 2:52 PM on September 21, 2026: contributor

    This PR adds a test to check that the ctx-provided SHA256 compression override takes effect for the following silentpayments module API functions:

    • secp256k1_silentpayments_label_create (hash result is used for calculating the label tweak)
    • secp256k1_silentpayments_sender_create_outputs (hash results are used for calculating the input hash and output tweak)
    • secp256k1_silentpayments_recipient_prevouts_summary_create (hash result is used for calculating the input hash)
    • secp256k1_silentpayments_recipient_scan_outputs (hash result is used for calculating the output tweak)

    With #1866 for musig and this PR, all public functions that take use of the SHA256 compression override should be covered by tests.

  2. in src/modules/silentpayments/tests_impl.h:938 in 35c5b99bd5 outdated
     931 | @@ -931,6 +932,82 @@ static void silentpayments_sha256_tag_test(void) {
     932 |      }
     933 |  }
     934 |  
     935 | +DEFINE_SHA256_TRANSFORM_PROBE(sha256_sp_label_create)
     936 | +DEFINE_SHA256_TRANSFORM_PROBE(sha256_sp_create_outputs)
     937 | +DEFINE_SHA256_TRANSFORM_PROBE(sha256_sp_prevouts_summary_create)
     938 | +DEFINE_SHA256_TRANSFORM_PROBE(sha256_sp_scan_outputs)
    


    theStack commented at 3:01 PM on September 21, 2026:

    self-nit: I was on the fence between adding multiple probes or a single one (that is set back repeatedly, leading to approximately the same LOC), but decided to reflect the style currently used in #1866. Happy with either style if reviewers have a preference.

  3. theStack added the label assurance on Sep 22, 2026
  4. theStack added the label tweak/refactor on Sep 22, 2026
  5. Yudis-bit commented at 2:38 AM on October 4, 2026: contributor

    In silentpayments_ctx_sha256, the check on secp256k1_silentpayments_recipient_scan_outputs currently only exercises the negative path (n_found_outputs == 0) against the default output. If scan_outputs encountered an internal calculation failure or returned early under custom compression, an assertion on zero matches alone could pass vacuously.

    Pairing this with a symmetric positive check confirms that sender output generation and recipient scanning remain isomorphic under the custom compression hook.

        /* When scanned against the custom output and custom prevouts summary under the same
         * override, the recipient successfully identifies the payment. */
        tx_outputs[0] = &output_custom;
        CHECK(secp256k1_silentpayments_recipient_scan_outputs(ctx, found_outputs, &n_found_outputs, tx_outputs, 1, bob_scan_seckey, &prevouts_summary_custom, &bob.spend_pubkey, NULL, NULL) == 1);
        CHECK(n_found_outputs == 1);
        CHECK(secp256k1_memcmp_var(found_output.output.data, output_custom.data, sizeof(output_custom.data)) == 0);
        CHECK(!found_output.found_with_label);
    

    Tested on top of 17242cc with tests.exe 1 on GCC 16.2.0, passes cleanly.

  6. silentpayments: add hash ctx (SHA256 compression override) test
    Co-authored-by: Yudistira Putra <pyudistira519@gmail.com>
    93d026ec5e
  7. theStack force-pushed on Oct 4, 2026
  8. theStack commented at 10:16 PM on October 4, 2026: contributor

    @Yudis-bit: Good idea, applied your patch in the same commit and added you as co-author. I changed the found output equality check to use the xonly-pubkey compare function though (secp256k1_xonly_pubkey_cmp), as I think that's a bit cleaner than comparing the raw bytes of the opaque objects. Also rebased on master, in order to avoid potential CI problems (see #1953).

  9. Yudis-bit commented at 11:40 AM on October 6, 2026: contributor

    ACK 93d026ec5e1f50fc7689b5941827013332e4231c.

    Using secp256k1_xonly_pubkey_cmp is definitely cleaner than raw byte comparisons. Re-tested locally on Clang 22.1.8, all tests pass. Thanks for adding co-author.


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-20 04:15 UTC

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