mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 16:02:38 +00:00
bench: add BIP-352 pubkey extraction benchmarks (standard + P2PKH worst-case) #36475
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36475
Loading…
Reference in a new issue
No description provided.
Delete branch "bip352-bench-pubkey_extraction"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
As there are ongoing changes to the Silent Payments public key extraction function
GetPubKeyFromInput(see recently merged #36338), 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_.*'):BIP352_GetPubKey_P2PKHBIP352_GetPubKey_P2PKH_WorstCaseBIP352_GetPubKey_P2SH_P2WPKHBIP352_GetPubKey_P2TRBIP352_GetPubKey_P2WPKHThe following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Base:
228877d7836a55c1d6fde90b0b7ba2d4c90248abHead:
56c0f168d1a81b19e4cd71ef81e7ce2d9c1624e3Findings
Suggestions
Add or label the P2TR key-path benchmark (src/bench/bip352.cpp:68, head)
This witness includes a leaf script and control block, so it exercises the script-path branch; a key-path witness skips those checks. Because this is the only P2TR benchmark and the PR description identifies the standard case as key-path, its timing is not a key-path baseline. Add a separate key-path case, or scope the benchmark and description explicitly to script-path so readers do not mistake its result for standard key-path timing.
Full review report
Concept ACK
Concept and approach ACK.
Numbers make sense given that
IsFullyValid()point validation dominates the standard paths. InP2PKH_WorstCase, hoistingpubkey_candidateoutside the while loop inGetPubKeyFromInputwould save ~290 heap reallocations across the dummy pushes.It might also be worth adding
P2TR_ScriptPathandP2TR_ScriptPath_NUMSto 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!
re-tACK
56c0f168d1Makes sense to stick to one P2TR case. Windows numbers:
BIP352_GetPubKey_P2PKHBIP352_GetPubKey_P2PKH_WorstCaseBIP352_GetPubKey_P2SH_P2WPKHBIP352_GetPubKey_P2TRBIP352_GetPubKey_P2WPKHtACK
56c0f168d1The 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.ACK https://github.com/bitcoin/bitcoin/pull/36475/commits/56c0f168d1a81b19e4cd71ef81e7ce2d9c1624e3
This introduced an ODR violation. Followed up here: #36966.