Repository navigation
Conversation
MuHash3072::operator/= multiplies the numerator by div's denominator and then the denominator by div's numerator. If div aliases *this, the first step has already changed m_numerator, so the second step uses the wrong value and x /= x does not give the empty set. Copy div's numerator before the first multiplication. Extend the unit test and the fuzz target (which only divided an object whose denominator was still 1) to cover self-division with a non-trivial denominator.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of bitcoin#36286.
MuHash3072::operator/=gives a wrong result when the divisor is the object itself (x /= x). Base:58398baf33(upstream/29.x-knots).Problem
src/crypto/muhash.cpp:569: the firstMultiplychangesm_numerator, and the second readsdiv.m_numerator, which is the same object. Forx = N/Dthe result isN·D / (D·N·D) = 1/Dinstead of1. It is only correct whenD = 1.Reach: production code (coinstats, coinstatsindex,
gettxoutsetinfo) only callsInsertandRemove. Nothing in the node calls/=or*=. This is a latent library bug, found by tests and fuzzing, with no effect on UTXO set hashes.Reproduction
Add the test hunks from this PR without the
muhash.cppchange, then runbuild/bin/test_bitcoin --run_test=crypto_tests/muhash_tests.Fuzz: configure with
-DBUILD_FOR_FUZZING=ON, buildfuzz, runFUZZ=muhash build_ff/bin/fuzz <files>. I used 300 random seed files because no qa-assets corpus was available, and built with gcc, not libFuzzer.Before
The original fuzz target (without the added
Remove) passes the same 300 files.Change
Plus Core's test changes in
src/test/crypto_tests.cpp(+6) andsrc/test/fuzz/muhash.cpp(+3). They applied unchanged from Core.After
muhash_testspasses. Fuzz:muhash: succeeded against 300 files.Test results
58398baf33plus this change.--extended: 359 tests, 295 passed, 64 skipped, 0 failed.Caveats