-
Notifications
You must be signed in to change notification settings - Fork 38.7k
fuzz: Mock GetRand in process_message(s) #28537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. |
src/test/fuzz/process_message.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not having this exception leads to an endless loop here:
bitcoin/src/net_processing.cpp
Lines 5225 to 5227 in c9f2882
| do { | |
| nonce = GetRand<uint64_t>(); | |
| } while (nonce == 0); |
src/random.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting g_mock_deterministic_tests is not a great alternative as it makes GetRand always return the same value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It is bad enough that there is a single test-only mock in here. Now, having two, it would make sense to remove one of them again. (Maybe in a follow-up)
0ec6ed0 to
24ddb4a
Compare
|
Concept ACK |
|
Can you add examples where this matters? I presume one example would be ping-pong handling? Longer term it would be nice to nuke the global |
bitcoin/src/net_processing.cpp Line 5369 in c9f2882
bitcoin/src/net_processing.cpp Line 1106 in c9f2882
bitcoin/src/net_processing.cpp Line 5270 in c9f2882
bitcoin/src/net_processing.cpp Line 5264 in c9f2882
|
|
The examples you linked to should still be non-deterministic, because the feefilter rounder is random, as well as the address relay, no? Also, no transactions are ever relayed, so while this makes the coverage data more deterministic, the benefits should be minimal? Considering that this may affect all fuzz inputs, I'd prefer to go the full and complete route instead. |
| FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); | ||
|
|
||
| g_mock_get_rand = [&](uint64_t max) -> uint64_t { | ||
| if (fuzzed_data_provider.remaining_bytes() == 0) return 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this return max - 1, otherwise it may return an invalid value when GetRand(1) is called?
|
Would be nice to start using one No need to fix everything, but it shouldn't be too hard to fix one instance (e.g. ping-pong handling) with the added benefit of not breaking the fuzz input format. Happy to review that. In the future, the deterministic seed can be read from the fuzz input (in a breaking fuzz change), and more places can be converted. |
This doesn't solve our problem in the fuzz tests since the peerman is global, so this will only help in fuzz tests that create a new peerman each iteration. |
4cafe9f [test] Make PeerManager's rng deterministic in tests (dergoegge) fecec3e [net processing] FeeFilterRounder doesn't own a FastRandomContext (dergoegge) 47520ed [net processing] Make fee filter rounder non-global (dergoegge) 77506f4 [net processing] Addr shuffle uses PeerManager's rng (dergoegge) a648dd7 [net processing] PushAddress uses PeerManager's rng (dergoegge) 87c7067 [net processing] PeerManager holds a FastRandomContext (dergoegge) Pull request description: This lets us avoid some non-determinism in tests (also see #28537). ACKs for top commit: MarcoFalke: re-ACK 4cafe9f 🕗 glozow: concept && light code review ACK 4cafe9f Tree-SHA512: 3c18700773d0bc547ccb6442c41567e6f26b0b50fab5b79620da417ec91b9c0ae1395d15258da3aa4a91447b8ce560145dd135e39fbbd0610749e528e665b111
4cafe9f [test] Make PeerManager's rng deterministic in tests (dergoegge) fecec3e [net processing] FeeFilterRounder doesn't own a FastRandomContext (dergoegge) 47520ed [net processing] Make fee filter rounder non-global (dergoegge) 77506f4 [net processing] Addr shuffle uses PeerManager's rng (dergoegge) a648dd7 [net processing] PushAddress uses PeerManager's rng (dergoegge) 87c7067 [net processing] PeerManager holds a FastRandomContext (dergoegge) Pull request description: This lets us avoid some non-determinism in tests (also see bitcoin#28537). ACKs for top commit: MarcoFalke: re-ACK 4cafe9f 🕗 glozow: concept && light code review ACK 4cafe9f Tree-SHA512: 3c18700773d0bc547ccb6442c41567e6f26b0b50fab5b79620da417ec91b9c0ae1395d15258da3aa4a91447b8ce560145dd135e39fbbd0610749e528e665b111
This PR introduces
g_mock_get_randto allow tests to mockGetRandand makesg_mock_get_randconsume from the fuzzed data in the process_message(s) targets.Mocking
GetRandreduces the non-determinism in these targets and results in more stable fuzzing.