Skip to content

Commit 82b27ae

Browse files
MarcoFalkesidhujag
MarcoFalke
authored and
sidhujag
committed
Merge bitcoin#17917: tests: Add amount compression/decompression fuzzing to existing fuzzing harness
7e9c711 compressor: Make the domain of CompressAmount(...) explicit (practicalswift) 4a7fd7a tests: Add amount compression/decompression fuzzing to existing fuzzing harness: test compression round-trip (practicalswift) Pull request description: Small fuzzing improvement: Add amount compression/decompression fuzzing to existing fuzzing harness: test compression round-trip (`DecompressAmount(CompressAmount(…))`). Make the domain of `CompressAmount(…)` explicit. Amount compression primer: ``` Compact serialization for amounts Special serializer/deserializer for amount values. It is optimized for values which have few non-zero digits in decimal representation. Most amounts currently in the txout set take only 1 or 2 bytes to represent. ``` **How to test this PR** ``` $ make distclean $ ./autogen.sh $ CC=clang CXX=clang++ ./configure --enable-fuzz \ --with-sanitizers=address,fuzzer,undefined $ make $ src/test/fuzz/integer … ``` Top commit has no ACKs. Tree-SHA512: 0f7c05b97012ccd5cd05a96c209e6b4d7d2fa73138bac9615cf531baa3f614f9003e29a198015bcc083af9f5bdc752bb52615b82c5df3c519b1a064bd4fc6664
1 parent b16e14b commit 82b27ae

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/test/fuzz/integer.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <amount.h>
56
#include <arith_uint256.h>
67
#include <compressor.h>
78
#include <consensus/merkle.h>
@@ -56,7 +57,14 @@ void test_one_input(const std::vector<uint8_t>& buffer)
5657

5758
const Consensus::Params& consensus_params = Params().GetConsensus();
5859
(void)CheckProofOfWork(u256, u32, consensus_params);
59-
(void)CompressAmount(u64);
60+
if (u64 <= MAX_MONEY) {
61+
const uint64_t compressed_money_amount = CompressAmount(u64);
62+
assert(u64 == DecompressAmount(compressed_money_amount));
63+
static const uint64_t compressed_money_amount_max = CompressAmount(MAX_MONEY - 1);
64+
assert(compressed_money_amount <= compressed_money_amount_max);
65+
} else {
66+
(void)CompressAmount(u64);
67+
}
6068
static const uint256 u256_min(uint256S("0000000000000000000000000000000000000000000000000000000000000000"));
6169
static const uint256 u256_max(uint256S("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
6270
const std::vector<uint256> v256{u256, u256_min, u256_max};

0 commit comments

Comments
 (0)