From e7f338fdeddd7314c2469b3390c3981a269bc799 Mon Sep 17 00:00:00 2001 From: ziggie Date: Mon, 20 Mar 2023 22:41:55 +0100 Subject: [PATCH 1/4] mod: bump version for psbt and btcwallet package --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index e24b7a8c24..23369d21ea 100644 --- a/go.mod +++ b/go.mod @@ -6,10 +6,10 @@ require ( github.com/btcsuite/btcd v0.23.5-0.20230125025938-be056b0a0b2f github.com/btcsuite/btcd/btcec/v2 v2.3.2 github.com/btcsuite/btcd/btcutil v1.1.3 - github.com/btcsuite/btcd/btcutil/psbt v1.1.5 + github.com/btcsuite/btcd/btcutil/psbt v1.1.8 github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f - github.com/btcsuite/btcwallet v0.16.7 + github.com/btcsuite/btcwallet v0.16.8-0.20230324081040-520f650ce045 github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2 github.com/btcsuite/btcwallet/wallet/txrules v1.2.0 github.com/btcsuite/btcwallet/walletdb v1.4.0 diff --git a/go.sum b/go.sum index 76d2ebd0c4..e26b250c1f 100644 --- a/go.sum +++ b/go.sum @@ -80,8 +80,8 @@ github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUB github.com/btcsuite/btcd/btcutil v1.1.1/go.mod h1:nbKlBMNm9FGsdvKvu0essceubPiAcI57pYBNnsLAa34= github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ= github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= -github.com/btcsuite/btcd/btcutil/psbt v1.1.5 h1:x0ZRrYY8j75ThV6xBz86CkYAG82F5bzay4H5D1c8b/U= -github.com/btcsuite/btcd/btcutil/psbt v1.1.5/go.mod h1:kA6FLH/JfUx++j9pYU0pyu+Z8XGBQuuTmuKYUf6q7/U= +github.com/btcsuite/btcd/btcutil/psbt v1.1.8 h1:4voqtT8UppT7nmKQkXV+T9K8UyQjKOn2z/ycpmJK8wg= +github.com/btcsuite/btcd/btcutil/psbt v1.1.8/go.mod h1:kA6FLH/JfUx++j9pYU0pyu+Z8XGBQuuTmuKYUf6q7/U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 h1:KdUfX2zKommPRa+PD0sWZUyXe9w277ABlgELO7H04IM= @@ -89,8 +89,8 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2/go.mod h1:7SFka0XMvUgj3hfZtyd github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= -github.com/btcsuite/btcwallet v0.16.7 h1:J6nBMMMc90n77/4QIfzRFn5XB1hPvMDfcgX5U6Ls0kI= -github.com/btcsuite/btcwallet v0.16.7/go.mod h1:J/q3/JxytAcuqR+zSTCRZ5K+0LtMuhxtCjLVXKDHBu0= +github.com/btcsuite/btcwallet v0.16.8-0.20230324081040-520f650ce045 h1:302lmdYbONzrLACkm9IlCobMYuYOjF8to+tUhaQsTzc= +github.com/btcsuite/btcwallet v0.16.8-0.20230324081040-520f650ce045/go.mod h1:WBcb0CNEgzjF2EdatcERzG7cd/lhHXtNJ4VjIePOdXM= github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2 h1:etuLgGEojecsDOYTII8rYiGHjGyV5xTqsXi+ZQ715UU= github.com/btcsuite/btcwallet/wallet/txauthor v1.3.2/go.mod h1:Zpk/LOb2sKqwP2lmHjaZT9AdaKsHPSbNLm2Uql5IQ/0= github.com/btcsuite/btcwallet/wallet/txrules v1.2.0 h1:BtEN5Empw62/RVnZ0VcJaVtVlBijnLlJY+dwjAye2Bg= From 4da26fb65a669fbee68fa36e60259a8da8ef6d3b Mon Sep 17 00:00:00 2001 From: ziggie Date: Mon, 20 Mar 2023 22:43:15 +0100 Subject: [PATCH 2/4] btcwallet+rpcwallet: verify input data for psbt package Use the new method in the psbt package InputsReadyToSign which makes sure that each input has either nonWitness Utxo or witness Utxo data specified. --- lnwallet/btcwallet/psbt.go | 5 +++-- lnwallet/rpcwallet/rpcwallet.go | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lnwallet/btcwallet/psbt.go b/lnwallet/btcwallet/psbt.go index 7dbe12c2b6..395c5667c6 100644 --- a/lnwallet/btcwallet/psbt.go +++ b/lnwallet/btcwallet/psbt.go @@ -135,8 +135,9 @@ func (b *BtcWallet) SignPsbt(packet *psbt.Packet) ([]uint32, error) { var signedInputs []uint32 // Let's check that this is actually something we can and want to sign. - // We need at least one input and one output. - err := psbt.VerifyInputOutputLen(packet, true, true) + // We need at least one input and one output. In addition each + // input needs nonWitness Utxo or witness Utxo data specified. + err := psbt.InputsReadyToSign(packet) if err != nil { return nil, err } diff --git a/lnwallet/rpcwallet/rpcwallet.go b/lnwallet/rpcwallet/rpcwallet.go index 38f345c14a..536ce62605 100644 --- a/lnwallet/rpcwallet/rpcwallet.go +++ b/lnwallet/rpcwallet/rpcwallet.go @@ -255,8 +255,9 @@ func (r *RPCKeyRing) SignPsbt(packet *psbt.Packet) ([]uint32, error) { // parameter in FinalizePsbt so we can get rid of this code duplication. func (r *RPCKeyRing) FinalizePsbt(packet *psbt.Packet, _ string) error { // Let's check that this is actually something we can and want to sign. - // We need at least one input and one output. - err := psbt.VerifyInputOutputLen(packet, true, true) + // We need at least one input and one output. In addition each + // input needs nonWitness Utxo or witness Utxo data specified. + err := psbt.InputsReadyToSign(packet) if err != nil { return err } From b649b552e664f5ec90711750058d454a2a1ddbce Mon Sep 17 00:00:00 2001 From: ziggie Date: Wed, 29 Mar 2023 23:33:32 +0200 Subject: [PATCH 3/4] itest: add test when signing without UTXO data Adds a testcase in the itest suite which tests that psbt input data needs its corresponding UTXO data when signing. --- itest/lnd_psbt_test.go | 15 +++++++++++++-- lntest/rpc/wallet_kit.go | 13 +++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/itest/lnd_psbt_test.go b/itest/lnd_psbt_test.go index 57a0a67b77..ffa680d75c 100644 --- a/itest/lnd_psbt_test.go +++ b/itest/lnd_psbt_test.go @@ -1009,17 +1009,28 @@ func assertPsbtSpend(ht *lntest.HarnessTest, alice *node.HarnessNode, packet, err := psbt.NewFromUnsignedTx(pendingTx) require.NoError(ht, err) + // We first try to sign the psbt without the necessary input data + // which should fail with the expected error. + var buf bytes.Buffer + err = packet.Serialize(&buf) + require.NoError(ht, err) + + signReq := &walletrpc.SignPsbtRequest{FundedPsbt: buf.Bytes()} + err = alice.RPC.SignPsbtErr(signReq) + require.ErrorContains(ht, err, "input (index=0) doesn't specify "+ + "any UTXO info", "error does not match") + // Now let's add the meta information that we need for signing. packet.Inputs[0].WitnessUtxo = utxo packet.Inputs[0].NonWitnessUtxo = prevTx decorateUnsigned(packet) // That's it, we should be able to sign the PSBT now. - var buf bytes.Buffer + buf.Reset() err = packet.Serialize(&buf) require.NoError(ht, err) - signReq := &walletrpc.SignPsbtRequest{FundedPsbt: buf.Bytes()} + signReq = &walletrpc.SignPsbtRequest{FundedPsbt: buf.Bytes()} signResp := alice.RPC.SignPsbt(signReq) // Let's make sure we have a partial signature. diff --git a/lntest/rpc/wallet_kit.go b/lntest/rpc/wallet_kit.go index 1d0a128580..9a88fe6e72 100644 --- a/lntest/rpc/wallet_kit.go +++ b/lntest/rpc/wallet_kit.go @@ -263,6 +263,19 @@ func (h *HarnessRPC) SignPsbt( return resp } +// SignPsbtErr makes a RPC call to the node's WalletKitClient and asserts +// an error returned. +func (h *HarnessRPC) SignPsbtErr(req *walletrpc.SignPsbtRequest) error { + ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout) + defer cancel() + + _, err := h.WalletKit.SignPsbt(ctxt, req) + require.Errorf(h, err, "%s: expect sign psbt to return an error", + h.Name) + + return err +} + // ImportTapscript makes a RPC call to the node's WalletKitClient and asserts. // //nolint:lll From 71b8fac819ef6445ec44f41d5b4b436b5f2368b8 Mon Sep 17 00:00:00 2001 From: ziggie Date: Mon, 20 Mar 2023 23:47:35 +0100 Subject: [PATCH 4/4] docs: add release-notes --- docs/release-notes/release-notes-0.16.1.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/release-notes/release-notes-0.16.1.md b/docs/release-notes/release-notes-0.16.1.md index 0265abc4cc..ebe476295e 100644 --- a/docs/release-notes/release-notes-0.16.1.md +++ b/docs/release-notes/release-notes-0.16.1.md @@ -38,7 +38,7 @@ ## RPC -- A [debug log](https://github.com/lightningnetwork/lnd/pull/7514) has been +* A [debug log](https://github.com/lightningnetwork/lnd/pull/7514) has been added to `lnrpc` so the node operator can know whether a certain request has happened or not. @@ -48,6 +48,11 @@ anything for the users since the message type(36) stays unchanged, except in the logging all the appearance of `funding_locked` replated experssion is replaced with `channel_ready`. +## Bug Fixes + +* [Fix a bug where lnd crashes when psbt data is not fully +available](https://github.com/lightningnetwork/lnd/pull/7529). + # Contributors (Alphabetical Order) @@ -56,3 +61,4 @@ * Oliver Gugger * Tommy Volk * Yong Yu +* ziggie1984 \ No newline at end of file