bench: add script verification benchmark for P2TR script-path spends #35038

pull theStack wants to merge 1 commits into bitcoin:master from theStack:202604-bench_add_script_verify_p2tr_scriptspend changing 1 files +26 −4
  1. theStack commented at 3:20 pm on April 9, 2026: contributor

    Similarly as #34472 already did for key-path spends, this PR adds a benchmark for P2TR script-path spends. So far we don’t have a benchmark on master yet that exercises the verification of taproot commitments (VerifyTaprootCommitment).

    Note that the tapscript leaf intentionally includes a single OP_CHECKSIG as it likely reflects the real world best. Spending tapscript leafs without any signature checks don’t make much sense (they could be trivially tampered with and thus stolen by miners), and doing more than one signature check seems the exception rather than the rule.

    The primary motivation for this PR is to evaluate how potential secp256k1 changes in pubkey tweaking (e.g. #1843) may impact script verification performance.

  2. bench: add script verification benchmark for P2TR script-path spends
    To reflect the likely most common real-world scenario, a single
    OP_CHECKSIG is contained in the Tapscript leaf.
    ba3cf01781
  3. DrahtBot added the label Tests on Apr 9, 2026
  4. DrahtBot commented at 3:20 pm on April 9, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK davidgumberg

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

  5. in src/bench/verify_script.cpp:86 in ba3cf01781
    81+        assert(false);
    82+    }()};
    83+    assert(txSpend.vin[0].scriptWitness.stack.size() == expected_wit_count);
    84+
    85     // Benchmark.
    86     bench.run([&] {
    


    davidgumberg commented at 1:41 am on April 10, 2026:

    nit: while touching this area:

    0    bench.unit("script").run([&] {
    
  6. davidgumberg commented at 1:45 am on April 10, 2026: contributor

    crACK https://github.com/bitcoin/bitcoin/pull/35038/commits/ba3cf017819177d6517292c200db7991c4371746

    0./build/bin/bench_bitcoin --filter="VerifyScript.*"
    
    ns/script script/s err% ins/script cyc/script IPC bra/script miss% total benchmark
    20,238.11 49,411.73 0.2% 467,600.47 86,770.69 5.389 4,548.08 0.0% 0.01 VerifyScriptP2TR_KeyPath
    36,073.54 27,721.15 0.1% 846,768.85 154,685.88 5.474 9,090.15 0.2% 0.01 VerifyScriptP2TR_ScriptPath
    20,260.06 49,358.19 0.3% 459,586.47 86,832.23 5.293 5,805.08 0.1% 0.01 VerifyScriptP2WPKH

    Feel free to disregard as out-of-scope, but maybe while touching this file anyways would be nice to use new setup api introduced in #34208 for the nested if script benchmark:

     0-    bench.run([&] {
     1-        auto stack_copy = stack;
     2+    bench.unit("script").epochIterations(1).setup([&] {
     3+        stack = {};
     4+    }).run([&] {
     5         ScriptError error;
     6-        bool ret = EvalScript(stack_copy, script, 0, BaseSignatureChecker(), SigVersion::BASE, &error);
     7+        bool ret = EvalScript(stack, script, 0, BaseSignatureChecker(), SigVersion::BASE, &error);
     8         assert(ret);
     9     });
    10 }
    

    on master:

    ns/op op/s err% ins/op cyc/op IPC bra/op miss% total benchmark
    19,890.59 50,275.02 1.3% 673,992.65 85,238.74 7.907 143,404.89 0.0% 0.01 VerifyNestedIfScript

    vs this diff:

    ns/script script/s err% ins/script cyc/script IPC bra/script miss% total benchmark
    12,089.00 82,719.83 0.4% 375,703.00 51,987.00 7.227 69,249.00 0.2% 0.00 VerifyNestedIfScript

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-04-12 00:13 UTC

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