fuzz: add corpus reachability checks #36098

Manually merged
HowHsu merged 13 commits from fuzz-reachability-goals into master 2026-10-28 14:53:38 +00:00 AGit
HowHsu commented 2026-08-27 11:48:25 +00:00 (Migrated from github.com)

This is a follow-up to #35482.

Add ReachabilityGoal() to aggregate whether selected conditions are reached across all inputs processed by a fuzz target. Goals are identified by source location and reported at shutdown. Setting FUZZ_ENFORCE_REACHABILITY=1 makes the process fail if any registered goal was not reached.

Add goals for selected high-value paths, including IBD and non-IBD message processing, completed P2P handshakes and transport messages, successful estimator/mempool/snapshot operations, transaction and package acceptance, and compact block reconstruction.

Testing

Built the fuzz binary and replayed the current qa-assets corpora for all instrumented targets with FUZZ_ENFORCE_REACHABILITY=1.

This is a follow-up to #35482. Add `ReachabilityGoal()` to aggregate whether selected conditions are reached across all inputs processed by a fuzz target. Goals are identified by source location and reported at shutdown. Setting `FUZZ_ENFORCE_REACHABILITY=1` makes the process fail if any registered goal was not reached. Add goals for selected high-value paths, including IBD and non-IBD message processing, completed P2P handshakes and transport messages, successful estimator/mempool/snapshot operations, transaction and package acceptance, and compact block reconstruction. ### Testing Built the fuzz binary and replayed the current qa-assets corpora for all instrumented targets with `FUZZ_ENFORCE_REACHABILITY=1`.
DrahtBot commented 2026-08-27 11:48:34 +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 Crypt-iQ, nervana21, maflcko
Concept ACK brunoerg

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:

  • #36631 (fuzz: add a custom mutator for PSBT by brunoerg)
  • #36608 (Reimplement private broadcast as node state-less jobs + package relay support by instagibbs)
  • #36598 ([Demo] validation: remove AssumeUTXO by l0rinc)

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/36098 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36098.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36098#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 | [Crypt-iQ](https://github.com/bitcoin/bitcoin/pull/36098#pullrequestreview-5308171905), [nervana21](https://github.com/bitcoin/bitcoin/pull/36098#issuecomment-5834469678), [maflcko](https://github.com/bitcoin/bitcoin/pull/36098#pullrequestreview-5505080283) | | Concept ACK | [brunoerg](https://github.com/bitcoin/bitcoin/pull/36098#issuecomment-5446893369) | 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: * [#36631](https://github.com/bitcoin/bitcoin/pull/36631) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36631.svg"></sub> (fuzz: add a custom mutator for PSBT by brunoerg) * [#36608](https://github.com/bitcoin/bitcoin/pull/36608) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36608.svg"></sub> (Reimplement private broadcast as node state-less jobs + package relay support by instagibbs) * [#36598](https://github.com/bitcoin/bitcoin/pull/36598) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([Demo] validation: remove AssumeUTXO by l0rinc) 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-->
DrahtBot commented 2026-08-27 11:53:48 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/33069008111/job/98506152003
LLM reason (✨ experimental): CI failed because the lint-locale-dependence check flagged a locale-dependent std::fprintf usage in src/test/fuzz/util/reachability.cpp.

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.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/33069008111/job/98506152003</sub> <sub>LLM reason (✨ experimental): CI failed because the `lint-locale-dependence` check flagged a locale-dependent `std::fprintf` usage in `src/test/fuzz/util/reachability.cpp`.</sub> <details><summary>Hints</summary> 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. </details>
maflcko (Migrated from github.com) approved these changes 2026-08-27 12:00:13 +00:00
maflcko (Migrated from github.com) left a comment

lgtm. I wonder if reachability goals can be formulated at a higher level. Maybe taking past issues or CVEs into account, to ensure they are covered and remain covered?

lgtm. I wonder if reachability goals can be formulated at a higher level. Maybe taking past issues or CVEs into account, to ensure they are covered and remain covered?
maflcko (Migrated from github.com) commented 2026-08-27 11:59:02 +00:00

Seems fine, but this seems a bit low-level. I am thinking that goals may be best higher level?

Eg. mempool.size()>=1, which implies non-ibd message?

Seems fine, but this seems a bit low-level. I am thinking that goals may be best higher level? Eg. `mempool.size()>=1`, which implies non-ibd message?
maflcko (Migrated from github.com) commented 2026-08-27 11:55:28 +00:00

nit: I wonder if this can use Mutex + the annotations

nit: I wonder if this can use `Mutex` + the annotations
maflcko (Migrated from github.com) commented 2026-08-27 11:56:49 +00:00
/// Record whether a reachability goal is satisfied by at least one fuzz input.

nit: Would be nice to use the /// for new doxygen comments, to avoid the formatting inconsistencies around /** comments.

```suggestion /// Record whether a reachability goal is satisfied by at least one fuzz input. ``` nit: Would be nice to use the `///` for new doxygen comments, to avoid the formatting inconsistencies around `/**` comments.
dergoegge (Migrated from github.com) reviewed 2026-08-27 12:20:44 +00:00
dergoegge (Migrated from github.com) commented 2026-08-27 12:20:45 +00:00

I think it'd be great to add a message to this, so failures are more verbose.

It could also make sense to provide multiple reachability functions for different condition types, where the parameters of the comparison are passed directly e.g. ReachabilityGoalGt(a, b, "sometimes a is greater than b");, this can be used to guide fuzzing in addition to asserting reachability. For example, the assertion feedback in this https://github.com/oss-garage/fuzzamoto/pull/69 PR could make use of the these reachability checks for guidance.

Maybe (although this is likely more controversial) we could also place these checks into production code, to get this feedback for all our tests not just fuzzing.

I think it'd be great to add a message to this, so failures are more verbose. It could also make sense to provide multiple reachability functions for different condition types, where the parameters of the comparison are passed directly e.g. `ReachabilityGoalGt(a, b, "sometimes a is greater than b");`, this can be used to guide fuzzing in addition to asserting reachability. For example, the assertion feedback in this https://github.com/oss-garage/fuzzamoto/pull/69 PR could make use of the these reachability checks for guidance. Maybe (although this is likely more controversial) we could also place these checks into production code, to get this feedback for all our tests not just fuzzing.
HowHsu commented 2026-08-27 12:25:01 +00:00 (Migrated from github.com)

lgtm. I wonder if reachability goals can be formulated at a higher level. Maybe taking past issues or CVEs into account, to ensure they are covered and remain covered?

Sure, I'll look into it.

> lgtm. I wonder if reachability goals can be formulated at a higher level. Maybe taking past issues or CVEs into account, to ensure they are covered and remain covered? Sure, I'll look into it.
maflcko (Migrated from github.com) reviewed 2026-08-27 13:17:50 +00:00
maflcko (Migrated from github.com) commented 2026-08-27 13:17:50 +00:00

It could also make sense to provide multiple reachability functions for different condition types, where the parameters of the comparison are passed directly e.g. ReachabilityGoalGt(a, b

I'd presume that -use_value_profile=1 of libFuzzer takes care of this for e.g. mempool.size() >= 200, but I haven't really benchmarked any of this. Is there some gist or background on how to best guide a fuzz engine toward a set goal? I know there is libFuzzers focus_function, but it is experimental and last time I tried it didn't work. Also, I haven't tried other fuzzing engines, so I wonder if others have nice findings here.

> It could also make sense to provide multiple reachability functions for different condition types, where the parameters of the comparison are passed directly e.g. `ReachabilityGoalGt(a, b` I'd presume that -use_value_profile=1 of libFuzzer takes care of this for e.g. `mempool.size() >= 200`, but I haven't really benchmarked any of this. Is there some gist or background on how to best guide a fuzz engine toward a set goal? I know there is libFuzzers `focus_function`, but it is experimental and last time I tried it didn't work. Also, I haven't tried other fuzzing engines, so I wonder if others have nice findings here.
Crypt-iQ (Migrated from github.com) reviewed 2026-08-27 13:28:36 +00:00
Crypt-iQ (Migrated from github.com) commented 2026-08-27 13:28:36 +00:00

Also, I haven't tried other fuzzing engines, so I wonder if others have nice findings here.

AFL++ does have IJON annotations which I think can just be added to the harness, though it requires specific macros (maybe there is a way to hide them though?). I tested them but since I did not properly benchmark it compared to not using it, I could not tell whether it actually guided AFL++ to the goal more efficiently.

> Also, I haven't tried other fuzzing engines, so I wonder if others have nice findings here. AFL++ does have IJON annotations which I think can just be added to the harness, though it requires specific macros (maybe there is a way to hide them though?). I tested them but since I did not properly benchmark it compared to not using it, I could not tell whether it actually guided AFL++ to the goal more efficiently.
dergoegge (Migrated from github.com) reviewed 2026-08-27 13:32:33 +00:00
dergoegge (Migrated from github.com) commented 2026-08-27 13:32:33 +00:00

I was more thinking of custom fuzzers that could make use of this (e.g. that fuzzamoto PR I linked), or AFL++ also has an IJON implementation now, and Antithesis has their Sometimes Assertions, which could both be used under the hood in ReachabilityGoal*. For Antithesis, this only makes sense if we put these goal annotations in non-test code, as the fuzz tests aren't running there.

So overall I think splitting into different functions and explicitly passing the parameters gives us: better error messages, as well as more flexibility for different fuzzers. This can of course also be added later. I think what's in this PR already provides value.

I was more thinking of custom fuzzers that could make use of this (e.g. that fuzzamoto PR I linked), or AFL++ also has an [IJON](https://github.com/AFLplusplus/AFLplusplus/blob/stable/docs/IJON.md) implementation now, and Antithesis has their [Sometimes Assertions](https://antithesis.com/docs/best_practices/sometimes_assertions/), which could both be used under the hood in `ReachabilityGoal*`. For Antithesis, this only makes sense if we put these goal annotations in non-test code, as the fuzz tests aren't running there. So overall I think splitting into different functions and explicitly passing the parameters gives us: better error messages, as well as more flexibility for different fuzzers. This can of course also be added later. I think what's in this PR already provides value.
dergoegge (Migrated from github.com) reviewed 2026-08-27 13:34:08 +00:00
dergoegge (Migrated from github.com) commented 2026-08-27 13:34:08 +00:00

The same argument could also be made for our Assert and Assume macros (e.g. having Assume{Gt,Lt,...})

The same argument could also be made for our `Assert` and `Assume` macros (e.g. having `Assume{Gt,Lt,...}`)
HowHsu (Migrated from github.com) reviewed 2026-08-27 13:46:37 +00:00
HowHsu (Migrated from github.com) commented 2026-08-27 13:46:37 +00:00

Seems fine, but this seems a bit low-level. I am thinking that goals may be best higher level?

Eg. mempool.size()>=1, which implies non-ibd message?

Not sure if the current corpus data can pass this.
Tested it, current corpus data fails on it. We have to first construct a valid Tx entry into corpus set first.

> Seems fine, but this seems a bit low-level. I am thinking that goals may be best higher level? > > Eg. `mempool.size()>=1`, which implies non-ibd message? ~Not sure if the current corpus data can pass this.~ Tested it, current corpus data fails on it. We have to first construct a valid Tx entry into corpus set first.
maflcko (Migrated from github.com) reviewed 2026-08-27 13:59:05 +00:00
maflcko (Migrated from github.com) commented 2026-08-27 13:59:05 +00:00

Tested it, current corpus data fails on it. We have to first construct a valid Tx entry into corpus set first.

Huh, I am pretty sure I generated those manually last week and uploaded the fuzz inputs for that?

$ FUZZ=process_messages ./bld-cmake/bin/fuzz -runs=1 ../qa-assets/fuzz_corpora/process_messages/273fac680feaaa99ede7542dbd7af07db80821e2 
INFO: Running with entropic power schedule (0xFF, 100).

test/fuzz/process_messages.cpp:139 void process_messages_fuzz_target(FuzzBufferType): Assertion `initial_sequence==end_sequence' failed.
> Tested it, current corpus data fails on it. We have to first construct a valid Tx entry into corpus set first. Huh, I am pretty sure I generated those manually last week and uploaded the fuzz inputs for that? ``` $ FUZZ=process_messages ./bld-cmake/bin/fuzz -runs=1 ../qa-assets/fuzz_corpora/process_messages/273fac680feaaa99ede7542dbd7af07db80821e2 INFO: Running with entropic power schedule (0xFF, 100). test/fuzz/process_messages.cpp:139 void process_messages_fuzz_target(FuzzBufferType): Assertion `initial_sequence==end_sequence' failed.
maflcko (Migrated from github.com) reviewed 2026-08-27 14:13:28 +00:00
maflcko (Migrated from github.com) commented 2026-08-27 14:13:28 +00:00

For Antithesis, this only makes sense if we put these goal annotations in non-test code, as the fuzz tests aren't running there.

Hmm, I'd presume that reachability goals are test-case dependant. Let's say you want to have a "full mempool". For a test that manually fills the mempool with dummy transactions (possibly just as an initial setup for a later test), this goal is mostly meaningless and would be better off not being checked globally. However, if there is a mempool-sepcific test, it could make sense to have a reachability goal toward a "full mempool" for this specific test.

Moreover, even if the goals are similar for different test-cases, the specific goal could still differ: E.g. the connman test could have a goal of 1000 peers, whereas the p2p test could have a goal of 10 peers (or so)...

> For Antithesis, this only makes sense if we put these goal annotations in non-test code, as the fuzz tests aren't running there. Hmm, I'd presume that reachability goals are test-case dependant. Let's say you want to have a "full mempool". For a test that manually fills the mempool with dummy transactions (possibly just as an initial setup for a later test), this goal is mostly meaningless and would be better off not being checked globally. However, if there is a mempool-sepcific test, it could make sense to have a reachability goal toward a "full mempool" for this specific test. Moreover, even if the goals are similar for different test-cases, the specific goal could still differ: E.g. the connman test could have a goal of 1000 peers, whereas the p2p test could have a goal of 10 peers (or so)...
HowHsu (Migrated from github.com) reviewed 2026-08-27 14:25:13 +00:00
HowHsu (Migrated from github.com) commented 2026-08-27 14:25:13 +00:00

Tested it, current corpus data fails on it. We have to first construct a valid Tx entry into corpus set first.

Huh, I am pretty sure I generated those manually last week and uploaded the fuzz inputs for that?

$ FUZZ=process_messages ./bld-cmake/bin/fuzz -runs=1 ../qa-assets/fuzz_corpora/process_messages/273fac680feaaa99ede7542dbd7af07db80821e2 
INFO: Running with entropic power schedule (0xFF, 100).

test/fuzz/process_messages.cpp:139 void process_messages_fuzz_target(FuzzBufferType): Assertion `initial_sequence==end_sequence' failed.

My bad, forgot to update the data set. But the thing is an input of add tx + del tx in process_messages is also valid. so perhaps end_sequence != initial_sequence is better?

> > Tested it, current corpus data fails on it. We have to first construct a valid Tx entry into corpus set first. > > Huh, I am pretty sure I generated those manually last week and uploaded the fuzz inputs for that? > > ``` > $ FUZZ=process_messages ./bld-cmake/bin/fuzz -runs=1 ../qa-assets/fuzz_corpora/process_messages/273fac680feaaa99ede7542dbd7af07db80821e2 > INFO: Running with entropic power schedule (0xFF, 100). > > test/fuzz/process_messages.cpp:139 void process_messages_fuzz_target(FuzzBufferType): Assertion `initial_sequence==end_sequence' failed. > ``` My bad, forgot to update the data set. But the thing is an input of `add tx + del tx` in `process_messages` is also valid. so perhaps `end_sequence != initial_sequence` is better?
HowHsu (Migrated from github.com) reviewed 2026-08-27 14:27:20 +00:00
HowHsu (Migrated from github.com) commented 2026-08-27 14:27:20 +00:00

I think it'd be great to add a message to this, so failures are more verbose.

Added.

It could also make sense to provide multiple reachability functions for different condition types, where the parameters of the comparison are passed directly e.g. ReachabilityGoalGt(a, b, "sometimes a is greater than b");, this can be used to guide fuzzing in addition to asserting reachability. For example, the assertion feedback in this oss-garage/fuzzamoto#69 PR could make use of the these reachability checks for guidance.

Beyond my knowledges, I'll take some time to get to know this first.

Maybe (although this is likely more controversial) we could also place these checks into production code, to get this feedback for all our tests not just fuzzing.

It is a good follow-up task, thanks.

> I think it'd be great to add a message to this, so failures are more verbose. > Added. > It could also make sense to provide multiple reachability functions for different condition types, where the parameters of the comparison are passed directly e.g. `ReachabilityGoalGt(a, b, "sometimes a is greater than b");`, this can be used to guide fuzzing in addition to asserting reachability. For example, the assertion feedback in this [oss-garage/fuzzamoto#69](https://github.com/oss-garage/fuzzamoto/pull/69) PR could make use of the these reachability checks for guidance. > Beyond my knowledges, I'll take some time to get to know this first. > Maybe (although this is likely more controversial) we could also place these checks into production code, to get this feedback for all our tests not just fuzzing. It is a good follow-up task, thanks.
maflcko (Migrated from github.com) reviewed 2026-08-27 14:29:34 +00:00
maflcko (Migrated from github.com) commented 2026-08-27 14:29:34 +00:00

Right, the assertion was just to trigger/find the input. The goal should obviously be inverted :)

Right, the assertion was just to trigger/find the input. The goal should obviously be inverted :)
brunoerg commented 2026-08-27 21:41:32 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
brunoerg (Migrated from github.com) reviewed 2026-08-28 00:08:35 +00:00
brunoerg (Migrated from github.com) commented 2026-08-28 00:08:35 +00:00

1e1144a468fed566dddd732886a0a5b78ad9df99: Is this deserialization a good candidate for it? I think the other ones for this target would implicitly catch it.

1e1144a468fed566dddd732886a0a5b78ad9df99: Is this deserialization a good candidate for it? I think the other ones for this target would implicitly catch it.
brunoerg commented 2026-08-28 00:35:02 +00:00 (Migrated from github.com)

Just playing with the idea, thought on coinselection:

diff --git a/src/wallet/test/fuzz/coinselection.cpp b/src/wallet/test/fuzz/coinselection.cpp
index 8949a6c20d..56703ecf0e 100644
--- a/src/wallet/test/fuzz/coinselection.cpp
+++ b/src/wallet/test/fuzz/coinselection.cpp
@@ -8,6 +8,7 @@
 #include <test/fuzz/FuzzedDataProvider.h>
 #include <test/fuzz/fuzz.h>
 #include <test/fuzz/util.h>
+#include <test/fuzz/util/reachability.h>
 #include <test/util/setup_common.h>
 #include <wallet/coinselection.h>
 
@@ -395,6 +396,7 @@ void FuzzCoinSelectionAlgorithm(std::span<const uint8_t> buffer) {
                 (void)result_bnb->GetInputSet();
             }
         }
+        ReachabilityGoal(result.has_value(), "coinselection_bnb finds a solution");
     }
 
     if constexpr (Algorithm == CoinSelectionAlgorithm::SRD) {
@@ -409,6 +411,7 @@ void FuzzCoinSelectionAlgorithm(std::span<const uint8_t> buffer) {
             (void)result_srd->GetShuffledInputVector();
             (void)result_srd->GetInputSet();
         }
+        ReachabilityGoal(result.has_value(), "coinselection_srd finds a solution");
     }
 
     if constexpr (Algorithm == CoinSelectionAlgorithm::KNAPSACK) {
@@ -436,6 +439,7 @@ void FuzzCoinSelectionAlgorithm(std::span<const uint8_t> buffer) {
             (void)result_knapsack->GetShuffledInputVector();
             (void)result_knapsack->GetInputSet();
         }
+        ReachabilityGoal(result.has_value(), "coinselection_knapsack finds a solution");
     }
 
     std::vector<COutput> utxos;

Just playing with the idea, thought on coinselection: ```diff diff --git a/src/wallet/test/fuzz/coinselection.cpp b/src/wallet/test/fuzz/coinselection.cpp index 8949a6c20d..56703ecf0e 100644 --- a/src/wallet/test/fuzz/coinselection.cpp +++ b/src/wallet/test/fuzz/coinselection.cpp @@ -8,6 +8,7 @@ #include <test/fuzz/FuzzedDataProvider.h> #include <test/fuzz/fuzz.h> #include <test/fuzz/util.h> +#include <test/fuzz/util/reachability.h> #include <test/util/setup_common.h> #include <wallet/coinselection.h> @@ -395,6 +396,7 @@ void FuzzCoinSelectionAlgorithm(std::span<const uint8_t> buffer) { (void)result_bnb->GetInputSet(); } } + ReachabilityGoal(result.has_value(), "coinselection_bnb finds a solution"); } if constexpr (Algorithm == CoinSelectionAlgorithm::SRD) { @@ -409,6 +411,7 @@ void FuzzCoinSelectionAlgorithm(std::span<const uint8_t> buffer) { (void)result_srd->GetShuffledInputVector(); (void)result_srd->GetInputSet(); } + ReachabilityGoal(result.has_value(), "coinselection_srd finds a solution"); } if constexpr (Algorithm == CoinSelectionAlgorithm::KNAPSACK) { @@ -436,6 +439,7 @@ void FuzzCoinSelectionAlgorithm(std::span<const uint8_t> buffer) { (void)result_knapsack->GetShuffledInputVector(); (void)result_knapsack->GetInputSet(); } + ReachabilityGoal(result.has_value(), "coinselection_knapsack finds a solution"); } std::vector<COutput> utxos; ```
HowHsu (Migrated from github.com) reviewed 2026-08-28 03:51:29 +00:00
HowHsu (Migrated from github.com) commented 2026-08-28 03:51:29 +00:00

Right, the assertion was just to trigger/find the input. The goal should obviously be inverted :)

I meant "compare to use mempool.size() >= 1, end_sequence != initial_sequence may be a better choice?"

> Right, the assertion was just to trigger/find the input. The goal should obviously be inverted :) I meant "compare to use mempool.size() >= 1, end_sequence != initial_sequence may be a better choice?"
maflcko (Migrated from github.com) reviewed 2026-08-28 10:16:56 +00:00
maflcko (Migrated from github.com) commented 2026-08-28 10:16:56 +00:00

I've also uploaded block messages, so marking them as another goal could also make sense?

I've also uploaded block messages, so marking them as another goal could also make sense?
HowHsu (Migrated from github.com) reviewed 2026-08-28 13:03:37 +00:00
HowHsu (Migrated from github.com) commented 2026-08-28 13:03:37 +00:00

Seems fine, but this seems a bit low-level. I am thinking that goals may be best higher level?

Eg. mempool.size()>=1, which implies non-ibd message?

One problem is we still need a goal to represent at least one input goes the IBD path, while mempool.size() == 0 is not accurate for that. If we keep ReachabilityGoal(saw_ibd_message, ...);, then seems keep both saw_ibd_message and saw_non_ibd_message would be more symmetrical

> Seems fine, but this seems a bit low-level. I am thinking that goals may be best higher level? > > Eg. `mempool.size()>=1`, which implies non-ibd message? One problem is we still need a goal to represent at least one input goes the IBD path, while `mempool.size() == 0` is not accurate for that. If we keep ` ReachabilityGoal(saw_ibd_message, ...); `, then seems keep both `saw_ibd_message` and `saw_non_ibd_message` would be more symmetrical
maflcko (Migrated from github.com) reviewed 2026-08-28 13:28:13 +00:00
maflcko (Migrated from github.com) commented 2026-08-28 13:28:13 +00:00

JumpOutOfIbd and ResetIbd already have internal assertions (both ways), so now that those function calls are added back, it is unlikely to regress, unless they are removed?

If you really want, you can add the redundant goals for it, but I don't think we need to turn every assertion into a goal.

`JumpOutOfIbd` and `ResetIbd` already have internal assertions (both ways), so now that those function calls are added back, it is unlikely to regress, unless they are removed? If you really want, you can add the redundant goals for it, but I don't think we need to turn every assertion into a goal.
HowHsu (Migrated from github.com) reviewed 2026-08-28 14:31:58 +00:00
HowHsu (Migrated from github.com) commented 2026-08-28 14:31:58 +00:00

Updated.

Updated.
HowHsu (Migrated from github.com) reviewed 2026-08-28 14:32:22 +00:00
HowHsu (Migrated from github.com) commented 2026-08-28 14:32:22 +00:00

Updated.

Updated.
HowHsu (Migrated from github.com) reviewed 2026-08-28 14:32:36 +00:00
HowHsu (Migrated from github.com) commented 2026-08-28 14:32:36 +00:00

Updated.

Updated.
HowHsu (Migrated from github.com) reviewed 2026-08-28 14:59:37 +00:00
HowHsu (Migrated from github.com) commented 2026-08-28 14:59:37 +00:00

right, but currently the Goal is registered while ReachabilityGoal() is called at the first time. Thus removing this causes the early return on line 59 escaped. This reminds me about the design, maybe a explicit Goal registration is better, otherwise we have to look out all the early returns? @maflcko any thoughts on this?

right, but currently the Goal is registered while `ReachabilityGoal()` is called at the first time. Thus removing this causes the early return on line 59 escaped. This reminds me about the design, maybe a explicit Goal registration is better, otherwise we have to look out all the early returns? @maflcko any thoughts on this?
maflcko (Migrated from github.com) reviewed 2026-08-28 17:28:21 +00:00
maflcko (Migrated from github.com) commented 2026-08-28 17:28:21 +00:00

Well, I'd say this shouldn't be needed, but maybe I am wrong. There could be options:

  • One hacky, where one globally looks at the coverage with a tool and then makes the tool complain when it sees uncovered ReachabilityGoals. The benefit would be that everything here stays as-is and the tool sits somewhere else?
  • Make reachability goals global and register them. (Probably with some kind of context to select/check only the active ones?). This will probably increase the state/code/logic a bit, but should be fine.

No strong opinion. I guess anything is fine here?

Well, I'd say this shouldn't be needed, but maybe I am wrong. There could be options: * One hacky, where one globally looks at the coverage with a tool and then makes the tool complain when it sees uncovered `ReachabilityGoal`s. The benefit would be that everything here stays as-is and the tool sits somewhere else? * Make reachability goals global and register them. (Probably with some kind of context to select/check only the active ones?). This will probably increase the state/code/logic a bit, but should be fine. No strong opinion. I guess anything is fine here?
HowHsu (Migrated from github.com) reviewed 2026-08-29 06:04:21 +00:00
HowHsu (Migrated from github.com) commented 2026-08-29 06:04:21 +00:00

Yes, I'm implementing the second way, will push the code soon.

Yes, I'm implementing the second way, will push the code soon.
HowHsu (Migrated from github.com) reviewed 2026-08-31 06:31:47 +00:00
HowHsu (Migrated from github.com) commented 2026-08-31 06:31:47 +00:00

Updated to "two-phase register/observe protocol".

Updated to "two-phase register/observe protocol".
HowHsu commented 2026-08-31 06:31:56 +00:00 (Migrated from github.com)

Updated to use a two-phase register/observe protocol: each target explicitly registers its reachability goals during target initialization and records observations while processing inputs. This avoids lazy registration at observation sites, where an early return could leave a goal entirely unknown to the tracker and cause enforcement to pass silently instead of reporting it as unreached.

Updated to use a two-phase register/observe protocol: each target explicitly registers its reachability goals during target initialization and records observations while processing inputs. This avoids lazy registration at observation sites, where an early return could leave a goal entirely unknown to the tracker and cause enforcement to pass silently instead of reporting it as unreached.
maflcko (Migrated from github.com) reviewed 2026-08-31 07:37:39 +00:00
maflcko (Migrated from github.com) commented 2026-08-31 07:37:39 +00:00

Updated.

This was reverted in the last push?

> Updated. This was reverted in the last push?
HowHsu (Migrated from github.com) reviewed 2026-08-31 08:04:42 +00:00
HowHsu (Migrated from github.com) commented 2026-08-31 08:04:42 +00:00

Updated.

This was reverted in the last push?

Thanks, fixed.

> > Updated. > > This was reverted in the last push? Thanks, fixed.
maflcko (Migrated from github.com) reviewed 2026-08-31 11:02:32 +00:00
maflcko (Migrated from github.com) commented 2026-08-31 11:02:32 +00:00

Instead of a plain "success" (which probably happens on an empty file), it may be better to ensure all features are covered:

  • txs
  • unbroadcast set
  • fee deltas
  • ... etc?
Instead of a plain "success" (which probably happens on an empty file), it may be better to ensure all features are covered: * txs * unbroadcast set * fee deltas * ... etc?
Crypt-iQ (Migrated from github.com) reviewed 2026-09-01 21:37:41 +00:00
Crypt-iQ (Migrated from github.com) commented 2026-09-01 21:37:41 +00:00

I'd presume that -use_value_profile=1 of libFuzzer takes care of this for e.g. mempool.size() >= 200, but I haven't really benchmarked any of this. Is there some gist or background on how to best guide a fuzz engine toward a set goal?

I did a mini experiment with different approaches to try and solve the maze AFL includes:

  1. for use_value_profile=1, I used a simple if (hashfunc(row, col) == 0) abort();. My idea is that this would count different positions in the maze as unique because of the hash function, but I'm not sure if I understand the feature. It eventually found the solution after ~67M iterations (this varied a bit, one run hit ~1B iterations).

  2. compiling with AFL++ IJON (i.e. IJON_SET macro is activated in the maze code) quickly found the solution in ~300K iterations

  3. using clang with __libfuzzer_extra_counters (incompatible on Darwin, though repurposing __sanitizer_cov_8bit_counters_init is compatible and works similarly) hit it in ~450K iterations:

__attribute__((section("__libfuzzer_extra_counters"))) static uint8_t maze_counters[1 << 20];

... in the maze code...
maze_counters[hashfunc(row, col) & 0xfffff]++;

Solving the maze is one type of problem that uses the state area of the IJON region which is limited to 65,535 globally unique states, so it would be a bit limiting if we wanted to track many types of states. Similarly, using __libfuzzer_extra_counters also seems to take up a bit of memory if we're using a lot of states (especially if we're using a hash function which we shouldn't do). If anybody has ideas on a bitcoin-specific "maze", I could also benchmark that.

> I'd presume that -use_value_profile=1 of libFuzzer takes care of this for e.g. mempool.size() >= 200, but I haven't really benchmarked any of this. Is there some gist or background on how to best guide a fuzz engine toward a set goal? I did a mini experiment with different approaches to try and solve the maze AFL [includes](https://github.com/AFLplusplus/AFLplusplus/blob/45bb74bd3a6591e6853b704c390ab6156c0a3c88/test/ijon-maze.c): 1. for `use_value_profile=1`, I used a simple `if (hashfunc(row, col) == 0) abort();`. My idea is that this would count different positions in the maze as unique because of the hash function, but I'm not sure if I understand the feature. It eventually found the solution after ~67M iterations (this varied a bit, one run hit ~1B iterations). 2. compiling with AFL++ IJON (i.e. `IJON_SET` macro is activated in the maze code) quickly found the solution in ~300K iterations 3. using clang with `__libfuzzer_extra_counters` (incompatible on Darwin, though repurposing `__sanitizer_cov_8bit_counters_init` is compatible and works similarly) hit it in ~450K iterations: ``` __attribute__((section("__libfuzzer_extra_counters"))) static uint8_t maze_counters[1 << 20]; ... in the maze code... maze_counters[hashfunc(row, col) & 0xfffff]++; ``` Solving the maze is one type of problem that uses the [state area](https://github.com/AFLplusplus/AFLplusplus/blob/stable/docs/IJON.md#memory-layout) of the IJON region which is limited to 65,535 globally unique states, so it would be a bit limiting if we wanted to track many types of states. Similarly, using `__libfuzzer_extra_counters` also seems to take up a bit of memory if we're using a lot of states (especially if we're using a hash function which we shouldn't do). If anybody has ideas on a bitcoin-specific "maze", I could also benchmark that.
Crypt-iQ (Migrated from github.com) reviewed 2026-09-03 15:58:48 +00:00
Crypt-iQ (Migrated from github.com) commented 2026-09-03 15:58:08 +00:00

I can only get this destructor to run when using libfuzzer by either running a single input or setting -runs=N. I guess the purpose of the reachability checks (without the fuzzing guidance mentioned in a thread above) is for a CI job running a static corpus + detecting regressions (i.e. not fuzzing)? I wasn't able to get this to work with AFL++ when using -E=N (equivalent to libfuzzer's -runs option).

I added a signal handler to catch SIGINT to make the destructor run, but seems like adding one is more trouble than it's worth since I ran into a hang and another weird issue.

I can only get this destructor to run when using libfuzzer by either running a single input or setting `-runs=N`. I guess the purpose of the reachability checks (without the fuzzing guidance mentioned in a thread above) is for a CI job running a static corpus + detecting regressions (i.e. not fuzzing)? I wasn't able to get this to work with AFL++ when using `-E=N` (equivalent to libfuzzer's -runs option). I added a signal handler to catch SIGINT to make the destructor run, but seems like adding one is more trouble than it's worth since I ran into a hang and another weird issue.
Crypt-iQ (Migrated from github.com) commented 2026-09-03 11:12:58 +00:00

Why buffer to std::cerr if it may have passed?

Why buffer to `std::cerr` if it may have passed?
Crypt-iQ (Migrated from github.com) commented 2026-09-03 11:17:25 +00:00

Why std::_Exit which according to https://en.cppreference.com/cpp/utility/program/_Exit does not clean up resources compared to std::exit? Also could just remove this since if the destructor runs, we shouldn't need to exit?

Why `std::_Exit` which according to https://en.cppreference.com/cpp/utility/program/_Exit does not clean up resources compared to `std::exit`? Also could just remove this since if the destructor runs, we shouldn't need to exit?
Crypt-iQ (Migrated from github.com) commented 2026-09-03 11:20:52 +00:00

nit: could instead be Assert(m_goals.try_emplace ...) ?

nit: could instead be `Assert(m_goals.try_emplace ...)` ?
nervana21 commented 2026-09-16 21:13:30 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
maflcko (Migrated from github.com) reviewed 2026-09-17 05:39:55 +00:00
maflcko (Migrated from github.com) commented 2026-09-17 05:39:55 +00:00

I can only get this destructor to run when using libfuzzer by either running a single input or setting -runs=N. I guess the purpose of the reachability checks (without the fuzzing guidance mentioned in a thread above) is for a CI job running a static corpus + detecting regressions (i.e. not fuzzing)?

Yes, mostly for a nightly CI job on a static corpora folder with -runs=1. Nightly, because we don't want master to randomly fail on (silent or otherwise) merge conflicts with the qa-assets repo.

I wasn't able to get this to work with AFL++ when using -E=N (equivalent to libfuzzer's -runs option).

Not sure about AFL, but I guess it won't work anyway, due to the use of global memory, which won't be updated (or not propagated back) due to the forkserver mode?

> I can only get this destructor to run when using libfuzzer by either running a single input or setting -runs=N. I guess the purpose of the reachability checks (without the fuzzing guidance mentioned in a thread above) is for a CI job running a static corpus + detecting regressions (i.e. not fuzzing)? Yes, mostly for a nightly CI job on a static corpora folder with `-runs=1`. Nightly, because we don't want master to randomly fail on (silent or otherwise) merge conflicts with the qa-assets repo. > I wasn't able to get this to work with AFL++ when using -E=N (equivalent to libfuzzer's -runs option). Not sure about AFL, but I guess it won't work anyway, due to the use of global memory, which won't be updated (or not propagated back) due to the forkserver mode?
maflcko (Migrated from github.com) reviewed 2026-09-17 05:40:51 +00:00
maflcko (Migrated from github.com) commented 2026-09-17 05:40:51 +00:00

Also could just remove this since if the destructor runs, we shouldn't need to exit?

Can you explain this? My intention was to have an exit code that indicates error. A normal exit would return 0, no?

> Also could just remove this since if the destructor runs, we shouldn't need to exit? Can you explain this? My intention was to have an exit code that indicates error. A normal exit would return 0, no?
HowHsu (Migrated from github.com) reviewed 2026-09-17 09:04:00 +00:00
HowHsu (Migrated from github.com) commented 2026-09-17 09:04:00 +00:00

I'll update this soon

I'll update this soon
Crypt-iQ (Migrated from github.com) reviewed 2026-09-17 13:02:59 +00:00
Crypt-iQ (Migrated from github.com) commented 2026-09-17 13:02:59 +00:00

My intention was to have an exit code that indicates error.

Ah, ok. I was assuming that you'd know if it error'd from stderr, but returning non-zero exit code is correct.

> My intention was to have an exit code that indicates error. Ah, ok. I was assuming that you'd know if it error'd from stderr, but returning non-zero exit code is correct.
Crypt-iQ (Migrated from github.com) reviewed 2026-09-17 20:19:36 +00:00
Crypt-iQ (Migrated from github.com) commented 2026-09-17 20:19:36 +00:00

Not sure about AFL, but I guess it won't work anyway, due to the use of global memory, which won't be updated (or not propagated back) due to the forkserver mode?

I checked AFL++ again and the destructor does run, but a non-zero exit code isn't reported as a crash so it fails silently. Also, with the forkserver, only batches of 100,000 iterations are included in the reachability goal so it won't be accurate.

> Not sure about AFL, but I guess it won't work anyway, due to the use of global memory, which won't be updated (or not propagated back) due to the forkserver mode? I checked AFL++ again and the destructor does run, but a non-zero exit code isn't reported as a crash so it fails silently. Also, with the forkserver, only batches of 100,000 iterations are included in the reachability goal so it won't be accurate.
HowHsu (Migrated from github.com) reviewed 2026-09-21 14:28:18 +00:00
HowHsu (Migrated from github.com) commented 2026-09-21 14:28:18 +00:00

updated

updated
HowHsu (Migrated from github.com) reviewed 2026-09-21 14:40:22 +00:00
HowHsu (Migrated from github.com) commented 2026-09-21 14:40:22 +00:00

make sense, how about only printing those FAIL goals?

make sense, how about only printing those FAIL goals?
maflcko (Migrated from github.com) reviewed 2026-09-21 14:57:51 +00:00
maflcko (Migrated from github.com) commented 2026-09-21 14:57:51 +00:00

Seems fine to print both for clarity

Seems fine to print both for clarity
Crypt-iQ (Migrated from github.com) reviewed 2026-09-23 15:16:21 +00:00
Crypt-iQ (Migrated from github.com) commented 2026-09-23 15:16:21 +00:00

I meant that it could go to std::cout instead if it passed, but it's pretty minor.

I meant that it could go to `std::cout` instead if it passed, but it's pretty minor.
Crypt-iQ (Migrated from github.com) reviewed 2026-09-24 17:59:39 +00:00
Crypt-iQ (Migrated from github.com) left a comment

crACK b3e4cdcf02

The code changes and the goals here make sense to me. I think it would be really nice if we could get some distance-metric stuff in at some point, I might try to code up a PoC for both libfuzzer + AFL++ and see if any pieces here could be reused.

crACK b3e4cdcf020c6be28e929e6d8b2d29dc372008df The code changes and the goals here make sense to me. I think it would be really nice if we could get some distance-metric stuff in at some point, I might try to code up a PoC for both libfuzzer + AFL++ and see if any pieces here could be reused.
Crypt-iQ (Migrated from github.com) commented 2026-09-24 17:56:03 +00:00

Just a thought, some of the failure cases could also be reachability goals? It would be nice if we could express each state is a goal without introducing separate goals, but I don't know how to do that.

Just a thought, some of the failure cases could also be reachability goals? It would be nice if we could express each state is a goal without introducing separate goals, but I don't know how to do that.
nervana21 commented 2026-09-25 14:53:59 +00:00 (Migrated from github.com)

tACK b3e4cdcf02

tACK b3e4cdcf020c6be28e929e6d8b2d29dc372008df
First-time contributor

Base: f8c9f2b5377c4a76f668b69ebecb060f100d062a
Head: b3e4cdcf020c6be28e929e6d8b2d29dc372008df

Design and approach

[Suggestion] Enable reachability enforcement in corpus CI or document the manual workflow

CI corpus replay does not fail when a reachability goal is lost because it never enables enforcement.

Explanation and suggested change

Enforcement runs only when FUZZ_ENFORCE_REACHABILITY=1, but the CI fuzz step and test_runner.py do not set this variable. A failed goal therefore only prints a FAIL line in the DEBUG log, and the job still passes. If CI should enforce these goals now, export the variable in the RUN_FUZZ_TESTS step or add a test_runner.py option; targets replayed against an empty corpus with --empty_min_time may need an exemption. If enforcement is intended to remain manual or come in a follow-up, document that workflow in doc/fuzzing.md or the PR description.

Location: src/test/fuzz/util/reachability.cpp:40 (head).

Previously reported concerns remain unresolved: 2 suggestion.

Previous findings
[Suggestion · still present] Track IBD-mode processing or narrow the coverage claim

Both goals can be met after IBD, so they do not detect lost coverage of message processing during IBD.

The observations in this harness, and the matching ones in process_message.cpp, record only whether the mempool sequence or block-index size changed. A tx returns early during IBD, so the mempool goal effectively requires non-IBD processing; a block-index change can occur in either mode. Although the harness toggles IBD inside the loop, it does not record whether a state-changing message was processed while IBD was active. A corpus that changes state only after JumpOutOfIbd() can therefore meet both goals without covering IBD-mode processing. If that coverage matters, add a goal observed when a state-changing message is processed while IsInitialBlockDownload() is true. Otherwise, revise the description so it does not claim IBD coverage.

Location: src/test/fuzz/process_messages.cpp:143 (head).

First reported at b3e4cdcf020c6be28e929e6d8b2d29dc372008df. Last checked at b3e4cdcf020c6be28e929e6d8b2d29dc372008df. Author reply 2026-08-28T13:05:50Z Author reply 2026-08-28T14:31:59Z Author reply 2026-08-28T14:32:23Z Author reply 2026-08-28T14:32:37Z

[Suggestion · still present] Account for filtered runs when registering goals

The goals are registered before LIMIT_TO_MESSAGE_TYPE is read. The existing test_runner.py corpus-generation workflow launches filtered process_message variants; with FUZZ_ENFORCE_REACHABILITY=1, a type such as PING cannot satisfy either mutation goal, so that filtered run fails regardless of corpus quality. Register only applicable goals, or explicitly reject/document enforcement for filtered runs.

Location: src/test/fuzz/process_message.cpp:54 (head).

First reported at b3e4cdcf020c6be28e929e6d8b2d29dc372008df. Last checked at b3e4cdcf020c6be28e929e6d8b2d29dc372008df.

Review tier: standard

Full review report

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:b5eb6090240ab38533ffd09c5b4d2b46fa5675a490ba0915df3d14631e6f4dbf:00633cd9cb08c8f4661c30fbf00eaba6318f037423dd36deda26cc4a9d01c2c2 --> Base: `f8c9f2b5377c4a76f668b69ebecb060f100d062a` Head: `b3e4cdcf020c6be28e929e6d8b2d29dc372008df` <!-- ralph-case:053b157e57cf4ca36364f5b5ff63c06f3037eb24a14300830e7961c490d33d59 --> ##### Design and approach **[Suggestion] Enable reachability enforcement in corpus CI or document the manual workflow** CI corpus replay does not fail when a reachability goal is lost because it never enables enforcement. <details> <summary>Explanation and suggested change</summary> Enforcement runs only when `FUZZ_ENFORCE_REACHABILITY=1`, but the CI fuzz step and `test_runner.py` do not set this variable. A failed goal therefore only prints a `FAIL` line in the DEBUG log, and the job still passes. If CI should enforce these goals now, export the variable in the `RUN_FUZZ_TESTS` step or add a `test_runner.py` option; targets replayed against an empty corpus with `--empty_min_time` may need an exemption. If enforcement is intended to remain manual or come in a follow-up, document that workflow in `doc/fuzzing.md` or the PR description. Location: `src/test/fuzz/util/reachability.cpp:40` (head). </details> Previously reported concerns remain unresolved: 2 suggestion. ##### Previous findings <details> <summary>[Suggestion · still present] Track IBD-mode processing or narrow the coverage claim</summary> Both goals can be met after IBD, so they do not detect lost coverage of message processing during IBD. The observations in this harness, and the matching ones in `process_message.cpp`, record only whether the mempool sequence or block-index size changed. A `tx` returns early during IBD, so the mempool goal effectively requires non-IBD processing; a block-index change can occur in either mode. Although the harness toggles IBD inside the loop, it does not record whether a state-changing message was processed while IBD was active. A corpus that changes state only after `JumpOutOfIbd()` can therefore meet both goals without covering IBD-mode processing. If that coverage matters, add a goal observed when a state-changing message is processed while `IsInitialBlockDownload()` is true. Otherwise, revise the description so it does not claim IBD coverage. Location: `src/test/fuzz/process_messages.cpp:143` (head). First reported at `b3e4cdcf020c6be28e929e6d8b2d29dc372008df`. Last checked at `b3e4cdcf020c6be28e929e6d8b2d29dc372008df`. [Author reply](https://github.com/bitcoin/bitcoin/pull/36098#discussion_r3880786944) 2026-08-28T13:05:50Z [Author reply](https://github.com/bitcoin/bitcoin/pull/36098#discussion_r3881415835) 2026-08-28T14:31:59Z [Author reply](https://github.com/bitcoin/bitcoin/pull/36098#discussion_r3881418816) 2026-08-28T14:32:23Z [Author reply](https://github.com/bitcoin/bitcoin/pull/36098#discussion_r3881420736) 2026-08-28T14:32:37Z </details> <details> <summary>[Suggestion · still present] Account for filtered runs when registering goals</summary> The goals are registered before LIMIT_TO_MESSAGE_TYPE is read. The existing test_runner.py corpus-generation workflow launches filtered process_message variants; with FUZZ_ENFORCE_REACHABILITY=1, a type such as PING cannot satisfy either mutation goal, so that filtered run fails regardless of corpus quality. Register only applicable goals, or explicitly reject/document enforcement for filtered runs. Location: `src/test/fuzz/process_message.cpp:54` (head). First reported at `b3e4cdcf020c6be28e929e6d8b2d29dc372008df`. Last checked at `b3e4cdcf020c6be28e929e6d8b2d29dc372008df`. </details> Review tier: standard [Full review report](<https://review.fish.foo/traces/36098-b3e4cdcf020c6be28e929e6d8b2d29dc372008df-1590-2.html>)
brunoerg (Migrated from github.com) reviewed 2026-10-08 16:59:38 +00:00
brunoerg (Migrated from github.com) commented 2026-10-08 16:59:38 +00:00

193101ba20: I think some goals can't be reached if this target is running with LIMIT_TO_MESSAGE_TYPE (ofc depending on the message).

193101ba20121149dba00474e753868e651dd423: I think some goals can't be reached if this target is running with `LIMIT_TO_MESSAGE_TYPE` (ofc depending on the message).
maflcko (Migrated from github.com) reviewed 2026-10-13 14:07:42 +00:00
maflcko (Migrated from github.com) commented 2026-10-13 14:07:42 +00:00

I'd say it is expected that LIMIT_TO_MESSAGE_TYPE=... and FUZZ_ENFORCE_REACHABILITY=1 are mutually exclusive. If there is a need for it, it can be changed in the future.

I'd say it is expected that LIMIT_TO_MESSAGE_TYPE=... and FUZZ_ENFORCE_REACHABILITY=1 are mutually exclusive. If there is a need for it, it can be changed in the future.
maflcko (Migrated from github.com) approved these changes 2026-10-13 14:49:31 +00:00
maflcko (Migrated from github.com) left a comment

lgtm, with some nits.

review ACK b3e4cdcf02 🗨

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 b3e4cdcf020c6be28e929e6d8b2d29dc372008df 🗨
JZLXYViEGnteg0N0a4AxK3IDIYBCjnPf9kqaWXVENqidnhIZtEs8lGaYIQzf+a8sQ4O7hhEh+fIbHUNEojJrBw==
lgtm, with some nits. review ACK b3e4cdcf020c6be28e929e6d8b2d29dc372008df 🗨 <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 b3e4cdcf020c6be28e929e6d8b2d29dc372008df 🗨 JZLXYViEGnteg0N0a4AxK3IDIYBCjnPf9kqaWXVENqidnhIZtEs8lGaYIQzf+a8sQ4O7hhEh+fIbHUNEojJrBw== ``` </details>
maflcko (Migrated from github.com) commented 2026-10-13 14:39:04 +00:00

bb09525fee: pretty sure this is wrong, because it includes single_submit, no?

bb09525fee68d95aed68076f7148f6a474dc042c: pretty sure this is wrong, because it includes `single_submit`, no?
maflcko (Migrated from github.com) commented 2026-10-13 14:40:36 +00:00

96ab84c13e: same?

96ab84c13e9a8053ceb9e26aff507f4a47dfd30d: same?
maflcko (Migrated from github.com) commented 2026-10-13 14:46:25 +00:00

454f917d02: Also, could make sense to also check that reconstruction works with 0 missing txs and with >0 missing txs. Otherwise, the fuzz target could accidentally decay into a trivial state.

454f917d020ccdfca7793ad23c131cbcfba9e1f2: Also, could make sense to also check that reconstruction works with 0 missing txs and with >0 missing txs. Otherwise, the fuzz target could accidentally decay into a trivial state.
maflcko (Migrated from github.com) commented 2026-10-13 14:25:50 +00:00

nit in 1a1ef162bf: Why not mempool estimator as well?

Also, I wonder if there should be some stricter checks for the goal. E.g. require the read was not from a empty file, but a file that contained some values for each field in the class.

nit in 1a1ef162bf89e649bbf4c94474ff4433379e03de: Why not mempool estimator as well? Also, I wonder if there should be some stricter checks for the goal. E.g. require the read was not from a empty file, but a file that contained some values for each field in the class.
maflcko (Migrated from github.com) commented 2026-10-13 14:27:04 +00:00

updated

I don't think it was. I still see 56a89c4e1d

> updated I don't think it was. I still see 56a89c4e1d88ad34016d4ac8fe7ccfd51c9972ad
sedited commented 2026-10-19 08:36:36 +00:00 (Migrated from github.com)

@HowHsu do you want to take the remaining nits here?

@HowHsu do you want to take the remaining nits here?
HowHsu commented 2026-10-19 09:18:43 +00:00 (Migrated from github.com)

@HowHsu do you want to take the remaining nits here?

Sorry for the delay, I got some life issue to handle these days, so will be back at the end of this month. Feel free to merge it anytime.

> @HowHsu do you want to take the remaining nits here? Sorry for the delay, I got some life issue to handle these days, so will be back at the end of this month. Feel free to merge it anytime.
brunoerg commented 2026-10-28 13:59:29 +00:00 (Migrated from github.com)

Did some tests, looks good, easier to use it than having to generate and check a coverage report for some cases (happy to review the code again when comments are addressed):

➜  bitcoin-core-dev git:(pr-36098) ✗ FUZZ_ENFORCE_REACHABILITY=1 FUZZ=tx_package_eval ./build_fuzz/bin/fuzz ../qa-assets/fuzz_corpora/tx_package_eval -runs=1
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 3809975728
INFO: Loaded 1 modules   (594461 inline 8-bit counters): 594461 [0x101b96fb8, 0x101c281d5),
INFO: Loaded 1 PC tables (594461 PCs): 594461 [0x101c281d8,0x10253a3a8),
INFO:     2862 files found in ../qa-assets/fuzz_corpora/tx_package_eval
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 620760 bytes
INFO: seed corpus: files: 2862 min: 1b max: 620760b total: 90206049b rss: 81Mb
#512	pulse  cov: 7022 ft: 30552 corp: 458/62Kb exec/s: 256 rss: 103Mb
#1024	pulse  cov: 7396 ft: 39852 corp: 849/355Kb exec/s: 170 rss: 220Mb
#2048	pulse  cov: 7894 ft: 49853 corp: 1501/7490Kb exec/s: 62 rss: 242Mb
#2863	INITED cov: 7934 ft: 51038 corp: 1760/25Mb exec/s: 35 rss: 245Mb
#2863	DONE   cov: 7934 ft: 51038 corp: 1760/25Mb lim: 606423 exec/s: 35 rss: 245Mb
Done 2863 runs in 80 second(s)
PASS reachability goal "tx_package_eval processes a valid package" at test/fuzz/package_eval.cpp:57:28
➜  bitcoin-core-dev git:(pr-36098) ✗ FUZZ_ENFORCE_REACHABILITY=1 FUZZ=p2p_handshake ./build_fuzz/bin/fuzz ../qa-assets/fuzz_corpora/p2p_handshake -runs=1
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 3680086710
INFO: Loaded 1 modules   (594461 inline 8-bit counters): 594461 [0x103a0afb8, 0x103a9c1d5),
INFO: Loaded 1 PC tables (594461 PCs): 594461 [0x103a9c1d8,0x1043ae3a8),
INFO:     1753 files found in ../qa-assets/fuzz_corpora/p2p_handshake
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 32585 bytes
INFO: seed corpus: files: 1753 min: 1b max: 32585b total: 1588641b rss: 81Mb
#1754	INITED cov: 2521 ft: 9479 corp: 870/703Kb exec/s: 1754 rss: 98Mb
#1754	DONE   cov: 2521 ft: 9479 corp: 870/703Kb lim: 32585 exec/s: 1754 rss: 98Mb
Done 1754 runs in 1 second(s)
PASS reachability goal "p2p_handshake completes a handshake" at test/fuzz/p2p_handshake.cpp:28:28
➜  bitcoin-core-dev git:(pr-36098) ✗ FUZZ_ENFORCE_REACHABILITY=1 FUZZ=process_message ./build_fuzz/bin/fuzz ../qa-assets/fuzz_corpora/process_message -runs=1
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 3655449125
INFO: Loaded 1 modules   (594461 inline 8-bit counters): 594461 [0x105ddafb8, 0x105e6c1d5),
INFO: Loaded 1 PC tables (594461 PCs): 594461 [0x105e6c1d8,0x10677e3a8),
INFO:     3734 files found in ../qa-assets/fuzz_corpora/process_message
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 542908 bytes
INFO: seed corpus: files: 3734 min: 1b max: 542908b total: 100071861b rss: 83Mb
#1024	pulse  cov: 8006 ft: 12826 corp: 644/76Kb exec/s: 512 rss: 108Mb
#2048	pulse  cov: 10098 ft: 19279 corp: 1206/230Kb exec/s: 409 rss: 119Mb
#3735	INITED cov: 10499 ft: 28198 corp: 2080/36Mb exec/s: 373 rss: 161Mb
#3735	DONE   cov: 10499 ft: 28198 corp: 2080/36Mb lim: 478160 exec/s: 373 rss: 161Mb
Done 3735 runs in 10 second(s)
PASS reachability goal "process_message changes the mempool" at test/fuzz/process_message.cpp:45:28
PASS reachability goal "process_message changes the block index" at test/fuzz/process_message.cpp:46:28
Did some tests, looks good, easier to use it than having to generate and check a coverage report for some cases (happy to review the code again when comments are addressed): ```sh ➜ bitcoin-core-dev git:(pr-36098) ✗ FUZZ_ENFORCE_REACHABILITY=1 FUZZ=tx_package_eval ./build_fuzz/bin/fuzz ../qa-assets/fuzz_corpora/tx_package_eval -runs=1 INFO: Running with entropic power schedule (0xFF, 100). INFO: Seed: 3809975728 INFO: Loaded 1 modules (594461 inline 8-bit counters): 594461 [0x101b96fb8, 0x101c281d5), INFO: Loaded 1 PC tables (594461 PCs): 594461 [0x101c281d8,0x10253a3a8), INFO: 2862 files found in ../qa-assets/fuzz_corpora/tx_package_eval INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 620760 bytes INFO: seed corpus: files: 2862 min: 1b max: 620760b total: 90206049b rss: 81Mb #512 pulse cov: 7022 ft: 30552 corp: 458/62Kb exec/s: 256 rss: 103Mb #1024 pulse cov: 7396 ft: 39852 corp: 849/355Kb exec/s: 170 rss: 220Mb #2048 pulse cov: 7894 ft: 49853 corp: 1501/7490Kb exec/s: 62 rss: 242Mb #2863 INITED cov: 7934 ft: 51038 corp: 1760/25Mb exec/s: 35 rss: 245Mb #2863 DONE cov: 7934 ft: 51038 corp: 1760/25Mb lim: 606423 exec/s: 35 rss: 245Mb Done 2863 runs in 80 second(s) PASS reachability goal "tx_package_eval processes a valid package" at test/fuzz/package_eval.cpp:57:28 ``` ```sh ➜ bitcoin-core-dev git:(pr-36098) ✗ FUZZ_ENFORCE_REACHABILITY=1 FUZZ=p2p_handshake ./build_fuzz/bin/fuzz ../qa-assets/fuzz_corpora/p2p_handshake -runs=1 INFO: Running with entropic power schedule (0xFF, 100). INFO: Seed: 3680086710 INFO: Loaded 1 modules (594461 inline 8-bit counters): 594461 [0x103a0afb8, 0x103a9c1d5), INFO: Loaded 1 PC tables (594461 PCs): 594461 [0x103a9c1d8,0x1043ae3a8), INFO: 1753 files found in ../qa-assets/fuzz_corpora/p2p_handshake INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 32585 bytes INFO: seed corpus: files: 1753 min: 1b max: 32585b total: 1588641b rss: 81Mb #1754 INITED cov: 2521 ft: 9479 corp: 870/703Kb exec/s: 1754 rss: 98Mb #1754 DONE cov: 2521 ft: 9479 corp: 870/703Kb lim: 32585 exec/s: 1754 rss: 98Mb Done 1754 runs in 1 second(s) PASS reachability goal "p2p_handshake completes a handshake" at test/fuzz/p2p_handshake.cpp:28:28 ``` ```sh ➜ bitcoin-core-dev git:(pr-36098) ✗ FUZZ_ENFORCE_REACHABILITY=1 FUZZ=process_message ./build_fuzz/bin/fuzz ../qa-assets/fuzz_corpora/process_message -runs=1 INFO: Running with entropic power schedule (0xFF, 100). INFO: Seed: 3655449125 INFO: Loaded 1 modules (594461 inline 8-bit counters): 594461 [0x105ddafb8, 0x105e6c1d5), INFO: Loaded 1 PC tables (594461 PCs): 594461 [0x105e6c1d8,0x10677e3a8), INFO: 3734 files found in ../qa-assets/fuzz_corpora/process_message INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 542908 bytes INFO: seed corpus: files: 3734 min: 1b max: 542908b total: 100071861b rss: 83Mb #1024 pulse cov: 8006 ft: 12826 corp: 644/76Kb exec/s: 512 rss: 108Mb #2048 pulse cov: 10098 ft: 19279 corp: 1206/230Kb exec/s: 409 rss: 119Mb #3735 INITED cov: 10499 ft: 28198 corp: 2080/36Mb exec/s: 373 rss: 161Mb #3735 DONE cov: 10499 ft: 28198 corp: 2080/36Mb lim: 478160 exec/s: 373 rss: 161Mb Done 3735 runs in 10 second(s) PASS reachability goal "process_message changes the mempool" at test/fuzz/process_message.cpp:45:28 PASS reachability goal "process_message changes the block index" at test/fuzz/process_message.cpp:46:28 ```
maflcko commented 2026-10-28 14:03:08 +00:00 (Migrated from github.com)

I think it is also fine to merge this and then address the nits in Q12027 or so. The approach itself looks good with three acks and the nits only concern the reachability goal of some fuzz targets.

I think it is also fine to merge this and then address the nits in Q12027 or so. The approach itself looks good with three acks and the nits only concern the reachability goal of some fuzz targets.
brunoerg commented 2026-10-28 14:05:39 +00:00 (Migrated from github.com)

I think it is also fine to merge this and then address the nits in Q12027 or so. The approach itself looks good with three acks and the nits only concern the reachability goal of some fuzz targets.

LGTM

> I think it is also fine to merge this and then address the nits in Q12027 or so. The approach itself looks good with three acks and the nits only concern the reachability goal of some fuzz targets. LGTM
fanquake commented 2026-10-28 14:48:25 +00:00 (Migrated from github.com)

Looks like there's a handful of touch-ups / follow-ups here, but I'll merge this now, and someone can pick them up?

Looks like there's a handful of touch-ups / follow-ups here, but I'll merge this now, and someone can pick them up?
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!36098
No description provided.