-
Notifications
You must be signed in to change notification settings - Fork 937
fuzz-tests: Add fuzz target for closing_complete #8216
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
Probably the best person to review this code is @morehouse |
Yeah, I've had a conversation with him over mail. He said he'd get around to it soon. |
size_t upto_closer_scriptpubkey = (uintptr_t)&x->closer_scriptpubkey - (uintptr_t)x; | ||
if (memcmp(x, y, upto_closer_scriptpubkey) != 0) | ||
return false; |
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 concerned that some architectures may pad/align struct members to 8 bytes, which means there would be 4 bytes of uninitialized padding between locktime
and fee_satoshis
that could trigger false positives.
If we want to use the memcmp
trick, we should probably move locktime
to after fee_satoshis
and then manually compare fields starting with locktime
and thereafter.
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.
The memcmp
dance takes as much lines as individually comparing struct closing_complete
's members, so I've replaced the former with the latter in the latest push.
Also would be good to add a minimal input set as a seed corpus. |
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.
Did you use the run.py
script to minimize the corpus?
Also, I think this should probably be a Changelog-None
.
assert(!memcmp(&x->channel_id, &y->channel_id, sizeof(struct channel_id))); | ||
assert(x->locktime == y->locktime); | ||
assert(!memcmp(&x->fee_satoshis, &y->fee_satoshis, sizeof(struct amount_sat))); |
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: for better readability can we use assert(memcmp(...) == 0)
? I've seen bugs arise because people thought !memcmp(...)
meant the buffers differed.
assert(!memcmp(&x->channel_id, &y->channel_id, sizeof(struct channel_id))); | |
assert(x->locktime == y->locktime); | |
assert(!memcmp(&x->fee_satoshis, &y->fee_satoshis, sizeof(struct amount_sat))); | |
assert(memcmp(&x->channel_id, &y->channel_id, sizeof(struct channel_id)) == 0); | |
assert(x->locktime == y->locktime); | |
assert(memcmp(&x->fee_satoshis, &y->fee_satoshis, sizeof(struct amount_sat)) == 0); |
assert(!memcmp(&x->channel_id, &y->channel_id, sizeof(struct channel_id))); | ||
assert(x->locktime == y->locktime); | ||
assert(!memcmp(&x->fee_satoshis, &y->fee_satoshis, sizeof(struct amount_sat))); |
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: common trick to avoid the memcmp
breaking if the struct type changes in the future:
assert(!memcmp(&x->channel_id, &y->channel_id, sizeof(struct channel_id))); | |
assert(x->locktime == y->locktime); | |
assert(!memcmp(&x->fee_satoshis, &y->fee_satoshis, sizeof(struct amount_sat))); | |
assert(!memcmp(&x->channel_id, &y->channel_id, sizeof(x->channel_id))); | |
assert(x->locktime == y->locktime); | |
assert(!memcmp(&x->fee_satoshis, &y->fee_satoshis, sizeof(x->fee_satoshis))); |
Changelog-None: 'closing_signed' and 'closing_complete' are channel closing negotiation messages defined in BOLT ElementsProject#2. While 'closing_signed' has a wire fuzz test, 'closing_complete' does not. Add a test to perform a round-trip encoding check (towire -> fromwire) similar to the other wire fuzzers.
Add a minimal input set as a seed corpus for the newly introduced test. This leads to discovery of interesting code paths faster.
I did. Doesn't seem to do a lot though.
Right. |
closing_signed
andclosing_complete
are channel closing negotiation messages defined in BOLT #2.While
closing_signed
has a wire fuzz test,closing_complete
does not. Add a test to perform a round-trip encoding check (towire -> fromwire) similar to the other wire fuzzers.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: