What changed, and why it matters
This change tightens the rules for opening Lightning payment channels by refusing a setting called the CSV delay when it is set to zero. The CSV delay is the waiting period a user must endure before reclaiming their own funds from a channel commitment, and it is also the time the other party has to punish a cheating attempt. A zero delay would remove that safety window, so the patch makes it impossible to accept or propose such a channel. The fix is applied at the single central checkpoint that all channel types and both sides of a channel pass through.
No immediate action beyond applying the patch is required. Operators should ensure they are running a version that includes this constraint check before opening new channels. Existing channels with a non-zero CSV delay are unaffected.
Security signals we found
Rejects a zero CSV delay that would eliminate the breach-remedy window
Centralizes the check in VerifyConstraints so all channel types and directions are covered
Adds explicit error type and unit test for the new constraint
Evidence from the diff
The commit adds a zero-CSV-delay check inside lnwallet.VerifyConstraints, which is invoked by CommitConstraints for the remote-required delay in both initiator and responder roles, and by the funding manager for the local-required delay of the remote party. Previously VerifyConstraints only enforced an upper bound on commitParams.CsvDelay. A zero value now returns the new ErrCsvDelayZero ReservationError. A unit test exercises zero, one, max, and above-max values.
Changed components
lnwallet/reservation.golnwallet/errors.golnwallet/reservation_test.goInspect captured patch +81 / −0
### lnwallet/errors.go
@@ -68,6 +68,14 @@ func ErrCsvDelayTooLarge(remoteDelay, maxDelay uint16) ReservationError {
}
}
+// ErrCsvDelayZero returns an error indicating that a CSV delay of zero was
+// proposed.
+func ErrCsvDelayZero() ReservationError {
+ return ReservationError{
+ errors.New("CSV delay must be greater than zero"),
+ }
+}
+
// ErrChanReserveTooSmall returns an error indicating that the channel reserve
// the remote is requiring is too small to be accepted.
func ErrChanReserveTooSmall(reserve, dustLimit btcutil.Amount) ReservationError {
### lnwallet/reservation.go
@@ -1020,6 +1020,12 @@ func VerifyConstraints(bounds *channeldb.ChannelStateBounds,
commitParams *channeldb.CommitmentParams, maxLocalCSVDelay uint16,
channelCapacity btcutil.Amount) error {
+ // A zero CSV delay leaves no time to respond to a breach of the
+ // commitment it applies to, so we never accept or propose one.
+ if commitParams.CsvDelay == 0 {
+ return ErrCsvDelayZero()
+ }
+
// Fail if the csv delay for our funds exceeds our maximum.
if commitParams.CsvDelay > maxLocalCSVDelay {
return ErrCsvDelayTooLarge(
### lnwallet/reservation_test.go
@@ -7,6 +7,7 @@ import (
"github.com/btcsuite/btcd/btcutil/v2"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/chanstate"
+ "github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)
@@ -435,3 +436,69 @@ func TestValidateInitialBalancesUnionIsAdditive(t *testing.T) {
"usability check adds, so it did "+
"not exercise the property")
}
+
+// TestVerifyConstraintsCsvDelay checks that a CSV delay is accepted only when
+// it is non-zero and within our maximum.
+func TestVerifyConstraintsCsvDelay(t *testing.T) {
+ t.Parallel()
+
+ const (
+ capacity = btcutil.Amount(1_000_000)
+ maxDelay = uint16(2016)
+ )
+
+ dustLimit := DustLimitForSize(input.UnknownWitnessSize)
+ bounds := &channeldb.ChannelStateBounds{
+ ChanReserve: capacity / 100,
+ MaxPendingAmount: lnwire.NewMSatFromSatoshis(capacity),
+ MinHTLC: 1,
+ MaxAcceptedHtlcs: input.MaxHTLCNumber / 2,
+ }
+
+ tests := []struct {
+ name string
+ delay uint16
+ err string
+ }{
+ {
+ name: "zero",
+ delay: 0,
+ err: "CSV delay must be greater than zero",
+ },
+ {
+ name: "one",
+ delay: 1,
+ },
+ {
+ name: "max",
+ delay: maxDelay,
+ },
+ {
+ name: "above max",
+ delay: maxDelay + 1,
+ err: "CSV delay too large",
+ },
+ }
+ for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+
+ params := &channeldb.CommitmentParams{
+ DustLimit: dustLimit,
+ CsvDelay: tc.delay,
+ }
+
+ err := VerifyConstraints(
+ bounds, params, maxDelay, capacity,
+ )
+ if tc.err == "" {
+ require.NoError(t, err)
+
+ return
+ }
+
+ require.ErrorContains(t, err, tc.err)
+ require.ErrorAs(t, err, &ReservationError{})
+ })
+ }
+}Why this scored 60/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.