1 // Copyright (c) 2019-2020 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 initialize()20void initialize() 21 { 22 static const ECCVerifyHandle verify_handle; 23 } 24 test_one_input(const std::vector<uint8_t> & buffer)25void 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 43 Optional<CMutableTransaction> tx = psbt.tx; 44 if (tx) { 45 const CMutableTransaction& mtx = *tx; 46 const PartiallySignedTransaction psbt_from_tx{mtx}; 47 } 48 49 for (const PSBTInput& input : psbt.inputs) { 50 (void)PSBTInputSigned(input); 51 (void)input.IsNull(); 52 } 53 54 for (const PSBTOutput& output : psbt.outputs) { 55 (void)output.IsNull(); 56 } 57 58 for (size_t i = 0; i < psbt.tx->vin.size(); ++i) { 59 CTxOut tx_out; 60 if (psbt.GetInputUTXO(tx_out, i)) { 61 (void)tx_out.IsNull(); 62 (void)tx_out.ToString(); 63 } 64 } 65 66 psbt_mut = psbt; 67 (void)FinalizePSBT(psbt_mut); 68 69 psbt_mut = psbt; 70 CMutableTransaction result; 71 if (FinalizeAndExtractPSBT(psbt_mut, result)) { 72 const PartiallySignedTransaction psbt_from_tx{result}; 73 } 74 75 psbt_mut = psbt; 76 (void)psbt_mut.Merge(psbt); 77 } 78