Skip to content

fuzz-tests: Improved fuzz coverage for fuzz-addr #8232

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

eshumanohare
Copy link

The current target fuzz-addr has the following coverage, features and the corpus when run for around 5 mins.

#16777216	pulse  cov: 225 ft: 328 corp: 22/501b lim: 4096 exec/s: 64776 rss: 490Mb

By adding a simple size constraint on the data which aligns with the actual size of script pub key for P2PKH, P2SH, P2WSH, P2WPKH, P2TR. Coverage with the new fuzz target.

#16777216	pulse  cov: 236 ft: 386 corp: 45/1112b lim: 4096 exec/s: 69615 rss: 489Mb

Added the newly discovered inputs to the seed corpus which increases the code-coverage.

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.

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.

Thanks for the contribution. The fuzz-addr corpus hasn't been updated for 2+ years, and there's been some changes to the underlying logic since then, so it's good to add the new inputs.

At the same time, I don't think the change to fuzz-addr.c is actually helpful. Could you remove that part from this PR?

Also, I think it may be worth minimizing the fuzz-addr corpus again in a second commit, since the underlying logic has changed and maybe we can prune some inputs that way:

cd tests/fuzz
mkdir -p tmp_corpora/fuzz-addr
mv corpora/fuzz-addr/* tmp_corpora/fuzz-addr/
./run.py corpora --merge_dir tmp_corpora

@@ -13,9 +13,11 @@ void init(int *argc, char ***argv)

void run(const uint8_t *data, size_t size)
{
uint8_t *script_pubkey = tal_dup_arr(tmpctx, uint8_t, data, size, 0);
if(size == 22 || size == 23 || size == 25 || size == 34) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm skeptical that this materially improves the fuzzer's ability to find new coverage, since all the size checks are also present deeper in the encode_scriptpubkey_to_addr logic. I think the increased coverage you saw is likely due to the fact that this change introduces at least 5 new branches for the fuzzer to find.

This change also doesn't seem very future-proof -- if support for a new script type is added, the fuzzer won't be able to exercise that code.

Choose a reason for hiding this comment

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

Hi! Thanks a lot for the feedback — really appreciate it.

I've removed the changes to fuzz-addr.c as suggested, and kept only the corpus update. Also, I ran the corpus minimization steps using ./run.py corpora --merge_dir, and added the minimized corpus.

I'm still getting the hang of fuzzing, so happy to learn and iterate!

@morehouse
Copy link
Contributor

Could you rework the commit structure as follows?

  • commit 1: new corpus inputs you found
  • commit 2: minimize fuzz-addr corpus

That would make this PR much easier to review, and is probably the commit structure we'd want for merging anyway.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants