Skip to content

Conversation

@chinggg
Copy link
Contributor

@chinggg chinggg commented Jun 22, 2022

This adds a low-level fuzz target for orphan transaction handling by creating random transactions and calling all functions in TxOrphanage.
It cannot simulate real-world orphan/unorphan scenarios effectively since it does not maintain any state about the node and the chain. A high-level fuzz target which construct well-designed transaction graphs will be added later.

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.

nice

@chinggg chinggg changed the title fuzz: add low level target for txorphanage fuzz: add low-level target for txorphanage Jun 23, 2022
@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 29, 2022

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #25527 ([kernel 3c/n] Decouple validation cache initialization from ArgsManager by dongcarl)
  • #25324 (refactor: add most of src/util to iwyu by fanquake)
  • #25227 (Handle invalid hex encoding in ParseHex by MarcoFalke)
  • #25112 (util: Move error message formatting of NonFatalCheckError to cpp by MarcoFalke)
  • #24974 (refactor: Make FEELER_SLEEP_WINDOW type safe (std::chrono) by MarcoFalke)

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

Choose a reason for hiding this comment

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

nit: I think this is no longer needed?

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 2 * DEFAULT_MAX_ORPHAN_TRANSACTIONS)
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10 * DEFAULT_MAX_ORPHAN_TRANSACTIONS)

nit: I think this can be larger, unless it takes a long time?

Copy link
Contributor Author

@chinggg chinggg Jun 29, 2022

Choose a reason for hiding this comment

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

There are two LIMITED_WHILE loops in the file, the outer loop determines how many transactions can be constructed, and the inner loop (the one you suggested) determines how many times can TxOrphange methods be triggered. I am not sure about the exact value to be set. I think it can be bigger, though the probability of actually reaching the limit may be very low.

Copy link
Member

Choose a reason for hiding this comment

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

could assert that the return value of HaveTx is true here?

@chinggg chinggg force-pushed the fuzz-txorphan branch 2 times, most recently from 2ebb93d to a5b4de3 Compare June 29, 2022 16:29
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.

If you want you can submit fuzz inputs to the qa-assets repo

Copy link
Member

Choose a reason for hiding this comment

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

I think you'll need to use SetMockTime throughout the test to expire txs

Copy link
Member

Choose a reason for hiding this comment

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

Also there is a non-deterministic FastRandomContext in this function, but I guess it won't be possible to fix that without touching non-fuzz code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find most targets set mocktime at the beginning so I put it here. How can we achieve better coverage by controlling mocktime/expiry?

Copy link
Member

Choose a reason for hiding this comment

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

This will just set it once and keep it constant. To change it you'd have to set it in the loop below

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
FUZZ_TARGET_INIT(orphanage, initialize_orphanage)
FUZZ_TARGET_INIT(txorphanage, initialize_orphanage)

Maybe rename the file and target to txorphanage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. orphanage is not so explicit. But the source file has the same name txorphanage.cpp, is txorphan better?

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.

Approach ACK.

While the existing process_messages target can achieve line coverage in this module, it fails to generate any meaningful path/branch coverage. So it makes sense to add a "unit" fuzz test.

@maflcko
Copy link
Member

maflcko commented Jul 6, 2022

review ACK 6eb0909 🐈

Show signature

Signature:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

review ACK 6eb0909cb7d5883a258f76ad6cf2c989fc6f892f 🐈
-----BEGIN PGP SIGNATURE-----

iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUhrmAwAye+c8glh2rwa+Qreh97bToMj6AF9aCUG1yCSIc08TsEKPCDujBF8LgIx
10NMTZuUrqTclBHZcyi7Sjs7XXfCO/aRVRHm5eFa78LIWRIVsP7QHSYo18MehZ51
f+/iDkM6G3e4AjUMXRIzNKiHnt9DQj8gh/NgqCa4c2LelJtIMvntTjBjDymUQKgO
sVvyTYuKBKTLWJsqSOD6d76oOlZxsZx6dHXjQhmtfXaDxBX2SFC9h6+MulEDMGmq
aq402tH3uwLOpVmPbJ+qEXrrDLKrG+Fd1O3me15gB1Oy8kEh14gXVlLbHGBzmbCF
NB21clLX5JYmCbFgmfXHiAQBNhBhPzS8ELkgHuW9Mv52pLv+nu7832koD7WTe9yj
cphjGYKK3nxiZ9VtLtBA/nWMAJVybjXtXRRcut6Hjt70n3RirY27eezc8EYSNdXI
37DBKxQtnyIJf0ul+A+QsJuPKFpbZmwX7Ch1y2oWeZE6v9PCKbU9zM6SAUdyBq4R
3sHS9w5D
=Bf9G
-----END PGP SIGNATURE-----

@maflcko maflcko merged commit bac52a1 into bitcoin:master Jul 7, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 11, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jul 7, 2023
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.

3 participants