chancloser: legacy closer accepts empty shutdown script
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 85/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- networking
Direzione di ricerca
Ispeziona lnwallet/chancloser/chancloser.go intorno a validateShutdownScript, dove il closer legacy convalida condizionalmente lo script del peer. Aggiorna la validazione e adatta lnwallet/chancloser/chancloser_test.go per TestMaybeMatchScript e TestTaprootFastClose; il test di riproduzione può essere aggiunto come descritto. Esegui go test ./lnwallet/chancloser -run TestReceiveShutdownEmptyScript -count=1 e poi i test completi del package.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Go
- Stelle
- 8.2k
- Fork
- 2.3k
- Merge medio
- 1g 11h
- PR unite (30g)
- 103
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di lightningnetwork/lnd
-
funding: failure logs print `<nil>` error and zero channel IDForse già presa @litbot-9000 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
lightningnetwork/lnd#11676 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
lightningnetwork/lnd#11672 ·
I maintainer di solito rispondono entro 1 giorno
-
test flake
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
lightningnetwork/lnd#11663 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[flake]: lnwallet/test/bitcoind.TestLightningWalletBitcoindRPCPolling/spend_unconfirmed_outputsApertatest flake
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
lightningnetwork/lnd#11642 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
docker: pin the final alpine base imageForse di nuovo libera @danieldzansi l’ha presa 27 giorni fa e non c’è nessuna pull request aperta. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
lightningnetwork/lnd#11437 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di lightningnetwork/lnd
Issue simili
-
feat(arithmetization): update `arithmetization` to ZkC version `v1.2.38`Forse già presa @DavePearce l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
LFDT-Lineth/lineth-monorepo#4679 ·
I maintainer di solito rispondono entro 1 giorno
-
macOS: MixMusic stalls as the GPU times out drawing frames, and the media keys fail to register at every startForse già presa @fzn0x l’ha presa oggi. Apertabug priority: high
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
effort:s impact:low raised-by:reviewer risk:low
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
medici-finance/assay#8050 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
factory:subtask
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno