bench: add BIP-352 pubkey extraction benchmarks (standard + P2PKH worst-case) #36475

pull theStack wants to merge 2 commits into bitcoin:master from theStack:bip352-bench-pubkey_extraction changing 2 files +112 −0
  1. theStack commented at 2:30 PM on October 8, 2026: contributor

    As there are ongoing changes to the Silent Payments public key extraction function GetPubKeyFromInput (see recently merged #36338, upcoming #36417), it seems reasonable to add benchmarks for it. The first commit covers the standard shape of each eligible input type (P2PKH, P2SH-P2WPKH, P2WPKH and P2TR script-path spend; see BIP-352). The second adds a worst-case P2PKH input with a maximally malleated scriptSig, where every push has to be hashed during the scan.

    Results on my arm64 machine (as per $ ./build/bin/bench_bitcoin -filter='BIP352_.*'):

    ns/input input/s err% total benchmark
    3,034.12 329,584.35 0.2% 0.01 BIP352_GetPubKey_P2PKH
    69,868.20 14,312.66 0.1% 0.01 BIP352_GetPubKey_P2PKH_WorstCase
    2,841.35 351,945.44 0.1% 0.01 BIP352_GetPubKey_P2SH_P2WPKH
    2,768.00 361,272.01 0.1% 0.01 BIP352_GetPubKey_P2TR
    2,757.57 362,637.66 0.0% 0.01 BIP352_GetPubKey_P2WPKH
  2. DrahtBot added the label Tests on Oct 8, 2026
  3. DrahtBot commented at 2:30 PM on October 8, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    ACK Yudis-bit, fametrano
    Concept ACK w0xlt

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

  4. theStack force-pushed on Oct 8, 2026
  5. DrahtBot added the label CI failed on Oct 8, 2026
  6. w0xlt commented at 5:52 PM on October 8, 2026: contributor

    Concept ACK

  7. Yudis-bit commented at 2:53 AM on October 9, 2026: none

    Concept and approach ACK.

    Numbers make sense given that IsFullyValid() point validation dominates the standard paths. In P2PKH_WorstCase, hoisting pubkey_candidate outside the while loop in GetPubKeyFromInput would save ~290 heap reallocations across the dummy pushes.

    It might also be worth adding P2TR_ScriptPath and P2TR_ScriptPath_NUMS to benchmark the control-block validation and the early rejection path.

  8. bench: add benchmarks for BIP-352 pubkey extraction (standard inputs)
    Benchmark the public key extraction (`GetPubKeyFromInput`) for the
    standard shape of each Silent Payments eligible input type, i.e.
    P2PKH, P2SH-P2WPKH, P2WPKH and P2TR. For P2TR, a script-path spend is
    used, as it runs all of the key-path extraction logic plus the control
    block checks and the NUMS-H internal key comparison.
    d71bc7127f
  9. theStack force-pushed on Oct 10, 2026
  10. theStack force-pushed on Oct 10, 2026
  11. bench: add worst-case P2PKH benchmark for BIP-352 pubkey extraction
    Add a P2PKH input with a malleated scriptSig that prepends as many
    33-byte pushes as the consensus scriptSig size limit (MAX_SCRIPT_SIZE)
    allows, each of which has to be hashed during the scan, followed by the
    actual signature and public key. The input respects all other consensus
    limits (data pushes don't count towards MAX_OPS_PER_SCRIPT, the stack
    stays below MAX_STACK_SIZE), but is non-standard as it exceeds
    MAX_STANDARD_SCRIPTSIG_SIZE.
    
    Results on my arm64 machine:
    ```
    $ ./build/bin/bench_bitcoin -filter='BIP352_.*'
    [...]
    
    |            ns/input |             input/s |    err% |     total | benchmark
    |--------------------:|--------------------:|--------:|----------:|:----------
    |            3,021.72 |          330,937.16 |    0.1% |      0.01 | `BIP352_GetPubKey_P2PKH`
    |           69,754.07 |           14,336.08 |    0.1% |      0.01 | `BIP352_GetPubKey_P2PKH_WorstCase`
    |            2,839.92 |          352,122.64 |    0.2% |      0.01 | `BIP352_GetPubKey_P2SH_P2WPKH`
    |            2,756.93 |          362,722.60 |    0.1% |      0.01 | `BIP352_GetPubKey_P2TR`
    |            2,752.45 |          363,312.34 |    0.0% |      0.01 | `BIP352_GetPubKey_P2WPKH`
    
    ```
    56c0f168d1
  12. theStack force-pushed on Oct 10, 2026
  13. theStack commented at 5:07 PM on October 10, 2026: contributor

    It might also be worth adding P2TR_ScriptPath and P2TR_ScriptPath_NUMS to benchmark the control-block validation and the early rejection path.

    Due to the strong similarity I think it's fine to have only a single representative P2TR benchmark, but I switched the one from key-path to script-path spending as the pubkey extraction contains (slightly) more logic. Also fixed the IWYU CI error. Thanks for the review!

  14. DrahtBot removed the label CI failed on Oct 10, 2026
  15. Yudis-bit commented at 11:51 AM on October 17, 2026: none

    re-tACK 56c0f168d1

    Makes sense to stick to one P2TR case. Windows numbers:

    ns/input input/s err% total benchmark
    4,660.44 214,571.81 0.2% 0.01 BIP352_GetPubKey_P2PKH
    81,266.67 12,305.17 0.2% 0.01 BIP352_GetPubKey_P2PKH_WorstCase
    4,624.56 216,236.72 0.4% 0.01 BIP352_GetPubKey_P2SH_P2WPKH
    4,330.00 230,946.88 0.6% 0.01 BIP352_GetPubKey_P2TR
    4,335.53 230,652.50 0.2% 0.01 BIP352_GetPubKey_P2WPKH
  16. fametrano commented at 7:37 AM on October 21, 2026: contributor

    tACK 56c0f168d1

    The five benchmarks build and run on an Apple M5 (Release build, bench_bitcoin -filter='BIP352_.*' -min-time=2000, three runs). The four standard inputs take 2.2-2.6 µs each. The worst case, a 10,000-byte P2PKH scriptSig with 291 dummy pushes, takes 39-43 µs. I also rebuilt the five input shapes independently. A separate BIP352 implementation (btclib-wallet) extracts the expected key from each.


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

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