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 < test/fuzz/FuzzedDataProvider.h>
5
6
#include < test/fuzz/fuzz.h>
6
7
7
8
#include < node/psbt.h>
8
9
#include < psbt.h>
9
10
#include < pubkey.h>
10
11
#include < script/script.h>
11
12
#include < streams.h>
13
+ #include < util/check.h>
12
14
#include < version.h>
13
15
14
16
#include < cstdint>
@@ -23,10 +25,10 @@ void initialize_psbt()
23
25
24
26
FUZZ_TARGET_INIT (psbt, initialize_psbt)
25
27
{
28
+ FuzzedDataProvider fuzzed_data_provider{buffer.data (), buffer.size ()};
26
29
PartiallySignedTransaction psbt_mut;
27
- const std::string raw_psbt{buffer.begin (), buffer.end ()};
28
30
std::string error;
29
- if (!DecodeRawPSBT (psbt_mut, raw_psbt , error)) {
31
+ if (!DecodeRawPSBT (psbt_mut, fuzzed_data_provider. ConsumeRandomLengthString () , error)) {
30
32
return ;
31
33
}
32
34
const PartiallySignedTransaction psbt = psbt_mut;
@@ -49,6 +51,7 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
49
51
(void )PSBTInputSigned (input);
50
52
(void )input.IsNull ();
51
53
}
54
+ (void )CountPSBTUnsignedInputs (psbt);
52
55
53
56
for (const PSBTOutput& output : psbt.outputs ) {
54
57
(void )output.IsNull ();
@@ -71,6 +74,20 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
71
74
const PartiallySignedTransaction psbt_from_tx{result};
72
75
}
73
76
77
+ PartiallySignedTransaction psbt_merge;
78
+ if (!DecodeRawPSBT (psbt_merge, fuzzed_data_provider.ConsumeRandomLengthString (), error)) {
79
+ psbt_merge = psbt;
80
+ }
81
+ psbt_mut = psbt;
82
+ (void )psbt_mut.Merge (psbt_merge);
83
+ psbt_mut = psbt;
84
+ (void )CombinePSBTs (psbt_mut, {psbt_mut, psbt_merge});
74
85
psbt_mut = psbt;
75
- (void )psbt_mut.Merge (psbt);
86
+ for (unsigned int i = 0 ; i < psbt_merge.tx ->vin .size (); ++i) {
87
+ (void )psbt_mut.AddInput (psbt_merge.tx ->vin [i], psbt_merge.inputs [i]);
88
+ }
89
+ for (unsigned int i = 0 ; i < psbt_merge.tx ->vout .size (); ++i) {
90
+ Assert (psbt_mut.AddOutput (psbt_merge.tx ->vout [i], psbt_merge.outputs [i]));
91
+ }
92
+ psbt_mut.unknown .insert (psbt_merge.unknown .begin (), psbt_merge.unknown .end ());
76
93
}
0 commit comments