Repository navigation
test: fuzz: check CoinGrinder completed flag - #36905
Conradgabe wants to merge 1 commit into
Conversation
CoinGrinder marks its result as completed when it exhausts the search space before reaching TOTAL_TRIES. No unit test reads this flag, and the coin_grinder and coin_grinder_is_optimal fuzz targets only use it to decide whether to check optimality, so a wrong value here goes unnoticed. Check GetAlgoCompleted() in coin_grinder_tests for cases that finish below the attempt limit, and assert in both fuzz targets that the flag is true exactly when fewer than TOTAL_TRIES selections were evaluated.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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. |
|
ACK e5ee8a9 |
There was a problem hiding this comment.
tACK e5ee8a9
I applied each mutant separately on macOS arm64. For each build, I ran coin_grinder_tests and replayed both seed corpora from qa-assets at 9c61fa724 using the standalone fuzz binary.
| Build | coin_grinder_tests |
coin_grinder (681 inputs) |
coin_grinder_is_optimal (231 inputs) |
|---|---|---|---|
| PR | Pass | Pass | Pass |
4402 (false on search exhaustion) |
All six new checks fail | Assertion fails at line 125 | Assertion fails at line 202 |
4401 (true at the attempt limit) |
Pass | Same assertion fails at line 125 | Pass, 231/231 |
Both assertion line numbers refer to src/wallet/test/fuzz/coinselection.cpp. I applied the mutations in src/wallet/coinselection.cpp.
cmake -B build_fuzz -DBUILD_FOR_FUZZING=ON
cmake --build build_fuzz
cmake --build build
build/bin/test_bitcoin --run_test=coinselector_tests/coin_grinder_tests
FUZZ=coin_grinder build_fuzz/bin/fuzz ../qa-assets/fuzz_corpora/coin_grinder
FUZZ=coin_grinder_is_optimal build_fuzz/bin/fuzz ../qa-assets/fuzz_corpora/coin_grinder_is_optimalFor 4401, f94e50c75af1ee1fbe07abb16850bcf5dd28775d was the first input to trigger the assertion in my run. The runner shuffles the corpus. [Reproducing input](https://github.com/bitcoin-core/qa-assets/blob/9c61fa724af7566eaa9f97ad23c637374ef469ea/fuzz_corpora/coin_grinder/f94e50c75af1ee1fbe07abb16850bcf5dd28775d)
One optional addition would be a unit test alongside bnb_exhaustion_with_solution_test in coinselection_tests.cpp. I tried 20 groups built with MakeCoin(COIN + i) for i from 0 to 19, a target of 10 * COIN, zero change target and MAX_STANDARD_TX_WEIGHT. With the PR, CoinGrinder returned enough to cover the target after exactly 100,000 evaluations, with GetAlgoCompleted() false. The same test passed with 4402. With 4401, only BOOST_CHECK(!result->GetAlgoCompleted()) failed.

CoinGrindermarks its result as completed when it exhausts the search space before reachingTOTAL_TRIES, and leaves it incomplete when it stops at the limit. No unit test reads this flag, and thecoin_grinderandcoin_grinder_is_optimalfuzz targets only use it to decide whether to assert optimality, so a wrong value would go unnoticed.This PR checks
GetAlgoCompleted()incoin_grinder_testsfor cases that finish below the attempt limit (100,000), and asserts in both fuzz targets that the flag is true below the limit and false once it is reached.Kills the following mutants:
https://mutanthub.space/mutants/4402
https://mutanthub.space/mutants/4401