Micropayment Channel and Lightning Network

Reference link:

Lightning Network Learning Resources Directory

1. Micropayment channel

Examples and understanding of micropayment channels

"If a tree in the forest falls down and no one around hears it, will it make a sound?"

Application scenarios:

​ A large number of small transactions are not cost-effective because of the existence of handling fees. Gather less and more through unpaid channels,Only need two transactions on the chain, To reduce the number of payments and the pressure of the blockchain.

Transaction Type:

  • Funding Transaction

    A transaction in which the payer deposits money on a public account, and this transaction needs to be chained.

  • Refund Transaction

    The public accounts in the money returned to the payer's transaction, this transaction in the margin trading before were , and this transaction will not be on the chain. The payer will first sign the transaction to the receiver so that the funds in the public account can be retrieved after waiting for nlocktime in the transaction . After the receiver has signed, it can send a margin transaction on the chain.

    Refund Tx can be regarded as the first update Tx, so its nlockTime is also the largest, and subsequent update Tx is to modify its amount.

  • update Transaction / Commitment Transaction

    Every time a micropayment is an off-chain transaction, the amount returned to the payer and the receiver is constantly updated (decrease the payer and increase the receiver) to achieve. These transactions are only known to both parties, and the newer the update Tx, the smaller its nLockTime time.

    Update Tx is a security guarantee that the receiver holds. Once the payer breaches the contract, the receiver can broadcast the latest Update Tx on the chain to reduce its own losses.

  • Settlement Transaction

    When all the micropayments are completed, the last step of the Update Tx transaction is generated. The output of this transaction is that the payer is 0 and the receiver is the full amount. After receiving this transaction, the receiver broadcasts it on the chain to realize the end of the entire micropayment transaction.

Personal understanding: The core idea of ​​the micro-payment channel is to conduct a large number of "micro" transactions under the chain. The multi-signature technology and the transaction time lock (nLockTime) mechanism are used to ensure the security of both parties. The real broadcast transaction on the chain only has the beginning Funding Transaction and Settlement Tx, micro-payment channels are trustless off-chain, because micropayments are expensive to establish trust, and rely on the support of cryptographic encryption algorithms to achieve the security of the interaction between the two parties

"By postponing the announcement of every transaction to the world, Bitcoin users can net their relationship at a later date , allowing them to do many things without increasing the blockchain or establishing trust among centralized counterparties. transaction."

2. Lightning Network

The core solution is the expansion of Bitcoin .

The micro-payment channel can solve the scalability problem through offline delayed transactions + time locks, but the problem is that it is difficult to establish such a one-way channel between the two.

Currently, hub-and-spoke micropayment channels (and trusted payment channel networks) have begun to build hub-and-spoke networks.

The two-way micropayment channel of the Lightning network needs a malleable soft fork to achieve near-infinite scalability while reducing the risk of default by intermediate nodes

By linking multiple micropayment channels together, it is possible to create a transaction path network . The path can be routed using a system similar to ***BGP***, and the sender can specify a specific path to the receiver. The output script is occupied by a hash generated by the receiver. By writing input information to the hash function, the recipient's counterparty will be able to withdraw funds in the process. (The recipient of the transaction uses the input information given by the sender to crack the hash)

Key Technologies of Lightning Network

Learning source: https://www.jianshu.com/p/e326802294e1

RSMC

(Recoverable Sequence Maturity Contract, revocable contract when sequence expires)

RSMC solves the problem of one-way currency flow in the micropayment channel

1. Establish a two-way micro-payment channel
y48MUU
  1. Zhang San and Li Si each took out a btc to build Funding Tx. This transaction requires the 2/2 dual signatures of Zhang San and Li Si to be valid on the chain. It is currently unsigned, so it does not take effect. The output of Funding Tx is Zhang San And Li Si's multi-signature address.

  2. Zhang San created Commitment Tx, which are C1A and D1A. Both transactions require the 2/2 dual signatures of Zhang San and Li Si to take effect. Zhang San 2 represents Zhang San's second private key.

    ​ Input in C1A: Output of Funding Tx

    ​ Output in C1A: 1. Zhang San & Li Si's multi-signature address, the amount is 1BTC. 2. Li Si address, amount 1BTC

    ​ Input in D1A: the first output in C1A

    ​ Output in D1A: Zhang San, amount 1BTC, serial number: 1000 (The function of the serial number is to prevent the current transaction from entering the block, and only the forward transaction can enter the block with Sequence confirmation)

    After Zhang San is constructed, give it to Li Si for signature

    For Li Si, construct C1B and D1B in the same way, and sign Zhang San after construction

  3. Both parties help each other to sign. At this time, because Funding Tx has not completed the multi-signature, even C1A, C1B, D1A, D1B transactions have been signed, but because the "source" transaction Funding Tx is not on the chain, it is an invalid transaction. .

  4. After both parties complete the signing of the Commitment Tx, they then sign the Funding Tx and exchange it.At this time, the Funding Tx is a complete transaction and can be broadcast into the main chain.

discuss

  • Because C1A and C1B both come from the same parent transaction (Funding Tx), because of the double-spending restriction of the main chain, only one side will be able to go on the chain in the end.
  • Punishment mechanism: If one party broadcasts the transaction first, for example, Zhang San first broadcasts C1A, then Li Si will immediately get 1BTC in return, but Zhang San will have to wait for 1,000 confirmations through D1A to get his own 1BTC. The person who unilaterally terminates the contract Will be punished for delayed refund .
2. Transfer (Update Commitment Tx)

I5HB88

When both parties need to transfer money, update the Commitment Tx. For example, if Zhang San bought something from Li Si and Zhang San transferred 0.5 BTC to Li Si, then the balance should be Zhang San 0.5 BTC and Li Si 1.5 BTC. At this time Zhang San updates It is C2A and D2A, but at this time the original C1A and D1A are all valid. How to abolish the previous state?

RSMC uses a clever approach:

For Zhang San, copying Zhang San 2's signature private key to Li Si means automatically giving up C1A and D1A and choosing the latest C2A, D2A.

Because once Li Si has Zhang San 2’s private key, he can modify D1A, resulting in punishment for Zhang San.

md0W3G

As shown in the figure, after Li Si received Zhang San 2’s private key, he modified D1A to F1A and held it in his own hand. If Zhang San updated to C2A after receiving the product and broadcasted C1A, then Li Si could publish The F1A in his hand punishes Zhang San (i.e. broadcasting F1A instead of D1A), and handing over the private key is equivalent to signing F1A . At this time, Zhang San will lose all his funds.

The purpose of introducing sequence is to give a penalty window.When the other party is found to have broken the contract, there can be 1000 confirmation transactions to impose the penalty, but if this time is missed, the penalty cannot be performed.

HTLC

(Hashed Timelock Contract, Hash Timelock Contract)

HTLC solves the problem of currency transfer across nodes

3. Transit transaction

When Zhang San and Wang Wu need to trade, they must repeat the construction of such a channel, but Zhang San and Li Si have a two-way channel, and Li Si and Wang Wu have a two-way channel, so at this time, you can use Li Si to pass HTLC. Realize the micropayment transfer transaction between Zhang San and Wang Wu.

i6MZwS

➊. Zhang San informs Wang Wu that I want to transfer 0.5 BTC to you, and then Wang Wu receives a random number R value from Zhang San;

➋, Wang Wu performs Hash operation on this R value to get H® and reply to Zhang San;

➌. After receiving the reply, Zhang San contacted Li Si and told Li Si: If you find the original R value of H(R), I will transfer it to you 0.5BTC;

➍. Li Si learned that Wang Wu knew the R value, so he started negotiations with Wang Wu. Li Si told Wang Wu that if you tell me the R value Zhang San sent you, I will transfer you 0.5 BTC;

➎, Wang Wu exchanged 0.5 BTC from Li Si with his R value;

➏, Li Si then used R value to exchange 0.5 BTC from Zhang San.

Finally, the transaction was completed and Zhang San paid Wang Wu 0.5 BTC in the form of off-chain/off-chain.

5bFtKf
Of course, in this process, Li Si can charge an intermediary fee.In the fourth step, Li Si gives Wang Wu 0.4 BTC to obtain an intermediary fee of 0.1 as a reward for Li Si.

4. Close the transaction

The way to close the RSMC is to directly construct the final Commitment Tx of the last state, and then both parties sign and broadcast the transaction.

Three, summary

advantage:

The Lightning Network cleverly implements a two-way micropayment channel through the multi-signature mechanism and the sequence delay penalty mechanism, and then uses the HTLC hash lock mechanism to achieve the establishment of the transit node. The hash lock mechanism has a certain degree of cross-chain technology. What to learn from. In addition, the most important thing is that, except for the initial Funding Tx and the final Commitment Tx that need to be on the chain, the Lightning Network is all carried out off-chain, which greatly reduces the load on the main chain.

Disadvantages:

  • The intermediate process will use a large number of public and private keys and need to be stored locally by the trader. Then the security of local storage is a problem. If the other party submits an expired transaction, it will be difficult to make up for the loss.

  • The counterfeit must be discovered within the specified time, otherwise the punishment will not take effect

  • There are currently two ways to solve the above, one is to become a lightning network node for yourself, and the other is to monitor the transactions on the main chain through a third-party lightning network node (watchtower), then there will be a third party.

Guess you like

Origin blog.csdn.net/weixin_43988498/article/details/114300536