<p>All transactions that are sent between the two parties in a channel are <em>valid</em> bitcoin transactions, and they can be used to close the channel at any time by either party. </p>

<p>When a channel is opened, those bitcoins are locked up in that channel until it is closed with a spending transaction, sending an agreed amount of bitcoin to each party in the channel. Initially this spending transaction is created to return the same amount of bitcoin that each party put in to the channel. But 'transactions' are made, which is really just each party agreeing to create <em>new</em> spending transactions to replace the old one, giving each party a different amount. </p>

<p>If each party, for example, locks in 1 BTC to a channel, they will also create a spending transaction at the same time returning that 1 BTC to each person. Then let's say person A wants to send 0.2 BTC to person B. To do this, they simply work together to create a new valid spending transaction to replace the old one, the new one would pay A 0.8 BTC and B 1.2 BTC, effectively transferring that 0.2 BTC from A to B. New transactions like this are continually created every time either person wants to send coins, until finally one of the two participants wishes to close the channel and actually get their BTC back. This also happens if one party stops responding/cooperating. The final transaction they agreed upon is broadcast to the actual blockchain, closing the channel and paying both participants.</p>

<p>Thus, at all times, the transactions are valid and the actual bitcoins being exchanged are locked up in the blockchain, so there is no way for anyone to double-spend the transactions.</p>

CC BY-SA 3.0
2017-12-14T23:17:18.330Z
Some hope is in the fact that with fewer on-chain transactions (more lightning adoption), there will be less congestion and so transactions will confirm faster. But it is likely some more on-chain scaling will take place too in the coming years
meshcollider
CC BY-SA 3.0
2017-12-29T23:08:18.803Z
So that means: You have to block your coins for a channel. So, you can't use them for other things. So basically: I can't work with my coin. I can't trade them, I can't spend them. They stock in this channel. Is that correct?
Citrullin
CC BY-SA 3.0
2017-12-30T02:45:09.367Z
@PhilippBlum no! You trade them within the lightning network! You just don't update the blockchain until the channel closes
meshcollider
CC BY-SA 3.0
2017-12-31T07:00:50.353Z
@MeshCollider I understand this. But you can only spend this to one party. Let's say, you have something where you have 20 transactions per month. So, but it is to low to spend everytime transaction fees. So, you open a channel. So now you have to block some coins to this channel. You cannot use this coins for another channel or the blockchain, right? So they are blocked for one month.
Citrullin
CC BY-SA 3.0
2017-12-31T08:03:35.313Z
Once locked in a channel, they can only be used on the lightning network yes, until the channel is closed (which can happy at any time if users cooperate, normally you don't need to wait 1 month). But you can send them anywhere on the network by routing payments through other channels created by other users, you aren't limited to sending to just the other user in the channel
meshcollider
CC BY-SA 3.0
2017-12-14T17:18:30.700Z
But what is the news here? who guarantees that the concluding transaction in the channel will be added to the blockchain in a timely manner? and what if in 2020 it takes 10 months to get 3 approval (even for lightning channels as it seems to be yet another client of the network)?
Nir O.
CC BY-SA 4.0
2018-07-01T21:45:50.527Z
But that one party may then relay the payment to a third aprty. Generally assume that you will lock up "significant" funds with one hub (significant: not a coffe but your hot wallet) and the hub will then have many channels open to many users and other hubs. And also assume you do NOT regularly close the channel every other week. You can spend them - on lightning. You can trade - because it is assumed that guess what, exchanges will accept lightining transfers. Basically: a LN channels "is" a hot wallet.
TomTom
CC BY-SA 3.0
2017-11-04T02:59:57.517Z
2017-11-04T02:59:57.517Z
meshcollider
<p>Transactions in a payment channel are still real Bitcoin transactions. They require the cooperation of both parties in the channel, so there is no bank and no central party that can rewrite history or double spend anything in a channel.</p>

<p>In order to change one party's balance in a payment channel, both parties must agree to it and sign the commitment transaction that changes the balances. So neither party can double spend nor can they change the transaction history without the other party agreeing to it.</p>

<p>To avoid a malicious party from broadcasting an old commitment transaction where they had a higher balance, such commitment transactions have a revocation key where the other party that would be defrauded is allowed to take ALL of the Bitcoin in the channel. This is an incentive for people to not broadcast old commitments as they would lose all of their money in the channel.</p>

CC BY-SA 3.0
2017-11-04T02:59:11.473Z
2017-11-04T02:59:11.473Z
Ava Chow
<p>At one point, sidechain channels have to be closed and a real transaction will happen on the bitcoin blockchain. When the channel close, it is the responsibility of both banks to make sure that everything is fine and they were not hacked. They have no incentive to allow double spend from any of their clients since it will result in a loss of money for them.</p>

<p>Banks agree on the direction and the amount of the bitcoin transaction, then they send the transaction. If there is any disagreement between them or if one of the bank is not honest, no bitcoin transfer will take place and each bank keep the same amount of bitcoins it had before the channel started.</p>

<p>One important point to note is that no individual client transactions ever took place on the bitcoin blockchain. Only a transaction between Bank 1 and Bank 2 will be recorded. The blockchain is not involved in the details of the client transactions between both banks, only the aggregation of all transactions will be recorded on the blockchain.</p>

<p>Example:</p>

<pre><code>Bank 1 send payments to Bank 2: A + B + C

Bank 1 receive payments from Bank 2: D, E

Sum_TX = A + B + C - D - E

When the channel is closed, if Sum_TX &gt; 0:

 * Bank 1 will send Sum_TX bitcoins to Bank 2
 * Bank 2 will send Sum_TX bitcoins to Bank 1
</code></pre>

CC BY-SA 3.0
2017-10-05T12:44:22.590Z
Thanks for your explication, but if responsibiliy and trust between the partys inside Lightning network, are the only things who garanty that there will be no doble spend inside the channel, than whats the differents between lightning and the banking system today, wich also is based on trust ... and how that goes out ... you know. And perhaps the banks dont cheat each other , but there is a big incentive for them to cheat the client, as they do today, with fractional reserve banking etc ... i prefer Bitcoin a trustless peer to peer digital cash as Satoshi Nakamoto point out in his white paper
laizess
CC BY-SA 4.0
2018-07-01T21:46:35.283Z
Actually no. There is a financial incentitive not to try to cheap and it is part of the protocol specs. The cheating party looses their money in the channel.
TomTom
CC BY-SA 4.0
2021-02-12T05:29:19.143Z
How do you know who cheated? What if both parties claim they were cheated by the other, but one of them actually was. How does the network know who is telling the truth?
theferrit32
CC BY-SA 3.0
2017-10-04T23:38:48.447Z
2017-10-04T23:46:19.973Z
2017-10-04T23:46:19.973Z
Julien Klepatch
<p>As I understand payment-channels, like the lightning network, they are working off chain (no record in the blockchain). The only record to the blockchain is the deposit transaction to open the payment-channel and by closing the payment channel. But later all the transactions inside the payment-channel running on centralized servers, like traditional bank transfers. This is very fast, and could be very cheap if there is competition. But how the banks, who would run such payment-channels can secure that inside the payment-channel the transactions are not hacked and safe? And how the bank guarantee the customers that they dont double spend the funds if inside the channel all transaction are totally anonymous? </p>

<security><lightning-network><micropaymentchannels>
How is the lightning network secured against hacking and double spends?
laizess
# How is the lightning network secured against hacking and double spends?

(Asked by: username_0 on 2017-10-04)

As I understand payment-channels, like the lightning network, they are working off chain (no record in the blockchain). The only record to the blockchain is the deposit transaction to open the payment-channel and by closing the payment channel. But later all the transactions inside the payment-channel running on centralized servers, like traditional bank transfers. This is very fast, and could be very cheap if there is competition. But how the banks, who would run such payment-channels can secure that inside the payment-channel the transactions are not hacked and safe? And how the bank guarantee the customers that they dont double spend the funds if inside the channel all transaction are totally anonymous?

**Tags:** security, lightning-network, micropaymentchannels


---

## 3 answers

### Answer by username_1 on 2017-11-04. Score: 5

All transactions that are sent between the two parties in a channel are *valid* bitcoin transactions, and they can be used to close the channel at any time by either party.

When a channel is opened, those bitcoins are locked up in that channel until it is closed with a spending transaction, sending an agreed amount of bitcoin to each party in the channel. Initially this spending transaction is created to return the same amount of bitcoin that each party put in to the channel. But 'transactions' are made, which is really just each party agreeing to create *new* spending transactions to replace the old one, giving each party a different amount.

If each party, for example, locks in 1 BTC to a channel, they will also create a spending transaction at the same time returning that 1 BTC to each person. Then let's say person A wants to send 0.2 BTC to person B. To do this, they simply work together to create a new valid spending transaction to replace the old one, the new one would pay A 0.8 BTC and B 1.2 BTC, effectively transferring that 0.2 BTC from A to B. New transactions like this are continually created every time either person wants to send coins, until finally one of the two participants wishes to close the channel and actually get their BTC back. This also happens if one party stops responding/cooperating. The final transaction they agreed upon is broadcast to the actual blockchain, closing the channel and paying both participants.

Thus, at all times, the transactions are valid and the actual bitcoins being exchanged are locked up in the blockchain, so there is no way for anyone to double-spend the transactions.

> **Comments:**
> **username_3**: But what is the news here? who guarantees that the concluding transaction in the channel will be added to the blockchain in a timely manner? and what if in 2020 it takes 10 months to get 3 approval (even for lightning channels as it seems to be yet another client of the network)?  
> **username_1**: Some hope is in the fact that with fewer on-chain transactions (more lightning adoption), there will be less congestion and so transactions will confirm faster. But it is likely some more on-chain scaling will take place too in the coming years  
> **username_2**: So that means: You have to block your coins for a channel. So, you can't use them for other things. So basically: I can't work with my coin. I can't trade them, I can't spend them. They stock in this channel. Is that correct?  
> **username_1**: @PhilippBlum no! You trade them within the lightning network! You just don't update the blockchain until the channel closes  
> **username_2**: @MeshCollider I understand this. But you can only spend this to one party. Let's say, you have something where you have 20 transactions per month. So, but it is to low to spend everytime transaction fees. So, you open a channel. So now you have to block some coins to this channel. You cannot use this coins for another channel or the blockchain, right? So they are blocked for one month.  
> **username_1**: Once locked in a channel, they can only be used on the lightning network yes, until the channel is closed (which can happy at any time if users cooperate, normally you don't need to wait 1 month). But you can send them anywhere on the network by routing payments through other channels created by other users, you aren't limited to sending to just the other user in the channel  
> **username_4**: But that one party may then relay the payment to a third aprty. Generally assume that you will lock up "significant" funds with one hub (significant: not a coffe but your hot wallet) and the hub will then have many channels open to many users and other hubs. And also assume you do NOT regularly close the channel every other week. You can spend them - on lightning. You can trade - because it is assumed that guess what, exchanges will accept lightining transfers. Basically: a LN channels "is" a hot wallet.  

---

### Answer by username_5 on 2017-11-04. Score: 3

Transactions in a payment channel are still real Bitcoin transactions. They require the cooperation of both parties in the channel, so there is no bank and no central party that can rewrite history or double spend anything in a channel.

In order to change one party's balance in a payment channel, both parties must agree to it and sign the commitment transaction that changes the balances. So neither party can double spend nor can they change the transaction history without the other party agreeing to it.

To avoid a malicious party from broadcasting an old commitment transaction where they had a higher balance, such commitment transactions have a revocation key where the other party that would be defrauded is allowed to take ALL of the Bitcoin in the channel. This is an incentive for people to not broadcast old commitments as they would lose all of their money in the channel.


---

### Answer by username_6 on 2017-10-04. Score: 0

At one point, sidechain channels have to be closed and a real transaction will happen on the bitcoin blockchain. When the channel close, it is the responsibility of both banks to make sure that everything is fine and they were not hacked. They have no incentive to allow double spend from any of their clients since it will result in a loss of money for them.

Banks agree on the direction and the amount of the bitcoin transaction, then they send the transaction. If there is any disagreement between them or if one of the bank is not honest, no bitcoin transfer will take place and each bank keep the same amount of bitcoins it had before the channel started.

One important point to note is that no individual client transactions ever took place on the bitcoin blockchain. Only a transaction between Bank 1 and Bank 2 will be recorded. The blockchain is not involved in the details of the client transactions between both banks, only the aggregation of all transactions will be recorded on the blockchain.

Example:

```
Bank 1 send payments to Bank 2: A + B + C

Bank 1 receive payments from Bank 2: D, E

Sum_TX = A + B + C - D - E

When the channel is closed, if Sum_TX > 0:

 * Bank 1 will send Sum_TX bitcoins to Bank 2
 * Bank 2 will send Sum_TX bitcoins to Bank 1

```

> **Comments:**
> **username_0**: Thanks for your explication, but if responsibiliy and trust between the partys inside Lightning network, are the only things who garanty that there will be no doble spend inside the channel, than whats the differents between lightning and the banking system today, wich also is based on trust ... and how that goes out ... you know. And perhaps the banks dont cheat each other , but there is a big incentive for them to cheat the client, as they do today, with fractional reserve banking etc ... i prefer Bitcoin a trustless peer to peer digital cash as Satoshi Nakamoto point out in his white paper  
> **username_4**: Actually no. There is a financial incentitive not to try to cheap and it is part of the protocol specs. The cheating party looses their money in the channel.  
> **username_7**: How do you know who cheated? What if both parties claim they were cheated by the other, but one of them actually was. How does the network know who is telling the truth?  

---

