<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2018-04-21T00:03:57.513Z
2018-04-21T00:03:57.513Z
Murch
<p>Based on your comments, I think one fundamental issue you're missing is that to pay with LN, the other party <em>has</em> 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.</p>

<p>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 - <a href="https://lightning.network/lightning-network-paper.pdf" rel="nofollow noreferrer">https://lightning.network/lightning-network-paper.pdf</a>.</p>

<p>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 <em>all</em> the money in the channel (even the part that never belonged to him).</p>

<p>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).</p>

CC BY-SA 4.0
2021-09-11T22:25:11.693Z
What stops Bob from broadcasting the penalty transaction even if Alice didn't do anything wrong?
theferrit32
CC BY-SA 4.0
2021-09-20T15:05:28.730Z
@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.
Meni Rosenfeld
CC BY-SA 4.0
2018-06-27T13:10:16.113Z
2018-06-27T13:10:16.113Z
Meni Rosenfeld
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>If need be, you can use “watchtowers” to protect you if your node is offline often.</p>
<p>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.</p>
<p>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.</p>

CC BY-SA 4.0
2020-11-01T00:53:34.020Z
That's a great first contribution. Welcome to the site!
Murch
CC BY-SA 4.0
2020-10-27T04:25:31.580Z
2020-10-27T04:25:31.580Z
D.Mistry
<p>How Lightning Network handles double-spend? What will happen when the other person is not available online to enforce the integrity of the transactions?</p>

<p>PFB my understanding of the Lightning Network.</p>

<blockquote>
  <p>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).</p>
</blockquote>

<p>In this example how is Alice prevented from double spending?</p>

<ol>
<li><p>Alice and Bob both send 0.05 BTC into a shared 2-of-2 multisig address. This requires a transaction on the Bitcoin blockchain.</p></li>
<li><p>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?</p></li>
</ol>

CC BY-SA 3.0
2018-01-01T14:51:57.983Z
In your example both the transactions are identical. They have the same balances.
Matthew Stannard
CC BY-SA 3.0
2018-01-01T15:00:26.863Z
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
CC BY-SA 3.0
2018-01-01T15:19:15.627Z
Which transaction is Alice broadcasting to close the channel?
Matthew Stannard
CC BY-SA 3.0
2018-01-01T15:21:54.207Z
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
CC BY-SA 3.0
2018-01-01T15:38:11.467Z
Did Bob receive and broadcast the 'anti-cheat' transaction from Alice after she sent him B2?
Matthew Stannard
CC BY-SA 3.0
2018-01-01T15:47:49.767Z
No, in that case can Alice double spend her coins ?
Holmes
CC BY-SA 3.0
2018-01-01T15:50:18.483Z
Did Bob provide any goods or services to Alice? If so, Yes. But only because Bob hasn't followed the protocol correctly.
Matthew Stannard
CC BY-SA 3.0
2018-01-01T21:20:00.163Z
Thanks! In general how does the protocol enforce integrity of the transactions since its not broadcasted to the blockchain?
Holmes
<lightning-network><ln-penalty-transaction><ln-closing-channels>
How is a doublespend prevented in the Lightning Network?
Holmes
# How is a doublespend prevented in the Lightning Network?

(Asked by: username_0 on 2018-01-01)

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?

**Tags:** lightning-network, ln-penalty-transaction, ln-closing-channels

> **Comments:**
> **username_1**: In your example both the transactions are identical. They have the same balances.  
> **username_0**: 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 ?  
> **username_1**: Which transaction is Alice broadcasting to close the channel?  
> **username_0**: 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  
> **username_1**: Did Bob receive and broadcast the 'anti-cheat' transaction from Alice after she sent him B2?  
> **username_0**: No, in that case can Alice double spend her coins ?  
> **username_1**: Did Bob provide any goods or services to Alice? If so, Yes. But only because Bob hasn't followed the protocol correctly.  
> **username_0**: Thanks! In general how does the protocol enforce integrity of the transactions since its not broadcasted to the blockchain?  

---

## 3 answers

### Answer by username_2 on 2018-04-21. Score: 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.


---

### Answer by username_3 on 2018-06-27. Score: 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).

> **Comments:**
> **username_4**: What stops Bob from broadcasting the penalty transaction even if Alice didn't do anything wrong?  
> **username_3**: @username_4: 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.  

---

### Answer by username_5 on 2020-10-27. Score: 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.

> **Comments:**
> **username_2**: That's a great first contribution. Welcome to the site!  

---

