6

How Lightning Network handles double-spend? What will happen when the other person is not available online to enforce the integrity of the transactions?

PFB my understanding of the Lightning Network.

Lightning Network builds an additional layer on top of the Bitcoin network that enables instant off-chain transfer of the ownership of the Bitcoin. Lightning Network utilises bi-directional payments channels that consist of multi-signature addresses.  Meaning Bitcoin will be held in a multi-signature address where transactions will use a multi-signature address as their input and point at two different addresses as their output. The transactions inside the lighting network are not broadcasted to the bitcoin network as long the channel is open (in order to reduce the load on the blockchain).

In this example how is Alice prevented from double spending?

  1. Alice and Bob both send 0.05 BTC into a shared 2-of-2 multisig address. This requires a transaction on the Bitcoin blockchain.

  2. Alice wants to pay 0.1 BTC to Bob. a. Alice creates a new transaction B2 and changes the balance to 0.4 BTC to Alice and 0.6BTC to Bob. b. Alice signs B2 and sends to Bob c. Now Bob creates a new transaction A2 and changes the balance to 0.4 BTC to Alice and 0.6BTC to Bob. d. Bob signs A2 and sends to Alice. After step 2a (before Bob verifies the transaction), can Alice close the channel and double spend the money?

8
  • In your example both the transactions are identical. They have the same balances. Commented Jan 1, 2018 at 14:51
  • Thanks! Have edited the question. Need to know how LN is stopping Alice from spending the same BTC to Bob and transfer the same by closing the channel if Bob is not online ?
    – Holmes
    Commented Jan 1, 2018 at 15:00
  • Which transaction is Alice broadcasting to close the channel? Commented Jan 1, 2018 at 15:19
  • can she broadcast the initial transaction balance 0.5 BTC to the blockchain & unilaterally close the channel? while Bob is unavailable to verify the transaction in the LN channel
    – Holmes
    Commented Jan 1, 2018 at 15:21
  • 1
    Thanks! In general how does the protocol enforce integrity of the transactions since its not broadcasted to the blockchain?
    – Holmes
    Commented Jan 1, 2018 at 21:20

3 Answers 3

2

Doublespends are not possible, because a payment on LN is only considered finalized once both payment channel owners have revoked the previous state of the payment channel by handing their partner a breach remedy that invalidates the previous state.

Thus, Bob should not hand over whatever service Alice was purchasing until the payment is finalized. Once the payment is finalized, Alice can no longer broadcast the old state without opening herself up to the penalty transaction being broadcast by Bob.

2

Based on your comments, I think one fundamental issue you're missing is that to pay with LN, the other party has to be online at the time. There's no question of "what happens if Bob is offline" because if he is offline, no payment is possible.

The other thing you need to know - especially if you meant that Bob is offline after the payment was completed - is that LN is complicated. Many transactions are involved in each payment. To get the full details you will have to read the whitepaper - https://lightning.network/lightning-network-paper.pdf.

But a main point is that as part of the process of accepting an LN payment, Bob gets a penalty transaction. If Alice ever tries to broadcast a tx representing an old channel state, thus reverting an earlier payment, Bob can broadcast his penalty tx, and take all the money in the channel (even the part that never belonged to him).

Because of this, it is recommended that Bob either stays online constantly, or delegates watchtowers to this job (which does not give the watchtowers access to Bob's money).

2
  • What stops Bob from broadcasting the penalty transaction even if Alice didn't do anything wrong? Commented Sep 11, 2021 at 22:25
  • @theferrit32: The penalty transaction spends outputs that are in Alice's old-state transactions, which shouldn't be public. Unless Alice cheats, those outputs don't exist, so the penalty tx is invalid and can't do anything. Commented Sep 20, 2021 at 15:05
2

Alice and Bob open a channel with a fixed balance equal to the amount in the multi-sig address. The channel opens with a balance sheet which includes proof for both Alice and Bob’s balance.

Every update to the balance sheet requires action and cooperation from both Alice and Bob, so they must both be online, and each step is designed with contingencies keeping the process fair by providing leverage against an uncooperative party.

The balance book is therefore always identical for both parties. When closing a channel, if both parties sign, the channel closes cleanly. One party could close the channel by themselves, as they have a signed contingency script provided by the other party but that script includes a time lock. This gives the other party time to see, verify and contest the closing transaction by providing details of a newer balance if it exists. There won’t be one if the first party was honest because that party would not agree to partake in any more payments.

The cost of cheating is that the cheater gets 0 and the would be victim gets the whole balance. If the victim is not online for the whole time lock duration and does not contest the transaction, they can be a victim of double spend. Users should always be online and the time lock provides a contingency in case of outages or down time for justice to be served.

If need be, you can use “watchtowers” to protect you if your node is offline often.

As long as one or both party is closing the channel, the balance sheet will not change and transactions will not route through your channel, so the lightning network will never experience an imbalance or double spend off-chain.

You can experience a double spend if you are not online, but with the time lock and the penalty of forfeiting all the funds, the risk of ending up worse off is very high so although possible, this type of attack is very unlikely.

1
  • That's a great first contribution. Welcome to the site!
    – Murch
    Commented Nov 1, 2020 at 0:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.