-
Notifications
You must be signed in to change notification settings - Fork 942
fuzz-tests: improve fuzz-bech32
#8311
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
Changelog-None: Use the common library utilities for temporary allocations instead of manually calling `malloc` and `free`. This makes the code conformant with rest of the codebase and reduces the chances of leaks.
According to `common/bech32.h`, the valid values of witness program version are between 0 and 16 (inclusive). Update the test to iterate over all of these values.
tests/fuzz/fuzz-bech32.c
Outdated
uint8_t *converted = tal_arr(tmpctx, uint8_t, size * 2); | ||
size_t converted_len = 0; | ||
if (bech32_convert_bits(converted, &converted_len, 5, data, size, 8, 1)) { | ||
uint8_t *deconverted = tal_arr(tmpctx, uint8_t, converted_len * 2); |
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.
Does deconverted
need to be size converted_len * 2
? If we're going from 5 bits back to 8 bits, shouldn't we need at most size
bytes?
tests/fuzz/fuzz-bech32.c
Outdated
@@ -60,5 +60,18 @@ void run(const uint8_t *data, size_t size) | |||
assert(memcmp(data_out, data, data_out_len) == 0); | |||
} | |||
|
|||
/* Test 8-to-5 bit roundtrip conversion */ |
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.
Would it make sense to do the roundtrip as part of the above call to bech32_convert_bits
?
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.
Makes sense, the calls above don't test a whole lot.
Currently, the test only verifies the 5-to-8 bit conversion. Replace it with a roundtrip check that verifies 8-to-5 bit conversion as well.
Change in the fuzzing scheme of fuzz-bech32 led to the discovery of test inputs that result in greater in code coverage. Add these inputs to the test's seed corpus.
Add improvements to
tests/fuzz/fuzz-bech32
and add the coverage increasing inputs to the corresponding corpus.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:
CC: @morehouse