-
Notifications
You must be signed in to change notification settings - Fork 942
fuzz-tests: Add a test for calculate_our_funding()
#8312
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
base: master
Are you sure you want to change the base?
Conversation
Hey @morehouse , this test fails with the error:
but the function under test,
What could be the cause? I tried inspecting the breakage using gdb but the values upon inspection seem to vary from the error output. I've added the breaking input as the corpus, I'd appreciate your thoughts on this. |
When it fails, is The check is skipped when the returned amount is 0. lightning/plugins/funder_policy.c Lines 297 to 299 in ad2dc97
|
Changelog-None: `calculate_our_funding()` in `plugins/funder_policy.c` is responsible for calculating our funding policy. Add a test for it.
Add a minimal input set as a seed corpus for the newly introduced test. This leads to discovery of interesting code paths faster.
This test is now ready to review. |
{ fprintf(stderr, "json_add_string called!\n"); abort(); } | ||
/* AUTOGENERATED MOCKS END */ | ||
|
||
#define MAX_BTC ((u32)WALLY_SATOSHI_PER_BTC * WALLY_BTC_MAX) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure this multiplication overflows u32
.
static struct amount_sat fromwire_amount_sat_bounded(const u8 **cursor, size_t *max) | ||
{ | ||
struct amount_sat amt = fromwire_amount_sat(cursor, max); | ||
amt.satoshis %= (MAX_BTC + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: whitespace
amt.satoshis %= (MAX_BTC + 1); | |
amt.satoshis %= (MAX_BTC + 1); |
|
||
void run(const u8 *data, size_t size) | ||
{ | ||
if (size < 85) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since data
is only ever read using fromwire*
functions, we probably don't need to check size
at all. If we run out of data
, fromwire
should automatically return 0 values.
struct amount_sat channel_size; | ||
struct amount_sat lease_request; | ||
struct funder_policy policy; | ||
struct amount_sat exp_our_funds; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exp_our_funds
is unused.
struct amount_sat their_funds; | ||
struct amount_sat available_funds; | ||
struct amount_sat *our_last_funds; | ||
struct amount_sat channel_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the max channel size allowed.
struct amount_sat channel_size; | |
struct amount_sat max_channel_size; |
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: