|
| 1 | +// Copyright (c) 2019 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include <test/fuzz/fuzz.h> |
| 6 | + |
| 7 | +#include <node/psbt.h> |
| 8 | +#include <optional.h> |
| 9 | +#include <psbt.h> |
| 10 | +#include <pubkey.h> |
| 11 | +#include <script/script.h> |
| 12 | +#include <streams.h> |
| 13 | +#include <util/memory.h> |
| 14 | +#include <version.h> |
| 15 | + |
| 16 | +#include <cstdint> |
| 17 | +#include <string> |
| 18 | +#include <vector> |
| 19 | + |
| 20 | +void initialize() |
| 21 | +{ |
| 22 | + static const auto verify_handle = MakeUnique<ECCVerifyHandle>(); |
| 23 | +} |
| 24 | + |
| 25 | +void test_one_input(const std::vector<uint8_t>& buffer) |
| 26 | +{ |
| 27 | + PartiallySignedTransaction psbt_mut; |
| 28 | + const std::string raw_psbt{buffer.begin(), buffer.end()}; |
| 29 | + std::string error; |
| 30 | + if (!DecodeRawPSBT(psbt_mut, raw_psbt, error)) { |
| 31 | + return; |
| 32 | + } |
| 33 | + const PartiallySignedTransaction psbt = psbt_mut; |
| 34 | + |
| 35 | + const PSBTAnalysis analysis = AnalyzePSBT(psbt); |
| 36 | + (void)PSBTRoleName(analysis.next); |
| 37 | + for (const PSBTInputAnalysis& input_analysis : analysis.inputs) { |
| 38 | + (void)PSBTRoleName(input_analysis.next); |
| 39 | + } |
| 40 | + |
| 41 | + (void)psbt.IsNull(); |
| 42 | + (void)psbt.IsSane(); |
| 43 | + |
| 44 | + Optional<CMutableTransaction> tx = psbt.tx; |
| 45 | + if (tx) { |
| 46 | + const CMutableTransaction& mtx = *tx; |
| 47 | + const PartiallySignedTransaction psbt_from_tx{mtx}; |
| 48 | + } |
| 49 | + |
| 50 | + for (const PSBTInput& input : psbt.inputs) { |
| 51 | + (void)PSBTInputSigned(input); |
| 52 | + (void)input.IsNull(); |
| 53 | + (void)input.IsSane(); |
| 54 | + } |
| 55 | + |
| 56 | + for (const PSBTOutput& output : psbt.outputs) { |
| 57 | + (void)output.IsNull(); |
| 58 | + } |
| 59 | + |
| 60 | + for (size_t i = 0; i < psbt.tx->vin.size(); ++i) { |
| 61 | + CTxOut tx_out; |
| 62 | + if (psbt.GetInputUTXO(tx_out, i)) { |
| 63 | + (void)tx_out.IsNull(); |
| 64 | + (void)tx_out.ToString(); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + psbt_mut = psbt; |
| 69 | + (void)FinalizePSBT(psbt_mut); |
| 70 | + |
| 71 | + psbt_mut = psbt; |
| 72 | + CMutableTransaction result; |
| 73 | + if (FinalizeAndExtractPSBT(psbt_mut, result)) { |
| 74 | + const PartiallySignedTransaction psbt_from_tx{result}; |
| 75 | + } |
| 76 | + |
| 77 | + psbt_mut = psbt; |
| 78 | + (void)psbt_mut.Merge(psbt); |
| 79 | +} |
0 commit comments