kernel: Add `btck_script_pubkey_is_p2tr` #35314

pull rustaceanrob wants to merge 2 commits into bitcoin:master from rustaceanrob:26-5-18-is-p2tr changing 4 files +34 −0
  1. rustaceanrob commented at 2:22 PM on May 18, 2026: contributor

    Currently users of the kernel must convert a script to bytes to interpret the OP codes, which can lead to errors. For instance, when scanning for silent payments, it is useful to filter transactions that do not have any P2TR outputs. Querying if a script is P2TR is non-trivial, as OP_1 = 0x51. This function removes the potential misinterpretation of script bytes.

    There are other similar methods for script, but I have omitted them as this is the only method that has a demonstrated use-case that I am aware of.

    ref: https://github.com/kernel-node/kernel-node/blob/master/crates/wallet/src/silentpayments/scanning.rs#L105

  2. kernel: Add `btck_script_pubkey_is_p2tr`
    Currently users of the kernel must convert a script to bytes to
    interpret the OP codes, which can lead to errors. For instance, when
    scanning for silent payments, it is useful to filter transactions that
    do not have any P2TR outputs. Querying if a script is P2TR is
    non-trivial, as `OP_1 = 0x51`. This function removes the potential
    mis-interpretation of script bytes.
    
    There are other similar methods for script, but I have omitted them as
    this is the only method that has a demonstrated use-case that I am aware
    of.
    
    ref: https://github.com/kernel-node/kernel-node/blob/master/crates/wallet/src/silentpayments/scanning.rs#L105
    133c41d651
  3. test(kernel): Update script tests to cover `is_p2tr`
    Unit testing counterpart to previous commit
    1b6fb0496c
  4. DrahtBot added the label Validation on May 18, 2026
  5. DrahtBot commented at 2:23 PM on May 18, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35314.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK yuvicc

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  6. in src/kernel/bitcoinkernel.h:802 in 133c41d651
     797 | + * @brief Returns 1 if the script pubkey is a pay-to-taproot (P2TR) output, 0 otherwise.
     798 | + *
     799 | + * @param[in] script_pubkey Non-null.
     800 | + * @return                  1 if P2TR, 0 otherwise.
     801 | + */
     802 | +BITCOINKERNEL_API int btck_script_pubkey_is_p2tr(
    


    yuvicc commented at 8:45 AM on May 20, 2026:

    Minor Nit (feel free to ignore): Maybe add BITCOINKERNEL_WARN_UNUSED_RESULT so that callers don't accidently drop the result.

  7. yuvicc commented at 8:46 AM on May 20, 2026: contributor

    ACK 1b6fb0496cc2215d250512671d740bb57958ccb0

  8. sedited commented at 10:44 AM on May 20, 2026: contributor

    My knee jerk reaction to this is that it should not be the kernel library's responsibility to ascertain the "type" of an output. Wallet software should be able to handle that by itself. It is not clear to me from the description you give what's wrong with letting the caller figure this out? Is it just inefficiency caused by having to copy the data in order for the caller to analyze it?

  9. rustaceanrob commented at 11:33 AM on May 20, 2026: contributor

    Right, each script would be copied to perform the query. Alternatively the bindings layer can handle it without copies as demonstrated here: https://github.com/sedited/rust-bitcoinkernel/compare/master...alexanderwiederin:rust-bitcoinkernel:bitcoin-interop


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-21 00:51 UTC

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