diff --git a/test/data/psbt_non_witness_utxo_segwit.patch b/test/data/psbt_non_witness_utxo_segwit.patch deleted file mode 100644 index 57e41c0..0000000 --- a/test/data/psbt_non_witness_utxo_segwit.patch +++ /dev/null @@ -1,370 +0,0 @@ -From eec69a3f42a654a62eacad78164e66b4ae8a68a1 Mon Sep 17 00:00:00 2001 -From: Andrew Chow -Date: Thu, 4 Jun 2020 23:43:25 -0400 -Subject: [PATCH 1/4] rpc: show both UTXOs in decodepsbt - ---- - src/rpc/rawtransaction.cpp | 9 +++++++-- - 1 file changed, 7 insertions(+), 2 deletions(-) - -diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp -index faec359d1c..5f8c02df65 100644 ---- a/src/rpc/rawtransaction.cpp -+++ b/src/rpc/rawtransaction.cpp -@@ -1104,6 +1104,7 @@ UniValue decodepsbt(const JSONRPCRequest& request) - const PSBTInput& input = psbtx.inputs[i]; - UniValue in(UniValue::VOBJ); - // UTXOs -+ bool have_a_utxo = false; - if (!input.witness_utxo.IsNull()) { - const CTxOut& txout = input.witness_utxo; - -@@ -1121,7 +1122,9 @@ UniValue decodepsbt(const JSONRPCRequest& request) - ScriptToUniv(txout.scriptPubKey, o, true); - out.pushKV("scriptPubKey", o); - in.pushKV("witness_utxo", out); -- } else if (input.non_witness_utxo) { -+ have_a_utxo = true; -+ } -+ if (input.non_witness_utxo) { - UniValue non_wit(UniValue::VOBJ); - TxToUniv(*input.non_witness_utxo, uint256(), non_wit, false); - in.pushKV("non_witness_utxo", non_wit); -@@ -1132,7 +1135,9 @@ UniValue decodepsbt(const JSONRPCRequest& request) - // Hack to just not show fee later - have_all_utxos = false; - } -- } else { -+ have_a_utxo = true; -+ } -+ if (!have_a_utxo) { - have_all_utxos = false; - } - --- -2.27.0 - - -From 6aa6d5495299a8e09f2e89a71fd5447351fbcf90 Mon Sep 17 00:00:00 2001 -From: Andrew Chow -Date: Thu, 4 Jun 2020 23:43:39 -0400 -Subject: [PATCH 2/4] psbt: Allow both non_witness_utxo and witness_utxo - ---- - src/psbt.cpp | 29 ----------------------------- - src/psbt.h | 7 ------- - src/test/fuzz/psbt.cpp | 2 -- - src/wallet/scriptpubkeyman.cpp | 10 ---------- - src/wallet/wallet.cpp | 5 ----- - 5 files changed, 53 deletions(-) - -diff --git a/src/psbt.cpp b/src/psbt.cpp -index 10260740f0..71a3e06708 100644 ---- a/src/psbt.cpp -+++ b/src/psbt.cpp -@@ -35,14 +35,6 @@ bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt) - return true; - } - --bool PartiallySignedTransaction::IsSane() const --{ -- for (PSBTInput input : inputs) { -- if (!input.IsSane()) return false; -- } -- return true; --} -- - bool PartiallySignedTransaction::AddInput(const CTxIn& txin, PSBTInput& psbtin) - { - if (std::find(tx->vin.begin(), tx->vin.end(), txin) != tx->vin.end()) { -@@ -158,18 +150,6 @@ void PSBTInput::Merge(const PSBTInput& input) - if (final_script_witness.IsNull() && !input.final_script_witness.IsNull()) final_script_witness = input.final_script_witness; - } - --bool PSBTInput::IsSane() const --{ -- // Cannot have both witness and non-witness utxos -- if (!witness_utxo.IsNull() && non_witness_utxo) return false; -- -- // If we have a witness_script or a scriptWitness, we must also have a witness utxo -- if (!witness_script.empty() && witness_utxo.IsNull()) return false; -- if (!final_script_witness.IsNull() && witness_utxo.IsNull()) return false; -- -- return true; --} -- - void PSBTOutput::FillSignatureData(SignatureData& sigdata) const - { - if (!redeem_script.empty()) { -@@ -261,11 +241,6 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& - bool require_witness_sig = false; - CTxOut utxo; - -- // Verify input sanity, which checks that at most one of witness or non-witness utxos is provided. -- if (!input.IsSane()) { -- return false; -- } -- - if (input.non_witness_utxo) { - // If we're taking our information from a non-witness UTXO, verify that it matches the prevout. - COutPoint prevout = tx.vin[index].prevout; -@@ -356,10 +331,6 @@ TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector - return TransactionError::PSBT_MISMATCH; - } - } -- if (!out.IsSane()) { -- return TransactionError::INVALID_PSBT; -- } -- - return TransactionError::OK; - } - -diff --git a/src/psbt.h b/src/psbt.h -index 0a8ea2ea0b..401889e2fe 100644 ---- a/src/psbt.h -+++ b/src/psbt.h -@@ -62,7 +62,6 @@ struct PSBTInput - void FillSignatureData(SignatureData& sigdata) const; - void FromSignatureData(const SignatureData& sigdata); - void Merge(const PSBTInput& input); -- bool IsSane() const; - PSBTInput() {} - - template -@@ -284,7 +283,6 @@ struct PSBTOutput - void FillSignatureData(SignatureData& sigdata) const; - void FromSignatureData(const SignatureData& sigdata); - void Merge(const PSBTOutput& output); -- bool IsSane() const; - PSBTOutput() {} - - template -@@ -401,7 +399,6 @@ struct PartiallySignedTransaction - /** Merge psbt into this. The two psbts must have the same underlying CTransaction (i.e. the - * same actual Bitcoin transaction.) Returns true if the merge succeeded, false otherwise. */ - NODISCARD bool Merge(const PartiallySignedTransaction& psbt); -- bool IsSane() const; - bool AddInput(const CTxIn& txin, PSBTInput& psbtin); - bool AddOutput(const CTxOut& txout, const PSBTOutput& psbtout); - PartiallySignedTransaction() {} -@@ -551,10 +548,6 @@ struct PartiallySignedTransaction - if (outputs.size() != tx->vout.size()) { - throw std::ios_base::failure("Outputs provided does not match the number of outputs in transaction."); - } -- // Sanity check -- if (!IsSane()) { -- throw std::ios_base::failure("PSBT is not sane."); -- } - } - - template -diff --git a/src/test/fuzz/psbt.cpp b/src/test/fuzz/psbt.cpp -index 64328fb66e..908e2b16f2 100644 ---- a/src/test/fuzz/psbt.cpp -+++ b/src/test/fuzz/psbt.cpp -@@ -39,7 +39,6 @@ void test_one_input(const std::vector& buffer) - } - - (void)psbt.IsNull(); -- (void)psbt.IsSane(); - - Optional tx = psbt.tx; - if (tx) { -@@ -50,7 +49,6 @@ void test_one_input(const std::vector& buffer) - for (const PSBTInput& input : psbt.inputs) { - (void)PSBTInputSigned(input); - (void)input.IsNull(); -- (void)input.IsSane(); - } - - for (const PSBTOutput& output : psbt.outputs) { -diff --git a/src/wallet/scriptpubkeyman.cpp b/src/wallet/scriptpubkeyman.cpp -index 3cc2611524..38d94335a3 100644 ---- a/src/wallet/scriptpubkeyman.cpp -+++ b/src/wallet/scriptpubkeyman.cpp -@@ -597,11 +597,6 @@ TransactionError LegacyScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& psb - continue; - } - -- // Verify input looks sane. This will check that we have at most one uxto, witness or non-witness. -- if (!input.IsSane()) { -- return TransactionError::INVALID_PSBT; -- } -- - // Get the Sighash type - if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) { - return TransactionError::SIGHASH_MISMATCH; -@@ -2086,11 +2081,6 @@ TransactionError DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction& - continue; - } - -- // Verify input looks sane. This will check that we have at most one uxto, witness or non-witness. -- if (!input.IsSane()) { -- return TransactionError::INVALID_PSBT; -- } -- - // Get the Sighash type - if (sign && input.sighash_type > 0 && input.sighash_type != sighash_type) { - return TransactionError::SIGHASH_MISMATCH; -diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp -index 19acfa3322..974985acbf 100644 ---- a/src/wallet/wallet.cpp -+++ b/src/wallet/wallet.cpp -@@ -2507,11 +2507,6 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp - continue; - } - -- // Verify input looks sane. This will check that we have at most one uxto, witness or non-witness. -- if (!input.IsSane()) { -- return TransactionError::INVALID_PSBT; -- } -- - // If we have no utxo, grab it from the wallet. - if (!input.non_witness_utxo && input.witness_utxo.IsNull()) { - const uint256& txhash = txin.prevout.hash; --- -2.27.0 - - -From 889f7b3ce8ba2fccd58ab352ca622e00648147fe Mon Sep 17 00:00:00 2001 -From: Andrew Chow -Date: Thu, 4 Jun 2020 23:43:43 -0400 -Subject: [PATCH 3/4] psbt: always put a non_witness_utxo and don't remove it - -Offline signers will always need a non_witness_utxo so make sure it is -there. ---- - src/psbt.cpp | 7 ++++--- - src/psbt.h | 4 ++-- - src/wallet/test/psbt_wallet_tests.cpp | 2 +- - src/wallet/wallet.cpp | 2 +- - test/functional/rpc_psbt.py | 4 +++- - 5 files changed, 11 insertions(+), 8 deletions(-) - -diff --git a/src/psbt.cpp b/src/psbt.cpp -index 71a3e06708..3fb743e5db 100644 ---- a/src/psbt.cpp -+++ b/src/psbt.cpp -@@ -136,8 +136,8 @@ void PSBTInput::Merge(const PSBTInput& input) - { - if (!non_witness_utxo && input.non_witness_utxo) non_witness_utxo = input.non_witness_utxo; - if (witness_utxo.IsNull() && !input.witness_utxo.IsNull()) { -+ // TODO: For segwit v1, we will want to clear out the non-witness utxo when setting a witness one. For v0 and non-segwit, this is not safe - witness_utxo = input.witness_utxo; -- non_witness_utxo = nullptr; // Clear out any non-witness utxo when we set a witness one. - } - - partial_sigs.insert(input.partial_sigs.begin(), input.partial_sigs.end()); -@@ -274,10 +274,11 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& - if (require_witness_sig && !sigdata.witness) return false; - input.FromSignatureData(sigdata); - -- // If we have a witness signature, use the smaller witness UTXO. -+ // If we have a witness signature, put a witness UTXO. -+ // TODO: For segwit v1, we should remove the non_witness_utxo - if (sigdata.witness) { - input.witness_utxo = utxo; -- input.non_witness_utxo = nullptr; -+ // input.non_witness_utxo = nullptr; - } - - // Fill in the missing info -diff --git a/src/psbt.h b/src/psbt.h -index 401889e2fe..0951b76f83 100644 ---- a/src/psbt.h -+++ b/src/psbt.h -@@ -67,12 +67,12 @@ struct PSBTInput - template - inline void Serialize(Stream& s) const { - // Write the utxo -- // If there is a non-witness utxo, then don't add the witness one. - if (non_witness_utxo) { - SerializeToVector(s, PSBT_IN_NON_WITNESS_UTXO); - OverrideStream os(&s, s.GetType(), s.GetVersion() | SERIALIZE_TRANSACTION_NO_WITNESS); - SerializeToVector(os, non_witness_utxo); -- } else if (!witness_utxo.IsNull()) { -+ } -+ if (!witness_utxo.IsNull()) { - SerializeToVector(s, PSBT_IN_WITNESS_UTXO); - SerializeToVector(s, witness_utxo); - } -diff --git a/src/wallet/test/psbt_wallet_tests.cpp b/src/wallet/test/psbt_wallet_tests.cpp -index 3f85a48ff3..ce7e661b67 100644 ---- a/src/wallet/test/psbt_wallet_tests.cpp -+++ b/src/wallet/test/psbt_wallet_tests.cpp -@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(psbt_updater_test) - CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); - ssTx << psbtx; - std::string final_hex = HexStr(ssTx); -- BOOST_CHECK_EQUAL(final_hex, "70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000"); -+ BOOST_CHECK_EQUAL(final_hex, "70736274ff01009a020000000258e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd750000000000ffffffff838d0427d0ec650a68aa46bb0b098aea4422c071b2ca78352a077959d07cea1d0100000000ffffffff0270aaf00800000000160014d85c2b71d0060b09c9886aeb815e50991dda124d00e1f5050000000016001400aea9a2e5f0f876a588df5546e8742d1d87008f00000000000100bb0200000001aad73931018bd25f84ae400b68848be09db706eac2ac18298babee71ab656f8b0000000048473044022058f6fc7c6a33e1b31548d481c826c015bd30135aad42cd67790dab66d2ad243b02204a1ced2604c6735b6393e5b41691dd78b00f0c5942fb9f751856faa938157dba01feffffff0280f0fa020000000017a9140fb9463421696b82c833af241c78c17ddbde493487d0f20a270100000017a91429ca74f8a08f81999428185c97b5d852e4063f6187650000000104475221029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f2102dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d752ae2206029583bf39ae0a609747ad199addd634fa6108559d6c5cd39b4c2183f1ab96e07f10d90c6a4f000000800000008000000080220602dab61ff49a14db6a7d02b0cd1fbb78fc4b18312b5b4e54dae4dba2fbfef536d710d90c6a4f0000008000000080010000800001008a020000000158e87a21b56daf0c23be8e7070456c336f7cbaa5c8757924f545887bb2abdd7501000000171600145f275f436b09a8cc9a2eb2a2f528485c68a56323feffffff02d8231f1b0100000017a914aed962d6654f9a2b36608eb9d64d2b260db4f1118700c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e8876500000001012000c2eb0b0000000017a914b7f5faf40e3d40a5a459b1db3535f2b72fa921e88701042200208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903010547522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7352ae2206023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e7310d90c6a4f000000800000008003000080220603089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc10d90c6a4f00000080000000800200008000220203a9a4c37f5996d3aa25dbac6b570af0650394492942460b354753ed9eeca5877110d90c6a4f000000800000008004000080002202027f6399757d2eff55a136ad02c684b1838b6556e5f1b6b34282a94b6b5005109610d90c6a4f00000080000000800500008000"); - - // Mutate the transaction so that one of the inputs is invalid - psbtx.tx->vin[0].prevout.n = 2; -diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp -index 974985acbf..235b269805 100644 ---- a/src/wallet/wallet.cpp -+++ b/src/wallet/wallet.cpp -@@ -2508,7 +2508,7 @@ TransactionError CWallet::FillPSBT(PartiallySignedTransaction& psbtx, bool& comp - } - - // If we have no utxo, grab it from the wallet. -- if (!input.non_witness_utxo && input.witness_utxo.IsNull()) { -+ if (!input.non_witness_utxo) { - const uint256& txhash = txin.prevout.hash; - const auto it = mapWallet.find(txhash); - if (it != mapWallet.end()) { -diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py -index 660953be9b..7703c4ecb1 100755 ---- a/test/functional/rpc_psbt.py -+++ b/test/functional/rpc_psbt.py -@@ -38,6 +38,7 @@ class PSBTTest(BitcoinTestFramework): - def skip_test_if_missing_module(self): - self.skip_if_no_wallet() - -+ # TODO: Re-enable this test with segwit v1 - def test_utxo_conversion(self): - mining_node = self.nodes[2] - offline_node = self.nodes[0] -@@ -352,7 +353,8 @@ class PSBTTest(BitcoinTestFramework): - for i, signer in enumerate(signers): - self.nodes[2].unloadwallet("wallet{}".format(i)) - -- self.test_utxo_conversion() -+ # TODO: Re-enable this for segwit v1 -+ # self.test_utxo_conversion() - - # Test that psbts with p2pkh outputs are created properly - p2pkh = self.nodes[0].getnewaddress(address_type='legacy') --- -2.27.0 - - -From 85d143347a9ef8d1be712b7a699da0f1835dc837 Mon Sep 17 00:00:00 2001 -From: Andrew Chow -Date: Mon, 8 Jun 2020 19:27:16 -0400 -Subject: [PATCH 4/4] tests: Check that segwit inputs in psbt have both UTXO - types - ---- - test/functional/rpc_psbt.py | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py -index 7703c4ecb1..e5e62fd646 100755 ---- a/test/functional/rpc_psbt.py -+++ b/test/functional/rpc_psbt.py -@@ -157,6 +157,10 @@ class PSBTTest(BitcoinTestFramework): - # spend single key from node 1 - rawtx = self.nodes[1].walletcreatefundedpsbt([{"txid":txid,"vout":p2wpkh_pos},{"txid":txid,"vout":p2sh_p2wpkh_pos},{"txid":txid,"vout":p2pkh_pos}], {self.nodes[1].getnewaddress():29.99})['psbt'] - walletprocesspsbt_out = self.nodes[1].walletprocesspsbt(rawtx) -+ # Make sure it has both types of UTXOs -+ decoded = self.nodes[1].decodepsbt(walletprocesspsbt_out['psbt']) -+ assert 'non_witness_utxo' in decoded['inputs'][0] -+ assert 'witness_utxo' in decoded['inputs'][0] - assert_equal(walletprocesspsbt_out['complete'], True) - self.nodes[1].sendrawtransaction(self.nodes[1].finalizepsbt(walletprocesspsbt_out['psbt'])['hex']) - --- -2.27.0 - diff --git a/test/setup_environment.sh b/test/setup_environment.sh index 6bf0c52..acb9af2 100755 --- a/test/setup_environment.sh +++ b/test/setup_environment.sh @@ -216,7 +216,6 @@ else bitcoind_setup_needed=true fi fi -git am ../../data/psbt_non_witness_utxo_segwit.patch # Build bitcoind. This is super slow, but it is cached so it runs fairly quickly. if [ "$bitcoind_setup_needed" == true ] ; then