Skip to content

fuzz: Block connection and chain reorganization fuzzing harnesses - #34651

Closed
RobinDavid wants to merge 1 commit into
bitcoin:masterfrom
RobinDavid:new-fuzz-harness-block-connection
Closed

RobinDavid wants to merge 1 commit into
bitcoin:masterfrom
RobinDavid:new-fuzz-harness-block-connection

Conversation

@RobinDavid

@RobinDavid RobinDavid commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

Hi Bitcoin Core maintainers.

This PR is a remastered version of fuzzing harnesses developed during a Bitcoin Core audit.
It includes 1 fuzzing harnesses:

  • connect_block: Test the ConnectBlock() function responsible of validating the block and
    all its transaction with consensus rules. Thanks to justCheck parameter no side effect
    is performed on the internal state enabling relatively fast fuzzing.

Besides pre-mining blocks, the harness initialization intends to bring a bit more of diversity by
introducing additional transactions in blocks (otherwise only coinbases), and put some transactions
in the mempool so that they can be 'picked' and put in a block by means of input mutation.

Note: Some additional harnesses are added in another PR: #34895

Authored by RobinDavid and nsurbay

@DrahtBot

DrahtBot commented Feb 22, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34651.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK marcofleon, dergoegge
Stale ACK ismaelsadeeq

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:

  • #34895 (fuzz: Fuzzing harnesses for ActivateBestChainStep and ActivateBestChain by RobinDavid)

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.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • keep a references on blocks -> keep references on blocks [“a references” is grammatically incorrect; “references” should not be preceded by “a”.]
  • It intend to leave more space to craft complex transactions and especially with various scripts types -> It is intended to leave more space to craft complex transactions and especially with various script types [“It intend” is a grammatical error (“intend” should be conjugated), and “scripts types” should be “script types” for clarity.]
  • It is exclusively used by ConsumeBlock to read transaction inside a block. -> It is exclusively used by ConsumeBlock to read transactions inside a block. [“transaction” should be plural to match “various scripts types” / general-purpose fuzz input.]
  • Create additional transaction in the mempool that are spending coins from mature blocks. -> Create additional transactions in the mempool that are spending coins from mature blocks. [Singular/plural mismatch (“transaction” should be “transactions” given “additional” and the loop that adds multiple txs).]

Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

  • active_chainstate.ConnectBlock(block, state, &new_index, active_coins, true) in src/test/fuzz/connect_block.cpp

2026-04-08 20:58:41

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task 32 bit ARM: https://github.com/bitcoin/bitcoin/actions/runs/22279929273/job/64448849605
LLM reason (✨ experimental): Compilation failed due to missing system header sys/sdt.h (not found).

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.

Comment thread src/test/fuzz/connect_block.cpp Resolved
@RobinDavid
RobinDavid force-pushed the new-fuzz-harness-block-connection branch from 98ad4d8 to 28afc49 Compare February 23, 2026 22:21
Comment thread ci/test/00_setup_env_arm.sh Resolved
@DrahtBot

DrahtBot commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Could turn into draft while CI is red?

@RobinDavid
RobinDavid marked this pull request as draft March 2, 2026 21:51
@RobinDavid
RobinDavid force-pushed the new-fuzz-harness-block-connection branch 5 times, most recently from 4737566 to 87c6d12 Compare March 16, 2026 22:54
@RobinDavid
RobinDavid marked this pull request as ready for review March 17, 2026 08:37
@RobinDavid

Copy link
Copy Markdown
Contributor Author

I fixed all the CI issues. Its ready for review now.
cc @dergoegge

@sedited
sedited requested a review from marcofleon March 17, 2026 08:54

@marcofleon marcofleon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dergoegge and I took a look at the connect_block harness and we think it'd be good to split that into its own PR. It's relatively straightforward, valuable on its own, and would likely get through review quicker. The other two harnesses could remain open in this PR as a draft on top of the new connect_block PR.

Comment thread src/test/fuzz/connect_block.cpp Resolved
Comment thread src/test/fuzz/connect_block.cpp Resolved
Comment thread src/test/fuzz/connect_block.cpp Resolved

@marcofleon marcofleon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base64: BAkAAAQJdwKGAAAAgBTpAACFBAk=

crash_activate_best_chain_step.txt

stack trace
===== stack trace ===== 
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 3223231957
INFO: Loaded 1 modules   (580898 inline 8-bit counters): 580898 [0x556d05d1e360, 0x556d05dac082), 
INFO: Loaded 1 PC tables (580898 PCs): 580898 [0x556d05dac088,0x556d066892a8), 
/workdir/out/libfuzzer_msan/fuzz: Running 1 inputs 1 time(s) each.
Running: /workdir/workspace/solutions/crash-aa5b43f99124f0e080b2b68ac94024c65fc8381b
validation.cpp:5502 double ChainstateManager::GuessVerificationProgress(const CBlockIndex *) const: Assertion `m_best_header->nHeight >= pindex->nHeight' failed.
==10489== ERROR: libFuzzer: deadly signal
    #0 0x556d01ef1db9 in __sanitizer_print_stack_trace /llvm-project/compiler-rt/lib/msan/msan.cpp:790:3
    #1 0x556d01e618d8 in fuzzer::PrintStackTrace() /llvm-project/compiler-rt/lib/fuzzer/FuzzerUtil.cpp:210:5
    #2 0x556d01e442f3 in fuzzer::Fuzzer::CrashCallback() /llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:231:3
    #3 0x556d01f50c3d in SignalAction(int, void*, void*) /llvm-project/compiler-rt/lib/msan/msan_interceptors.cpp:1166:3
    #4 0x7f65ae046def  (/lib/x86_64-linux-gnu/libc.so.6+0x3fdef) (BuildId: fce446c9d4ad48e2b0c90cce1a11722897805281)
    #5 0x7f65ae09b95b  (/lib/x86_64-linux-gnu/libc.so.6+0x9495b) (BuildId: fce446c9d4ad48e2b0c90cce1a11722897805281)
    #6 0x7f65ae046cc1 in raise (/lib/x86_64-linux-gnu/libc.so.6+0x3fcc1) (BuildId: fce446c9d4ad48e2b0c90cce1a11722897805281)
    #7 0x7f65ae02f4ab in abort (/lib/x86_64-linux-gnu/libc.so.6+0x284ab) (BuildId: fce446c9d4ad48e2b0c90cce1a11722897805281)
    #8 0x556d03409b63 in assertion_fail(std::__1::source_location const&, std::__1::basic_string_view<char, std::__1::char_traits<char>>) /workdir/bitcoin/src/util/check.cpp:41:5
    #9 0x556d05435257 in bool&& inline_assertion_check<false, bool>(bool&&, std::__1::source_location const&, std::__1::basic_string_view<char, std::__1::char_traits<char>>) /workdir/bitcoin/src/util/check.h:90:13
    #10 0x556d05435257 in ChainstateManager::GuessVerificationProgress(CBlockIndex const*) const /workdir/bitcoin/src/validation.cpp:5502:10
    #11 0x556d05424776 in UpdateTipLog(ChainstateManager const&, CCoinsViewCache const&, CBlockIndex const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&) /workdir/bitcoin/src/validation.cpp:2867:5
    #12 0x556d05422f9e in Chainstate::UpdateTip(CBlockIndex const*) /workdir/bitcoin/src/validation.cpp:2911:5
    #13 0x556d0542a016 in Chainstate::ConnectTip(BlockValidationState&, CBlockIndex*, std::__1::shared_ptr<CBlock const>, std::__1::vector<ConnectedBlock, std::__1::allocator<ConnectedBlock>>&, DisconnectedBlockTransactions&) /workdir/bitcoin/src/validation.cpp:3076:5
    #14 0x556d0543004c in Chainstate::ActivateBestChainStep(BlockValidationState&, CBlockIndex*, std::__1::shared_ptr<CBlock const> const&, bool&, std::__1::vector<ConnectedBlock, std::__1::allocator<ConnectedBlock>>&) /workdir/bitcoin/src/validation.cpp:3232:18
    #15 0x556d02312811 in (anonymous namespace)::TestChainstate::CallActivateBestChainStep(BlockValidationState&, CBlockIndex*, std::__1::shared_ptr<CBlock const> const&, bool&, std::__1::vector<ConnectedBlock, std::__1::allocator<ConnectedBlock>>&) /workdir/bitcoin/src/test/fuzz/connect_block.cpp:40:16
    #16 0x556d02312811 in activate_best_chain_step_fuzz_target(std::__1::span<unsigned char const, 18446744073709551615ul>) /workdir/bitcoin/src/test/fuzz/connect_block.cpp:755:32
    #17 0x556d01f6a365 in std::__1::__invoke_result_impl<void, void (*&)(std::__1::span<unsigned char const, 18446744073709551615ul>), std::__1::span<unsigned char const, 18446744073709551615ul>>::type std::__1::__invoke[abi:de210108]<void (*&)(std::__1::span<unsigned char const, 18446744073709551615ul>), std::__1::span<unsigned char const, 18446744073709551615ul>>(void (*&)(std::__1::span<unsigned char const, 18446744073709551615ul>), std::__1::span<unsigned char const, 18446744073709551615ul>&&) /libcxx_msan/include/c++/v1/__type_traits/invoke.h:87:27
    #18 0x556d01f6a365 in void std::__1::__invoke_void_return_wrapper<void, true>::__call[abi:de210108]<void (*&)(std::__1::span<unsigned char const, 18446744073709551615ul>), std::__1::span<unsigned char const, 18446744073709551615ul>>(void (*&)(std::__1::span<unsigned char const, 18446744073709551615ul>), std::__1::span<unsigned char const, 18446744073709551615ul>&&) /libcxx_msan/include/c++/v1/__type_traits/invoke.h:342:5
    #19 0x556d01f6a365 in void std::__1::__invoke_r[abi:de210108]<void, void (*&)(std::__1::span<unsigned char const, 18446744073709551615ul>), std::__1::span<unsigned char const, 18446744073709551615ul>>(void (*&)(std::__1::span<unsigned char const, 18446744073709551615ul>), std::__1::span<unsigned char const, 18446744073709551615ul>&&) /libcxx_msan/include/c++/v1/__type_traits/invoke.h:348:10
    #20 0x556d01f6a365 in std::__1::__function::__func<void (*)(std::__1::span<unsigned char const, 18446744073709551615ul>), void (std::__1::span<unsigned char const, 18446744073709551615ul>)>::operator()(std::__1::span<unsigned char const, 18446744073709551615ul>&&) /libcxx_msan/include/c++/v1/__functional/function.h:174:12
    #21 0x556d02d8b8c1 in std::__1::__function::__value_func<void (std::__1::span<unsigned char const, 18446744073709551615ul>)>::operator()[abi:de210108](std::__1::span<unsigned char const, 18446744073709551615ul>&&) const /libcxx_msan/include/c++/v1/__functional/function.h:274:12
    #22 0x556d02d8b8c1 in std::__1::function<void (std::__1::span<unsigned char const, 18446744073709551615ul>)>::operator()(std::__1::span<unsigned char const, 18446744073709551615ul>) const /libcxx_msan/include/c++/v1/__functional/function.h:772:10
    #23 0x556d02d8b8c1 in test_one_input(std::__1::span<unsigned char const, 18446744073709551615ul>) /workdir/bitcoin/src/test/fuzz/fuzz.cpp:88:5
    #24 0x556d02d8b8c1 in LLVMFuzzerTestOneInput /workdir/bitcoin/src/test/fuzz/fuzz.cpp:216:5
    #25 0x556d01e45a4b in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:619:13
    #26 0x556d01e2f6f2 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:329:6
    #27 0x556d01e35590 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:864:9
    #28 0x556d01e62262 in main /llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
    #29 0x7f65ae030ca7  (/lib/x86_64-linux-gnu/libc.so.6+0x29ca7) (BuildId: fce446c9d4ad48e2b0c90cce1a11722897805281)
    #30 0x7f65ae030d64 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29d64) (BuildId: fce446c9d4ad48e2b0c90cce1a11722897805281)
    #31 0x556d01e286e0 in _start (/workdir/out/libfuzzer_msan/fuzz+0x13696e0)

NOTE: libFuzzer has rudimentary signal handlers.
      Combine libFuzzer with AddressSanitizer or similar for better crash reports.
SUMMARY: libFuzzer: deadly signal

Comment thread src/test/fuzz/connect_block.cpp Resolved
@RobinDavid
RobinDavid force-pushed the new-fuzz-harness-block-connection branch 2 times, most recently from 8829b69 to 016bfd5 Compare March 22, 2026 14:52
@RobinDavid
RobinDavid force-pushed the new-fuzz-harness-block-connection branch from 016bfd5 to c14b46a Compare March 22, 2026 15:17
@RobinDavid
RobinDavid force-pushed the new-fuzz-harness-block-connection branch from c14b46a to 673cfd3 Compare March 22, 2026 15:33
@RobinDavid
RobinDavid requested a review from marcofleon March 24, 2026 08:24

@ismaelsadeeq ismaelsadeeq left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review 392fac5

I have spent some time reviewing this PR and the related #34651, which includes additional fuzz harnesses. After several iterations of review, I think I have a
good understanding of what this PR is doing and what it aims to achieve.

The PR can be simplified significantly. I started inline comments but switched rather than leaving many inline comments, I think it would be cleaner to share a few fixup commits that demonstrate my suggestions.

  • ismaelsadeeq@976c605 slims down the harness file significantly, wraps the setup in a
    class and performs several cleanups in line with Bitcoin Core coding style, and nits making it reusable across other fuzz harnesses and future ones.

  • ismaelsadeeq@8cb0273 validation changes should live in it's own commit with a rationale
    and not be baked into the test commit.

  • ismaelsadeeq@297f4ac introduces the activate_best_chain and activate_best_chain_step harnesses
    from #34651 along with the methods they need. As you can see, this is cleaner — there is no need for a Cleanup class or a redundant disconnect_pool; we should just
    explicitly replay the chain on each iteration, I think.

  • We can go further and hide the setup member variables, exposing only getters see
    ismaelsadeeq@1184d67.

footnotes

// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <algorithm>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 6fceab3 "Implement connect_block fuzzing harness"

nit: Standard library headers usually aren't mixed with project headers. They come after project header, with some line separation between the

@@ -0,0 +1,498 @@
// Copyright (c) 2025-present The Bitcoin Core developers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 6fceab3 "Implement connect_block fuzzing harness"

Suggested change
// Copyright (c) 2025-present The Bitcoin Core developers
// Copyright (c) The Bitcoin Core developers

namespace {


/** Testing setup used by the three harnesses */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 6fceab3 "Implement connect_block fuzzing harness"

This is incorrect; there is only one harness here.

#include <validation.h>


#define DEBUGOUTPUT(x) //(x);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 6fceab3 "Implement connect_block fuzzing harness"

Why is this needed? And later the std::cout? I guess it's used for debugging; not sure whether it is ideal to merge with this.


#include <algorithm>
#include <consensus/merkle.h>
#include <kernel/disconnected_transactions.h>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 6fceab3 "Implement connect_block fuzzing harness"

This include is not needed.

Suggested change
#include <kernel/disconnected_transactions.h>

Comment on lines +486 to +495
if (success) {
DEBUGOUTPUT(std::cout << "Block connected successfully: " << curr_header.GetHash().ToString() << std::endl);
DEBUGOUTPUT(std::cout << "State: " << state.ToString() << std::endl);
//Assert(active_chainstate.DisconnectBlock(block, &new_index, active_coins) == DISCONNECT_OK);
}
else {
DEBUGOUTPUT(std::cout << "Block connection failed: " << state.GetRejectReason() << std::endl);
// If the connection failed, we can still try to disconnect the block
// to ensure that the disconnect logic is robust.
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 6fceab3 "Implement connect_block fuzzing harness"

This is good for debugging, but it won't help us. If you'd like to document that the goal is to test a connect/disconnect block round trip, please proceed.
A comment is ideal; why can't we do that now? Maybe link to @marcofleon's comment permalink.

Also, we can test some invariants; when valid, no reject reason should be added vis-à-vis

Suggested change
if (success) {
DEBUGOUTPUT(std::cout << "Block connected successfully: " << curr_header.GetHash().ToString() << std::endl);
DEBUGOUTPUT(std::cout << "State: " << state.ToString() << std::endl);
//Assert(active_chainstate.DisconnectBlock(block, &new_index, active_coins) == DISCONNECT_OK);
}
else {
DEBUGOUTPUT(std::cout << "Block connection failed: " << state.GetRejectReason() << std::endl);
// If the connection failed, we can still try to disconnect the block
// to ensure that the disconnect logic is robust.
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's better to drop this whole chunk, unless there is some truly useful assertion we can make upon success/failure. Doing the connect-disconnect block roundtrip would require a refactor in validation, which I may tackle at some point.

@marcofleon marcofleon left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 6fceab3

I think this test accomplishes its goal and could be merged, despite it being a bit messy. There are several clean up nits which could be addressed in a followup PR or in #34895.

style nit: Some variables throughout the test use camelCase, where snake_case would be preferred (dev notes).

#include <validation.h>


#define DEBUGOUTPUT(x) //(x);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We don't usually keep debug logs around in tests afaik, so this should be removed.

static std::vector<std::shared_ptr<CBlock>> listBlocks;
/** Set of block hashes in listBlocks */
static std::set<uint256> existingBlockHash;
/** Spending script for all UTXOs (excluding OP_RETURN) including not mature CoinBase and already spend one */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spent instead of spend

* Initialize the chain for the three harnesses.
*/
static void initialize_connect_block() {
Assert(EnableFuzzDeterminism());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This is redundant, so it should be removed. And it would prevent (crash on) the use of the nondeterminism env that we have in our fuzzing framework

} else {
/** Read arbitrary data in input as scriptSig */
auto scriptSig = ConsumeRandomLengthByteVector<unsigned char>(fuzzed_data_provider, 100);
tx.vin[0].scriptSig << scriptSig;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could make sense to replace these two lines with the existing ConsumeScript helper.

Something like tx.vin[0].scriptSig = ConsumeScript(fuzzed_data_provider) or appending its output if that was the intent.

Same goes for the scriptSig in the else branch below and the scriptPubKey in the switch statement below.

tx.vin[i].scriptWitness.stack.clear();
int numWit = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 10);
for (int j = 0; j < numWit; j++) {
tx.vin[i].scriptWitness.stack.push_back(ConsumeRandomLengthByteVector<unsigned char>(fuzzed_data_provider, 100));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could replace this with ConsumeScriptWitness.


/** Enable fuzzer to mutate every CTxIn fields after it being taken from existing UTXOs */
if (fuzzed_data_provider.ConsumeBool()) {
tx.vin[i].nSequence = fuzzed_data_provider.ConsumeIntegral<uint32_t>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could use ConsumeSequence instead.

Comment thread src/test/fuzz/connect_block.cpp Resolved
@DrahtBot
DrahtBot requested a review from ismaelsadeeq April 20, 2026 17:59
@ismaelsadeeq

Copy link
Copy Markdown
Member

I think this test accomplishes its goal and could be merged, despite it being a bit messy. There are several clean up nits which could be addressed in a followup PR or in #34895.

Why the rush? I would like to see my suggestions fixed or addressed.

https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#decision-making-process

In general, all pull requests must:
Be well peer-reviewed;
Follow code style guidelines (C++, functional tests);

I tend to disagree here; I think merging a messy change lowers the bar.

@marcofleon

Copy link
Copy Markdown
Contributor

Why the rush?

The fuzz harnesses in this PR and in #34895 were part of an external security audit and were made without all the specifics of this project in mind. I figure if the test is logically sound, adds good coverage, and does the job it's meant to do, then there isn't a need for us to stall it with style nits and refactors. A member of the project could likely more quickly and easily get those done and merged in a followup.

Looking at it again, I do think, at the minimum, the DEBUGOUTPUT(x) and all related code should be dropped before this PR is merged, so my ack was premature.

I'm not looking to rush, more just trying not to stall a test-only addition of fuzz targets that overall look effective to me. Ultimately, I agree with this project's high bar and of course, am willing to go through the necessary rounds of review.

@ismaelsadeeq

Copy link
Copy Markdown
Member

That makes sense, though it wasn't clear from your ACK or the PR description. You mentioned merging despite the messiness being okay, which is what made me push back a bit.
Glad we're on the same page now. I'd note that "fix in a follow-up" doesn't always happen.

Also, thanks for the audit and this work @RobinDavid. Given that this originated from external audit work, I'd like to suggest a potentially better approach that might be more efficient for everyone:

  1. Have a project member take over and apply the suggested changes, as they're familiar with the codebase and conventions, which would save both the researchers and reviewers bandwidth.

  2. Open a follow-up PR with a committed author who will see it through. In past cases, when the author opens the follow-up and directly references the outstanding comments, it signals continuity e.g rpc: followups for min fee changes #33189, Cluster mempool followups #33591, v3 followups #29424 and I'd be happy to ACK that while we work through the remaining suggestions in that branch.

@sedited

sedited commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

Have a project member take over and apply the suggested changes, as they're familiar with the codebase and conventions, which would save both the researchers and reviewers bandwidth.

I think I would prefer this, given that we have made slow progress here. @RobinDavid is that good with you?

@RobinDavid

Copy link
Copy Markdown
Contributor Author

Yes I only work on this PR on my free time so I can't make it progress as fast as I'd want. So yes @sedited and @ismaelsadeeq I am fine to hand over applying these changes, I agree with all of them.

I would be even better if you could hand over the second PR #34895 which would requires more significant refactoring than this one.

@ismaelsadeeq

Copy link
Copy Markdown
Member

Yes I only work on this PR on my free time so I can't make it progress as fast as I'd want. So yes @sedited and @ismaelsadeeq I am fine to hand over applying these changes, I agree with all of them.

I would be even better if you could hand over the second PR #34895 which would requires more significant refactoring than this one.

@RobinDavid cool.

I talked with @marcofleon a few days ago, and we concluded that I will incorporate the suggestions here and open a new PR. I expected it to be up by today, but did not because I got sucked into parallel work :(.
I will focus on this for the rest of the week and have a PR up soon.

@dergoegge

Copy link
Copy Markdown
Member

Why the rush?

I agree that there is no rush, so I don't see the need for this to be handed over (unless Robin has no interest in maintaining this, which I think he has, given that he is doing this in his spare time). These types of PRs take months or years on a regular basis (regardless of who the author is). The bottleneck is primarily review.

This PR was opened in February but review started later on, and splitting the connect_block harness into it's own PR (i.e. what we now have in this PR) was only suggested a little more than a month ago (#34651 (review)).

Have a project member take over and apply the suggested changes, as they're familiar with the codebase and conventions, which would save both the researchers and reviewers bandwidth

Open a follow-up PR with a committed author who will see it through

I don't know if an LLM wrote this or if it's your opinion, but I don't think this is a fair thing to say, given that Robin has made an obviously genuine attempt at contributing and has been responsive throughout.

Contributing to this project is not limited to members (GitHub org membership means nothing beyond being able to edit the wiki and restart CI jobs), and should be possible without getting paid to do so full time. Someone showing up to contribute in their spare time is great, and also how a lot of us started out (thank you Robin for contributing your time!).


From what I've seen, the harness here works as intended. It should be cleaned up before merge (style, comments, etc.) but there is no need to completely re-write it (as suggested here #34651 (review)).

@RobinDavid if you're still interested to work on this when you have the time, I'd be happy to ACK this once the nits have been addressed.

@ismaelsadeeq

Copy link
Copy Markdown
Member

I don't know if an LLM wrote this or if it's your opinion, but I don't think this is a fair thing to say, given that Robin has made an obviously genuine attempt at contributing and has been responsive throughout.

I wrote this to suggest moving forward because of the eagerness to merge I see here #34651 (comment) and #34651 (review), for the reason mentioned #34651 (comment), which I believe other contributors agree with me on this.

Contributing to this project is not limited to members (GitHub org membership means nothing beyond being able to edit the wiki and restart CI jobs), and should be possible without getting paid to do so full time. Someone showing up to contribute in their spare time is great, and also how a lot of us started out (thank you Robin for contributing your time!

I am happy to have this continue review as well and will ACK as well, even without a rewrite, as long as the suggestions are addressed. I am not in any rush to take over someone's work; I did almost similar work in parallel, and and @marcofleon and you suggested we close and focus on this, which is what I am doing now. I am here in good faith, wanting to move this work forward and have this harness up so that it can be used beyond this #34651 (review).

@ismaelsadeeq

Copy link
Copy Markdown
Member

Re #34651 (comment) see master...ismaelsadeeq:bitcoin:block-chain-validation-harness branch with all comments addressed and an added harness using #34651 (review).

@RobinDavid

Copy link
Copy Markdown
Contributor Author

@ismaelsadeeq the branch https://github.com/ismaelsadeeq/bitcoin/tree/block-chain-validation-harness do not seems to just address the aforementioned remarks. It is significantly different than this current PR (that only contains one fuzz harness). Do we want to restore all 3 harnesses (connect_block, activate_best_chain_step, activate_best_chain) and a new one into a single PR ? I though we wanted to keep them split. I would happy to take @marcofleon and @dergoegge opinion on this.

@marcofleon

Copy link
Copy Markdown
Contributor

Do we want to restore all 3 harnesses (connect_block, activate_best_chain_step, activate_best_chain) and a new one into a single PR ?

I think we should keep it split up, as we decided earlier. Makes it easier to review. This PR would map to the first commit of Sadiq's branch: 1a34a13

I've taken a better look at https://github.com/ismaelsadeeq/bitcoin/tree/block-chain-validation-harness and I think the refactoring of shared setup and helpers into util files makes sense. We can reuse them for future validation harnesses.

If this PR were generally kept as is (all in one file) and cleaned up style-wise as reviewers have suggested above, then I would ack it and also review a refactor followup. @RobinDavid another option could be to take 1a34a13 for this PR (or re-work parts of it if something stands out to you), essentially accomplishing the refactor here, which would then be used for #34895 later on. It's up to you, either option would work fine for me.

if (fuzzed_data_provider.ConsumeBool()) {
block.nVersion = fuzzed_data_provider.ConsumeIntegral<int32_t>();
}
if (fuzzed_data_provider.ConsumeBool() && !forceValidBlock) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the intention here with forceValidBlock? Is it to create a fully valid header that would pass the contextual checks in validation.cpp? If that's the case, I think it should be applied to the other three header fields as well (nVersion, nBits, nTime).

Also, I think force_valid_header would be a clearer name.

@marcofleon

marcofleon commented Jun 26, 2026 •

Copy link
Copy Markdown
Contributor

This fell by the wayside. How do we want to proceed here?

I really like the fuzz tests here and in #34895 so it'd be cool to get them in.

@sedited

sedited commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

For code that does not follow our style, but is otherwise correct, we have in the past merged the pull request and then followed up with improvements and style corrections. I'd be fine with doing that here too, if reviewers think it is correct.

@brunoerg

brunoerg commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This fell by the wayside. How do we want to proceed here?

I understand that Robin might be busy so one of us could grab it and move on? I intend to review it by tomorrow btw.

@marcofleon

Copy link
Copy Markdown
Contributor

I can follow up with the small fixes / cleanups once this is merged.

@RobinDavid

Copy link
Copy Markdown
Contributor Author

Yes @brunoerg and @marcofleon please go ahead. You will probably do it better that I would ever do :)

@marcofleon

Copy link
Copy Markdown
Contributor

@RobinDavid The meat of the tests was all your doing, we appreciate it! It's just minor stuff from here that we can get done relatively quickly.

@dergoegge

Copy link
Copy Markdown
Member

utACK 6fceab3

I'd also be fine with merging this now, and fixing up later.

Thank you, Robin!

@sedited

sedited commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This doesn't compile if I merge it into current master:

/home/drgrid/bitcoin/src/test/fuzz/connect_block.cpp:164:15: error: no member named 'BlockAssembler' in namespace 'node'
  164 |         node::BlockAssembler::Options options;
      |         ~~~~~~^
/home/drgrid/bitcoin/src/test/fuzz/connect_block.cpp:164:39: error: use of undeclared identifier 'options'; did you mean 'optind'?
  164 |         node::BlockAssembler::Options options;
      |                                       ^~~~~~~
      |                                       optind
/usr/include/x86_64-linux-gnu/bits/getopt_core.h:50:12: note: 'optind' declared here
   50 | extern int optind;
      |            ^
/home/drgrid/bitcoin/src/test/fuzz/connect_block.cpp:165:9: error: use of undeclared identifier 'options'; did you mean 'optind'?
  165 |         options.coinbase_output_script = P2WSH_OP_TRUE;
      |         ^~~~~~~
      |         optind
/usr/include/x86_64-linux-gnu/bits/getopt_core.h:50:12: note: 'optind' declared here
   50 | extern int optind;
      |            ^

This should be rebased and the following patch applied:

diff --git a/src/test/fuzz/connect_block.cpp b/src/test/fuzz/connect_block.cpp
index c141fe4841..ebe473650d 100644
--- a/src/test/fuzz/connect_block.cpp
+++ b/src/test/fuzz/connect_block.cpp
@@ -161,9 +161,8 @@ void ResetChainman(TestingSetup& setup)
     setup.LoadVerifyActivateChainstate();
 
     for (int i = 0; i < 2 * COINBASE_MATURITY; i++) {
-        node::BlockAssembler::Options options;
+        node::BlockCreateOptions options;
         options.coinbase_output_script = P2WSH_OP_TRUE;
-        options.include_dummy_extranonce = true;
         MineBlock(setup.m_node, options);
     }
     setup.m_node.validation_signals->SyncWithValidationInterfaceQueue();
@@ -244,7 +243,7 @@ static void initialize_connect_block() {
      */
     addExtraTxsInMempool(*test_setup);
     /** Mine block 201 that shall contain the transactions added in the mempool */
-    node::BlockAssembler::Options options;
+    node::BlockCreateOptions options;
     options.coinbase_output_script = P2WSH_OP_TRUE;
     MineBlock(test_setup->m_node, options);
     Assert(test_setup->m_node.chainman->ActiveChainstate().GetMempool()->size() == 0);

@fanquake
fanquake marked this pull request as draft July 3, 2026 15:46
@marcofleon

Copy link
Copy Markdown
Contributor

I'll open a new PR then, and take this commit as a starting point.

@fanquake

Copy link
Copy Markdown
Member

Closing, now that #35850 is open.

@fanquake fanquake closed this Jul 30, 2026
fanquake added a commit that referenced this pull request Aug 27, 2026
2777300 fuzz: Implement connect_block harness (Robin David)
40add91 test: Add reset to CuckooCache (Eugene Siegel)

Pull request description:

  Adds a fuzz target that directly calls `ConnectBlock` with `fJustCheck` set to true, so it hits block/transaction validation without writing undo data or updating the chainstate.

  This PR is essentially #34651 with some minor tweaks and style cleanups. Additional validation harnesses (e.g. #34895) could build on this test's setup.

ACKs for top commit:
  Crypt-iQ:
    ACK 2777300
  nervana21:
    tACK 2777300

Tree-SHA512: e2dc74154a6e29e0f3eaec9caeeec53d64bcc96adb0d1739281da97712dd931c3937eaf71f977bfc9c9330f26e35b3633f72788143b76e24e17c37b0a4258ba4
Kino1994 pushed a commit to Kino1994/bitcoin-full-history that referenced this pull request Aug 31, 2026
2777300c68f575565dabdcef4d0498ebc91a401e fuzz: Implement connect_block harness (Robin David)
40add915be5c5d204d85474a2704362cb635ef6d test: Add reset to CuckooCache (Eugene Siegel)

Pull request description:

  Adds a fuzz target that directly calls `ConnectBlock` with `fJustCheck` set to true, so it hits block/transaction validation without writing undo data or updating the chainstate.

  This PR is essentially bitcoin/bitcoin#34651 with some minor tweaks and style cleanups. Additional validation harnesses (e.g. bitcoin/bitcoin#34895) could build on this test's setup.

ACKs for top commit:
  Crypt-iQ:
    ACK 2777300c68f575565dabdcef4d0498ebc91a401e
  nervana21:
    tACK 2777300c68f575565dabdcef4d0498ebc91a401e

Tree-SHA512: e2dc74154a6e29e0f3eaec9caeeec53d64bcc96adb0d1739281da97712dd931c3937eaf71f977bfc9c9330f26e35b3633f72788143b76e24e17c37b0a4258ba4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants