Skip to content

Commit

Permalink
fuzz: Extend psbt fuzz target a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoFalke committed Apr 9, 2021
1 parent 265a3a7 commit faaf395
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/test/fuzz/psbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <test/fuzz/FuzzedDataProvider.h>
#include <test/fuzz/fuzz.h>

#include <node/psbt.h>
#include <psbt.h>
#include <pubkey.h>
#include <script/script.h>
#include <streams.h>
#include <util/check.h>
#include <version.h>

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

FUZZ_TARGET_INIT(psbt, initialize_psbt)
{
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
PartiallySignedTransaction psbt_mut;
const std::string raw_psbt{buffer.begin(), buffer.end()};
std::string error;
if (!DecodeRawPSBT(psbt_mut, raw_psbt, error)) {
if (!DecodeRawPSBT(psbt_mut, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
return;
}
const PartiallySignedTransaction psbt = psbt_mut;
Expand All @@ -49,6 +51,7 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
(void)PSBTInputSigned(input);
(void)input.IsNull();
}
(void)CountPSBTUnsignedInputs(psbt);

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

PartiallySignedTransaction psbt_merge;
if (!DecodeRawPSBT(psbt_merge, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
psbt_merge = psbt;
}
psbt_mut = psbt;
(void)psbt_mut.Merge(psbt_merge);
psbt_mut = psbt;
(void)CombinePSBTs(psbt_mut, {psbt_mut, psbt_merge});
psbt_mut = psbt;
(void)psbt_mut.Merge(psbt);
for (unsigned int i = 0; i < psbt_merge.tx->vin.size(); ++i) {
(void)psbt_mut.AddInput(psbt_merge.tx->vin[i], psbt_merge.inputs[i]);
}
for (unsigned int i = 0; i < psbt_merge.tx->vout.size(); ++i) {
Assert(psbt_mut.AddOutput(psbt_merge.tx->vout[i], psbt_merge.outputs[i]));
}
psbt_mut.unknown.insert(psbt_merge.unknown.begin(), psbt_merge.unknown.end());
}

0 comments on commit faaf395

Please sign in to comment.