mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
fuzz: several improvements to scriptpubkeyman harness #34969
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!34969
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-03-fuzz-spkm-improvements"
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?
The scriptpubkeyman harness is slow - I'm getting under 40 exec/s on my personal server. This PR solves the following issues that may be affecting the performance:
IsMinecallsConsumeCoinsalways create up to 10'000 coins which may cause slowness.GetNewDestinationcalls (see flamegraph below).GetDescriptorStringunconditionally. It looks like an inofensive function but this is extremely costly due to calls toToNormalizedString/ToPrivateStringfunctions that touch key operations.The 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.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
Getting decent throughput when running on my laptop:
How is your server configured? Do you see a big speedup after applying this patch?
What are the specs? How did you build it? Building with
--preset=libfuzzeron my Ubuntu machine (AMD Ryzen 9 7900 / 32GB RAM), I get around 20 exec/s. With this PR, on same machine, I could reach similar coverage from master with an avg of 150 exec/s.I'm on a i9-14900 with 96 GB RAM.
I was running with only fuzzer sanitizer. When
--preset=libfuzzerthat usesundefined,address,fuzzer. With those I get a lot slower. It started at at 39 but after a few minutes was up to 128 exec/s. I checked out this PR and then it started at 128 and after a few minutes was up to 385 exec/s. Not bad!Running with only
fuzzersanitizer on this branch however didn't seem to speed up it was around 1100 exec/s.Ah, got it. This is expected, because ASan instruments most memory accesses in instrumented code and tracks heap allocations, while UBSan adds runtime checks for selected undefined behaviors. So operations like GetScriptPubKeys(), ConsumeCoins(), and some string operations, such as GetDescriptorString() can become more expensive under these sanitizers.
1d826e5b8c49f8ebb8acd84c50861ea65c4129f8: Can you explain this a bit better? Sure, it may be internally covered in
MarkUnusedAddresses, but the goal of fuzz tests is not only to cover code, but also to assert on results or assumptionsI've changed this commit to say that it's removing excessive
IsMinecalls (e.g. calling it for every single spk fromGetScriptPubKeys. In a later commit, I add the assert back but in a smoothly way.🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/25183113515/job/73833297823LLM reason (✨ experimental): CI failed because the IWYU include/format check for
src/util/feefrac.hgenerated a failure (^^^ ⚠️ Failure generated from IWYU).Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
Rebased
I get around 2000 exec/s on master (
4c99ed1076) and 40786bb2f8 with --preset=libfuzzer.I also fuzzed the scriptpubkeyman target for 10 minutes on both commits, and got a similar amount of runs:
Intel(R) Xeon(R) CPU E3-1275 v6 @ 4.20GHz with 64GB RAM
I thought maybe the latest changes to the harness since your comments changed performance:
I checked out
c6f225c757andc6f225c757^. Same performance with around 2000 exec/s:So not sure where the low exec/s on your machines are coming from.
Running from our corpus?
Oh, no. With the scriptpubkeyman corpus from qa-assets, I get about 200–300 exec/s on the same machine. Thanks, this clears up my confusion! Sorry for the noise
🐙 This pull request conflicts with the target branch and needs rebase.
Rebased
Concept ACK
A real improvement — the early return bug fix and moving expensive ops (
GetDescriptorString,GetNewDestination) out of the hot path are the right calls.Left a comment inline on the assertion coverage (not blocking).
Following up on @maflcko's concern about assertions: the assert is restored in the last commit but only for one randomly picked script from
GetScriptPubKeys(). The original code assertedIsMinefor every script in the set — a stronger invariant that would catch a bug where some (but not all) returned scripts failIsMine.Also, the inverse direction check from the old code is gone entirely:
if (IsMine(random_script)) → assert(GetScriptPubKeys().contains(script)). That covered the other direction of the invariant — a bug whereIsMineclaims ownership of a script that isn't listed inGetScriptPubKeys().Since
spksis already computed once outside the loop, the full assertion can be kept cheaply:The expensive part was calling
GetScriptPubKeys()repeatedly in the loop — iterating over the already-computedspksis negligible.minor nit: redundant default construction + assignment...
Yes, I agree. Just changed it to full assertion since it's cheap.
will leave as-is for now.
Base:
a773e1e33b349dc819b5a0edc1c7a4839dc73b48Head:
0b0df80ba02863fd95128822558625a4c2367d15Findings
Major
The conditional result cannot bind to
auto&(src/wallet/test/fuzz/scriptpubkeyman.cpp:144, head)PickValuereturns a reference to an element, whileConsumeScriptreturns aCScriptby value. The conditional expression therefore yields a value, which cannot bind to the non-constauto&; this prevents the fuzz target from compiling. Store the result by value or split the alternatives into branches.Design and approach
Retain bounded stateful operation sequencing (src/wallet/test/fuzz/scriptpubkeyman.cpp:123, head)
Previously,
GetNewDestinationandMarkUnusedAddresseswere selectable on each iteration of a loop bounded at 20 iterations, allowing valid ranged descriptors to encounter repeated calls in different orders. Now destination generation happens at most once beforespksis captured, andMarkUnusedAddresseshappens at most once afterward. Both mutate keypool state:GetNewDestinationtops up the pool and incrementsnext_index, whileMarkUnusedAddressescan advance it and top up. Could the expensive branches remain gated while a smaller bounded sequence preserves coverage of these state transitions? The profile motivates reducing hot-path work but does not establish that losing this stateful exploration is acceptable.Full review report
ACK
0b0df80ba0Since my last review, only a rebase plus the last commit, which now asserts the full
IsMine/GetScriptPubKeysinvariant in both directions using the precomputedspksset, thanks for taking that! Also nice catch on asserting the inverse direction beforeMarkUnusedAddresses(), since it mayTopUp().