Skip to content
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

fuzz: txorphan tests fixups #29974

Merged
merged 1 commit into from May 13, 2024
Merged

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Apr 26, 2024

Motivated by #28970 (comment)

Adds the following fixups in txorphan fuzz tests:

  • Don't bond the output count of the created orphans to the number of available coins
  • Allow duplicate inputs but don't store duplicate outpoints

Most significantly, this gets rid of the duplicate_input flag altogether, making the test easier to reason about. Notice how, under normal conditions, duplicate inputs would be caught by MemPoolAccept::PreChecks, however, no validations checks are run on the test before adding data to the orphanage (neither were they before this patch)

Rationale

The way the test is currently written, duplicate inputs are allowed based on a random flag (duplicate_input). If the flag is unset, upon selecting an outpoint as input for a new transaction, the input is popped to prevent re-selection and later re-added to the collection (once all inputs have been picked). However, the re-addition to the collection is performed independently of whether the flag was set or not. This means that, if the flag is set, the selected inputs are duplicated which in turn makes these inputs more likely to be re-picked in the following iteration of the loop.

Additionally, both the input and output count of the transaction are bonded to the number of available outpoints. This makes sense for the former, but the latter shouldn't be.

@DrahtBot
Copy link
Contributor

DrahtBot commented Apr 26, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK glozow, instagibbs, maflcko

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@DrahtBot DrahtBot added the Tests label Apr 26, 2024
Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

ACK 6998f02

src/test/fuzz/txorphan.cpp Outdated Show resolved Hide resolved
src/test/fuzz/txorphan.cpp Outdated Show resolved Hide resolved
@sr-gi sr-gi force-pushed the 2024-04-txorphan-fuzz branch 2 times, most recently from ec29dc4 to 0ab279e Compare April 30, 2024 17:20
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/24436241229

Adds the following fixups in txorphan fuzz tests:

- Don't bond the output count of the created orphans based on the number of available coins
- Allow duplicate inputs, when applicable, but don't store duplicate outpoints

Rationale
---------

The way the test is currently written, duplicate inputs are allowed based on a random flag (`duplicate_input`).
If the flag is unset, upon selecting an outpoint as input for a new transaction, the input is popped to prevent re-selection,
and later re-added to the collection (once all inputs have been picked). However, the re-addition to the collection is performed independently of whether the flag was set or not.
This means that, if the flag is set, the selected inputs are duplicated which in turn makes these inputs more likely to be re-picked in the following iteration of the loop.

Additionally, both the input and output count of the transaction and bonded to the number of available outpoints. This makes sense for the former, but the latter shouldn't be.
@sr-gi
Copy link
Member Author

sr-gi commented May 1, 2024

Updated the approach to get rid of duplicate_input altogether, simplifying the test and reducing the boilerplate when dealing with duplicate outpoints

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

ACK 58594c7

@DrahtBot DrahtBot requested a review from instagibbs May 1, 2024 18:07
Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

ACK 58594c7

ran fuzz for a while, no issues

src/test/fuzz/txorphan.cpp Show resolved Hide resolved
@sr-gi
Copy link
Member Author

sr-gi commented May 8, 2024

@maflcko would you mind taking a look at this (given you reviewed the original PR for this fuzz test)?

@maflcko
Copy link
Member

maflcko commented May 13, 2024

Additionally, both the input and output count of the transaction are bonded to the number of available outpoints. This makes sense for the former, but the latter shouldn't be.

IIRC this was done to start with a few outputs in the beginning, and increase the number of outputs as the size of the fuzz input increases. The hope is that the runtime is linear with the size of the fuzz input, and that minimizing a potential crash results in a transaction with less outputs. If you allow 256 in the first iteration, the minimizer may spit out a transaction with that many outputs.

However, I haven't benchmarked this. Should be fine either way.

utACK 58594c7

@glozow glozow merged commit ff8c606 into bitcoin:master May 13, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants