mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 09:38:38 +00:00
fuzz: reuse one fuzzed wallet across inputs #36068
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!36068
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-08-fuzz-fuzzedwallet-impv"
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?
FuzzedWallet was rebuilt for every input. That imports eight
descriptors, and each address it then hands out costs a BIP32
derivation plus three separate WalletBatch transactions (see
DescriptorScriptPubKeyMan::GetNewDestination) - all paid before the
target reaches the code under test.
This PR changes it to build the wallet once in the target's .init hook and
reset it perinput instead. I benchmarked on my Ubuntu machine without
sanitizers and got a ~6x speedup.
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.
cc @maflcko
Approach ACK
Ran the qa-assets corpus on master and on this head, the speedup reproduces, around 4x here.
One thing I didn't expect. With the fixed pool the biggest
OutputGroupin this target goes from 1 to 19, soGroupOutputsfinally has something to group. I didn't see the pool mentioned in the PR description or the commits, might be worth a line?Left two inline comments.
The descriptor's
next_indexisn't reset here, so the same input builds a different transaction depending on how many ran before it. I don't think it hurts in practice since only the change output and its signature move, but the comment on the drift assert assumes an iteration advances one index and the APS retry can keep two. Is this intended?Nit,
mapWallet.clear()runs beforewtxOrderedandm_txos, and both point into it. Nothing dereferences in between so it's latent, butRemoveTxsdoes it the other way round and leavesmapWalletfor last. Any reason for the order?Good point, I think the comment should be improved to reflect it - "one index per iteration" might not be correct. Thanks.
Force-pushed addressing https://github.com/bitcoin/bitcoin/pull/36068#discussion_r3887572966
No reason, will leave as is but can think about it in case I have to touch it again. Thanks.
Concept ACK on improving performance
I think that this check runs at the start of an input, but checks the state left by earlier inputs. So when one input leaks, the crash is reported on the next input, which then does not reproduce on its own.
To test this, I made one input (A) leak 100 change keys, and ran it before a normal input (B):
A then B -> crash reported on B
B alone -> no crash
A alone -> no crash (with
-detect_leaks=0)Maybe we could check at the end of each input instead , so the crash lands on the right input..?..That would also seem to allow for a much tighter bound: on my corpus side with 4640 inputs, no input moved the range by more than 2 (0: 4490, 1: 147, 2: 4).
A suggestion of a potential fix diff
Good catch, better to check at the end. I'm going to address your suggestion, but also I'm going to add a non-negative assertion.
Force-pushed addressing https://github.com/bitcoin/bitcoin/pull/36068#discussion_r4070883464
tACK
12d9ed130f. This improves performance of this harness.Added 2 additional comments which are not related to the specific goals of the PR but I think important for this harness, for the author's consideration.
Asserting inserted output counts here would help catch any future regression in this harness as you had suggested in https://github.com/bitcoin/bitcoin/pull/35790#pullrequestreview-4782030244, Initially I proposed it be added in https://github.com/bitcoin/bitcoin/pull/34264 but the author has not been available for a while.
Also, I think we could do an assert check on the result here ?..had also suggested this elswhere
Earlier concerns remain unresolved; see the Run archive linked from the Review report.
🟠 Minor · Wallet resets leave fuzz execution dependent on earlier inputs
Retained descriptor state and periodic post-seed rebuilds make
wallet_create_transactionhistory-dependent, potentially impairing crash reproduction; no divergent corpus input has been demonstrated.Location:
src/test/fuzz/util/wallet.h:45(head).Review coverage was incomplete.
Reviewed:
fd3b09e8bcb8· Review report · Previous reportspermalink
@brunoerg do you want to take @frankomosh's nits here?
This is a good one, but I'll leave this for a follow-up PR (improving the effectiveness of this target) and leave this ne for the performance improvements.
Same: https://github.com/bitcoin/bitcoin/pull/36068#discussion_r4316065579
No, will leave that suggestions for a follow-up PR and leave this one focused on the performance improvements.
I guess this is going to break stability (https://github.com/bitcoin/bitcoin/issues/36139) even more, but given that it is only at ~80% (https://oss-garage.github.io/fuzzor-dashboard/#harness=wallet_create_transaction&campaign=a854785ff1d926d3ef0132439842d8c5e61806affb7ddbc3b7158ee237a57434), it seems fine.
Also, I wonder if the fuzz target ever found a meaningful bug?
Didn't look closely, but this lgtm.
review ACK
12d9ed130f📨Show signature
Signature:
Not sure, but with the current exec/s of this target I wouldn't expect too much.
I guess those, but I am not sure if they were issues in the fuzz or test setup:
cc @marcofleon @Crypt-iQ
🐙 This pull request conflicts with the target branch and needs rebase.
Rebased
reACK
fd3b09e8bcre-ACK
fd3b09e8bc👕Show signature
Signature:
https://oss-garage.github.io/fuzzor-dashboard/#harness=wallet_create_transaction: Looks like executions/s went up, but as predicted, stability went from 80% to 20%.
Thus, the corpus count doubled, but coverage did not increase (as expected).
Sure, a speedup is nice, but I wonder if this is worth it? Maybe it can be reverted again?
I'm checking it now.
Thx. Just for context, I am asking because a larger corpus will take a longer time in every CI run, so while a 6x speedup during fuzz search may be nice, it could also be achieved by using 6x compute. However, the CI runs this in one go, because https://github.com/bitcoin/bitcoin/pull/36121 didn't make it, so this will be a cost currently that can not be offset with more compute.
Not sure how to trade this off, and if it is worth it to come up with complicated solutions. I just think experimentation for fuzzing is great and it would be fine to revert this again and possibly try other experiments in the future?
@marcofleon @Crypt-iQ any opinions?
I haven't reviewed the PR, so take my comment with a grain of salt. IMO if stability drops that much, we should fix it or revert the change. I did open an issue on fuzzor (https://github.com/oss-garage/fuzzor/issues/96) where we could try to start tackling some of the stability issues, but I haven't gotten around to implementing it yet. I think it would be good to slowly start to fix these stability issues as mentioned in https://github.com/bitcoin/bitcoin/issues/36139. My idea for fuzzor was to have it automatically report to us what code paths were unstable and then work through the list.
I took a look on what could be causing the instability, noticed:
some other points that might be affecting it:
DescriptorScriptPubKeyMan keypool/cache drift onReserveDestination.m_map_signing_providerscache inDescriptorScriptPubKeyMan.Reset()runs at the start of the next input instead of the end of the current input.std::unordered_map::clear()retainsbucket_count()across inputsMy clanker suggested a small fix (maybe 25 lines) for it without losing the speed up (I'm going to test it):
Sure, but I wonder if this is worth it in the long term.
This is just adding a 6x or so speedup to a fuzz target that seems pretty much saturated to me, but if it wasn't one could simply spin up 6x compute or wait 6x to get the same benefit.
Also, all of this code has to be maintained going forward. Sure, it is possible to let an LLM do it. Though, the fuzz targets are meant to be simple, so that they are easy to write and understand, and if this one gets increasingly complicated that only an LLM can understand it, we may lose that property.
It reminds me a bit of https://github.com/bitcoin/bitcoin/pull/32526
No strong opinion on it. https://github.com/bitcoin/bitcoin/pull/36859 changed the same target
wallet_create_transactionand found a bug with it. So sometimes the saturation is a fault in the harness? Something that could be better checked?Just tested this and got 97.87% of stability. Pre-#36068 got 74.51% and #36068 39.13%.