
Source: Byte Yuan CKB
As a P2P network built on the Bitcoin blockchain, Lightning Network can not only effectively solve the problem of Bitcoin’s “slow and expensive”, but also has an unparalleled advantage in the field of crypto payments. It is our implementation of P2PThe foundation of the economy is also an important part of the Web5 world we long for.
In this article today, we will continue to introduce the Lightning Network and explain the operating principles and related technologies of the Lightning Network.
The cornerstone of Lightning Network: Payment Channel
Lightning Network is essentially a well-designed payment channel system.Taking the transaction between Alice and Bob as an example, when they use the Lightning Network to settle, they will go through the following three key stages: opening the channel, conducting transactions, and closing the channel.
1. Open the channel: build a bridge of trust
The so-called opening of the channel is essentially creating a multi-signature wallet jointly controlled by both parties and injecting funds into the wallet.The total amount of funds received by this wallet is the balance of this channel.
We assume that Alice and Bob each hold 100,000 BTC.First, they need to transfer their respective 100,000 cong to a multi-signature wallet address jointly controlled by the two as a mortgage to establish a channel.This transaction, known as “Funding Transaction” or “Anchor Transaction”, needs to be broadcast to the network and recorded on the Bitcoin blockchain to indicate the official opening of the channel.In this example, the payment channel connecting Alice and Bob is essentially an ordinary 2-of-2 multi-signature wallet, which contains a balance of 200,000 (for simplification, we do not consider the miner’s fee to be paid when opening the channel for the time being (for the sake of simplification).).
2. Start trading: the art of off-chain trading
After the channel is opened, all subsequent transactions of the participating parties will be conducted outside the Bitcoin blockchain, achieving efficient off-chain settlement.Let’s assume that the following 3 transactions were made between Alice and Bob:
-
Alice transferred 10,000 to Bob. At this time, Alice owns 90,000 to Bob owns 110,000.
-
Alice continues to transfer 20,000 to Bob, at this time Alice owns 70,000 to Bob and 130,000 to Bob.
-
Bob transferred 10,000 to Alice, at this time Alice owns 80,000 to Bob owns 120,000.
From the example above, we can see that no matter how many transfers are made between Alice and Bob, the channel balance between them remains unchanged, and it is 200,000 Cong.
Every time Alice and Bob trade, both parties need to update their respective balances in the channel and exchange a signed “Commitment Transaction”.These transactions themselves are valid and can be sent to the Bitcoin network at any time, but both parties will usually save it without broadcasting unless they intend to close the channel.In this way, the balance status of Alice and Bob in the channel will change dozens or hundreds of times in one second. The update speed is limited by the speed at which both parties create, sign and send promised transactions to each other.
3. Close the channel: the final settlement time
The closing channel can be carried out in two ways: one is that both parties agree to close and send a settlement transaction to the Bitcoin network; the other is that the unilateral decision to close and send the last Commitment Transaction to theIn the Bitcoin network.The latter is designed to prevent one party from offline causing the other party to remain locked in the channel.
In the example of Alice and Bob, they decided to close the channel after 3 transactions.After closing, Alice retrieves 80kon and Bob retrieves 120kon (again, for simplicity, we do not consider the miner’s fees incurred when closing the channel).
Security guarantees for two-way payment channels: from LN-Penalty to eltoo to Daric
As mentioned above, closing the channel can be either closed by both parties unanimously or unilaterally decided to close.So, in the two-way payment channel, how to prevent fraud from one party?For example, in the above example, how can Bob prevent him from closing the channel by holding the second rather than the third promise transaction?If you use the second promised transaction to close the channel, Bob can denied the 10,000 payment that was last paid to Alice, which obviously looks very tempting.
The Bitcoin Lightning Network has introduced the LN-Penalty mechanism to prevent a party from closing the channel by sending an outdated but beneficial state on the chain.LN-Penalty uses complex technologies such as “asymmetric commitment transactions” and “revoked keys” to ensure that if Bob tries to close the channel using outdated commitment transactions, Alice will be entitled to all funds in the channel — 200,000.This punishment mechanism effectively curbs potential fraud.
However, LN-Penalty also has some shortcomings, which in addition to its own complexity, also creates a storage burden – users must save data from every time they update the channel status in the past, and some rare situations may cause it to unexpectedlyPunish honest users.
To overcome these shortcomings, as early as 2018, the Bitcoin community proposed the title “eltoo” solution to eliminate the risk of storage burden and accidental punishment. In this solution, users only need to save the latest promised transaction and its settlement transaction. However,The eltoo scheme is still not available because its implementation requires a soft fork of Bitcoin and introduces a new signature hash type——SIGHASH_ANYPREVOUT.
The Fiber Network launched by Nervos CKB chose the Fiber Network proposed in 2022Daricplan.Based on eltoo, Daric effectively solved the cost and security issues of watchtower.The watchtower is a lightning network node running on independent machines and networks. It monitors payment channels and helps the victims execute confiscation transactions when malicious behavior is detected, thereby protecting users’ funds.Node operators usually run their own watchtowers to protect their nodes.
Conclusion
As a Bitcoin expansion solution, Lightning Network lies in a cleverly designed payment channel system.Through three stages: opening the channel, off-chain transaction and closing the channel, Lightning Network has greatly improved the transaction speed and reduced costs.
In order to ensure the security of the two-way payment channel, Lightning Network adopts the LN-Penalty mechanism, and the Bitcoin community has also proposed better security mechanisms such as eltoo and Daric to effectively prevent potential fraud.
These innovations have enabled Lightning Network to ensure security while bringing significant performance improvements to the Bitcoin network, paving the way for fast and low-cost small payments.