Repository navigation
fuzz: improve coinselection - #27585
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. ConflictsNo conflicts as of last run. |
c59582a to
d5282a4
Compare
murchandamus
left a comment
There was a problem hiding this comment.
I’m pretty new to fuzz testing, so I am not sure whether we want to have all these additional calls for each selection result. It seems to me that if we wanted to test the behavior of SelectionResult, it might make more sense to separately fuzz that instead of fuzzing that in the context of running all the different coin selection algorithms, since it might lower the number of executions we get on fuzzing coin selection.
OTOH, it’s great to get fuzzing coverage for these codepaths.
Code changes look good to me.
Tentative ACK d5282a45bd452844dc815181825e3dd46133ac51, except that I’d be curious to hear what others think about expanding the responsibility of this fuzz target vs adding a second fuzz target for testing SelectionResult.
d5282a4 to
82cd264
Compare
|
Force-pushed addressing #27585 (comment) and #27585 (comment) |
82cd264 to
2d739a4
Compare
murchandamus
left a comment
There was a problem hiding this comment.
ACK 2d739a425c92e2dd409c45273e8e376d39ead1cc
My concern about the min_viable_change and change_fee causing issues did not substantiate after some light fuzzing. Since it does not seem to cause crashes, having independent values for the two parameters may be better. Thanks for adding more coverage.
2d739a4 to
bd6315a
Compare
|
Rebased |
murchandamus
left a comment
There was a problem hiding this comment.
reACK bd6315a2a75d2891a8d3476c492d6b53309b7296
furszy
left a comment
There was a problem hiding this comment.
Left few comments. I think that we could go further in few places and check that the called functions are actually doing what they suppose to be doing.
For instance, all valid results must have a target below the sum of the selected inputs amounts. Also, waste on results with more difference between target and inputs sum should be greater than results with closer diff between target and inputs sum.
bd6315a to
1e0f5f0
Compare
|
Force-pushed: Addressed: Also, I added support for |
|
Force-pushed addressing @furszy's suggestion to check whether |
8c76af1 to
9e2b805
Compare
d501e1a to
5f0237f
Compare
|
Force-pushed fixing |
There was a problem hiding this comment.
Code review ACK 5f0237f2
As an extra small nit, I would merge the GetInputSet and GetShuffledInputSet commits into one (ec82d1c3a523a9b28adf66f840e239f4adead37a, 4531ab1aee85a6801e0de00816b3764b8462771c) as they are basically doing the same. But, not a big deal if you don't do it anyway.
Instead of using `cost_of_change` for `min_viable_change` and `change_cost`, and 0 for `change_fee`, use values from `coin_params`. The previous values don't generate any effects that is relevant for that context.
The valid results should have a target below the sum of the selected inputs amounts. Also, it increases the minimum value for target to make it more realistic.
`m_cost_of_change` must not be generated randomly independent from m_change_fee. This commit changes it to set it up according to `wallet/spend`.
5f0237f to
bf26f97
Compare
|
Force-pushed: changed to use |
|
reACK with some minimal fuzzing bf26f97 |
|
ACK bf26f97 |
|
This crashes: |
Yea. OSS-Fuzz has this this now as well https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=61790: Crash Type: ASSERT
Crash Address:
Crash State:
result_bnb->GetChange(coin_params.m_cost_of_change, CAmount{0}) == 0
wallet::coinselection_fuzz_target
std::__1::__function::__func<void |
|
Investigating. |
|
Follow-up in #28372 |
|
Fuzz found an issue! Fix #28395 |
bf26f97 fuzz: coinselection, fix `m_cost_of_change` (brunoerg) 6d9b26d fuzz: coinselection, BnB should never produce change (brunoerg) b2eb558 fuzz: coinselection, compare `GetSelectedValue` with target (brunoerg) 0df0438 fuzz: coinselection, improve `ComputeAndSetWaste` (brunoerg) 1e351e5 fuzz: coinselection, add coverage for `Merge` (brunoerg) f0244a8 fuzz: coinselection, add coverage for `GetShuffledInputVector`/`GetInputSet` (brunoerg) 808618b fuzz: coinselection, add coverage for `AddInputs` (brunoerg) 90c4e6a fuzz: coinselection, add coverage for `EligibleForSpending` (brunoerg) 2a031cb fuzz: coinselection, add `CreateCoins` (brunoerg) Pull request description: This PR: - Moves coin creation to its own function called `CreateCoins`. - Add coverage for `EligibleForSpending` - Add coverage for `AddInputs`: get result of each algorithm (srd, knapsack and bnb), call `CreateCoins` and add into them. - Add coverage for `GetShuffledInputVector` and `GetInputSet` using the result of each algorithm (srd, knapsack and bnb). - Add coverage for `Merge`: Call SRD with the new utxos and, if successful, try to merge with the previous SRD result. ACKs for top commit: murchandamus: reACK with some minimal fuzzing bf26f97 achow101: ACK bf26f97 furszy: re-ACK bf26f97 Tree-SHA512: bdd2b0a39de37be0a9b21a7c51260b6b8abe538cc0ea74312eb658b90a121a1ae07306c09fb0e75e93b531ce9ea2402feb041b0d852902d07739257f792e64ab
This PR:
CreateCoins.EligibleForSpendingAddInputs: get result of each algorithm (srd, knapsack and bnb), callCreateCoinsand add into them.GetShuffledInputVectorandGetInputSetusing the result of each algorithm (srd, knapsack and bnb).Merge: Call SRD with the new utxos and, if successful, try to merge with the previous SRD result.