Skip to content

Commit 347dd76

Browse files
author
MarcoFalke
committed
Merge #17093: tests: Add fuzzing harness for various CTx{In,Out} related functions
d5766f2 tests: Add corpora suppression (FUZZERS_MISSING_CORPORA) for fuzzers missing in https://github.com/bitcoin-core/qa-assets/tree/master/fuzz_seed_corpus (practicalswift) e75ecb9 tests: Add fuzzing harness for various CTxOut related functions (practicalswift) ce93529 tests: Add fuzzing harness for various CTxIn related functions (practicalswift) Pull request description: Add fuzzing harness for various `CTx{In,Out}` related functions. **Testing this PR** Run: ``` $ CC=clang CXX=clang++ ./configure --enable-fuzz --with-sanitizers=address,fuzzer,undefined $ make $ src/test/fuzz/tx_in … $ src/test/fuzz/tx_out … # And to to quickly verify that the relevant code regions are triggered, that the # fuzzing throughput seems reasonable, etc. $ contrib/devtools/test_fuzzing_harnesses.sh '^tx_' ``` `test_fuzzing_harnesses.sh` can be found in PR #17000. Top commit has no ACKs. Tree-SHA512: f1374307a2581ebc3968d012ea2438061bbb84ece068e584fae9750669a6cd003723dde14db88e77c9579281ecd4eaa2a7ff0614f253d8c075e6dd16dd2e68d5
2 parents 74c6ad3 + d5766f2 commit 347dd76

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

src/Makefile.test.include

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ FUZZ_TARGETS = \
4747
test/fuzz/spanparsing \
4848
test/fuzz/sub_net_deserialize \
4949
test/fuzz/transaction \
50+
test/fuzz/tx_in \
5051
test/fuzz/tx_in_deserialize \
52+
test/fuzz/tx_out \
5153
test/fuzz/txoutcompressor_deserialize \
5254
test/fuzz/txundo_deserialize
5355

@@ -497,6 +499,18 @@ test_fuzz_tx_in_deserialize_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
497499
test_fuzz_tx_in_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
498500
test_fuzz_tx_in_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
499501

502+
test_fuzz_tx_in_SOURCES = $(FUZZ_SUITE) test/fuzz/tx_in.cpp
503+
test_fuzz_tx_in_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
504+
test_fuzz_tx_in_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
505+
test_fuzz_tx_in_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
506+
test_fuzz_tx_in_LDADD = $(FUZZ_SUITE_LD_COMMON)
507+
508+
test_fuzz_tx_out_SOURCES = $(FUZZ_SUITE) test/fuzz/tx_out.cpp
509+
test_fuzz_tx_out_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
510+
test_fuzz_tx_out_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
511+
test_fuzz_tx_out_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
512+
test_fuzz_tx_out_LDADD = $(FUZZ_SUITE_LD_COMMON)
513+
500514
endif # ENABLE_FUZZ
501515

502516
nodist_test_test_bitcoin_SOURCES = $(GENERATED_TEST_FILES)

src/test/fuzz/tx_in.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <consensus/validation.h>
6+
#include <core_memusage.h>
7+
#include <policy/policy.h>
8+
#include <primitives/transaction.h>
9+
#include <streams.h>
10+
#include <test/fuzz/fuzz.h>
11+
#include <version.h>
12+
13+
#include <cassert>
14+
15+
void test_one_input(const std::vector<uint8_t>& buffer)
16+
{
17+
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
18+
CTxIn tx_in;
19+
try {
20+
int version;
21+
ds >> version;
22+
ds.SetVersion(version);
23+
ds >> tx_in;
24+
} catch (const std::ios_base::failure&) {
25+
return;
26+
}
27+
28+
(void)GetTransactionInputWeight(tx_in);
29+
(void)GetVirtualTransactionInputSize(tx_in);
30+
(void)RecursiveDynamicUsage(tx_in);
31+
32+
(void)tx_in.ToString();
33+
}

src/test/fuzz/tx_out.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2019 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <consensus/validation.h>
6+
#include <core_memusage.h>
7+
#include <policy/policy.h>
8+
#include <primitives/transaction.h>
9+
#include <streams.h>
10+
#include <test/fuzz/fuzz.h>
11+
#include <version.h>
12+
13+
void test_one_input(const std::vector<uint8_t>& buffer)
14+
{
15+
CDataStream ds(buffer, SER_NETWORK, INIT_PROTO_VERSION);
16+
CTxOut tx_out;
17+
try {
18+
int version;
19+
ds >> version;
20+
ds.SetVersion(version);
21+
ds >> tx_out;
22+
} catch (const std::ios_base::failure&) {
23+
return;
24+
}
25+
26+
const CFeeRate dust_relay_fee{DUST_RELAY_TX_FEE};
27+
(void)GetDustThreshold(tx_out, dust_relay_fee);
28+
(void)IsDust(tx_out, dust_relay_fee);
29+
(void)RecursiveDynamicUsage(tx_out);
30+
31+
(void)tx_out.ToString();
32+
(void)tx_out.IsNull();
33+
tx_out.SetNull();
34+
assert(tx_out.IsNull());
35+
}

test/fuzz/test_runner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"script_deserialize",
3333
"sub_net_deserialize",
3434
"tx_in_deserialize",
35+
"tx_in",
36+
"tx_out",
3537
]
3638

3739
def main():

0 commit comments

Comments
 (0)