fuzz: reuse one fuzzed wallet across inputs #36068

Manually merged
brunoerg merged 2 commits from 2026-08-fuzz-fuzzedwallet-impv into master 2026-11-11 17:37:02 +00:00 AGit
brunoerg commented 2026-08-24 17:19:49 +00:00 (Migrated from github.com)

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.

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.
DrahtBot commented 2026-08-24 17:19:57 +00:00 (Migrated from github.com)

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.

Type Reviewers
ACK frankomosh, maflcko
Approach ACK jeanpablojp

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:

  • #36074 (scripted-diff: [test] Add util/check.h includes for assertions by maflcko)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36068 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36068.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36068#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [frankomosh](https://github.com/bitcoin/bitcoin/pull/36068#issuecomment-6799694523), [maflcko](https://github.com/bitcoin/bitcoin/pull/36068#issuecomment-6800914465) | | Approach ACK | [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/36068#pullrequestreview-5059090941) | 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. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36074](https://github.com/bitcoin/bitcoin/pull/36074) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36074.svg"></sub> (scripted-diff: [test] Add util/check.h includes for assertions by maflcko) 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
brunoerg commented 2026-08-24 17:21:33 +00:00 (Migrated from github.com)

cc @maflcko

cc @maflcko
jeanpablojp (Migrated from github.com) reviewed 2026-08-29 20:14:54 +00:00
jeanpablojp (Migrated from github.com) left a comment

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 OutputGroup in this target goes from 1 to 19, so GroupOutputs finally 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.

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 `OutputGroup` in this target goes from 1 to 19, so `GroupOutputs` finally 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.
jeanpablojp (Migrated from github.com) commented 2026-08-29 20:14:54 +00:00

The descriptor's next_index isn'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?

The descriptor's `next_index` isn'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?
jeanpablojp (Migrated from github.com) commented 2026-08-29 20:14:54 +00:00

Nit, mapWallet.clear() runs before wtxOrdered and m_txos, and both point into it. Nothing dereferences in between so it's latent, but RemoveTxs does it the other way round and leaves mapWallet for last. Any reason for the order?

Nit, `mapWallet.clear()` runs before `wtxOrdered` and `m_txos`, and both point into it. Nothing dereferences in between so it's latent, but `RemoveTxs` does it the other way round and leaves `mapWallet` for last. Any reason for the order?
brunoerg (Migrated from github.com) reviewed 2026-09-07 14:23:56 +00:00
brunoerg (Migrated from github.com) commented 2026-09-07 14:23:56 +00:00

Good point, I think the comment should be improved to reflect it - "one index per iteration" might not be correct. Thanks.

Good point, I think the comment should be improved to reflect it - "one index per iteration" might not be correct. Thanks.
brunoerg commented 2026-09-07 14:24:08 +00:00 (Migrated from github.com)
Force-pushed addressing https://github.com/bitcoin/bitcoin/pull/36068#discussion_r3887572966
brunoerg (Migrated from github.com) reviewed 2026-09-07 14:24:33 +00:00
brunoerg (Migrated from github.com) commented 2026-09-07 14:24:33 +00:00

No reason, will leave as is but can think about it in case I have to touch it again. Thanks.

No reason, will leave as is but can think about it in case I have to touch it again. Thanks.
frankomosh (Migrated from github.com) reviewed 2026-09-22 14:41:25 +00:00
frankomosh (Migrated from github.com) left a comment

Concept ACK on improving performance

Concept ACK on improving performance
frankomosh (Migrated from github.com) commented 2026-09-22 11:00:34 +00:00

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
--- a/src/test/fuzz/util/wallet.h
+++ b/src/test/fuzz/util/wallet.h
@@ void Reset()
 
         assert(wallet->GetTXOs().empty());
 
-        // Deriving a change address advances one descriptor's next_index and
-        // extends its range. A single CreateTransaction() can do this more than
-        // once: the avoid-partial-spends retry reserves a second change key on
-        // the same descriptor when the first attempt was changeless. Rather
-        // than track the exact count, bound the total drift loosely at
-        // m_iterations * m_spkms.size() as a tripwire: growing faster than that
-        // means an iteration is leaving behind state this class does not know
-        // about.
-        const int64_t drift{RangeTotal() - m_baseline_range_total};
-        assert(drift >= 0);
-        assert(static_cast<uint64_t>(drift) <= m_iterations * m_spkms.size());
     }
 
@@
     CScript GetScriptPubKey(FuzzedDataProvider& fuzzed_data_provider) {
         return GetScriptForDestination(GetDestination(fuzzed_data_provider));
     }
 
+    int64_t RangeTotal() const
+    {
+        int64_t total{0};
+        for (const DescriptorScriptPubKeyMan* spkm : m_spkms) total += spkm->GetEndRange();
+        return total;
+    }
+
 private:
 
@@
     std::vector<DescriptorScriptPubKeyMan*> m_spkms;
-    int64_t m_baseline_range_total{0};
     uint64_t m_iterations{0};
 
@@ void Build()
 
         PrecomputeDestinations();
 
-        m_baseline_range_total = RangeTotal();
         m_iterations = 0;
     }
 
@@
-
-    int64_t RangeTotal() const
-    {
-        int64_t total{0};
-        for (const DescriptorScriptPubKeyMan* spkm : m_spkms) total += spkm->GetEndRange();
-        return total;
-    }
-
 };
 
--- a/src/wallet/test/fuzz/spend.cpp
+++ b/src/wallet/test/fuzz/spend.cpp
@@
 FUZZ_TARGET(wallet_create_transaction, .init = initialize_setup)
 
     FuzzedWallet& fuzzed_wallet{*g_wallet};
     fuzzed_wallet.Reset();
+    // Checked when this input ends, so a failure is reported on the input that caused it.
+    // At most 2: one change key, plus one more if the avoid-partial-spends retry runs.
+    struct DriftCheck {
+        FuzzedWallet& w;
+        int64_t before;
+        ~DriftCheck() { assert(w.RangeTotal() - before <= 2); }
+    } drift_check{fuzzed_wallet, fuzzed_wallet.RangeTotal()};
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). <details> <summary><strong>A suggestion of a potential fix diff </strong></summary> ```diff --- a/src/test/fuzz/util/wallet.h +++ b/src/test/fuzz/util/wallet.h @@ void Reset() assert(wallet->GetTXOs().empty()); - // Deriving a change address advances one descriptor's next_index and - // extends its range. A single CreateTransaction() can do this more than - // once: the avoid-partial-spends retry reserves a second change key on - // the same descriptor when the first attempt was changeless. Rather - // than track the exact count, bound the total drift loosely at - // m_iterations * m_spkms.size() as a tripwire: growing faster than that - // means an iteration is leaving behind state this class does not know - // about. - const int64_t drift{RangeTotal() - m_baseline_range_total}; - assert(drift >= 0); - assert(static_cast<uint64_t>(drift) <= m_iterations * m_spkms.size()); } @@ CScript GetScriptPubKey(FuzzedDataProvider& fuzzed_data_provider) { return GetScriptForDestination(GetDestination(fuzzed_data_provider)); } + int64_t RangeTotal() const + { + int64_t total{0}; + for (const DescriptorScriptPubKeyMan* spkm : m_spkms) total += spkm->GetEndRange(); + return total; + } + private: @@ std::vector<DescriptorScriptPubKeyMan*> m_spkms; - int64_t m_baseline_range_total{0}; uint64_t m_iterations{0}; @@ void Build() PrecomputeDestinations(); - m_baseline_range_total = RangeTotal(); m_iterations = 0; } @@ - - int64_t RangeTotal() const - { - int64_t total{0}; - for (const DescriptorScriptPubKeyMan* spkm : m_spkms) total += spkm->GetEndRange(); - return total; - } - }; --- a/src/wallet/test/fuzz/spend.cpp +++ b/src/wallet/test/fuzz/spend.cpp @@ FUZZ_TARGET(wallet_create_transaction, .init = initialize_setup) FuzzedWallet& fuzzed_wallet{*g_wallet}; fuzzed_wallet.Reset(); + // Checked when this input ends, so a failure is reported on the input that caused it. + // At most 2: one change key, plus one more if the avoid-partial-spends retry runs. + struct DriftCheck { + FuzzedWallet& w; + int64_t before; + ~DriftCheck() { assert(w.RangeTotal() - before <= 2); } + } drift_check{fuzzed_wallet, fuzzed_wallet.RangeTotal()}; ``` </details>
brunoerg (Migrated from github.com) reviewed 2026-09-22 18:23:52 +00:00
brunoerg (Migrated from github.com) commented 2026-09-22 18:23:52 +00:00

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.

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.
brunoerg commented 2026-09-22 18:24:33 +00:00 (Migrated from github.com)
Force-pushed addressing https://github.com/bitcoin/bitcoin/pull/36068#discussion_r4070883464
frankomosh (Migrated from github.com) reviewed 2026-09-24 17:17:24 +00:00
frankomosh (Migrated from github.com) left a comment

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.

tACK 12d9ed130f9cbe43e2bec7dd6afd44f53fa6a346. 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.
frankomosh (Migrated from github.com) commented 2026-09-24 16:35:02 +00:00

{
    LOCK(fuzzed_wallet.wallet->cs_wallet);
    assert(fuzzed_wallet.wallet->GetTXOs().size() == static_cast<size_t>(next_locktime));
}

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.

```suggestion { LOCK(fuzzed_wallet.wallet->cs_wallet); assert(fuzzed_wallet.wallet->GetTXOs().size() == static_cast<size_t>(next_locktime)); } ``` 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.
frankomosh (Migrated from github.com) commented 2026-09-24 16:45:47 +00:00
              auto res_ct{CreateTransaction(*fuzzed_wallet.wallet, recipients, change_pos, coin_control)};
              if (res_ct) { assert(res_ct->fee >= 0); }

Also, I think we could do an assert check on the result here ?..had also suggested this elswhere

```suggestion auto res_ct{CreateTransaction(*fuzzed_wallet.wallet, recipients, change_pos, coin_control)}; if (res_ct) { assert(res_ct->fee >= 0); } ``` Also, I think we could do an assert check on the result here ?..had also suggested this elswhere
First-time contributor

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_transaction history-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 reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:7eebed8027c96ac27bcd79eeb7a88e35799cd96eb8fbacf34d3257986a959f64:cdc1bd61213c9363d5bb4c7b7ee073ccfd6fecdafbb2c4c18d9d9e031a6afcf8 --> <!-- ralph-base:6f1365e34f518fdc9fb963cd246abeb47a34ce8b --> <!-- ralph-head:fd3b09e8bcb83351c30b37505501c2a9756d907e --> <!-- ralph-case:e521a7634297b0e7c0fa1e759c8a9f03d910f3fe51061ccd588d85b7e9c9b338 --> 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_transaction` history-dependent, potentially impairing crash reproduction; no divergent corpus input has been demonstrated. Location: [`src/test/fuzz/util/wallet.h:45`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/fd3b09e8bcb83351c30b37505501c2a9756d907e/src/test/fuzz/util/wallet.h#L45>) (head). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`fd3b09e8bcb8`](<https://git.fish.foo/bitcoin/bitcoin/commit/fd3b09e8bcb83351c30b37505501c2a9756d907e>) · [Review report](<https://review.fish.foo/report/36068-fd3b09e8bcb83351c30b37505501c2a9756d907e-2517-3.html>) · [Previous reports](<https://review.fish.foo/traces/36068/>) [permalink](<https://review.fish.foo/report/36068-fd3b09e8bcb83351c30b37505501c2a9756d907e-2517-3.html>)
sedited commented 2026-10-19 14:11:30 +00:00 (Migrated from github.com)

@brunoerg do you want to take @frankomosh's nits here?

@brunoerg do you want to take @frankomosh's nits here?
brunoerg (Migrated from github.com) reviewed 2026-10-19 16:07:24 +00:00
brunoerg (Migrated from github.com) commented 2026-10-19 16:07:24 +00:00

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.

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.
brunoerg (Migrated from github.com) reviewed 2026-10-19 16:07:37 +00:00
brunoerg (Migrated from github.com) commented 2026-10-19 16:07:37 +00:00
Same: https://github.com/bitcoin/bitcoin/pull/36068#discussion_r4316065579
brunoerg commented 2026-10-19 16:08:36 +00:00 (Migrated from github.com)

@brunoerg do you want to take @frankomosh's nits here?

No, will leave that suggestions for a follow-up PR and leave this one focused on the performance improvements.

> @brunoerg do you want to take @frankomosh's nits here? No, will leave that suggestions for a follow-up PR and leave this one focused on the performance improvements.
maflcko commented 2026-10-20 11:31:58 +00:00 (Migrated from github.com)

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:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: review ACK 12d9ed130f9cbe43e2bec7dd6afd44f53fa6a346 📨
ktH5MHZnvs1ki2e19LceE8ALYggwyoYmxsL9MkU2rZeorsPH3v6/ej7wfaaS7nQmUNTfa0ZBVBdQiY/TqsmXCg==
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 12d9ed130f9cbe43e2bec7dd6afd44f53fa6a346 📨 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: review ACK 12d9ed130f9cbe43e2bec7dd6afd44f53fa6a346 📨 ktH5MHZnvs1ki2e19LceE8ALYggwyoYmxsL9MkU2rZeorsPH3v6/ej7wfaaS7nQmUNTfa0ZBVBdQiY/TqsmXCg== ``` </details>
brunoerg commented 2026-10-20 13:02:07 +00:00 (Migrated from github.com)

Also, I wonder if the fuzz target ever found a meaningful bug?

Not sure, but with the current exec/s of this target I wouldn't expect too much.

> Also, I wonder if the fuzz target ever found a meaningful bug? Not sure, but with the current exec/s of this target I wouldn't expect too much.
maflcko commented 2026-10-20 13:08:16 +00:00 (Migrated from github.com)
I guess those, but I am not sure if they were issues in the fuzz or test setup: * https://github.com/bitcoin/bitcoin/pull/27865#issuecomment-5313692035 * https://github.com/bitcoin/bitcoin/pull/34299#issuecomment-3823609006
fanquake commented 2026-10-21 12:59:22 +00:00 (Migrated from github.com)

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%

cc @marcofleon @Crypt-iQ

> 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% cc @marcofleon @Crypt-iQ
DrahtBot commented 2026-11-10 14:00:31 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
brunoerg commented 2026-11-11 11:37:46 +00:00 (Migrated from github.com)

Rebased

Rebased
frankomosh commented 2026-11-11 15:19:01 +00:00 (Migrated from github.com)

reACK fd3b09e8bc

reACK fd3b09e8bcb83351c30b37505501c2a9756d907e
maflcko commented 2026-11-11 16:11:17 +00:00 (Migrated from github.com)

re-ACK fd3b09e8bc 👕

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: re-ACK fd3b09e8bcb83351c30b37505501c2a9756d907e 👕
jMnq9IVBUze1n/1qAaSNlG1i/WMREa8tdpyxYEAyKiW6oxSShOx9UNp/WrzSIG+1ZAFrIaVLYjz23K51ORkDBw==
re-ACK fd3b09e8bcb83351c30b37505501c2a9756d907e 👕 <details><summary>Show signature</summary> Signature: ``` untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}" RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM= trusted comment: re-ACK fd3b09e8bcb83351c30b37505501c2a9756d907e 👕 jMnq9IVBUze1n/1qAaSNlG1i/WMREa8tdpyxYEAyKiW6oxSShOx9UNp/WrzSIG+1ZAFrIaVLYjz23K51ORkDBw== ``` </details>
maflcko commented 2026-12-02 08:57:52 +00:00 (Migrated from github.com)

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?

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?
brunoerg commented 2026-12-02 09:25:39 +00:00 (Migrated from github.com)

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.

> 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.
maflcko commented 2026-12-02 09:41:32 +00:00 (Migrated from github.com)

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?

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?
fanquake commented 2026-12-02 10:17:53 +00:00 (Migrated from github.com)

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?

> 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?
Crypt-iQ commented 2026-12-02 14:53:06 +00:00 (Migrated from github.com)

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 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.
brunoerg commented 2026-12-02 15:04:27 +00:00 (Migrated from github.com)

I took a look on what could be causing the instability, noticed:

  1. REBUILD_INTERVAL{1000} executes Build() inside FUZZ_TARGET (I think this is the main one. Every 1,000th input triggers Build() inside the instrumented target, calling a lot of setup edges once and never again on re-runs, which AFL++ permanently marks as unstable).

some other points that might be affecting it:

  1. DescriptorScriptPubKeyMan keypool/cache drift on ReserveDestination.
  2. Lazy m_map_signing_providers cache in DescriptorScriptPubKeyMan.
  3. Reset() runs at the start of the next input instead of the end of the current input.
  4. std::unordered_map::clear() retains bucket_count() across inputs

My clanker suggested a small fix (maybe 25 lines) for it without losing the speed up (I'm going to test it):

  1. Remove REBUILD_INTERVAL and m_iterations so Build() only ever runs once in .init.
  2. Pre-top-up internal SPKMs by 2 spare keys in Build() (in .init)
  3. Pre-warm m_map_signing_providers in Build() (in .init) using existing public methods.
  4. Run Reset() in an RAII guard at the end of FUZZ_TARGET (replacing DriftCheck, so even the early return on all_values > MAX_MONEY cleans up)
  5. Reset bucket counts in ClearInMemoryTxStateForTest()
I took a look on what could be causing the instability, noticed: 1. REBUILD_INTERVAL{1000} executes Build() inside FUZZ_TARGET (I think this is the main one. Every 1,000th input triggers Build() inside the instrumented target, calling a lot of setup edges once and never again on re-runs, which AFL++ permanently marks as unstable). some other points that might be affecting it: 2. `DescriptorScriptPubKeyMa`n keypool/cache drift on `ReserveDestination`. 3. Lazy `m_map_signing_providers` cache in `DescriptorScriptPubKeyMan`. 4. `Reset()` runs at the start of the next input instead of the end of the current input. 5. `std::unordered_map::clear()` retains `bucket_count()` across inputs My clanker suggested a small fix (maybe 25 lines) for it without losing the speed up (I'm going to test it): 1. Remove REBUILD_INTERVAL and m_iterations so Build() only ever runs once in .init. 2. Pre-top-up internal SPKMs by 2 spare keys in Build() (in .init) 3. Pre-warm m_map_signing_providers in Build() (in .init) using existing public methods. 4. Run Reset() in an RAII guard at the end of FUZZ_TARGET (replacing DriftCheck, so even the early return on all_values > MAX_MONEY cleans up) 5. Reset bucket counts in ClearInMemoryTxStateForTest()
maflcko commented 2026-12-02 15:50:26 +00:00 (Migrated from github.com)

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

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
brunoerg commented 2026-12-02 16:07:16 +00:00 (Migrated from github.com)

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

No strong opinion on it. https://github.com/bitcoin/bitcoin/pull/36859 changed the same target wallet_create_transaction and found a bug with it. So sometimes the saturation is a fault in the harness? Something that could be better checked?

> 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 #32526 No strong opinion on it. https://github.com/bitcoin/bitcoin/pull/36859 changed the same target `wallet_create_transaction` and found a bug with it. So sometimes the saturation is a fault in the harness? Something that could be better checked?
brunoerg commented 2026-12-02 16:10:07 +00:00 (Migrated from github.com)

I took a look on what could be causing the instability, noticed:

  1. REBUILD_INTERVAL{1000} executes Build() inside FUZZ_TARGET (I think this is the main one. Every 1,000th input triggers Build() inside the instrumented target, calling a lot of setup edges once and never again on re-runs, which AFL++ permanently marks as unstable).

some other points that might be affecting it:

  1. DescriptorScriptPubKeyMan keypool/cache drift on ReserveDestination.
  2. Lazy m_map_signing_providers cache in DescriptorScriptPubKeyMan.
  3. Reset() runs at the start of the next input instead of the end of the current input.
  4. std::unordered_map::clear() retains bucket_count() across inputs

My clanker suggested a small fix (maybe 25 lines) for it without losing the speed up (I'm going to test it):

  1. Remove REBUILD_INTERVAL and m_iterations so Build() only ever runs once in .init.
  2. Pre-top-up internal SPKMs by 2 spare keys in Build() (in .init)
  3. Pre-warm m_map_signing_providers in Build() (in .init) using existing public methods.
  4. Run Reset() in an RAII guard at the end of FUZZ_TARGET (replacing DriftCheck, so even the early return on all_values > MAX_MONEY cleans up)
  5. Reset bucket counts in ClearInMemoryTxStateForTest()

Just tested this and got 97.87% of stability. Pre-#36068 got 74.51% and #36068 39.13%.

> I took a look on what could be causing the instability, noticed: > > 1. REBUILD_INTERVAL{1000} executes Build() inside FUZZ_TARGET (I think this is the main one. Every 1,000th input triggers Build() inside the instrumented target, calling a lot of setup edges once and never again on re-runs, which AFL++ permanently marks as unstable). > > some other points that might be affecting it: > > 2. `DescriptorScriptPubKeyMa`n keypool/cache drift on `ReserveDestination`. > 3. Lazy `m_map_signing_providers` cache in `DescriptorScriptPubKeyMan`. > 4. `Reset()` runs at the start of the next input instead of the end of the current input. > 5. `std::unordered_map::clear()` retains `bucket_count()` across inputs > > My clanker suggested a small fix (maybe 25 lines) for it without losing the speed up (I'm going to test it): > > 1. Remove REBUILD_INTERVAL and m_iterations so Build() only ever runs once in .init. > 2. Pre-top-up internal SPKMs by 2 spare keys in Build() (in .init) > 3. Pre-warm m_map_signing_providers in Build() (in .init) using existing public methods. > 4. Run Reset() in an RAII guard at the end of FUZZ_TARGET (replacing DriftCheck, so even the early return on all_values > MAX_MONEY cleans up) > 5. Reset bucket counts in ClearInMemoryTxStateForTest() Just tested this and got 97.87% of stability. Pre-#36068 got 74.51% and #36068 39.13%.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36068
No description provided.