diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-04-05 17:29:19 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-04-09 13:17:37 +0200 |
commit | faaf3954e2f0089b6c6b9965f15e7f9af09c6fb0 (patch) | |
tree | c74251aa4abb98fbabee9c582808bd4ad849152c /src/test/fuzz/psbt.cpp | |
parent | 265a3a774b35449c3eec79c61825b7a073d78166 (diff) |
fuzz: Extend psbt fuzz target a bit
Diffstat (limited to 'src/test/fuzz/psbt.cpp')
-rw-r--r-- | src/test/fuzz/psbt.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/test/fuzz/psbt.cpp b/src/test/fuzz/psbt.cpp index d1cc6f9c7e..6c62dd6e48 100644 --- a/src/test/fuzz/psbt.cpp +++ b/src/test/fuzz/psbt.cpp @@ -2,6 +2,7 @@ // 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> @@ -9,6 +10,7 @@ #include <pubkey.h> #include <script/script.h> #include <streams.h> +#include <util/check.h> #include <version.h> #include <cstdint> @@ -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; @@ -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(); @@ -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()); } |