Skip to content

Commit faaf395

Browse files
author
MarcoFalke
committed
fuzz: Extend psbt fuzz target a bit
1 parent 265a3a7 commit faaf395

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/test/fuzz/psbt.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <test/fuzz/FuzzedDataProvider.h>
56
#include <test/fuzz/fuzz.h>
67

78
#include <node/psbt.h>
89
#include <psbt.h>
910
#include <pubkey.h>
1011
#include <script/script.h>
1112
#include <streams.h>
13+
#include <util/check.h>
1214
#include <version.h>
1315

1416
#include <cstdint>
@@ -23,10 +25,10 @@ void initialize_psbt()
2325

2426
FUZZ_TARGET_INIT(psbt, initialize_psbt)
2527
{
28+
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
2629
PartiallySignedTransaction psbt_mut;
27-
const std::string raw_psbt{buffer.begin(), buffer.end()};
2830
std::string error;
29-
if (!DecodeRawPSBT(psbt_mut, raw_psbt, error)) {
31+
if (!DecodeRawPSBT(psbt_mut, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
3032
return;
3133
}
3234
const PartiallySignedTransaction psbt = psbt_mut;
@@ -49,6 +51,7 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
4951
(void)PSBTInputSigned(input);
5052
(void)input.IsNull();
5153
}
54+
(void)CountPSBTUnsignedInputs(psbt);
5255

5356
for (const PSBTOutput& output : psbt.outputs) {
5457
(void)output.IsNull();
@@ -71,6 +74,20 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
7174
const PartiallySignedTransaction psbt_from_tx{result};
7275
}
7376

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});
7485
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());
7693
}

0 commit comments

Comments
 (0)