Skip to content

Commit b6a71b8

Browse files
committed
Merge #19055: Add MuHash3072 implementation
9815332 test: Change MuHash Python implementation to match cpp version again (Fabian Jahr) 01297fb fuzz: Add MuHash consistency fuzz test (Fabian Jahr) b111410 test: Add MuHash3072 fuzz test (Fabian Jahr) c122527 bench: Add Muhash benchmarks (Fabian Jahr) 7b12422 test: Add MuHash3072 unit tests (Fabian Jahr) adc708c crypto: Add MuHash3072 implementation (Fabian Jahr) 0b4d290 crypto: Add Num3072 implementation (Fabian Jahr) 589f958 build: 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 ACK 9815332 Tree-SHA512: 4bc090738f0e3d80b74bdd8122e24a8ce80121120fd37c7e4335a73e7ba4fcd7643f2a2d559e2eebf54b8e3a3bd5f12cfb27ba61ded135fda210a07a233eae45
2 parents 3a6acd1 + 9815332 commit b6a71b8

File tree

10 files changed

+694
-7
lines changed

10 files changed

+694
-7
lines changed

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,9 @@ if test x$use_lcov_branch != xno; then
753753
AC_SUBST(LCOV_OPTS, "$LCOV_OPTS --rc lcov_branch_coverage=1")
754754
fi
755755

756+
dnl Check for __int128
757+
AC_CHECK_TYPES([__int128])
758+
756759
dnl Check for endianness
757760
AC_C_BIGENDIAN
758761

src/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ crypto_libbitcoin_crypto_base_a_SOURCES = \
408408
crypto/hmac_sha512.h \
409409
crypto/poly1305.h \
410410
crypto/poly1305.cpp \
411+
crypto/muhash.h \
412+
crypto/muhash.cpp \
411413
crypto/ripemd160.cpp \
412414
crypto/ripemd160.h \
413415
crypto/sha1.cpp \

src/Makefile.test.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ test_fuzz_fuzz_SOURCES = \
230230
test/fuzz/locale.cpp \
231231
test/fuzz/merkleblock.cpp \
232232
test/fuzz/message.cpp \
233+
test/fuzz/muhash.cpp \
233234
test/fuzz/multiplication_overflow.cpp \
234235
test/fuzz/net.cpp \
235236
test/fuzz/net_permissions.cpp \

src/bench/crypto_hash.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
#include <bench/bench.h>
7+
#include <crypto/muhash.h>
78
#include <crypto/ripemd160.h>
89
#include <crypto/sha1.h>
910
#include <crypto/sha256.h>
@@ -105,6 +106,54 @@ static void FastRandom_1bit(benchmark::Bench& bench)
105106
});
106107
}
107108

109+
static void MuHash(benchmark::Bench& bench)
110+
{
111+
MuHash3072 acc;
112+
unsigned char key[32] = {0};
113+
int i = 0;
114+
bench.run([&] {
115+
key[0] = ++i;
116+
acc *= MuHash3072(key);
117+
});
118+
}
119+
120+
static void MuHashMul(benchmark::Bench& bench)
121+
{
122+
MuHash3072 acc;
123+
FastRandomContext rng(true);
124+
MuHash3072 muhash{rng.randbytes(32)};
125+
126+
bench.run([&] {
127+
acc *= muhash;
128+
});
129+
}
130+
131+
static void MuHashDiv(benchmark::Bench& bench)
132+
{
133+
MuHash3072 acc;
134+
FastRandomContext rng(true);
135+
MuHash3072 muhash{rng.randbytes(32)};
136+
137+
for (size_t i = 0; i < bench.epochIterations(); ++i) {
138+
acc *= muhash;
139+
}
140+
141+
bench.run([&] {
142+
acc /= muhash;
143+
});
144+
}
145+
146+
static void MuHashPrecompute(benchmark::Bench& bench)
147+
{
148+
MuHash3072 acc;
149+
FastRandomContext rng(true);
150+
std::vector<unsigned char> key{rng.randbytes(32)};
151+
152+
bench.run([&] {
153+
MuHash3072{key};
154+
});
155+
}
156+
108157
BENCHMARK(RIPEMD160);
109158
BENCHMARK(SHA1);
110159
BENCHMARK(SHA256);
@@ -116,3 +165,8 @@ BENCHMARK(SipHash_32b);
116165
BENCHMARK(SHA256D64_1024);
117166
BENCHMARK(FastRandom_32bit);
118167
BENCHMARK(FastRandom_1bit);
168+
169+
BENCHMARK(MuHash);
170+
BENCHMARK(MuHashMul);
171+
BENCHMARK(MuHashDiv);
172+
BENCHMARK(MuHashPrecompute);

0 commit comments

Comments
 (0)