fuzz-tests: test 8-to-5 bit conversion
What changed, and why it matters
This commit only adds a new fuzz test that checks whether converting data from 5-bit to 8-bit and back to 5-bit produces the original value. It does not change any production code, wallet logic, or network behavior. There is no security fix or vulnerability here.
No action required. This is a test-only change and does not affect security posture.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is confined to tests/fuzz/fuzz-bech32.c. It extends an existing fuzz target to perform a round-trip test of bech32_convert_bits: it masks input bytes to 5 bits, converts 5-to-8 without padding, then converts 8-to-5 with padding, and asserts the result matches the masked input. No library or runtime code is modified.
Changed components
tests/fuzz/fuzz-bech32.cInspect captured patch +20 / −5
diff --git a/tests/fuzz/fuzz-bech32.c b/tests/fuzz/fuzz-bech32.c
index 6d6b346f..9e92ef7e 100644
--- a/tests/fuzz/fuzz-bech32.c
+++ b/tests/fuzz/fuzz-bech32.c
@@ -39,13 +39,28 @@ void run(const uint8_t *data, size_t size)
assert(memcmp(data_out, data + 1, data_out_len) == 0);
}
- data_out = tal_arr(tmpctx, uint8_t, size);
+ /* Convert data to 5-bit values (0-31) */
+ u8 *five_bit_data = tal_dup_arr(tmpctx, u8, data, size, 0);
+ for (size_t i = 0; i < size; i++)
+ five_bit_data[i] &= 0x1F;
- /* This is also used as part of sign and check message. */
- data_out_len = 0;
- bech32_convert_bits(data_out, &data_out_len, 8, data, size, 5, 1);
+ u8 *eight_bit_data = tal_arr(tmpctx, u8, size);
+ size_t eight_bit_len = 0;
+ /* Convert 5-to-8 without padding */
+ if (bech32_convert_bits(eight_bit_data, &eight_bit_len, 8,
+ five_bit_data, size, 5, 0)) {
+ u8 *five_bit_deconv = tal_arr(tmpctx, u8, size);
+ size_t five_bit_deconv_len = 0;
+ /* Convert 8-to-5 with padding */
+ if (bech32_convert_bits(five_bit_deconv, &five_bit_deconv_len, 5,
+ eight_bit_data, eight_bit_len, 8, 1)) {
+ assert(five_bit_deconv_len == size);
+ assert(memcmp(five_bit_data, five_bit_deconv, five_bit_deconv_len) == 0);
+ }
+ }
+
+ data_out = tal_arr(tmpctx, uint8_t, size);
data_out_len = 0;
- bech32_convert_bits(data_out, &data_out_len, 8, data, size, 5, 0);
addr = tal_arr(tmpctx, char, 73 + strlen(hrp_addr));
for (int wit_version = 0; wit_version <= 16; ++wit_version) {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.