mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
Merge #21606: fuzz: Extend psbt fuzz target a bit
faaf3954e2
fuzz: Extend psbt fuzz target a bit (MarcoFalke) Pull request description: Previously it only merged the psbt with itself, now it tries to merge another. ACKs for top commit: practicalswift: Tested ACKfaaf3954e2
Tree-SHA512: e1b1d31a47d35e1767285bc2fda176c79cb0550d6d383fe467104272e61e1c83f6cbc0c7d6bbc0c3027729eec13ae1f289f8950117ee91e0fb3703e66d5e6918
This commit is contained in:
commit
f0fa32450e
@ -2,6 +2,7 @@
|
|||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
|
|
||||||
#include <node/psbt.h>
|
#include <node/psbt.h>
|
||||||
@ -9,6 +10,7 @@
|
|||||||
#include <pubkey.h>
|
#include <pubkey.h>
|
||||||
#include <script/script.h>
|
#include <script/script.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
|
#include <util/check.h>
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
@ -23,10 +25,10 @@ void initialize_psbt()
|
|||||||
|
|
||||||
FUZZ_TARGET_INIT(psbt, initialize_psbt)
|
FUZZ_TARGET_INIT(psbt, initialize_psbt)
|
||||||
{
|
{
|
||||||
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||||
PartiallySignedTransaction psbt_mut;
|
PartiallySignedTransaction psbt_mut;
|
||||||
const std::string raw_psbt{buffer.begin(), buffer.end()};
|
|
||||||
std::string error;
|
std::string error;
|
||||||
if (!DecodeRawPSBT(psbt_mut, raw_psbt, error)) {
|
if (!DecodeRawPSBT(psbt_mut, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const PartiallySignedTransaction psbt = psbt_mut;
|
const PartiallySignedTransaction psbt = psbt_mut;
|
||||||
@ -49,6 +51,7 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
|
|||||||
(void)PSBTInputSigned(input);
|
(void)PSBTInputSigned(input);
|
||||||
(void)input.IsNull();
|
(void)input.IsNull();
|
||||||
}
|
}
|
||||||
|
(void)CountPSBTUnsignedInputs(psbt);
|
||||||
|
|
||||||
for (const PSBTOutput& output : psbt.outputs) {
|
for (const PSBTOutput& output : psbt.outputs) {
|
||||||
(void)output.IsNull();
|
(void)output.IsNull();
|
||||||
@ -71,6 +74,20 @@ FUZZ_TARGET_INIT(psbt, initialize_psbt)
|
|||||||
const PartiallySignedTransaction psbt_from_tx{result};
|
const PartiallySignedTransaction psbt_from_tx{result};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PartiallySignedTransaction psbt_merge;
|
||||||
|
if (!DecodeRawPSBT(psbt_merge, fuzzed_data_provider.ConsumeRandomLengthString(), error)) {
|
||||||
|
psbt_merge = psbt;
|
||||||
|
}
|
||||||
psbt_mut = psbt;
|
psbt_mut = psbt;
|
||||||
(void)psbt_mut.Merge(psbt);
|
(void)psbt_mut.Merge(psbt_merge);
|
||||||
|
psbt_mut = psbt;
|
||||||
|
(void)CombinePSBTs(psbt_mut, {psbt_mut, psbt_merge});
|
||||||
|
psbt_mut = 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());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user