Skip to content

fuzz: add test for the gossipd message processing#9115

Open
NishantBansal2003 wants to merge 3 commits into
ElementsProject:masterfrom
NishantBansal2003:fuzz-gossipd
Open

fuzz: add test for the gossipd message processing#9115
NishantBansal2003 wants to merge 3 commits into
ElementsProject:masterfrom
NishantBansal2003:fuzz-gossipd

Conversation

@NishantBansal2003

Copy link
Copy Markdown
Contributor

Add state machine fuzz tests for gossipd message processing. Currently, all message states handled by gossipd are covered here, but other gossip messages like gossip_timestamp_filter, query_short_channel_id, and query_channel_range are handled by connectd, so those states need to be explicitly tested in separate fuzz tests.

Most of the work here is based on #8423, so I've added the PR author as a co-author. I also rebased the changes and fixed the entropy issue afterward. Additionally, some new states have been added (e.g. UTXO lookup, update blockheight, seeker state machine), and a few existing states have been updated to support e2e message processing (e.g. UTXO lookup in channel announcements).

Also, in the ref PR there was a discussion about issues with multi worker fuzzing. I’ve addressed that in 26f7b52. I think with this we can run regression tests on some previously observed edge-cases

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade

Comment thread gossipd/gossip_store.c Outdated

#define GOSSIP_STORE_TEMP_FILENAME "gossip_store.tmp"
#define GOSSIP_STORE_TEMP_FILENAME tal_strcat(tmpctx, GOSSIP_STORE_FILENAME, ".tmp")
#define GOSSIP_STORE_CORRUPT_FILENAME tal_strcat(tmpctx, GOSSIP_STORE_FILENAME, ".corrupt")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The correct C way to do this is:

#define GOSSIP_STORE_TEMP_FILENAME    GOSSIP_STORE_FILENAME ".tmp"

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.

Yes, but that would fail in our fuzzing setup, where we need to define a different GOSSIP_STORE_FILENAME for each worker to avoid corruption from multiple fuzz workers accessing the same file. String concatenation only works with string literals, but here we need GOSSIP_STORE_FILENAME to be a variable so that it can vary across workers

@ddustin ddustin Jun 15, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In general caps macros (particularly without parens) imply something constant. Replacing it with something dynamic, particularly one dependent on tmpctx can easily throw someone off in the future causing hard-to-discover bugs and issues down the line.

What's the issue that's causing multiple fuzz workers to access the same file?

@madelinevibes madelinevibes added this to the v26.09 milestone Jun 15, 2026
NishantBansal2003 and others added 3 commits June 16, 2026 14:59
The .tmp, .corrupt and .compact paths are derived from
GOSSIP_STORE_FILENAME, but were hardcoded as literal constants. Wrap
their definitions in #ifndef GOSSIP_STORE_FUZZ_OVERRIDE so a fuzz target
can supply its own paths before including these files.

In production nothing defines GOSSIP_STORE_FUZZ_OVERRIDE, so the literals
are used unchanged: no behaviour change. This is done for fuzz-gossipd:
it already overrides GOSSIP_STORE_FILENAME with a per-process path, and
this lets the derived .tmp/.corrupt/.compact paths follow, so parallel
libFuzzer workers don't race on the same files in CWD.

Changelog-None

Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
Changelog-None

Co-authored-by: Chandra Pratap <Chand-ra@users.noreply.github.com>
Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
Signed-off-by: Nishant Bansal <nishant.bansal.282003@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants