From 2298ef81ab39bbf40deeb319f2135719305338bd Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 1 Jun 2022 13:26:01 -0700 Subject: [PATCH] lnrpc/walletrpc: reject PSBT packets w/o any UTXO input info Fixes https://github.com/lightningnetwork/lnd/issues/6567 --- docs/release-notes/release-notes-0.15.0.md | 2 ++ lnrpc/walletrpc/walletkit_server.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/docs/release-notes/release-notes-0.15.0.md b/docs/release-notes/release-notes-0.15.0.md index 97829e8e3..267a8942f 100644 --- a/docs/release-notes/release-notes-0.15.0.md +++ b/docs/release-notes/release-notes-0.15.0.md @@ -183,6 +183,8 @@ from occurring that would result in an erroneous force close.](https://github.co * [Fixes an issue related to HTLCs on lease enforced channels that can lead to itest flakes](https://github.com/lightningnetwork/lnd/pull/6605/files) +* [Fixes a bug that would cause `SignPsbt` to panic w/ an underspecified packet](https://github.com/lightningnetwork/lnd/pull/6611) + ## Routing * [Add a new `time_pref` parameter to the QueryRoutes and SendPayment APIs](https://github.com/lightningnetwork/lnd/pull/6024) that diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 1f6425878..bb8fb8d06 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -1234,6 +1234,19 @@ func (w *WalletKit) SignPsbt(_ context.Context, req *SignPsbtRequest) ( return nil, fmt.Errorf("error parsing PSBT: %v", err) } + // Before we attempt to sign the packet, ensure that every input either + // has a witness UTXO, or a non witness UTXO. + for idx := range packet.UnsignedTx.TxIn { + in := packet.Inputs[idx] + + // Doesn't have either a witness or non witness UTXO so we need + // to exit here as otherwise signing will fail. + if in.WitnessUtxo == nil && in.NonWitnessUtxo == nil { + return nil, fmt.Errorf("input (index=%v) doesn't "+ + "specify any UTXO info", idx) + } + } + // Let the wallet do the heavy lifting. This will sign all inputs that // we have the UTXO for. If some inputs can't be signed and don't have // witness data attached, they will just be skipped.