Skip to content

fuzz-tests: Improve the fuzz-bolt12-invrequest-decode wire test #8404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Chand-ra
Copy link

@Chand-ra Chand-ra commented Jul 9, 2025

Currently, the BOLT #12 invrequest parsing test only tests the invrequest decode function. Add a test for the encoding function as well by making the test roundtrip.

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.

CC: @morehouse

@morehouse
Copy link
Contributor

Doesn't fuzz-bolt12-invrequest-decode.c already cover most of what is being tested here, plus more in invoice_decode?

@Chand-ra
Copy link
Author

Chand-ra commented Jul 11, 2025

Doesn't fuzz-bolt12-invrequest-decode.c already cover most of what is being tested here, plus more in invoice_decode?

Right, I guess it makes more sense then to replicate this test as an improvement to fuzz-bolt12-invrequest-decode instead of adding a new test here.

@Chand-ra Chand-ra force-pushed the tlv_invoice_request branch from 1a8f7a6 to 48bf887 Compare July 14, 2025 04:50
@Chand-ra Chand-ra changed the title fuzz-tests: Add a wire test for struct tlv_invoice_request fuzz-tests: Improve the fuzz-bolt12-invrequest-decode wire test Jul 14, 2025
static bool sciddir_or_pubkey_eq(const struct sciddir_or_pubkey *a,
const struct sciddir_or_pubkey *b)
{
return memcmp(a, b, sizeof(*a)) == 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure the full sciddir_or_pubkey struct gets initialized? It looks like only one of sciddir or pubkey is expected to be present, so maybe we could end up comparing uninitialized memory here...

MEM_EQ(offer_issuer);
VAL_EQ(offer_quantity_max);
PTR_EQ(offer_issuer_id, pubkey_eq);
STRUCT_EQ(offer_recurrence, struct recurrence);
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like struct recurrence contains 5 bytes of data, which means it probably gets padded to 8 bytes. We can't safely memcmp in this case, as there's 3 bytes of uninitialized memory.

VAL_EQ(offer_quantity_max);
PTR_EQ(offer_issuer_id, pubkey_eq);
STRUCT_EQ(offer_recurrence, struct recurrence);
STRUCT_EQ(offer_recurrence_paywindow, struct recurrence_paywindow);
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, struct recurrence paywindow is 9 bytes and likely unsafe to memcmp.

STRUCT_EQ(offer_recurrence, struct recurrence);
STRUCT_EQ(offer_recurrence_paywindow, struct recurrence_paywindow);
VAL_EQ(offer_recurrence_limit);
STRUCT_EQ(offer_recurrence_base, struct recurrence_base);
Copy link
Contributor

Choose a reason for hiding this comment

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

struct offer_recurrence_base is 9 bytes and likely unsafe to memcmp.

Changelog-None: Currently, the `BOLT ElementsProject#12` invrequest parsing test
only tests the invrequest decode function. Add a test for the
encoding function as well by making the test roundtrip.
@Chand-ra Chand-ra force-pushed the tlv_invoice_request branch from 48bf887 to 384ffd8 Compare July 17, 2025 06:16
Copy link
Contributor

@morehouse morehouse left a comment

Choose a reason for hiding this comment

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

The target LGTM.

Within a couple minutes of fuzzing, I was able to find inputs with more coverage:

#1485   INITED cov: 607 ft: 2022 corp: 251/22Kb exec/s: 0 rss: 179Mb
...
#424149 RELOAD cov: 620 ft: 2105 corp: 286/26Kb lim: 4096 exec/s: 2754 rss: 632Mb

Could you run the target a little longer and re-merge the new inputs?

@morehouse
Copy link
Contributor

After an hour I got even more coverage:

#21785465       REDUCE cov: 630 ft: 2204 corp: 324/35Kb lim: 4096 exec/s: 5243 rss: 819Mb L: 126/1752 MS: 2 EraseBytes-Custom-

Improvements in the fuzz-testing scheme of
`fuzz-bolt12-invrequest-decode` led to the discovery of test inputs
that result in greater in code coverage.

Add these inputs to the test's seed corpus.
@Chand-ra Chand-ra force-pushed the tlv_invoice_request branch from 384ffd8 to 86d9fa8 Compare July 19, 2025 07:55
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.

2 participants