Skip to content

fuzz-tests: verify round‑trip scriptpubkey-to-addr conversion#8297

Merged
rustyrussell merged 2 commits intoElementsProject:masterfrom
Chand-ra:addr
Sep 15, 2025
Merged

fuzz-tests: verify round‑trip scriptpubkey-to-addr conversion#8297
rustyrussell merged 2 commits intoElementsProject:masterfrom
Chand-ra:addr

Conversation

@Chand-ra
Copy link

Currently, fuzz-addr only tests encoding via encode_scriptpubkey_to_addr(), without checking decoding. Add a round‑trip assertion: if encoding produces an address, decode it back with decode_scriptpubkey_from_addr() and confirm the result matches the original scriptpubkey.

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

encode_scriptpubkey_to_addr(tmpctx, chainparams, script_pubkey);
char *addr = encode_scriptpubkey_to_addr(tmpctx, chainparams, script_pubkey);

uint8_t *decoded_script_pubkey;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the scope of this variable should be reduced to the if-block below.

Comment on lines +24 to +23
decode_scriptpubkey_from_addr(tmpctx, chainparams, addr, &decoded_script_pubkey);
assert(tal_arr_eq(script_pubkey, decoded_script_pubkey));
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check the returned bool as well:

Suggested change
decode_scriptpubkey_from_addr(tmpctx, chainparams, addr, &decoded_script_pubkey);
assert(tal_arr_eq(script_pubkey, decoded_script_pubkey));
assert(decode_scriptpubkey_from_addr(tmpctx, chainparams, addr, &decoded_script_pubkey));
assert(tal_arr_eq(script_pubkey, decoded_script_pubkey));

@morehouse
Copy link
Contributor

Code almost LGTM. Tested and verified coverage.

Chandra Pratap added 2 commits May 20, 2025 08:32
Changelog-None: Currently, fuzz-addr only tests encoding via
encode_scriptpubkey_to_addr(), without checking decoding. Add a
round‑trip assertion: if encoding produces an address, decode
it back with decode_scriptpubkey_from_addr() and confirm the
result matches the original scriptpubkey.
Change in the fuzz-testing scheme of fuzz-addr led to the
discovery of test inputs that result in greater in code
coverage. Add these inputs to the test's seed corpus.
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.

ACK 2d9ecbf

@rustyrussell rustyrussell merged commit a23dcf6 into ElementsProject:master Sep 15, 2025
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.

4 participants