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: member

    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
    Approach NACK stickies-v

    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.~


    stickies-v commented at 10:20 AM on May 21, 2026:

    Why would dropping the result here be an issue?


    stickies-v commented at 11:00 AM on May 21, 2026:

    Opened #35344 to clarify and ensure consistency.


    yuvicc commented at 11:49 AM on May 21, 2026:

    Was thinking something else. Thanks, Will be helpful!

  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: member

    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

  10. stickies-v commented at 11:11 AM on May 21, 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.

    I agree. It is useful to have a good library that does this, but output types are not a kernel concern. Approach NACK.

    As an alternative, what about a function that gets the witness version and program?

  11. rustaceanrob commented at 3:33 PM on May 21, 2026: member

    what about a function that gets the witness version and program?

    Within this repository, or elsewhere at the bindings layer?

  12. stickies-v commented at 4:43 PM on May 21, 2026: contributor

    Here, as part of the kernel interface.

  13. sedited added this to a project on May 22, 2026
  14. github-project-automation[bot] changed the project status on May 22, 2026
  15. sedited changed the project status on May 22, 2026
  16. rustaceanrob commented at 12:24 PM on May 29, 2026: member

    As a first option, I like the approach of https://github.com/sedited/rust-bitcoinkernel/pull/190 which removes any copies or allocation, does not explicitly add a dependency at the bindings layer, but is compatible with rust-bitcoin. I'll wait to see what happens there.

  17. stickies-v commented at 1:53 PM on May 29, 2026: contributor

    I'll wait to see what happens there.

    Would suggest drafting or closing until then so reviewers know this is currently on hold?

  18. rustaceanrob marked this as a draft on May 29, 2026
  19. rustaceanrob commented at 10:23 AM on June 5, 2026: member

    https://github.com/sedited/rust-bitcoinkernel/pull/190 is merged and is a good solution for the time being

  20. rustaceanrob closed this on Jun 5, 2026

  21. github-project-automation[bot] changed the project status on Jun 5, 2026
  22. rustaceanrob deleted the branch on Jun 5, 2026

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-06-10 04:51 UTC

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