<oembed><type>rich</type><version>1.0</version><author_name>npub1vjzmc45k8dgujppapp2ue20h3l9apnsntgv4c0ukncvv549q64gsz4x8dd</author_name><author_url>https://nostr.ae/npub1vjzmc45k8dgujppapp2ue20h3l9apnsntgv4c0ukncvv549q64gsz4x8dd</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2020-04-22&#xA;📝 Original message:&#xA;Personally, I would have wait a bit before to go public on this, like&#xA;letting some implementations&#xA;increasing their CLTV deltas, but anyway, it&#39;s here now.&#xA;&#xA;Mempool-pinning attacks were already discussed on this list [0], but what&#xA;we found is you&#xA;can _reverse_ the scenario, where it&#39;s not the malicious party delaying&#xA;confirmation of honest&#xA;party transactions but malicious deliberately stucking its own transactions&#xA;in the mempool to avoid&#xA;confirmation of timeout. And therefore gaming inter-link timelock to&#xA;provoke an unbalanced&#xA;settlement for the victim (&#34;aka you pay forward, but don&#39;t get pay&#xA;backward&#34;).&#xA;&#xA;How much attacks are practical is based on how you can leverage mempool&#xA;rules to pin your own&#xA;transaction. What you&#39;re looking for is a  _mempool-obstruction_ trick, i.e&#xA;a way to get honest party&#xA;transaction being bounce off due to your transaction being already there.&#xA;&#xA;Beyond disabling RBF on your transaction (with current protocol, not anchor&#xA;proposal), there is&#xA;two likely candidates:&#xA;* BIP 125 rule 3: &#34;The replacement transaction pays an absolute fee of at&#xA;least the sum paid by the original transactions.&#34;&#xA;* BIP 125 rule 5: &#34;The number of original transactions to be replaced and&#xA;their descendant transactions which will be evicted from the mempool must&#xA;not exceed a total of 100 transactions.&#34;&#xA;&#xA;Let&#39;s go through whole scenario:&#xA;* Mallory and Eve are colluding&#xA;* Eve and Mallory are opening channels with Alice, Mallory do a bit of&#xA;rebalancing&#xA;to get full incoming capacity, like receiving funds on an onchain address&#xA;through another Alice&#xA;link&#xA;* Eve send a HTLC #1 to Mallory through Alice expirying at block 100&#xA;* Eve send a second HTLC #2 to Mallory through Alice, expirying at block&#xA;110 on outgoing link&#xA;(A&lt;-&gt;M), 120 on incoming link (E&lt;-&gt;A)&#xA;* Before block 100, without cancellation from Mallory, Alice will&#xA;force-close channel and broadcast&#xA;her local commitment and HTLC-timeout to get back HTLC #1&#xA;* Alice can&#39;t broadcast HTLC-timeout for HTLC #2 as it&#39;s only expires at 110&#xA;* Mallory can broadcast its Pinning Preimage Tx on offered HTLC #2 output&#xA;on Alice&#39;s transaction,&#xA;feerate is maliciously chosen to get in network mempools but never to&#xA;confirm. Absolute fee must&#xA;be higher than HTLC-timeout #2, a fact known to Mallory. There is no p2p&#xA;race.&#xA;* As Alice doesn&#39;t watch the mempool, she is never going to learn the&#xA;preimage to redeeem incoming&#xA;HTLC #2&#xA;* At block 110, Alice is going to broadcast HTLC-timeout #2, feerate may be&#xA;higher but as absolute&#xA;fee is lower, it&#39;s going to be rejected from network mempools as&#xA;replacement for Pinning Preimage&#xA;Tx (BIP 125 rule 3)&#xA;* At block 120, Eve closes channel and HTLC-timeout HTLC #2&#xA;* Mallory can RBF its Pinning Preimage Tx by a high-feerate one and get it&#xA;confirmed&#xA;&#xA;New anchor_output proposal, by disabling RBF, forces attacker to bid on the&#xA;absolute fee. It may&#xA;be now a risk to loose the fee if Pinning Tx is confirming. You may extend&#xA;your &#34;pinning&#xA;lease&#34; by ejecting your malicious tx, like conflicting or trimming out of&#xA;the mempool one of its&#xA;parents. And then reannounce your preimage tx with a&#xA;lower-feerate-but-still-high-fee before a&#xA;new block and a honest HTLC-timeout rebroadcast.&#xA;&#xA;AFAICT, even with anchor_output deployed, even assuming empty mempools,&#xA;success rate and economic&#xA;rationality of attacks is finding such cheap, reliable &#34;pinning lease&#xA;extension&#34; trick.&#xA;&#xA;I think any mempool watching mitigation is at best a cat-and-mouse hack.&#xA;Contrary to node&#xA;advancing towards a global blockchain view thanks to PoW, network mempools&#xA;don&#39;t have a convergence&#xA;guarantee. This means,  in a distributed system like bitcoin, node don&#39;t&#xA;see events in the same&#xA;order, Alice may observe tx X, tx Y, tx Z and Bob may observe tx Z, tx X,&#xA;tx Y. And order of events&#xA;affects if a future event is going to be rejected or not, like if tx Z&#xA;disable-RBF and tx X try to&#xA;replace Z, Alice accepts X and Bob rejects it. And this divergence may&#xA;perserve until a new block.&#xA;&#xA;Practically, it means an attacker can provoke a local conflict to bounce&#xA;off HTLC preimage tx out&#xA;of your mempool while broadcasting preimage tx without conflict to the rest&#xA;of the network by&#xA;tweaking tx-relay protocol and so easily manipulating order of events for&#xA;every node. A local&#xA;conflict is easy to provoke, just make tx A double-spent by both&#xA;HTLC-preimage-tx and non-RBF-tx-B.&#xA;Announce txA+txB to mempool victim and txA+HTLC-preimage-tx to rest of&#xA;network. When rest of&#xA;network announce HTLC-preimage-tx, it&#39;s going to rejected by your mempool.&#xA;&#xA;Provoking local conflict assumes of course _interlayer_ mapping by an&#xA;attacker, i.e mapping your LN&#xA;node to your full-node(s). Last time, we check, there was 982 match by IP&#xA;for 4,500 LN/52,000&#xA;full-node. Mapping heuristics is an ongoing research subject and sadly&#xA;seems affordable.&#xA;&#xA;Yes a) you can enable full-RBF on your local node but blinding conflicting&#xA;may still be with higher&#xA;feerate as everything is attacker malleable b) you may want to catch tx and&#xA;extract preimage&#xA;on the p2p wire, but processing raw transaction would be such a DoS&#xA;vector...&#xA;&#xA;Overall, I think we all agree on the long term direction to get a&#xA;Contracting-Protocols-Enhanced&#xA;mempool with a multiparty-safe-API, bundled with package relay deployment.&#xA;Even if there is current&#xA;move toward this direction, this may take longer than expected as with any&#xA;critical-safety&#xA;component in Core.&#xA;&#xA;A temporary fix could be to resuscitate old work to ensure peering through&#xA;a full-RBF propagation path,&#xA;but p2p implications are hard to gauge, like wouldn&#39;t guarantee p2p&#xA;censorship resistance of this...&#xA;&#xA;It&#39;s quite a tangled issue, with a good deal of both bitcoin and lightning&#xA;knowledge so feel free&#xA;to verify and double-check more than usual&#xA;&#xA;Cheers&#xA;&#xA;[0]&#xA;https://lists.linuxfoundation.org/pipermail/lightning-dev/2019-October/002240.html&#xA;&#xA;Le mer. 22 avr. 2020 à 02:08, ZmnSCPxj via bitcoin-dev &lt;&#xA;bitcoin-dev at lists.linuxfoundation.org&gt; a écrit :&#xA;&#xA;&gt; Good morning Laolu, Matt, and list,&#xA;&gt;&#xA;&gt;&#xA;&gt; &gt; &gt;  * With `SIGHASH_NOINPUT` we can make the C-side signature&#xA;&gt; &gt; &gt;  `SIGHASH_NOINPUT|SIGHASH_SINGLE` and allow B to re-sign the B-side&#xA;&gt; &gt; &gt;  signature for a higher-fee version of HTLC-Timeout (assuming my cached&#xA;&gt; &gt; &gt;  understanding of `SIGHASH_NOINPUT` still holds).&#xA;&gt; &gt;&#xA;&gt; &gt; no_input isn&#39;t needed. With simply single+anyone can pay, then B can&#xA;&gt; attach&#xA;&gt; &gt; a new input+output pair to increase the fees on their HTLC redemption&#xA;&gt; &gt; transaction. As you mention, they now enter into a race against this&#xA;&gt; &gt; malicious ndoe to bump up their fees in order to win over the other&#xA;&gt; party.&#xA;&gt;&#xA;&gt; Right, right, that works as well.&#xA;&gt;&#xA;&gt; &gt;&#xA;&gt; &gt; If the malicious node uses a non-RBF signalled transaction to sweep their&#xA;&gt; &gt; HTLC, then we enter into another level of race, but this time on the&#xA;&gt; mempool&#xA;&gt; &gt; propagation level. However, if there exists a relay path to a miner&#xA;&gt; running&#xA;&gt; &gt; full RBF, then B&#39;s higher fee rate spend will win over.&#xA;&gt;&#xA;&gt; Hmm.&#xA;&gt;&#xA;&gt; So basically:&#xA;&gt;&#xA;&gt; * B has no mempool, because it wants to reduce its costs and etc.&#xA;&gt; * C broadcasts a non-RBF claim tx with low fee before A-&gt;B locktime (L+1).&#xA;&gt; * B does not notice this tx because:&#xA;&gt;   1.  The tx is too low fee to be put in a block.&#xA;&gt;   2.  B has no mempool so it cannot see the tx being propagated over the&#xA;&gt; P2P network.&#xA;&gt; * B tries to broadcast higher-fee HTLC-timeout, but fails because it&#xA;&gt; cannot replace a non-RBF tx.&#xA;&gt; * After L+1, C contacts the miners off-band and offers fee payment by&#xA;&gt; other means.&#xA;&gt;&#xA;&gt; It seems to me that, if my cached understanding that `&lt;0&gt;&#xA;&gt; OP_CHECKSEQUENCEVERIFY` is sufficient to require RBF-flagging, then adding&#xA;&gt; that to the hashlock branch (2 witness bytes, 0.5 weight) would be a pretty&#xA;&gt; low-weight mitigation against this attack.&#xA;&gt;&#xA;&gt; So I think the combination below gives us good size:&#xA;&gt;&#xA;&gt; * The HTLC-Timeout signature from C is flagged with&#xA;&gt; `OP_SINGLE|OP_ANYONECANPAY`.&#xA;&gt;   * Normally, the HTLC-Timeout still deducts the fee from the value of the&#xA;&gt; UTXO being spent.&#xA;&gt;   * However, if B notices that the L+1 timeout is approaching, it can&#xA;&gt; fee-bump HTLC-Timeout with some onchain funds, recreating its own signature&#xA;&gt; but reusing the (still valid) C signature.&#xA;&gt; * The hashlock branch in this case includes `&lt;0&gt; OP_CHECKSEQUENCEVERIFY`,&#xA;&gt; preventing C from broadcasting a low-fee claim tx.&#xA;&gt;&#xA;&gt; This has the advantages:&#xA;&gt;&#xA;&gt; * B does not need a mempool still and can run in `blocksonly`.&#xA;&gt; * The normal path is still the same as current behavior, we &#34;only&#34; add a&#xA;&gt; new path where if the L+1 timeout is approaching we fee-bump the&#xA;&gt; HTLC-Timeout.&#xA;&gt; * Costs are pretty low:&#xA;&gt;   * No need for extra RBF carve-out txo.&#xA;&gt;   * Just two additional witness bytes in the hashlock branch.&#xA;&gt; * No mempool rule changes needed, can be done with the P2P network of&#xA;&gt; today.&#xA;&gt;   * Probably still resilient even with future changes in mempool rules, as&#xA;&gt; long as typical RBF behaviors still remain.&#xA;&gt;&#xA;&gt; Is my understanding correct?&#xA;&gt;&#xA;&gt; Regards,&#xA;&gt; ZmnSCPxj&#xA;&gt;&#xA;&gt; &gt;&#xA;&gt; &gt; -- Laolu&#xA;&gt; &gt;&#xA;&gt; &gt; On Tue, Apr 21, 2020 at 9:13 PM ZmnSCPxj via bitcoin-dev &lt;&#xA;&gt; bitcoin-dev at lists.linuxfoundation.org&gt; wrote:&#xA;&gt; &gt;&#xA;&gt; &gt; &gt; Good morning Matt, and list,&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; &gt;     RBF Pinning HTLC Transactions (aka &#34;Oh, wait, I can steal funds,&#xA;&gt; how, now?&#34;)&#xA;&gt; &gt; &gt; &gt;     =============================&#xA;&gt; &gt; &gt; &gt;&#xA;&gt; &gt; &gt; &gt;     You&#39;ll note that in the discussion of RBF pinning we were pretty&#xA;&gt; broad, and that that discussion seems to in fact cover&#xA;&gt; &gt; &gt; &gt;     our HTLC outputs, at least when spent via (3) or (4). It does,&#xA;&gt; and in fact this is a pretty severe issue in today&#39;s&#xA;&gt; &gt; &gt; &gt;     lightning protocol [2]. A lightning counterparty (C, who&#xA;&gt; received the HTLC from B, who received it from A) today could,&#xA;&gt; &gt; &gt; &gt;     if B broadcasts the commitment transaction, spend an HTLC using&#xA;&gt; the preimage with a low-fee, RBF-disabled transaction.&#xA;&gt; &gt; &gt; &gt;     After a few blocks, A could claim the HTLC from B via the&#xA;&gt; timeout mechanism, and then after a few days, C could get the&#xA;&gt; &gt; &gt; &gt;     HTLC-claiming transaction mined via some out-of-band agreement&#xA;&gt; with a small miner. This leaves B short the HTLC value.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; My (cached) understanding is that, since RBF is signalled using&#xA;&gt; `nSequence`, any `OP_CHECKSEQUENCEVERIFY` also automatically imposes the&#xA;&gt; requirement &#34;must be RBF-enabled&#34;, including `&lt;0&gt; OP_CHECKSEQUENCEVERIFY`.&#xA;&gt; &gt; &gt; Adding that clause (2 bytes in witness if my math is correct) to the&#xA;&gt; hashlock branch may be sufficient to prevent C from making an RBF-disabled&#xA;&gt; transaction.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; But then you mention out-of-band agreements with miners, which&#xA;&gt; basically means the transaction might not be in the mempool at all, in&#xA;&gt; which case the vulnerability is not really about RBF or relay, but sheer&#xA;&gt; economics.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; The payment is A-&gt;B-&gt;C, and the HTLC A-&gt;B must have a larger timeout&#xA;&gt; (L + 1) than the HTLC B-&gt;C (L), in abstract non-block units.&#xA;&gt; &gt; &gt; The vulnerability you are describing means that the current time must&#xA;&gt; now be L + 1 or greater (&#34;A could claim the HTLC from B via the timeout&#xA;&gt; mechanism&#34;, meaning the A-&gt;B HTLC has timed out already).&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; If so, then the B-&gt;C transaction has already timed out in the past and&#xA;&gt; can be claimed in two ways, either via B timeout branch or C hashlock&#xA;&gt; branch.&#xA;&gt; &gt; &gt; This sets up a game where B and C bid to miners to get their version&#xA;&gt; of reality committed onchain.&#xA;&gt; &gt; &gt; (We can neglect out-of-band agreements here; miners have the incentive&#xA;&gt; to publicly leak such agreements so that other potential bidders can offer&#xA;&gt; even higher fees for their versions of that transaction.)&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; Before L+1, C has no incentive to bid, since placing any bid at all&#xA;&gt; will leak the preimage, which B can then turn around and use to spend from&#xA;&gt; A, and A and C cannot steal from B.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; Thus, B should ensure that *before* L+1, the HTLC-Timeout has been&#xA;&gt; committed onchain, which outright prevents this bidding war from even&#xA;&gt; starting.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; The issue then is that B is using a pre-signed HTLC-timeout, which is&#xA;&gt; needed since it is its commitment tx that was broadcast.&#xA;&gt; &gt; &gt; This prevents B from RBF-ing the HTLC-Timeout transaction.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; So what is needed is to allow B to add fees to HTLC-Timeout:&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; * We can add an RBF carve-out output to HTLC-Timeout, at the cost of&#xA;&gt; more blockspace.&#xA;&gt; &gt; &gt; * With `SIGHASH_NOINPUT` we can make the C-side signature&#xA;&gt; `SIGHASH_NOINPUT|SIGHASH_SINGLE` and allow B to re-sign the B-side&#xA;&gt; signature for a higher-fee version of HTLC-Timeout (assuming my cached&#xA;&gt; understanding of `SIGHASH_NOINPUT` still holds).&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; With this, B can exponentially increase the fee as L+1 approaches.&#xA;&gt; &gt; &gt; If B can get HTLC-Timeout confirmed before L+1, then C cannot steal&#xA;&gt; the HTLC value at all, since the UTXO it could steal from has already been&#xA;&gt; spent.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; In particular, it does not seem to me that it is necessary to change&#xA;&gt; the hashlock-branch transaction of C at all, since this mechanism is enough&#xA;&gt; to sidestep the issue (as I understand it).&#xA;&gt; &gt; &gt; But it does point to a need to make HTLC-Timeout (and possibly&#xA;&gt; symmetrically, HTLC-Success) also fee-bumpable.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; Note as well that this does not require a mempool: B can run in&#xA;&gt; `blocksonly` mode and as each block comes in from L to L+1, if HTLC-Timeout&#xA;&gt; is not confirmed, feebump HTLC-Timeout.&#xA;&gt; &gt; &gt; In particular, HTLC-Timeout comes into play only if B broadcast its&#xA;&gt; own commitment transaction, and B *should* be aware that it did so ---&#xA;&gt; there is still no need for mempool monitoring here.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; Now, of course this only delays the war.&#xA;&gt; &gt; &gt; Let us now consider what C can do to ensure that the bidding war will&#xA;&gt; happen eventually.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; * C can bribe a miner to prevent HTLC-Timeout from confirming between&#xA;&gt; L and L+1.&#xA;&gt; &gt; &gt;   * Or in other words, this is a censorship attack.&#xA;&gt; &gt; &gt;     * The Bitcoin censorship-resistance model is that censored&#xA;&gt; transactions can be fee-bumped, which attracts non-censoring miners to try&#xA;&gt; their luck at mining and evict the censoring miner.&#xA;&gt; &gt; &gt;       * Thus, letting B bump the fee on HTLC-Timeout is precisely the&#xA;&gt; mechanism we need.&#xA;&gt; &gt; &gt;       * This sets up a bidding war between C requesting miners to&#xA;&gt; censor, vs. B requesting miners to confirm, but that only sets the stage&#xA;&gt; for a second bidding war later between C and B, thus C is at a&#xA;&gt; disadvantage: it has to bribe miners to censor continuously from L to L+1&#xA;&gt; *and* additional bribe miners to confirm its transaction after L+1, whereas&#xA;&gt; B can offer its bribe as being something that miners can claim now without&#xA;&gt; waiting after L+1.&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; The issue of course is the additional output that bloats the UTXO set&#xA;&gt; and requires another transaction to claim later.&#xA;&gt; &gt; &gt; And if we have `SIGHASH_NOINPUT`, it seems to me that&#xA;&gt; Decker-Russell-Osuntokun sidesteps this issue as well, as any timed-out&#xA;&gt; HTLC can be claimed with a fee-bumpable transaction directly without&#xA;&gt; RBF-carve-out.&#xA;&gt; &gt; &gt; (As well, it seems to me that, if both nodes support doing so, a&#xA;&gt; Poon-Dryja channel can be upgraded, without onchain activity, to a&#xA;&gt; Decker-Russell-Osuntokun channel: sign a transaction spending the funding&#xA;&gt; tx to a txo that has been set up as Decker-Russell-Osuntokun, do not&#xA;&gt; broadcast that transaction, then revoke the latest Poon-Dryja commitment&#xA;&gt; transactions, then switch the mechanism over to Decker-Russell-Osuntokun;&#xA;&gt; you still need to monitor for previous Poon-Dryja commitment transactions,&#xA;&gt; but HTLCs now sidestep the issue under discussion here.)&#xA;&gt; &gt; &gt;&#xA;&gt; &gt; &gt; Regards,&#xA;&gt; &gt; &gt; ZmnSCPxj&#xA;&gt; &gt; &gt; _______________________________________________&#xA;&gt; &gt; &gt; bitcoin-dev mailing list&#xA;&gt; &gt; &gt; bitcoin-dev at lists.linuxfoundation.org&#xA;&gt; &gt; &gt; https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev&#xA;&gt;&#xA;&gt;&#xA;&gt; _______________________________________________&#xA;&gt; bitcoin-dev mailing list&#xA;&gt; bitcoin-dev at lists.linuxfoundation.org&#xA;&gt; https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev&#xA;&gt;&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/lightning-dev/attachments/20200422/951291f7/attachment-0001.html&gt;</html></oembed>