<p>Yes. Since you cannot sign a signature and signatures in a transaction are used when calculating a <code>txid</code>, therefore only segregated witnesses or normalized txids would fix transaction malleability. </p>

CC BY-SA 3.0
2016-08-25T09:06:21.330Z
Thanks for this answer. I understand the Payment tx can still suffer from that kind of malleability, as it points to a tx (the Deposit) that is not yet in the blockchain. But it seems to me that the payee is insulated from any risk thanks to BIP65, as the deposit can be spent by the payee at a later date (viz. when Deposit will have been added to the blockchain and malleability will not be an issue). Is not it so? (I edited my question following your answer. Thanks agn)
hartmut
CC BY-SA 3.0
2016-08-25T09:22:21.390Z
It still depends on time frame and what's your risk tolerance. If you're 100% risk-averse, then the payee is always at risk as its possible for a conflicting fork to become the winning chain and malleability can still affect the payee in the fork.
rny
CC BY-SA 3.0
2016-08-24T21:59:18.887Z
2016-08-24T21:59:18.887Z
rny
<p>There are a variety of different ways to construct a micropayment channel, but there are two designs that I think are particularly relevant to your question about "simple, one-directional, micropayment channels":</p>

<ul>
<li><p><strong>Spillman-style micropayment channels:</strong> this was a commonly-described micropayment channel design prior to <a href="https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki" rel="noreferrer">BIP65</a> (<code>OP_CHECKLOCKTIMEVERIFY</code>, CLTV).  Spillman-style channels were first <a href="https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2013-April/002433.html" rel="noreferrer">described by Jeremy Spillman</a> in April 2013 and <a href="https://bitcoinj.github.io/working-with-micropayments" rel="noreferrer">implemented in the BitcoinJ library</a> in <a href="https://bitcointalk.org/index.php?topic=244656.0" rel="noreferrer">2013</a>.</p></li>
<li><p><strong>CLTV-style micropayment channels:</strong> this is a new way to construct a payment channel that became possible when CLTV became enforced in mid-December 2015.  CLTV-style channels were described by BIP65 author Peter Todd as part of that BIP and implemented in <a href="https://github.com/21dotco/two1-python" rel="noreferrer">two1-python</a> in <a href="https://medium.com/@21/true-micropayments-with-bitcoin-e64fec23ffd8" rel="noreferrer">February 2016</a>.</p></li>
</ul>

<p>The following two sections describe how malleability relates to those two different types of micropayment channels.</p>

<h2>Malleability in Spillman-style micropayment channels</h2>

<p>BIP65 does not change how malleability affects Spillman-style micropayment channels, so the following description was true before BIP65 became enforced as well as now (at least for transactions which do not use segwit).</p>

<p>A Spillman-style micropayment channel is constructed using the following sequence of events between the Merchant (who is receiving the funds) and the Customer (who is spending the funds):</p>

<ol>
<li>The Merchant gives his public key to the customer.</li>
<li>The Customer uses his public key and the Merchant's public key to construct a multisig P2SH address[1] that will require signatures from both the Merchant and the Customer to spend any funds paid to that address.</li>
<li>The Customer generates (but does not transmit) a transaction that pays the multisig P2SH address.</li>
<li>The Customer generates a second transaction that spends the first transaction back to one of the Customer's addresses, gives this transaction a locktime (so it can't be added to the blockchain until a certain time), and signs this transaction.</li>
<li>The Customer gives this second transaction to the Merchant (without giving him the first transaction), and the Merchant signs it and returns the signed transaction to the Customer.</li>
<li>Now the Customer will be able to use this second transaction, called the <em>refund transaction,</em> to claim a refund if the Merchant doesn't do anything by the time the locktime is reached.</li>
<li>With a backup refund assured, the Customer broadcasts the first transaction (called the <em>deposit transaction</em>) so it gets added to the blockchain.</li>
<li>Now the Customer can sign alternatives (called <em>payment transactions</em>) to the refund transaction which have no locktime, and so can be added to the blockchain immediately except for the fact that they also require the merchant's signature.  By giving those to the Merchant, who can co-sign them (without returning them to the Customer), the Merchant can be assured that he can add them to the blockchain at a point earlier than when the refund transaction becomes valid.</li>
</ol>

<p>The problem with malleability occurs in the seventh step above, when the deposit transaction is broadcast.  If the transaction that gets added to the blockchain isn't byte-for-byte identical to the refund transaction which the Merchant signed in the fifth step, then the refund transaction is no longer valid because it attempts to spend a transaction with at different txid than the deposit transaction.</p>

<p>The Merchant can still voluntarily work with the Customer to return the Customer's money, but this means we don't have the trustless-style micropayment channels that we want.</p>

<p><strong>A note on segregated witness (segwit):</strong> because segwit eliminates the type of malleability which would allow someone to change the txid of the deposit transaction without the Customer's permission, transactions that use segwit can safely use Spillman-style micropayment channels without risk of malleability-caused problems.  As of this writing, segwit is not implemented on mainnet, but I expect it will be sooner or later, so I'm describing this here for future readers of this answer.  Note that segwit is an optional feature that the Customer would already have to be using in order to eliminate malleability in this case, so activation of segwit by itself does not automatically eliminate malleability in Spillman-style channels.</p>

<p>[1] Bare multisig (multisig without a P2SH address) may also be used.</p>

<h2>Malleability in CLTV-style micropayment channels</h2>

<p>A CLTV-style micropayment channel is constructed using the following sequence of events between the Merchant and the Customer.  These steps will be identical both before and after segwit is activated.</p>

<ol>
<li>The Merchant gives his public key to the Customer.</li>
<li>The Customer uses his public key and the Merchant's public key to construct a P2SH address that will require either of the following sets of conditions to be satisfied:

<ol>
<li>Both the Merchant and Customer sign any transaction that spends from this P2SH address.</li>
<li>Just the Customer signs any transaction that spends from this P2SH---but those spending transactions must have a locktime greater than the refund time.</li>
</ol></li>
<li>The Customer generates and immediately broadcasts the deposit transaction.  The Customer is assured their ability to generate a refund transaction <em>on demand</em> by Condition 2.2 above.</li>
<li>Now the Customer can use Condition 2.1 above to half-sign (sign 1-of-2 required signatures) payment transactions that pay the Merchant.  The Merchant can generate the second signature (without providing it to the Customer) and be assured that he can broadcast the final payment transaction before the Customer can add a refund transaction to the blockchain that was generated under the terms of Condition 2.2.</li>
</ol>

<p>This process eliminates the concerns with malleability in CLTV-style micropayment channels, although it does not eliminate the malleability itself.  Because the Customer can generate the refund transaction at any time per Condition 2.2 above, he doesn't need to pre-commit to a particular txid; he can wait until the deposit transaction has been added to the blockchain and its txid made nearly immutable before generating the refund transaction.</p>

<p>If, despite waiting for multiple confirmations, malleability happens anyway, the Customer can always generate and sign a new refund transaction using his private key.  That's because all that is necessary, according to Condition 2.2 in the P2SH address, is a signature from the authorized key plus a locktime past a certain date.</p>

<p>The Merchant can be affected by malleability if the deposit transaction txid changes after he has accepted any payments.  For this reason, it is best for the Merchant to wait for the deposit transaction to receive at least one confirmation before the Merchant accepts any payment transactions (waiting for more confirmations will provide more security and is recommended for high values).  Since the Merchant should be waiting for the deposit transaction to receive confirmation any way in order to prevent the Customer from double-spending it (which is also the case in Spillman-style channels), this source of malleability doesn't significantly affect the security model.</p>

<h2>Conclusion</h2>

<p>BIP65 did not fix malleability for older Spillman-style channels, but it did make possible CLTV-style payment channels that are not adversely affected by transaction malleability.  Segwit will also fix malleability for Spillman-style channels when all inputs in the deposit transaction are spending from segwit outputs.</p>

CC BY-SA 3.0
2017-01-14T04:12:52.393Z
that is a superb answer, thanks so much (just upvoted you). Now can I ask you 2 more questions? 1) Can one create payment channles with CSV instead of CLTV. 2) Would CSV-based payment channels be also resistant to malleability? 3) Is a CSV-based payment channel any better than a CLTV one?
knocte
CC BY-SA 3.0
2017-01-14T14:53:41.687Z
@knocte 1) Yes, you can use CSV easily. 2) Yes, you get the same malleability resistance.  3) They have different tradeoffs; CLTV allows expiration dates up to far in the future (see Unix year 2038 problem), CSV allows ~1 year max; CLTV expiration is chosen when channel is created, for CSV the clock only starts ticking when the deposit tx confirms.  In my opinion, CSV is slightly better for short-duration channels and it really shines when used as part of an HTLC like Lightning: https://en.bitcoin.it/wiki/Hashed_Timelock_Contracts
David A. Harding
CC BY-SA 3.0
2016-09-12T23:56:05.410Z
2016-09-13T12:09:22.383Z
2016-09-13T12:09:22.383Z
David A. Harding
<p>After BIP 65, are simple, unidirectional, MPC still subject to transaction malleability?</p>

<p>More specifically: </p>

<p><strong>Is the payee at risk because of malleability?</strong> If yes, how? (as far as I understood, the payee is not at risk anymore)</p>

<p><strong>Is the payor at risk because of malleability?</strong> If yes, how?  (as far as I understood, the payee is still at risk)</p>

<unconfirmed-transactions><transaction-malleability><micropaymentchannels><checklocktimeverify>
Are Micropayment channels still subject to malleability after BIP65?
hartmut
# Are Micropayment channels still subject to malleability after BIP65?

(Asked by: username_0 on 2016-08-24)

After BIP 65, are simple, unidirectional, MPC still subject to transaction malleability?

More specifically:

**Is the payee at risk because of malleability?** If yes, how? (as far as I understood, the payee is not at risk anymore)

**Is the payor at risk because of malleability?** If yes, how? (as far as I understood, the payee is still at risk)

**Tags:** unconfirmed-transactions, transaction-malleability, micropaymentchannels, checklocktimeverify


---

## 2 answers

### Answer by username_2 on 2016-09-12. Score: 9 | Accepted answer

There are a variety of different ways to construct a micropayment channel, but there are two designs that I think are particularly relevant to your question about "simple, one-directional, micropayment channels":

* **Spillman-style micropayment channels:** this was a commonly-described micropayment channel design prior to [BIP65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki) (`OP_CHECKLOCKTIMEVERIFY`, CLTV). Spillman-style channels were first [described by Jeremy Spillman](https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2013-April/002433.html) in April 2013 and [implemented in the BitcoinJ library](https://bitcoinj.github.io/working-with-micropayments) in [2013](https://bitcointalk.org/index.php?topic=244656.0).
* **CLTV-style micropayment channels:** this is a new way to construct a payment channel that became possible when CLTV became enforced in mid-December 2015. CLTV-style channels were described by BIP65 author Peter Todd as part of that BIP and implemented in [two1-python](https://github.com/21dotco/two1-python) in [February 2016](https://medium.com/@21/true-micropayments-with-bitcoin-e64fec23ffd8).

The following two sections describe how malleability relates to those two different types of micropayment channels.

## Malleability in Spillman-style micropayment channels

BIP65 does not change how malleability affects Spillman-style micropayment channels, so the following description was true before BIP65 became enforced as well as now (at least for transactions which do not use segwit).

A Spillman-style micropayment channel is constructed using the following sequence of events between the Merchant (who is receiving the funds) and the Customer (who is spending the funds):

1. The Merchant gives his public key to the customer.
2. The Customer uses his public key and the Merchant's public key to construct a multisig P2SH address[1] that will require signatures from both the Merchant and the Customer to spend any funds paid to that address.
3. The Customer generates (but does not transmit) a transaction that pays the multisig P2SH address.
4. The Customer generates a second transaction that spends the first transaction back to one of the Customer's addresses, gives this transaction a locktime (so it can't be added to the blockchain until a certain time), and signs this transaction.
5. The Customer gives this second transaction to the Merchant (without giving him the first transaction), and the Merchant signs it and returns the signed transaction to the Customer.
6. Now the Customer will be able to use this second transaction, called the *refund transaction,* to claim a refund if the Merchant doesn't do anything by the time the locktime is reached.
7. With a backup refund assured, the Customer broadcasts the first transaction (called the *deposit transaction*) so it gets added to the blockchain.
8. Now the Customer can sign alternatives (called *payment transactions*) to the refund transaction which have no locktime, and so can be added to the blockchain immediately except for the fact that they also require the merchant's signature. By giving those to the Merchant, who can co-sign them (without returning them to the Customer), the Merchant can be assured that he can add them to the blockchain at a point earlier than when the refund transaction becomes valid.

The problem with malleability occurs in the seventh step above, when the deposit transaction is broadcast. If the transaction that gets added to the blockchain isn't byte-for-byte identical to the refund transaction which the Merchant signed in the fifth step, then the refund transaction is no longer valid because it attempts to spend a transaction with at different txid than the deposit transaction.

The Merchant can still voluntarily work with the Customer to return the Customer's money, but this means we don't have the trustless-style micropayment channels that we want.

**A note on segregated witness (segwit):** because segwit eliminates the type of malleability which would allow someone to change the txid of the deposit transaction without the Customer's permission, transactions that use segwit can safely use Spillman-style micropayment channels without risk of malleability-caused problems. As of this writing, segwit is not implemented on mainnet, but I expect it will be sooner or later, so I'm describing this here for future readers of this answer. Note that segwit is an optional feature that the Customer would already have to be using in order to eliminate malleability in this case, so activation of segwit by itself does not automatically eliminate malleability in Spillman-style channels.

[1] Bare multisig (multisig without a P2SH address) may also be used.

## Malleability in CLTV-style micropayment channels

A CLTV-style micropayment channel is constructed using the following sequence of events between the Merchant and the Customer. These steps will be identical both before and after segwit is activated.

1. The Merchant gives his public key to the Customer.
2. The Customer uses his public key and the Merchant's public key to construct a P2SH address that will require either of the following sets of conditions to be satisfied:
   1. Both the Merchant and Customer sign any transaction that spends from this P2SH address.
   2. Just the Customer signs any transaction that spends from this P2SH---but those spending transactions must have a locktime greater than the refund time.
3. The Customer generates and immediately broadcasts the deposit transaction. The Customer is assured their ability to generate a refund transaction *on demand* by Condition 2.2 above.
4. Now the Customer can use Condition 2.1 above to half-sign (sign 1-of-2 required signatures) payment transactions that pay the Merchant. The Merchant can generate the second signature (without providing it to the Customer) and be assured that he can broadcast the final payment transaction before the Customer can add a refund transaction to the blockchain that was generated under the terms of Condition 2.2.

This process eliminates the concerns with malleability in CLTV-style micropayment channels, although it does not eliminate the malleability itself. Because the Customer can generate the refund transaction at any time per Condition 2.2 above, he doesn't need to pre-commit to a particular txid; he can wait until the deposit transaction has been added to the blockchain and its txid made nearly immutable before generating the refund transaction.

If, despite waiting for multiple confirmations, malleability happens anyway, the Customer can always generate and sign a new refund transaction using his private key. That's because all that is necessary, according to Condition 2.2 in the P2SH address, is a signature from the authorized key plus a locktime past a certain date.

The Merchant can be affected by malleability if the deposit transaction txid changes after he has accepted any payments. For this reason, it is best for the Merchant to wait for the deposit transaction to receive at least one confirmation before the Merchant accepts any payment transactions (waiting for more confirmations will provide more security and is recommended for high values). Since the Merchant should be waiting for the deposit transaction to receive confirmation any way in order to prevent the Customer from double-spending it (which is also the case in Spillman-style channels), this source of malleability doesn't significantly affect the security model.

## Conclusion

BIP65 did not fix malleability for older Spillman-style channels, but it did make possible CLTV-style payment channels that are not adversely affected by transaction malleability. Segwit will also fix malleability for Spillman-style channels when all inputs in the deposit transaction are spending from segwit outputs.

> **Comments:**
> **username_3**: that is a superb answer, thanks so much (just upvoted you). Now can I ask you 2 more questions? 1) Can one create payment channles with CSV instead of CLTV. 2) Would CSV-based payment channels be also resistant to malleability? 3) Is a CSV-based payment channel any better than a CLTV one?  
> **username_2**: @username_3 1) Yes, you can use CSV easily. 2) Yes, you get the same malleability resistance.  3) They have different tradeoffs; CLTV allows expiration dates up to far in the future (see Unix year 2038 problem), CSV allows ~1 year max; CLTV expiration is chosen when channel is created, for CSV the clock only starts ticking when the deposit tx confirms.  In my opinion, CSV is slightly better for short-duration channels and it really shines when used as part of an HTLC like Lightning: https://en.bitcoin.it/wiki/Hashed_Timelock_Contracts  

---

### Answer by username_1 on 2016-08-24. Score: 1

Yes. Since you cannot sign a signature and signatures in a transaction are used when calculating a `txid`, therefore only segregated witnesses or normalized txids would fix transaction malleability.

> **Comments:**
> **username_0**: Thanks for this answer. I understand the Payment tx can still suffer from that kind of malleability, as it points to a tx (the Deposit) that is not yet in the blockchain. But it seems to me that the payee is insulated from any risk thanks to BIP65, as the deposit can be spent by the payee at a later date (viz. when Deposit will have been added to the blockchain and malleability will not be an issue). Is not it so? (I edited my question following your answer. Thanks agn)  
> **username_1**: It still depends on time frame and what's your risk tolerance. If you're 100% risk-averse, then the payee is always at risk as its possible for a conflicting fork to become the winning chain and malleability can still affect the payee in the fork.  

---

