diff options
Diffstat (limited to 'src/wallet/test/fuzz')
-rw-r--r-- | src/wallet/test/fuzz/CMakeLists.txt | 16 | ||||
-rw-r--r-- | src/wallet/test/fuzz/coinselection.cpp | 2 | ||||
-rw-r--r-- | src/wallet/test/fuzz/crypter.cpp | 10 | ||||
-rw-r--r-- | src/wallet/test/fuzz/notifications.cpp | 2 | ||||
-rw-r--r-- | src/wallet/test/fuzz/scriptpubkeyman.cpp | 11 | ||||
-rw-r--r-- | src/wallet/test/fuzz/wallet_bdb_parser.cpp | 15 |
6 files changed, 41 insertions, 15 deletions
diff --git a/src/wallet/test/fuzz/CMakeLists.txt b/src/wallet/test/fuzz/CMakeLists.txt new file mode 100644 index 0000000000..c30671db48 --- /dev/null +++ b/src/wallet/test/fuzz/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2023-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +target_sources(fuzz + PRIVATE + coincontrol.cpp + coinselection.cpp + crypter.cpp + fees.cpp + $<$<BOOL:${USE_SQLITE}>:${CMAKE_CURRENT_LIST_DIR}/notifications.cpp> + parse_iso8601.cpp + $<$<BOOL:${USE_SQLITE}>:${CMAKE_CURRENT_LIST_DIR}/scriptpubkeyman.cpp> + wallet_bdb_parser.cpp +) +target_link_libraries(fuzz bitcoin_wallet) diff --git a/src/wallet/test/fuzz/coinselection.cpp b/src/wallet/test/fuzz/coinselection.cpp index 209c87fd42..31fa00c0a2 100644 --- a/src/wallet/test/fuzz/coinselection.cpp +++ b/src/wallet/test/fuzz/coinselection.cpp @@ -252,7 +252,7 @@ FUZZ_TARGET(coinselection) GroupCoins(fuzzed_data_provider, utxo_pool, coin_params, /*positive_only=*/false, group_all); for (const OutputGroup& group : group_all) { - const CoinEligibilityFilter filter(fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()); + const CoinEligibilityFilter filter{fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeIntegral<int>(), fuzzed_data_provider.ConsumeIntegral<uint64_t>()}; (void)group.EligibleForSpending(filter); } diff --git a/src/wallet/test/fuzz/crypter.cpp b/src/wallet/test/fuzz/crypter.cpp index 4d6dd43c5f..7869f5f39c 100644 --- a/src/wallet/test/fuzz/crypter.cpp +++ b/src/wallet/test/fuzz/crypter.cpp @@ -35,11 +35,11 @@ FUZZ_TARGET(crypter, .init = initialize_crypter) const unsigned int derivation_method = fuzzed_data_provider.ConsumeBool() ? 0 : fuzzed_data_provider.ConsumeIntegral<unsigned int>(); - // Limiting the value of nRounds since it is otherwise uselessly expensive and causes a timeout when fuzzing. - crypt.SetKeyFromPassphrase(/*strKeyData=*/secure_string, - /*chSalt=*/ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_SALT_SIZE), - /*nRounds=*/fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 25000), - /*nDerivationMethod=*/derivation_method); + // Limiting the value of rounds since it is otherwise uselessly expensive and causes a timeout when fuzzing. + crypt.SetKeyFromPassphrase(/*key_data=*/secure_string, + /*salt=*/ConsumeFixedLengthByteVector(fuzzed_data_provider, WALLET_CRYPTO_SALT_SIZE), + /*rounds=*/fuzzed_data_provider.ConsumeIntegralInRange<unsigned int>(0, 25000), + /*derivation_method=*/derivation_method); } LIMITED_WHILE(good_data && fuzzed_data_provider.ConsumeBool(), 100) diff --git a/src/wallet/test/fuzz/notifications.cpp b/src/wallet/test/fuzz/notifications.cpp index 792079e6c6..a7015f6685 100644 --- a/src/wallet/test/fuzz/notifications.cpp +++ b/src/wallet/test/fuzz/notifications.cpp @@ -68,7 +68,7 @@ void ImportDescriptors(CWallet& wallet, const std::string& seed_insecure) FlatSigningProvider keys; std::string error; - auto parsed_desc = Parse(descriptor, keys, error, /*require_checksum=*/false); + auto parsed_desc = std::move(Parse(descriptor, keys, error, /*require_checksum=*/false).at(0)); assert(parsed_desc); assert(error.empty()); assert(parsed_desc->IsRange()); diff --git a/src/wallet/test/fuzz/scriptpubkeyman.cpp b/src/wallet/test/fuzz/scriptpubkeyman.cpp index 315efa0dca..091d42f6cf 100644 --- a/src/wallet/test/fuzz/scriptpubkeyman.cpp +++ b/src/wallet/test/fuzz/scriptpubkeyman.cpp @@ -69,10 +69,10 @@ static std::optional<std::pair<WalletDescriptor, FlatSigningProvider>> CreateWal FlatSigningProvider keys; std::string error; - std::unique_ptr<Descriptor> parsed_desc{Parse(desc_str.value(), keys, error, false)}; - if (!parsed_desc) return std::nullopt; + std::vector<std::unique_ptr<Descriptor>> parsed_descs = Parse(desc_str.value(), keys, error, false); + if (parsed_descs.empty()) return std::nullopt; - WalletDescriptor w_desc{std::move(parsed_desc), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/1, /*next_index=*/1}; + WalletDescriptor w_desc{std::move(parsed_descs.at(0)), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/1, /*next_index=*/1}; return std::make_pair(w_desc, keys); } @@ -186,7 +186,10 @@ FUZZ_TARGET(scriptpubkeyman, .init = initialize_spkm) auto psbt{*opt_psbt}; const PrecomputedTransactionData txdata{PrecomputePSBTData(psbt)}; const int sighash_type{fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 150)}; - (void)spk_manager->FillPSBT(psbt, txdata, sighash_type, fuzzed_data_provider.ConsumeBool(), fuzzed_data_provider.ConsumeBool(), nullptr, fuzzed_data_provider.ConsumeBool()); + auto sign = fuzzed_data_provider.ConsumeBool(); + auto bip32derivs = fuzzed_data_provider.ConsumeBool(); + auto finalize = fuzzed_data_provider.ConsumeBool(); + (void)spk_manager->FillPSBT(psbt, txdata, sighash_type, sign, bip32derivs, nullptr, finalize); } ); } diff --git a/src/wallet/test/fuzz/wallet_bdb_parser.cpp b/src/wallet/test/fuzz/wallet_bdb_parser.cpp index 6fbd695fc5..5ec24faede 100644 --- a/src/wallet/test/fuzz/wallet_bdb_parser.cpp +++ b/src/wallet/test/fuzz/wallet_bdb_parser.cpp @@ -18,6 +18,13 @@ #include <fstream> #include <iostream> +// There is an inconsistency in BDB on Windows. +// See: https://github.com/bitcoin/bitcoin/pull/26606#issuecomment-2322763212 +#undef USE_BDB_NON_MSVC +#if defined(USE_BDB) && !defined(_MSC_VER) +#define USE_BDB_NON_MSVC +#endif + using wallet::DatabaseOptions; using wallet::DatabaseStatus; @@ -50,7 +57,7 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser) } g_setup->m_args.ForceSetArg("-dumpfile", fs::PathToString(bdb_ro_dumpfile)); -#ifdef USE_BDB +#ifdef USE_BDB_NON_MSVC bool bdb_ro_err = false; bool bdb_ro_strict_err = false; #endif @@ -58,7 +65,7 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser) if (db) { assert(DumpWallet(g_setup->m_args, *db, error)); } else { -#ifdef USE_BDB +#ifdef USE_BDB_NON_MSVC bdb_ro_err = true; #endif if (error.original.starts_with("AutoFile::ignore: end of file") || @@ -90,7 +97,7 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser) error.original == "Subdatabase has an unexpected name" || error.original == "Unsupported BDB data file version number" || error.original == "BDB builtin encryption is not supported") { -#ifdef USE_BDB +#ifdef USE_BDB_NON_MSVC bdb_ro_strict_err = true; #endif } else { @@ -98,7 +105,7 @@ FUZZ_TARGET(wallet_bdb_parser, .init = initialize_wallet_bdb_parser) } } -#ifdef USE_BDB +#ifdef USE_BDB_NON_MSVC // Try opening with BDB fs::path bdb_dumpfile{g_setup->m_args.GetDataDirNet() / "fuzzed_dumpfile_bdb.dump"}; if (fs::exists(bdb_dumpfile)) { // Writing into an existing dump file will throw an exception |