|
2 | 2 | // Distributed under the MIT software license, see the accompanying
|
3 | 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
4 | 4 |
|
5 |
| -#include <chainparams.h> |
6 |
| -#include <key.h> |
| 5 | +#include <consensus/amount.h> |
| 6 | +#include <primitives/transaction.h> |
7 | 7 | #include <pubkey.h>
|
| 8 | +#include <script/interpreter.h> |
8 | 9 | #include <script/sigcache.h>
|
| 10 | +#include <span.h> |
9 | 11 | #include <test/fuzz/FuzzedDataProvider.h>
|
10 | 12 | #include <test/fuzz/fuzz.h>
|
11 | 13 | #include <test/fuzz/util.h>
|
12 | 14 | #include <test/util/setup_common.h>
|
| 15 | +#include <uint256.h> |
13 | 16 |
|
14 |
| -#include <cstdint> |
| 17 | +#include <cstddef> |
15 | 18 | #include <optional>
|
16 |
| -#include <string> |
17 | 19 | #include <vector>
|
18 | 20 |
|
19 |
| -namespace { |
20 |
| -const BasicTestingSetup* g_setup; |
21 |
| -SignatureCache* g_signature_cache; |
22 |
| -} // namespace |
23 |
| - |
24 | 21 | void initialize_script_sigcache()
|
25 | 22 | {
|
26 | 23 | static const auto testing_setup = MakeNoLogFileContext<>();
|
27 |
| - static SignatureCache signature_cache{DEFAULT_SIGNATURE_CACHE_BYTES}; |
28 |
| - g_setup = testing_setup.get(); |
29 |
| - g_signature_cache = &signature_cache; |
30 | 24 | }
|
31 | 25 |
|
32 | 26 | FUZZ_TARGET(script_sigcache, .init = initialize_script_sigcache)
|
33 | 27 | {
|
34 | 28 | FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
35 | 29 |
|
| 30 | + const auto max_sigcache_bytes{fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, DEFAULT_SIGNATURE_CACHE_BYTES)}; |
| 31 | + SignatureCache signature_cache{max_sigcache_bytes}; |
| 32 | + |
36 | 33 | const std::optional<CMutableTransaction> mutable_transaction = ConsumeDeserializable<CMutableTransaction>(fuzzed_data_provider, TX_WITH_WITNESS);
|
37 | 34 | const CTransaction tx{mutable_transaction ? *mutable_transaction : CMutableTransaction{}};
|
38 | 35 | const unsigned int n_in = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
|
39 | 36 | const CAmount amount = ConsumeMoney(fuzzed_data_provider);
|
40 | 37 | const bool store = fuzzed_data_provider.ConsumeBool();
|
41 | 38 | PrecomputedTransactionData tx_data;
|
42 |
| - CachingTransactionSignatureChecker caching_transaction_signature_checker{mutable_transaction ? &tx : nullptr, n_in, amount, store, *g_signature_cache, tx_data}; |
| 39 | + CachingTransactionSignatureChecker caching_transaction_signature_checker{mutable_transaction ? &tx : nullptr, n_in, amount, store, signature_cache, tx_data}; |
43 | 40 | if (fuzzed_data_provider.ConsumeBool()) {
|
44 | 41 | const auto random_bytes = fuzzed_data_provider.ConsumeBytes<unsigned char>(64);
|
45 | 42 | const XOnlyPubKey pub_key(ConsumeUInt256(fuzzed_data_provider));
|
|
0 commit comments