Branch data Line data Source code
1 : : // Copyright (c) 2020-present 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 <pubkey.h>
6 : : #include <script/descriptor.h>
7 : : #include <streams.h>
8 : : #include <test/fuzz/FuzzedDataProvider.h>
9 : : #include <test/fuzz/fuzz.h>
10 : : #include <test/fuzz/util.h>
11 : :
12 : : #include <cstdint>
13 : : #include <optional>
14 : : #include <string>
15 : : #include <vector>
16 : :
17 [ + - ]: 599 : FUZZ_TARGET(script_descriptor_cache)
18 : : {
19 : 123 : FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
20 : 123 : DescriptorCache descriptor_cache;
21 [ + + + + ]: 50650 : LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 10000) {
22 [ + - ]: 50527 : const std::vector<uint8_t> code = fuzzed_data_provider.ConsumeBytes<uint8_t>(BIP32_EXTKEY_SIZE);
23 [ - + + + ]: 50527 : if (code.size() == BIP32_EXTKEY_SIZE) {
24 : 50481 : CExtPubKey xpub;
25 [ + - ]: 50481 : SpanReader{code} >> xpub;
26 : 50481 : const uint32_t key_exp_pos = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
27 : 50481 : CExtPubKey xpub_fetched;
28 [ + + ]: 50481 : if (fuzzed_data_provider.ConsumeBool()) {
29 [ + - ]: 46076 : (void)descriptor_cache.GetCachedParentExtPubKey(key_exp_pos, xpub_fetched);
30 [ + - ]: 46076 : descriptor_cache.CacheParentExtPubKey(key_exp_pos, xpub);
31 [ + - - + ]: 46076 : assert(descriptor_cache.GetCachedParentExtPubKey(key_exp_pos, xpub_fetched));
32 : : } else {
33 : 4405 : const uint32_t der_index = fuzzed_data_provider.ConsumeIntegral<uint32_t>();
34 [ + - ]: 4405 : (void)descriptor_cache.GetCachedDerivedExtPubKey(key_exp_pos, der_index, xpub_fetched);
35 [ + - ]: 4405 : descriptor_cache.CacheDerivedExtPubKey(key_exp_pos, der_index, xpub);
36 [ + - - + ]: 4405 : assert(descriptor_cache.GetCachedDerivedExtPubKey(key_exp_pos, der_index, xpub_fetched));
37 : : }
38 [ - + ]: 50481 : assert(xpub == xpub_fetched);
39 : 50481 : }
40 [ + - ]: 50527 : (void)descriptor_cache.GetCachedParentExtPubKeys();
41 [ + - ]: 101054 : (void)descriptor_cache.GetCachedDerivedExtPubKeys();
42 : 50527 : }
43 : 123 : }
|