The Lightning Network Daemon (lnd) is an implementation of the Lightning Network, which is an overlay network built on top of the Bitcoin protocol as a second-layer scaling solution to enable instant, low-cost transactions. Recently, a vulnerability (CVE-2022-39389) has been discovered in all lnd nodes prior to version v.15.4. This vulnerability is a block parsing bug that can force lnd nodes to enter a degraded state and potentially lead to a loss of funds.

In this post, we will discuss the technical details of the vulnerability, its potential impact on lnd nodes, and the actions node operators need to take to protect their funds.

Vulnerability Details

The block parsing bug is triggered when an lnd node encounters a particular block in the chain. Once a node has entered the degraded state, it can still make payments, forward HTLCs (Hashed TimeLock Contracts), and close out channels. However, opening new channels and detecting on-chain transaction events will be prohibited.

This restriction can cause funds to be lost if either a CSV (CheckSequenceVerify) expiry is breached during an attempted channel breach or a CLTV (CheckLockTimeVerify) delta expires, leaving funds locked in an HTLC. Such scenarios are likely to happen in busy nodes with substantial funds.

Exploit Details

The block parsing bug is present in lnd due to a glitch in the code that handles the processing of incoming blocks. Here's a code snippet that demonstrates the bug:

func (s *SyncManager) handleBlockConnected(blockHeader []byte, _) {
    decodedBlock, err := wire.NewFromBytes(blockHeader)
    if err != nil {
        s.log.Errorf("Unable to decode block: %v", err)
        // BUG: the block is not retried, and the node enters a degraded state.
        return
    }

    // ... normal block processing continues.
}

When an undecodable block is encountered, the handleBlockConnected function logs an error message but does not retry to parse the block correctly or exit the degraded state, causing any subsequent events and operations to be affected.

Prevention and Mitigation

A patch for the vulnerability is available in lnd version .15.4. Node operators are strongly advised to upgrade their nodes to the latest version as soon as possible.

In case a node operator is unable to upgrade to version .15.4, they can utilize the lncli updatechanpolicy RPC call to increase the CLTV delta value to a very high amount or increase their fee policies, as shown below:

lncli updatechanpolicy --time_lock_delta=<high_delta_value> --fee_base_msat=<high_fee_base_value> --fee_rate=<high_fee_rate>

Increasing the CLTV delta value or fee policies will discourage other nodes from routing their transactions through your node. As a result, there would be no pending HTLCs, reducing the chances of losing funds due to expired CLTV deltas or breached CSV expiries.

Original References

- Lightning Network Daemon GitHub Repository
- lnd v.15.4 Release Notes

Conclusion

CVE-2022-39389 is a critical vulnerability affecting lnd nodes before version v.15.4, potentially leading to loss of funds. Node operators should upgrade to the latest version or apply temporary workarounds to increase the CLTV delta value or fee policies to minimize the risks associated with this bug. Developers should thoroughly test and validate their code to prevent similar issues from emerging in the future.

Timeline

Published on: 11/17/2022 22:15:00 UTC
Last modified on: 11/22/2022 16:49:00 UTC