mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-03 01:33:20 +02:00
Merge #19055: Add MuHash3072 implementation
9815332d51test: Change MuHash Python implementation to match cpp version again (Fabian Jahr)01297fb3cafuzz: Add MuHash consistency fuzz test (Fabian Jahr)b111410914test: Add MuHash3072 fuzz test (Fabian Jahr)c122527385bench: Add Muhash benchmarks (Fabian Jahr)7b1242229dtest: Add MuHash3072 unit tests (Fabian Jahr)adc708c98dcrypto: Add MuHash3072 implementation (Fabian Jahr)0b4d290bf5crypto: Add Num3072 implementation (Fabian Jahr)589f958662build: Check for 128 bit integer support (Fabian Jahr) Pull request description: This is the first split of #18000 which implements the Muhash algorithm and uses it to calculate the UTXO set hash in `gettxoutsetinfo`. ACKs for top commit: laanwj: Code review ACK9815332d51Tree-SHA512: 4bc090738f0e3d80b74bdd8122e24a8ce80121120fd37c7e4335a73e7ba4fcd7643f2a2d559e2eebf54b8e3a3bd5f12cfb27ba61ded135fda210a07a233eae45
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <crypto/hmac_sha256.h>
|
||||
#include <crypto/hmac_sha512.h>
|
||||
#include <crypto/muhash.h>
|
||||
#include <crypto/ripemd160.h>
|
||||
#include <crypto/sha1.h>
|
||||
#include <crypto/sha256.h>
|
||||
@@ -35,6 +36,7 @@ FUZZ_TARGET(crypto)
|
||||
CSHA512 sha512;
|
||||
SHA3_256 sha3;
|
||||
CSipHasher sip_hasher{fuzzed_data_provider.ConsumeIntegral<uint64_t>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()};
|
||||
MuHash3072 muhash;
|
||||
|
||||
while (fuzzed_data_provider.ConsumeBool()) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 2)) {
|
||||
@@ -60,6 +62,12 @@ FUZZ_TARGET(crypto)
|
||||
(void)Hash(data);
|
||||
(void)Hash160(data);
|
||||
(void)sha512.Size();
|
||||
|
||||
if (fuzzed_data_provider.ConsumeBool()) {
|
||||
muhash *= MuHash3072(data);
|
||||
} else {
|
||||
muhash /= MuHash3072(data);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
@@ -70,10 +78,11 @@ FUZZ_TARGET(crypto)
|
||||
(void)sha256.Reset();
|
||||
(void)sha3.Reset();
|
||||
(void)sha512.Reset();
|
||||
muhash = MuHash3072();
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 9)) {
|
||||
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 10)) {
|
||||
case 0: {
|
||||
data.resize(CHash160::OUTPUT_SIZE);
|
||||
hash160.Finalize(data);
|
||||
@@ -124,6 +133,11 @@ FUZZ_TARGET(crypto)
|
||||
sha3.Finalize(data);
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
uint256 out;
|
||||
muhash.Finalize(out);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
53
src/test/fuzz/muhash.cpp
Normal file
53
src/test/fuzz/muhash.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) 2020 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <crypto/muhash.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
std::vector<uint8_t> data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
std::vector<uint8_t> data2 = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
if (data.empty()) {
|
||||
data.resize(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 4096), fuzzed_data_provider.ConsumeIntegral<uint8_t>());
|
||||
}
|
||||
if (data2.empty()) {
|
||||
data2.resize(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(1, 4096), fuzzed_data_provider.ConsumeIntegral<uint8_t>());
|
||||
}
|
||||
|
||||
data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
data2 = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||
|
||||
MuHash3072 muhash;
|
||||
|
||||
// Test that MuHash result is consistent independent of order of operations
|
||||
muhash.Insert(data);
|
||||
muhash.Insert(data2);
|
||||
|
||||
uint256 out;
|
||||
muhash.Finalize(out);
|
||||
|
||||
muhash = MuHash3072();
|
||||
muhash.Insert(data2);
|
||||
muhash.Insert(data);
|
||||
|
||||
uint256 out2;
|
||||
muhash.Finalize(out2);
|
||||
|
||||
assert(out == out2);
|
||||
|
||||
// Test that removing all added elements brings the object back to it's initial state
|
||||
muhash /= muhash;
|
||||
muhash.Finalize(out);
|
||||
|
||||
MuHash3072 muhash2;
|
||||
muhash2.Finalize(out2);
|
||||
|
||||
assert(out == out2);
|
||||
}
|
||||
Reference in New Issue
Block a user