Skip to content

fuzz: improve ipc fuzz coverage - #35916

Open
enochaz wants to merge 4 commits into
bitcoin:masterfrom
enochaz:08-26-fuzz-ipc-coverage
Open

enochaz wants to merge 4 commits into
bitcoin:masterfrom
enochaz:08-26-fuzz-ipc-coverage

Conversation

@enochaz

@enochaz enochaz commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

This PR follows up on #35118 and continues the IPC fuzzing work proposed in #23015.

The initial ipc fuzz target exercised normal calls through a libmultiprocess client and server. This PR extends the target with

The raw request and response cases allow the fuzz target to exercise deserialization with data that was not first produced by libmultiprocess serialization.

The ipc setup and callback handling closely follow the existing libmultiprocess tests, particularly their use of EventLoop, ProxyClient, ProxyServer, two-way pipes, and initThreadMap.

The transaction and UniValue payload cases exercise the serialization hooks defined in common-types.h.

These files may provide useful background when reviewing the changes.

Generated coverage report after fuzzing the IPC target for a while using the qa-assets corpus.

@DrahtBot

DrahtBot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

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
Concept ACK frankomosh, ryanofsky
Stale ACK jeanpablojp

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35932 (ipc: make ipc::disconnectIncoming wait for in-progress calls to complete by ryanofsky)

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.

@enochaz enochaz changed the title fuzz: improve IPC fuzz coverage fuzz: improve ipc fuzz coverage Aug 6, 2026

@jeanpablojp jeanpablojp 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.

tACK bd24122

All green, and it matches the follow-up #35118 asked for.

Comment thread src/ipc/test/fuzz/ipc.cpp Resolved
@enochaz
enochaz force-pushed the 08-26-fuzz-ipc-coverage branch 2 times, most recently from 85a5464 to 82bed57 Compare August 26, 2026 12:33
@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task Windows native, fuzz, VS: https://github.com/bitcoin/bitcoin/actions/runs/32963804197/job/98161775031
LLM reason (✨ experimental): CI failed because the fuzz target rpc crashed with Windows exit code 3221225477 (access violation).

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.

@enochaz

enochaz commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

See the generated coverage report after fuzzing the IPC target for a while using the qa-assets corpus.

Also included in the pr description

@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task macOS native, fuzz: https://github.com/bitcoin/bitcoin/actions/runs/34830127159/job/103931261872
LLM reason (✨ experimental): CI failed because the fuzz test (fuzz target ipc) crashed with std::runtime_error: invalid JSON received over IPC (uncaught exception, exit code 1).

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.

@Eunovo Eunovo 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.

1ea3507:

I'm not sure why random bytes are being used for CTransaction and UniValue; the chances of a randomly generated byte vector deserialising to a CTransaction are slim.

Comment thread src/ipc/test/fuzz/ipc.cpp
fuzzed_data_provider.ConsumeRandomLengthString(512));
},
[&] {
ipc.receiveTransactionPayload(ConsumeRandomLengthByteVector<uint8_t>(fuzzed_data_provider, 512));

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.

1ea3507:

Use ConsumeTransaction in src/test/fuzz/util.cpp to create a random tx from a FuzzedDataProvider instead of using a random lenght byte vector.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We intentionally return arbitrary transaction bytes from the raw server so the client deserialization is exercised with malformed responses.

Using ConsumeTransaction would only generate valid transactions and duplicate the existing passTransaction coverage.

I’ve added a comment clarifying the purpose of this branch.

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.

the chances of a randomly generated byte vector deserialising to a CTransaction are slim.

FWIW I tried to measure this and found raw bytes to reach a real tx in only under a minute, and a witness tx within a 10-minute duration of my run. I think the fuzzer does learn from coverage to build valid txs,

Comment thread src/ipc/test/fuzz/ipc.cpp
ipc.receiveTransactionPayload(ConsumeRandomLengthByteVector<uint8_t>(fuzzed_data_provider, 512));
},
[&] {
ipc.receiveUniValuePayload(fuzzed_data_provider.ConsumeRandomLengthString(512));

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.

1ea3507:

Most of the generated data will be invalid JSON; this means the fuzzer will hit the "invalid JSON received over IPC" error most of the time. I think it's much better to construct a valid JSON payload, the same way we construct valid TXs with ConsumeTransaction.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Invalid json is intentional here because it tests client side rejection of malformed ipc responses.

Valid json round trips are covered separately by passUniValue, which parses arbitrary input and proceeds when it is valid.

I’ve added a comment clarifying the distinction.

Comment thread src/ipc/test/fuzz/ipc.cpp
},
[&] {
ipc.sendTransactionPayload(
ConsumeRandomLengthByteVector<uint8_t>(fuzzed_data_provider, 512));

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.

f5db594:

You should use ConsumeTransaction from src/test/fuzz/util.cpp. Most of the vectors produced will be invalid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same rationale as #35916 (comment): this intentionally bypasses normal serialization to exercise malformed transaction payload handling.

Comment thread src/ipc/test/fuzz/ipc.cpp
ConsumeRandomLengthByteVector<uint8_t>(fuzzed_data_provider, 512));
},
[&] {
ipc.sendUniValuePayload(

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.

f5db594:

Same as in my previous UniValue comment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reason as #35916 (comment)

@frankomosh frankomosh 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.

Concept ACK

Comment thread src/ipc/test/fuzz/ipc.cpp Resolved
Comment thread src/ipc/test/fuzz/ipc.cpp Resolved
@enochaz

enochaz commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @frankomosh. Added local deserialization checks for transaction and UniValue payloads on both the request and response sides, so the fuzz target now fails when ipc accepts malformed data or rejects locally decodable data.

Keep a reference to the IPC fuzz implementation so fuzz inputs can be compared
directly with values deserialized by the proxy server.

This ensures serialization errors are detected on the client to server path instead
of potentially being hidden by the return trip.
Add a callback interface to the IPC fuzz target so requests exercise communication
from the server back to the client.

Check the callback argument and return value on both sides.
@enochaz
enochaz force-pushed the 08-26-fuzz-ipc-coverage branch from 20ba949 to deb462d Compare November 12, 2026 11:00
Use the underlying capnp client to send arbitrary transaction data and JSON text to the
libmultiprocess server.

Accept normal transaction deserialization failures while surfacing unexpected IPC errors.
Connect a normal libmultiprocess client to a manual capnp server.

Return arbitrary transaction data and json text to exercise client side
deserialization.
@enochaz
enochaz force-pushed the 08-26-fuzz-ipc-coverage branch from deb462d to 966457f Compare November 12, 2026 11:16
@DrahtBot

Copy link
Copy Markdown
Contributor

🚧 At least one of the CI tasks failed.
Task test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/43205413018/job/131139208283
LLM reason (✨ experimental): The build failed because fuzz target ipc.cpp cannot find the header ipc/util.h.

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.

@enochaz

enochaz commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

friendly ping @marcofleon @Crypt-iQ

@Crypt-iQ

Copy link
Copy Markdown
Contributor

@enochaz sorry, I can't meaningfully review. I have no idea how ipc works at all at the code level. I haven't reviewed marco's ipc-mining approach but I think we both had some moderate success in fuzzamoto by simply calling random ipc methods with random values. There's currently no merged support for IPC in fuzzamoto, though I'd be happy to review a fuzzamoto IPC PR assuming it simply did something like this (calling random methods like this is really the limit of my understanding here).

@enochaz

enochaz commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

I have no idea how ipc works at all at the code level. I haven't reviewed marco's ipc-mining approach but I think we both had some moderate success in fuzzamoto by simply calling random ipc methods with random values.

Thanks @Crypt-iQ, no worries.

This target is a bit lower level than calling random ipc methods. It runs a libmultiprocess client and server in process and sends malformed transaction and json payloads in both directions, checking that ipc accepts only what decodes locally and rejects the rest.

If you have time, the accept/reject checks in sendTransactionPayload and receiveTransactionPayload might still be reviewable without much ipc background. Otherwise all good, thanks for the fuzzamoto pointer.

@ryanofsky

Copy link
Copy Markdown
Contributor

Concept ACK (966457f) on focusing this on the types the Mining and Chain interfaces actually pass. The type-conversion layer is where in-process fuzz tests are most useful: several real IPC bugs were values the C++ side could never produce arriving over the wire, like a CFeeRate with a negative size (#36816), a NaN read into a duration, or an out-of-range enum. Bugs involving object lifetimes, threads or disconnects are less likely to be found this way, and hard to reproduce when they are, because the fuzzer doesn't control which thread runs when. Those need tests that do control the schedule, either with hooks that pause calls at chosen points (as some libmultiprocess unit tests already do) or with a deterministic scheduler like Antithesis.

For each type the Mining and Chain interfaces pass, I think it would be good to cover:

  • Round trips: the server-side checks that values arrive unchanged (as @sedited suggested in #35118 (review)). They catch conversions that lose or change valid values.
  • Raw payloads: bytes that skip normal serialization, checking that invalid ones are rejected cleanly. These catch readers that accept values the C++ side couldn't produce.
  • Both directions: besides requests and responses, callback arguments go through their own generated code, with the server building the parameters and the client reading them. Chain's notification callbacks send transactions and block data this way. So instead of passing only an int, the callback case could pass the same types, which covers the conversions in that direction too without much extra work for the fuzzer.

@maflcko

maflcko commented Dec 2, 2026

Copy link
Copy Markdown
Member

cross-ref to #37063

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.

8 participants