chancloser: legacy closer accepts empty shutdown script
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- Half a day
- Newbie friendliness
- 85/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- networking
Research direction
Inspect lnwallet/chancloser/chancloser.go around validateShutdownScript, where the legacy closer conditionally validates the peer script. Update the validation and adjust lnwallet/chancloser/chancloser_test.go for TestMaybeMatchScript and TestTaprootFastClose; the reproducer test can be added as described. Run go test ./lnwallet/chancloser -run TestReceiveShutdownEmptyScript -count=1 and then the full package tests.
Written by the indexing model from the issue text.
Description
BOLT 2 requires shutdown's scriptpubkey to be P2WPKH, P2WSH, a witness program of version 1 to 16 (with option_shutdown_anysegwit), or an OP_RETURN (with option_simple_close).
But the legacy closer only checks the peer's script if it isn't empty:
If the peer set no upfront shutdown script, LND accepts an empty scriptpubkey, replies with its own shutdown, and negotiates a closing transaction that pays the peer's balance to an empty PkScript:
TestMaybeMatchScript actually asserts that the empty script is accepted:
The RBF closer has rejected it since #11019, which added an explicit check before calling the same function:
Impact
A transaction with an empty output script is non-standard, so the closing transaction never relays. The operator has to notice and force close.
Reproducer
lnwallet/chancloser/empty_shutdown_script_test.go:
package chancloser
import (
"testing"
"github.com/btcsuite/btcd/chaincfg/v2"
"github.com/btcsuite/btcd/wire/v2"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)
// TestReceiveShutdownEmptyScript checks that the legacy closer rejects a
// shutdown with an empty scriptpubkey from a peer that set no upfront shutdown
// script. BOLT 2 doesn't allow an empty scriptpubkey, and a closing
// transaction paying to one isn't standard.
func TestReceiveShutdownEmptyScript(t *testing.T) {
t.Parallel()
tests := []struct {
name string
script lnwire.DeliveryAddress
wantErr bool
}{
{
name: "p2tr",
script: remoteAddr,
},
{
name: "empty",
script: lnwire.DeliveryAddress{},
wantErr: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
// The peer opened the channel without an upfront
// shutdown script, and now starts a cooperative close.
channel := &mockChannel{}
closer := NewChanCloser(
ChanCloseCfg{
Channel: channel,
ChainParams: &chaincfg.SimNetParams,
DisableChannel: func(wire.OutPoint) error {
return nil
},
}, DeliveryAddrWithKey{
DeliveryAddress: localAddr,
}, chainfee.SatPerKWeight(506), 0, nil,
lntypes.Remote,
)
_, err := closer.ReceiveShutdown(lnwire.Shutdown{
ChannelID: lnwire.NewChanIDFromOutPoint(
channel.chanPoint,
),
Address: tc.script,
})
if tc.wantErr {
require.Error(t, err, "accepted an empty "+
"shutdown script")
return
}
require.NoError(t, err)
})
}
}
$ go test ./lnwallet/chancloser -run TestReceiveShutdownEmptyScript -count=1
--- FAIL: TestReceiveShutdownEmptyScript (0.00s)
--- FAIL: TestReceiveShutdownEmptyScript/empty (0.00s)
empty_shutdown_script_test.go:64:
Error: An error is expected but got nil.
Messages: accepted an empty shutdown script
FAIL
Suggested fix
Check every peer script. ValidateUpfrontShutdown already rejects an empty one:
--- a/lnwallet/chancloser/chancloser.go
+++ b/lnwallet/chancloser/chancloser.go
@@ -660,10 +660,10 @@ func validateShutdownScript(upfrontScript, peerScript lnwire.DeliveryAddress,
return ErrInvalidShutdownScript
}
}
- if len(peerScript) != 0 {
- if !lnwallet.ValidateUpfrontShutdown(peerScript, netParams) {
- return ErrInvalidShutdownScript
- }
+ // BOLT 2 requires the peer's scriptpubkey to be one of the standard
+ // forms, so an empty one is invalid too.
+ if !lnwallet.ValidateUpfrontShutdown(peerScript, netParams) {
+ return ErrInvalidShutdownScript
}
// If no upfront shutdown script was set, return early because we do
Two existing tests also need to be updated for the new behavior:
TestMaybeMatchScriptTestTaprootFastClose
Discovery
Found incidentally during LLM-assisted analysis of artifacts from a smite fuzzing campaign.
- Dominant language
- Go
- Stars
- 8.2k
- Forks
- 2.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 103
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lightningnetwork/lnd
-
funding: failure logs print `<nil>` error and zero channel IDPossibly taken @litbot-9000 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
lightningnetwork/lnd#11676 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
lightningnetwork/lnd#11672 ·
Maintainers usually reply within 1 day
-
test flake
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
lightningnetwork/lnd#11663 · 1 comment ·
Maintainers usually reply within 1 day
-
[flake]: lnwallet/test/bitcoind.TestLightningWalletBitcoindRPCPolling/spend_unconfirmed_outputsOpentest flake
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lightningnetwork/lnd#11642 · 1 comment ·
Maintainers usually reply within 1 day
-
docker: pin the final alpine base imageMay be free again @danieldzansi claimed this 27 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
lightningnetwork/lnd#11437 · 3 comments ·
Maintainers usually reply within 1 day
All issues in lightningnetwork/lnd
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
containers/gvisor-tap-vsock#796 ·
Maintainers usually reply within 2 days
-
external needs:triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
celestiaorg/celestia-node#5448 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 1 day
-
[Bug]: Azure SAS signing uses local time instead of UTC, shifting validity window on non-UTC hostsPossibly taken @huanghaoyuanhhy claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
zilliztech/milvus-backup#1418 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
projectdiscovery/nuclei#8423 ·
Maintainers usually reply within 1 day