From ca5f8deefd778195cb10a3419d3b5c0693abb958 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 19 Nov 2019 14:54:13 -0500 Subject: [PATCH] Mark PSBTs spending unspendable outputs as invalid in analysis Github-Pull: #17524 Rebased-From: 773d4572a4864ab7b6380858d07d9579ff6dd9a2 --- src/node/psbt.cpp | 6 ++++++ test/functional/rpc_psbt.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/node/psbt.cpp b/src/node/psbt.cpp index 12559c5a5f1..9a30c3f0830 100644 --- a/src/node/psbt.cpp +++ b/src/node/psbt.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -39,6 +40,11 @@ PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx) calc_fee = false; } + if (!utxo.IsNull() && utxo.scriptPubKey.IsUnspendable()) { + result.SetInvalid(strprintf("PSBT is not valid. Input %u spends unspendable output", i)); + return result; + } + // Check if it is final if (!utxo.IsNull() && !PSBTInputSigned(input)) { input_analysis.is_final = false; diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index 61572654e0b..57333955b26 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -416,5 +416,10 @@ class PSBTTest(BitcoinTestFramework): analyzed = self.nodes[0].analyzepsbt(signed) assert analyzed['inputs'][0]['has_utxo'] and analyzed['inputs'][0]['is_final'] and analyzed['next'] == 'extractor' + self.log.info("PSBT spending unspendable outputs should have error message and Creator as next") + analysis = self.nodes[0].analyzepsbt('cHNidP8BAJoCAAAAAljoeiG1ba8MI76OcHBFbDNvfLqlyHV5JPVFiHuyq911AAAAAAD/////g40EJ9DsZQpoqka7CwmK6kQiwHGyyng1Kgd5WdB86h0BAAAAAP////8CcKrwCAAAAAAWAEHYXCtx0AYLCcmIauuBXlCZHdoSTQDh9QUAAAAAFv8/wADXYP/7//////8JxOh0LR2HAI8AAAAAAAEBIADC6wsAAAAAF2oUt/X69ELjeX2nTof+fZ10l+OyAokDAQcJAwEHEAABAACAAAEBIADC6wsAAAAAF2oUt/X69ELjeX2nTof+fZ10l+OyAokDAQcJAwEHENkMak8AAAAA') + assert_equal(analysis['next'], 'creator') + assert_equal(analysis['error'], 'PSBT is not valid. Input 0 spends unspendable output') + if __name__ == '__main__': PSBTTest().main()