Skip to content

Conversation

practicalswift
Copy link
Contributor

@practicalswift practicalswift commented Sep 18, 2020

Add fuzzing harness for node eviction logic.

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 :)

@practicalswift practicalswift changed the title tests: Add fuzzing harness for node eviction logic tests/net: Add fuzzing harness for node eviction logic. Make node eviction logic testable. Sep 18, 2020
@jonatack
Copy link
Member

Concept ACK, thanks for working on this. Will review.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 19, 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.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK c57cabd code review, ran the fuzzer up to 10M execs, ran bitcoind grepping the net logging and observing the peer conns. Consider maybe running clang-format on the changes.

#10750687	REDUCE cov: 1502 ft: 7161 corp: 469/821Kb lim: 4096 exec/s: 527 rss: 631Mb L: 2188/4091 MS: 1 EraseBytes-
#10761148	REDUCE cov: 1502 ft: 7161 corp: 469/821Kb lim: 4096 exec/s: 527 rss: 642Mb L: 1430/4091 MS: 1 EraseBytes-
#10761655	REDUCE cov: 1502 ft: 7161 corp: 469/821Kb lim: 4096 exec/s: 527 rss: 642Mb L: 3142/4091 MS: 2 PersAutoDict-EraseBytes- DE: "_\xb0\x00\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d\x8d"-
#10770237	REDUCE cov: 1502 ft: 7161 corp: 469/821Kb lim: 4096 exec/s: 527 rss: 642Mb L: 2961/4091 MS: 2 ChangeBinInt-EraseBytes-
#10778939	REDUCE cov: 1502 ft: 7161 corp: 469/821Kb lim: 4096 exec/s: 527 rss: 643Mb L: 3266/4091 MS: 2 ChangeByte-EraseBytes-

@jonatack
Copy link
Member

(am running the node with this logging)

+++ b/src/net.cpp
@@ -972,6 +972,7 @@ bool CConnman::AttemptToEvictConnection()
 
     const Optional<NodeEvictionCandidate> node_to_evict = SelectNodeToEvict(vEvictionCandidates);
     if (!node_to_evict) {
+        LogPrintf("ATEC: no node to evict returned by SelectNodeToEvict()\n");
         return false;
     }
     const NodeId evicted = node_to_evict->id;
@@ -979,9 +980,12 @@ bool CConnman::AttemptToEvictConnection()
     for (CNode* pnode : vNodes) {
         if (pnode->GetId() == evicted) {
             pnode->fDisconnect = true;
+            LogPrintf("ATEC: node to evict FOUND in vEvictioncandidates and disconnected: %s\n", evicted);
             return true;
         }
     }
+    LogPrintf("ATEC: node to evict selected but not found in vEvictioncandidates: %s\n", evicted);
+
     return false;
 }

@jonatack
Copy link
Member

A month has passed since reviewing, so a gentle bump for reviewers.

Copy link
Member

@sipa sipa left a comment

Choose a reason for hiding this comment

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

Concept ACK

@practicalswift practicalswift force-pushed the fuzzers-eviction-logic branch 3 times, most recently from 1533813 to 0b236f9 Compare November 5, 2020 15:33
@practicalswift practicalswift changed the title tests/net: Add fuzzing harness for node eviction logic. Make node eviction logic testable. test/net: Add fuzzing harness for node eviction logic. Make node eviction logic testable. Nov 24, 2020
@practicalswift practicalswift changed the title test/net: Add fuzzing harness for node eviction logic. Make node eviction logic testable. fuzz/net: Add fuzzing harness for node eviction logic. Make node eviction logic testable. Nov 24, 2020
@practicalswift practicalswift changed the title fuzz/net: Add fuzzing harness for node eviction logic. Make node eviction logic testable. [draft] fuzz/net: Add fuzzing harness for node eviction logic. Make node eviction logic testable. Dec 6, 2020
@practicalswift
Copy link
Contributor Author

Marking this as draft since it depends on the changes in #20477 ("test/net: Add unit testing of node eviction logic") :)

@practicalswift practicalswift force-pushed the fuzzers-eviction-logic branch 2 times, most recently from c6f0bc1 to 1c03aa6 Compare December 16, 2020 11:29
@practicalswift practicalswift changed the title [draft] fuzz/net: Add fuzzing harness for node eviction logic. Make node eviction logic testable. fuzz: Add fuzzing harness for node eviction logic Dec 16, 2020
@practicalswift
Copy link
Contributor Author

practicalswift commented Dec 16, 2020

Rebased on top of master now that the prerequisite #20477 has been merged.

This PR is now touches only the fuzz tests and should hopefully be easy to review :)

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

Aren't the code paths already exercised through the unit test?

@practicalswift
Copy link
Contributor Author

Aren't the code paths already exercised through the unit test?

There are differences: the unit test clamp the eviction candidate parameters (like static_cast<int64_t>(random_context.randrange(100)) ) in order to trigger duplicate values, whereas this fuzzing harness can span the entire input space (like fuzzed_data_provider.ConsumeIntegral<int64_t>()). The latter is good for catching integer overflows and similar stuff resulting from "extreme" inputs.

Also the unit testing performs a couple of thousand test eviction rounds whereas the fuzzing test runs indefinitely :)

I think it makes sense to both unit test and fuzz test SelectNodeToEvict since that function is of extreme importance :)

@maflcko
Copy link
Member

maflcko commented Dec 16, 2020

cr ACK 5a9ee08

@maflcko maflcko merged commit 43fc7a5 into bitcoin:master Dec 25, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 25, 2020
5a9ee08 tests: Add fuzzing harness for node eviction logic (practicalswift)

Pull request description:

  Add fuzzing harness for node eviction logic.

  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 :)

ACKs for top commit:
  MarcoFalke:
    cr ACK 5a9ee08

Tree-SHA512: c2401d22134867e23dab1ba94ae7ef36fdf52aa0588fdc4705d9cb765ddf979fd775fdf153ce2359f1bc1787cf60bf0ebcd47c7aa29c672e6a253fa58cac292d
Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

ACK 5a9ee08

fuzzed_data_provider.ConsumeBool(),
fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
fuzzed_data_provider.ConsumeBool(),
fuzzed_data_provider.ConsumeBool(),
Copy link
Member

Choose a reason for hiding this comment

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

Following this merge I needed to update this fuzzer for #20197 and found the documentation for each data member previously added in net_tests.cpp both useful and missing here. Added it in #20197.

@practicalswift practicalswift deleted the fuzzers-eviction-logic branch April 10, 2021 19:43
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 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