Skip to content

Conversation

practicalswift
Copy link
Contributor

Add fuzzing harness for BanMan.

See doc/fuzzing.md for information on how to fuzz Bitcoin Core. Don't forget to contribute any coverage increasing inputs you find to the Bitcoin Core fuzzing corpus repo.

Happy fuzzing :)

@fanquake fanquake added the Tests label Jun 9, 2020
@practicalswift
Copy link
Contributor Author

Now fuzzing BanMan::Discourage(…) too: the commit from #19219 is now part of this PR.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 9, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

const fs::path banlist_file = GetDataDir() / "fuzzed_banlist.dat";
fs::remove(banlist_file);
{
BanMan ban_man{banlist_file, nullptr, ConsumeBanTimeOffset(fuzzed_data_provider)};
Copy link
Contributor

Choose a reason for hiding this comment

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

@practicalswift Do you think adding random data to "fuzzed_banlist.dat", then calling BanMan ban_man{banlist_file, nullptr, ConsumeBanTimeOffset(fuzzed_data_provider)}; could be its own fuzz test? It would basically fuzz DeserializeFileDB in src/addrdb.cpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is a good idea that can be tackled in a follow-up PR, but instead of writing files to disk I think we should use a mocked/fuzzed filesystem interface like the one that will be introduced as part of #19143. Please consider reviewing that PR :)

@practicalswift
Copy link
Contributor Author

Rebased on master now that @sipa's discouragement filter change in #19219 has been merged :)

@Crypt-iQ
Copy link
Contributor

Tested ACK :)

Ran against ad953a2 for about 18 hours on a Ubuntu VM with 2 core and 2g RAM. It was pretty slow even for a weak VM, probably because of file io when dumping the banlist.

start_time        : 1594037321
last_update       : 1594098196
fuzzer_pid        : 16179
cycles_done       : 0
execs_done        : 379262
execs_per_sec     : 6.20
paths_total       : 341
paths_favored     : 108
paths_found       : 340
paths_imported    : 0
max_depth         : 4
cur_path          : 134
pending_favs      : 81
pending_total     : 301
variable_paths    : 329
stability         : 98.81%
bitmap_cvg        : 13.03%
unique_crashes    : 0
unique_hangs      : 0
last_path         : 1594098172
last_crash        : 0
last_hang         : 0
execs_since_crash : 379262
exec_timeout      : 320
afl_banner        : banman
afl_version       : 2.57b
target_mode       : no_forksrv 
command_line      : afl/afl-fuzz -i inputs/ -o outputs/ -m500 -- src/test/fuzz/banman
slowest_exec_ms   : 320
peak_rss_mb       : 53

Coverage for banman.cpp here: https://crypt-iq.github.io/btc/fuzz-cov/src/banman.cpp.gcov.html

#include <primitives/transaction.h>
#include <script/script.h>
#include <script/standard.h>
#include <serialize.h>
#include <streams.h>
#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>
#include <test/util/setup_common.h>
#include <txmempool.h>
#include <uint256.h>
#include <version.h>
Copy link
Member

Choose a reason for hiding this comment

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

instead of having a fuzz header which is included in all fuzz test, and itself includes all of bitcoin core, what about moving the implementations to a cpp file or maybe even a fuzz/util/net etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a plan! :)

@maflcko maflcko merged commit a426317 into bitcoin:master Jul 11, 2020
@practicalswift
Copy link
Contributor Author

@Crypt-iQ Thanks a lot for testing and reviewing. Great to have you on board as one of the actively reviewing fuzzing enthusiasts of the project! :)

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 11, 2020
97846d7 tests: Add fuzzing harness for BanMan (practicalswift)
deba199 tests: Add ConsumeSubNet(...). Move and increase coverage in ConsumeNetAddr(...). (practicalswift)

Pull request description:

  Add fuzzing harness for `BanMan`.

  See [`doc/fuzzing.md`](https://github.com/bitcoin/bitcoin/blob/master/doc/fuzzing.md) for information on how to fuzz Bitcoin Core. Don't forget to contribute any coverage increasing inputs you find to the [Bitcoin Core fuzzing corpus repo](https://github.com/bitcoin-core/qa-assets).

  Happy fuzzing :)

Top commit has no ACKs.

Tree-SHA512: f4126c15bbb77638833367d73f58193c8f05d16bed0b1d6c33b39387d5b610ff34af78cd721adb51778062ce3ac5e79756d1c3895ef54c6c80c61dcf056e94ff
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 3, 2021
Summary: Backport of core [[bitcoin/bitcoin#19222 | PR19222]].

Test Plan:
  ninja bitcoin-fuzzers
  ./src/test/fuzz/banman <path_to_corpus>

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9130
@practicalswift practicalswift deleted the fuzzers-banman branch April 10, 2021 19:42
kwvg added a commit to kwvg/dash that referenced this pull request May 7, 2022
kwvg added a commit to kwvg/dash that referenced this pull request May 7, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jun 14, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jun 14, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jun 14, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jun 18, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jun 18, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jul 4, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jul 4, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jul 6, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jul 6, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jul 6, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jul 13, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jul 13, 2022
kwvg added a commit to kwvg/dash that referenced this pull request Jul 15, 2022
PastaPastaPasta added a commit to dashpay/dash that referenced this pull request Jul 17, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants