From fec0b59112a57038499f5ee060bdc37cbdd5c676 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Fri, 1 Oct 2021 20:10:27 +0000 Subject: [PATCH] pset: make sure combinepsbt doesn't crash when explicit values are missing I accidentally dropped this check (and its test) in the previous commits. Restore both. --- src/psbt.cpp | 2 ++ test/functional/rpc_psbt.py | 1 + 2 files changed, 3 insertions(+) diff --git a/src/psbt.cpp b/src/psbt.cpp index 0700f98c1f..1cb308f461 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -138,6 +138,7 @@ CMutableTransaction PartiallySignedTransaction::GetUnsignedTx(bool force_unblind txout.scriptPubKey = *output.script; bool exp_value = output.m_value_commitment.IsNull() || force_unblinded; + exp_value = exp_value && output.amount != nullopt; if (!output.m_value_commitment.IsNull() && output.amount != nullopt) { exp_value = exp_value && !output.m_blind_value_proof.empty(); exp_value = exp_value && !output.m_asset_commitment.IsNull(); @@ -151,6 +152,7 @@ CMutableTransaction PartiallySignedTransaction::GetUnsignedTx(bool force_unblind } bool exp_asset = output.m_asset_commitment.IsNull() || force_unblinded; + exp_asset = exp_asset && !output.m_asset.IsNull(); if (!output.m_asset_commitment.IsNull() && !output.m_asset.IsNull()) { exp_asset = exp_asset && !output.m_blind_asset_proof.empty(); exp_asset = exp_asset && !output.m_asset.IsNull(); diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index f9e87bd716..7925a98977 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -805,6 +805,7 @@ class PSBTTest(BitcoinTestFramework): assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [BAD_VALUE_PROOF, BAD_ASSET_PROOF]) for bad_pset in [ NO_VALUE_PROOF, BAD_VALUE_PROOF, NO_ASSET_PROOF, BAD_ASSET_PROOF ]: assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [UNBLINDED, bad_pset]) + assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [ONLY_BLIND, bad_pset]) assert_raises_rpc_error(-8, "PSBTs not compatible (different transactions)", self.nodes[0].combinepsbt, [BLINDED, bad_pset]) def run_test(self):