Return-Path: Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2102AC0037; Sun, 17 Dec 2023 22:56:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id DA97F40873; Sun, 17 Dec 2023 22:56:54 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org DA97F40873 Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CWI2Ydbh X-Virus-Scanned: amavisd-new at osuosl.org X-Spam-Flag: NO X-Spam-Score: -2.098 X-Spam-Level: X-Spam-Status: No, score=-2.098 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id b7UNRohwaIpk; Sun, 17 Dec 2023 22:56:51 +0000 (UTC) Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by smtp4.osuosl.org (Postfix) with ESMTPS id E306840862; Sun, 17 Dec 2023 22:56:50 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org E306840862 Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-7b783ee6d73so119069439f.2; Sun, 17 Dec 2023 14:56:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702853810; x=1703458610; darn=lists.linuxfoundation.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=X+RGaoxFOvJyqEmeVr7Yr5iC6CDRhNzsGPs7UxcXfLU=; b=CWI2YdbhiGp1GrGH10KF15wL3Ew0Yai6MNt4e+p/m014reLfqqUU4zz7awRkolNDSQ uMONedUwJb0zBYGwoGhU14TLnO6ADpxFmkDUQZTrIYE1VeUwxnK77QCYDNp5O1m9J5ws ekYhyrfzLStgsVTlwEpRNZFvI1cIFEnwqAQCWx0xY0aBB6ND2yDm6YRP7K9KDav6xwwn BNG75AhYzMckdGz04kz++274xn/fWFDjoVhU22+7txs7z2LdW+Ld70huKvjD9+2RxEir rV+pAXmAEBH1351FUXhB9oUKbeb4DuSXMfrXQ4TTZgmfs7Vic028wF+hxSC5+dSKtmPq //uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702853810; x=1703458610; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X+RGaoxFOvJyqEmeVr7Yr5iC6CDRhNzsGPs7UxcXfLU=; b=If/+qk8bhWVbV4HemaTfgf36PkTGKj4xfR9jq/XmTVrcL5rCxUl0JfVVnQumNNeuoE z7eT4z3ZNyWttVXDLn/ZEa9d/YpbpGLiGn3uyI0Lt+Jv2/NCPQ5Ij4KOEF36z/lUkwc2 MKLJDk/78Y4GeSvrRlLZ9T4Ec7x5Kl+m08XhddQ5myrjcm20d+LT3P1Ri+Hv4+31xzkX ooyZFEbc+p1opOn/G2D9oG9lECrlpqK9KSr11xzmZrpWcfRqoI1WWyzp3hu0eD20kWQ8 TSY8BGCWRXkL/ijMGp20UvuIrg9WUOheTkRUVj1TJbsieHPfHkY1D53DECze9aQBw7Yy PaqA== X-Gm-Message-State: AOJu0YzTHg8IHAzT+LnPWR+gP3qCagef78LltIfnRZZiOYlkE3Fd7qD1 FOufkVi3UznoEI69By/YqToFqc7VNYSvMdRIC38= X-Google-Smtp-Source: AGHT+IHZArY4lO+po2tld0x3EFy3hEnqvKxhBDWP377gEO/Z7hOsdUQglHy1XbzqM8qBXaT5enNoyovGX17mH9Ixouo= X-Received: by 2002:a05:6602:2d95:b0:7a6:7bbe:5aa0 with SMTP id k21-20020a0566022d9500b007a67bbe5aa0mr17912788iow.0.1702853809617; Sun, 17 Dec 2023 14:56:49 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Antoine Riard Date: Sun, 17 Dec 2023 22:56:38 +0000 Message-ID: To: =?UTF-8?Q?Johan_Tor=C3=A5s_Halseth?= Content-Type: multipart/alternative; boundary="0000000000006d3f3b060cbc8c92" X-Mailman-Approved-At: Mon, 18 Dec 2023 00:35:49 +0000 Cc: Bitcoin Protocol Discussion , "lightning-dev\\\\@lists.linuxfoundation.org" Subject: Re: [bitcoin-dev] HTLC output aggregation as a mitigation for tx recycling, jamming, and on-chain efficiency (covenants) X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Bitcoin Protocol Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Dec 2023 22:56:55 -0000 --0000000000006d3f3b060cbc8c92 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Johan, > Is this a concern though, if we assume there's no revoked state that > can be broadcast (Eltoo)? Could you share an example of how this would > be played out by an attacker? Sure, let's assume no revoked state can be broadcast (Eltoo). My understanding of the new covenant mechanism is the aggregation or collapsing of all HTLC outputs in one or at least 2 outputs (offered / received). Any spend of an aggregated HTLC "payout" should satisfy the script locking condition by presenting a preimage and a signature. An offerd aggregated HTLC output might collapse a M number of HTLC "payout", where M is still limited by the max standard transaction relay, among other things. The offered-to counterparty can claim any subset N of the aggregation M by presenting the list of signatures and preimages (How they're feeded to the spent script is a covenant implementation detail). However, there is no guarantee that the offered-to counterparty reveal "all" the preimages she is awarded off. Non-spent HTLC outputs are clawback to a remainder subset of M, M'. I think this partial reveal of HTLC payout preimages still opens the door to replacement cycling attacks. Let's say you have 5 offered HTLC "payouts" between Alice and Bob aggregated in a single output, 4 of value 0.1 BTC and 1 of value 1 BTC. All expire at timelock T. At T, Alice broadcasts an aggregated HTLC-timeout spend for the 5 HTLC with 0.0.1 BTC on-chain fee. Bob can craft a HTLC-preimage spend of the single offered output spending one of 0.1 BTC HTLC payout (and revealing its preimage) while burning all the value as fee. This replaces out Alice's honest HTLC-timeout out of network mempools, are they're concurrent spend. Bob can repeat this trick as long as there is HTLC "payout" remaining in the offered set, until he's being able to do a HTLC off-chain double-spend of the 1 BTC HTLC "payout". This stealing gain of the 1 BTC HTLC "payout" covers what has been burned as miners fees to replace cycle out Alice's sequence of honest HTLC-timeout. And it should be noted that Bob might benefit from network mempools congestion delaying the confirmation of his malicious low-value high-fee HTLC-preimage transactions. > I'm not sure what you mean here, could you elaborate? See https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2023-December/0= 22191.html and my answer there. I think "self-sustained" fees is one only part of the solution, the other part being the sliding delay of the HTLC timelock based on block feerate. Otherwise, a replacement cycling attacker can always benefit from network mempools congestion spontaneously pushing out a malicious cycling transaction out of block templates. > That sounds possible, but how would you deal with the exponential > blowup in the number of combinations? In a taproot-world, "swallow the bullet" in terms of witness size growth in case of non-cooperative closure. I think this is where introducing an accumulator at the Script level to efficiently test partial set membership would make sense. Note, exponential blowup is an issue for mass non-coordinated withdrawals of a payment pool too. Best, Antoine Le lun. 11 d=C3=A9c. 2023 =C3=A0 09:17, Johan Tor=C3=A5s Halseth a =C3=A9crit : > Hi, Antoine. > > > The attack works on legacy channels if the holder (or local) commitment > transaction confirms first, the second-stage HTLC claim transaction is > fully malleable by the counterparty. > > Yes, correct. Thanks for pointing that out! > > > I think one of the weaknesses of this approach is the level of > malleability still left to the counterparty, where one might burn in mine= rs > fees all the HTLC accumulated value promised to the counterparty, and for > which the preimages have been revealed off-chain. > > Is this a concern though, if we assume there's no revoked state that > can be broadcast (Eltoo)? Could you share an example of how this would > be played out by an attacker? > > > I wonder if a more safe approach, eliminating a lot of competing > interests style of mempool games, wouldn't be to segregate HTLC claims in > two separate outputs, with full replication of the HTLC lockscripts in bo= th > outputs, and let a covenant accepts or rejects aggregated claims with > satisfying witness and chain state condition for time lock. > > I'm not sure what you mean here, could you elaborate? > > > I wonder if in a PTLC world, you can generate an aggregate curve point > for all the sub combinations of scalar plausible. Unrevealed curve points > in a taproot branch are cheap. It might claim an offered HTLC near-consta= nt > size too. > > That sounds possible, but how would you deal with the exponential > blowup in the number of combinations? > > Cheers, > Johan > > > On Tue, Nov 21, 2023 at 3:39=E2=80=AFAM Antoine Riard > wrote: > > > > Hi Johan, > > > > Few comments. > > > > ## Transaction recycling > > The transaction recycling attack is made possible by the change made > > to HTLC second level transactions for the anchor channel type[8]; > > making it possible to add fees to the transaction by adding inputs > > without violating the signature. For the legacy channel type this > > attack was not possible, as all fees were taken from the HTLC outputs > > themselves, and had to be agreed upon by channel counterparties during > > signing (of course this has its own problems, which is why we wanted > > to change it). > > > > The attack works on legacy channels if the holder (or local) commitment > transaction confirms first, the second-stage HTLC claim transaction is > fully malleable by the counterparty. > > > > See > https://github.com/lightning/bolts/blob/master/03-transactions.md#offered= -htlc-outputs > (only remote_htlcpubkey required) > > > > Note a replacement cycling attack works in a future package-relay world > too. > > > > See test: > https://github.com/ariard/bitcoin/commit/19d61fa8cf22a5050b51c4005603f43d= 72f1efcf > > > > > The idea of HTLC output aggregation is to collapse all HTLC outputs o= n > > > the commitment to a single one. This has many benefits (that I=E2=80= =99ll get > > > to), one of them being the possibility to let the spender claim the > > > portion of the output that they=E2=80=99re right to, deciding how muc= h should > > > go to fees. Note that this requires a covenant to be possible. > > > > Another advantage of HTLC output aggregation is the reduction of > fee-bumping reserves requirements on channel counterparties, as > second-stage HTLC transactions have common fields (nVersion, nLocktime, > ...) *could* be shared. > > > > > ## A single HTLC output > > > Today, every forwarded HTLC results in an output that needs to be > > > manifested on the commitment transaction in order to claw back money > > > in case of an uncooperative channel counterparty. This puts a limit o= n > > > the number of active HTLCs (in order for the commitment transaction t= o > > > not become too large) which makes it possible to jam the channel with > > > small amounts of capital [1]. It also turns out that having this limi= t > > > be large makes it expensive and complicated to sweep the outputs > > > efficiently [2]. > > > > > Instead of having new HTLC outputs manifest for each active > > > forwarding, with covenants on the base layer one could create a singl= e > > > aggregated output on the commitment. The output amount being the sum > > > of the active HTLCs (offered and received), alternatively one output > > > for received and one for offered. When spending this output, you woul= d > > > only be entitled to the fraction of the amount corresponding to the > > > HTLCs you know the preimage for (received), or that has timed out > > > (offered). > > > > > ## Impacts to transaction recycling > > > Depending on the capabilities of the covenant available (e.g. > > > restricting the number of inputs to the transaction) the transaction > > > spending the aggregated HTLC output can be made self sustained: the > > > spender will be able to claim what is theirs (preimage or timeout) an= d > > > send it to whatever output they want, or to fees. The remainder will > > > go back into a covenant restricted output with the leftover HTLCs. > > > Note that this most likely requires Eltoo in order to not enable fee > > > siphoning[7]. > > > > I think one of the weaknesses of this approach is the level of > malleability still left to the counterparty, where one might burn in mine= rs > fees all the HTLC accumulated value promised to the counterparty, and for > which the preimages have been revealed off-chain. > > > > I wonder if a more safe approach, eliminating a lot of competing > interests style of mempool games, wouldn't be to segregate HTLC claims in > two separate outputs, with full replication of the HTLC lockscripts in bo= th > outputs, and let a covenant accepts or rejects aggregated claims with > satisfying witness and chain state condition for time lock. > > > > > ## Impacts to slot jamming > > > With the aggregated output being a reality, it changes the nature of > > > =E2=80=9Cslot jamming=E2=80=9D [1] significantly. While channel capac= ity must still be > > > reserved for in-flight HTLCs, one no longer needs to allocate a > > > commitment output for each up to some hardcoded limit. > > > > > In today=E2=80=99s protocol this limit is 483, and I believe most > > > implementations default to an even lower limit. This leads to channel > > > jamming being quite inexpensive, as one can quickly fill a channel > > > with small HTLCs, without needing a significant amount of capital to > > > do so. > > > > > The origins of the 483 slot limits is the worst case commitment size > > > before getting into unstandard territory [3]. With an aggregated > > > output this would no longer be the case, as adding HTLCs would no > > > longer affect commitment size. Instead, the full on-chain footprint o= f > > > an HTLC would be deferred until claim time. > > > > > Does this mean one could lift, or even remove the limit for number of > > > active HTLCs? Unfortunately, the obvious approach doesn=E2=80=99t see= m to get > > > rid of the problem entirely, but mitigates it quite a bit. > > > > Yes, protocol limit of 483 is a long-term limit on the payment > throughput of the LN, though as an upper bound we have the dust limits an= d > mempool fluctuations rendering irrelevant the claim of such aggregated du= st > outputs. Aggregated claims might give a more dynamic margin of what is a > tangible and trust-minimized HTLC payment. > > > > > ### Slot jamming attack scenario > > > Consider the scenario where an attacker sends a large number of > > > non-dust* HTLCs across a channel, and the channel parties enforce no > > > limit on the number of active HTLCs. > > > > > The number of payments would not affect the size of the commitment > > > transaction at all, only the size of the witness that must be > > > presented when claiming or timing out the HTLCs. This means that ther= e > > > is still a point at which chain fees get high enough for the HTLC to > > > be uneconomical to claim. This is no different than in today=E2=80=99= s spec, > > > and such HTLCs will just be stranded on-chain until chain fees > > > decrease, at which point there is a race between the success and > > > timeout spends. > > > > > There seems to be no way around this; if you want to claim an HTLC > > > on-chain, you need to put the preimage on-chain. And when the HTLC > > > first reaches you, you have no way of predicting the future chain fee= . > > > With a large number of uneconomical HTLCs in play, the total BTC > > > exposure could still be very large, so you might want to limit this > > > somewhat. > > > > > * Note that as long as the sum of HTLCs exceeds the dust limit, one > > > could manifest the output on the transaction. > > > > Unless we introduce sliding windows during which the claim periods of a= n > HTLC can be claimed and freeze accordingly the HTLC-timeout path. > > > > See: https://fc22.ifca.ai/preproceedings/119.pdf > > > > Bad news: you will need off-chain consensus on the feerate threshold at > which the sliding windows kick-out among all the routing nodes > participating in the HTLC payment path. > > > > > ## The good news > > > With an aggregated HTLC output, the number of HTLCs would no longer > > > impact the commitment transaction size while the channel is open and > > > operational. > > > > > The marginal cost of claiming an HTLC with a preimage on-chain would > > > be much lower; no new inputs or outputs, only a linear increase in th= e > > > witness size. With a covenant primitive available, the extra footprin= t > > > of the timeout and success transactions would no longer exist. > > > > > Claiming timed out HTLCs could still be made close to constant size > > > (no preimage to present), so no additional on-chain cost with more > > > HTLCs. > > > > I wonder if in a PTLC world, you can generate an aggregate curve point > for all the sub combinations of scalar plausible. Unrevealed curve points > in a taproot branch are cheap. It might claim an offered HTLC near-consta= nt > size too. > > > > > ## The bad news > > > The most obvious problem is that we would need a new covenant > > > primitive on L1 (see below). However, I think it could be beneficial > > > to start exploring these ideas now in order to guide the L1 effort > > > towards something we could utilize to its fullest on L2. > > > > > As mentioned, even with a functioning covenant, we don=E2=80=99t esca= pe the > > > fact that a preimage needs to go on-chain, pricing out HTLCs at > > > certain fee rates. This is analogous to the dust exposure problem > > > discussed in [6], and makes some sort of limit still required. > > > > Ideally such covenant mechanisms would generalize to the withdrawal > phase of payment pools, where dozens or hundreds of participants wish to > confirm their non-competing withdrawal transactions concurrently. While > unlocking preimage or scalar can be aggregated in a single witness, there > will still be a need to verify that each withdrawal output associated wit= h > an unlocking secret is present in the transaction. > > > > Maybe few other L2s are answering this N-inputs-to-M-outputs pattern > with advanced locking scripts conditions to satisfy. > > > > > ### Open question > > > With PTLCs, could one create a compact proof showing that you know th= e > > > preimage for m-of-n of the satoshis in the output? (some sort of > > > threshold signature). > > > > > If we could do this we would be able to remove the slot jamming issue > > > entirely; any number of active PTLCs would not change the on-chain > > > cost of claiming them. > > > > See comments above, I think there is a plausible scheme here you just > generate all the point combinations possible, and only reveal the one you > need at broadcast. > > > > > ## Covenant primitives > > > A recursive covenant is needed to achieve this. Something like OP_CTV > > > and OP_APO seems insufficient, since the number of ways the set of > > > HTLCs could be claimed would cause combinatorial blowup in the number > > > of possible spending transactions. > > > > > Personally, I=E2=80=99ve found the simple yet powerful properties of > > > OP_CHECKCONTRACTVERIFY [4] together with OP_CAT and amount inspection > > > particularly interesting for the use case, but I=E2=80=99m certain ma= ny of the > > > other proposals could achieve the same thing. More direct inspection > > > like you get from a proposal like OP_TX[9] would also most likely hav= e > > > the building blocks needed. > > > > As pointed out during the CTV drama and payment pool public discussion > years ago, what would be very useful to tie-break among all covenant > constructions would be an efficiency simulation framework. Even if the sa= me > semantic can be achieved independently by multiple covenants, they > certainly do not have the same performance trade-offs (e.g average and > worst-case witness size). > > > > I don't think the blind approach of activating many complex covenants a= t > the same time is conservative enough in Bitcoin, where one might design > "malicious" L2 contracts, of which the game-theory is not fully understoo= d. > > > > See e.g https://blog.bitmex.com/txwithhold-smart-contracts/ > > > > > ### Proof-of-concept > > > I=E2=80=99ve implemented a rough demo** of spending an HTLC output th= at pays > > > to a script with OP_CHECKCONTRACTVERIFY to achieve this [5]. The idea > > > is to commit to all active HTLCs in a merkle tree, and have the > > > spender provide merkle proofs for the HTLCs to claim, claiming the su= m > > > into a new output. The remainder goes back into a new output with the > > > claimed HTLCs removed from the merkle tree. > > > > > An interesting trick one can do when creating the merkle tree, is > > > sorting the HTLCs by expiry. This means that one in the timeout case > > > claim a subtree of HTLCs using a single merkle proof (and RBF this > > > batched timeout claim as more and more HTLCs expire) reducing the > > > timeout case to constant size witness (or rather logarithmic in the > > > total number of HTLCs). > > > > > **Consider it an experiment, as it is missing a lot before it could b= e > > > usable in any real commitment setting. > > > > I think this is an interesting question if more advanced cryptosystems > based on assumptions other than the DL problem could constitute a factor = of > scalability of LN payment throughput by orders of magnitude, by decouplin= g > number of off-chain payments from the growth of the on-chain witness size > need to claim them, without lowering in security as with trimmed HTLC due > to dust limits. > > > > Best, > > Antoine > > > > Le jeu. 26 oct. 2023 =C3=A0 20:28, Johan Tor=C3=A5s Halseth via bitcoin= -dev < > bitcoin-dev@lists.linuxfoundation.org> a =C3=A9crit : > >> > >> Hi all, > >> > >> After the transaction recycling has spurred some discussion the last > >> week or so, I figured it could be worth sharing some research I=E2=80= =99ve > >> done into HTLC output aggregation, as it could be relevant for how to > >> avoid this problem in a future channel type. > >> > >> TLDR; With the right covenant we can create HTLC outputs that are much > >> more chain efficient, not prone to tx recycling and harder to jam. > >> > >> ## Transaction recycling > >> The transaction recycling attack is made possible by the change made > >> to HTLC second level transactions for the anchor channel type[8]; > >> making it possible to add fees to the transaction by adding inputs > >> without violating the signature. For the legacy channel type this > >> attack was not possible, as all fees were taken from the HTLC outputs > >> themselves, and had to be agreed upon by channel counterparties during > >> signing (of course this has its own problems, which is why we wanted > >> to change it). > >> > >> The idea of HTLC output aggregation is to collapse all HTLC outputs on > >> the commitment to a single one. This has many benefits (that I=E2=80= =99ll get > >> to), one of them being the possibility to let the spender claim the > >> portion of the output that they=E2=80=99re right to, deciding how much= should > >> go to fees. Note that this requires a covenant to be possible. > >> > >> ## A single HTLC output > >> Today, every forwarded HTLC results in an output that needs to be > >> manifested on the commitment transaction in order to claw back money > >> in case of an uncooperative channel counterparty. This puts a limit on > >> the number of active HTLCs (in order for the commitment transaction to > >> not become too large) which makes it possible to jam the channel with > >> small amounts of capital [1]. It also turns out that having this limit > >> be large makes it expensive and complicated to sweep the outputs > >> efficiently [2]. > >> > >> Instead of having new HTLC outputs manifest for each active > >> forwarding, with covenants on the base layer one could create a single > >> aggregated output on the commitment. The output amount being the sum > >> of the active HTLCs (offered and received), alternatively one output > >> for received and one for offered. When spending this output, you would > >> only be entitled to the fraction of the amount corresponding to the > >> HTLCs you know the preimage for (received), or that has timed out > >> (offered). > >> > >> ## Impacts to transaction recycling > >> Depending on the capabilities of the covenant available (e.g. > >> restricting the number of inputs to the transaction) the transaction > >> spending the aggregated HTLC output can be made self sustained: the > >> spender will be able to claim what is theirs (preimage or timeout) and > >> send it to whatever output they want, or to fees. The remainder will > >> go back into a covenant restricted output with the leftover HTLCs. > >> Note that this most likely requires Eltoo in order to not enable fee > >> siphoning[7]. > >> > >> ## Impacts to slot jamming > >> With the aggregated output being a reality, it changes the nature of > >> =E2=80=9Cslot jamming=E2=80=9D [1] significantly. While channel capaci= ty must still be > >> reserved for in-flight HTLCs, one no longer needs to allocate a > >> commitment output for each up to some hardcoded limit. > >> > >> In today=E2=80=99s protocol this limit is 483, and I believe most > >> implementations default to an even lower limit. This leads to channel > >> jamming being quite inexpensive, as one can quickly fill a channel > >> with small HTLCs, without needing a significant amount of capital to > >> do so. > >> > >> The origins of the 483 slot limits is the worst case commitment size > >> before getting into unstandard territory [3]. With an aggregated > >> output this would no longer be the case, as adding HTLCs would no > >> longer affect commitment size. Instead, the full on-chain footprint of > >> an HTLC would be deferred until claim time. > >> > >> Does this mean one could lift, or even remove the limit for number of > >> active HTLCs? Unfortunately, the obvious approach doesn=E2=80=99t seem= to get > >> rid of the problem entirely, but mitigates it quite a bit. > >> > >> ### Slot jamming attack scenario > >> Consider the scenario where an attacker sends a large number of > >> non-dust* HTLCs across a channel, and the channel parties enforce no > >> limit on the number of active HTLCs. > >> > >> The number of payments would not affect the size of the commitment > >> transaction at all, only the size of the witness that must be > >> presented when claiming or timing out the HTLCs. This means that there > >> is still a point at which chain fees get high enough for the HTLC to > >> be uneconomical to claim. This is no different than in today=E2=80=99s= spec, > >> and such HTLCs will just be stranded on-chain until chain fees > >> decrease, at which point there is a race between the success and > >> timeout spends. > >> > >> There seems to be no way around this; if you want to claim an HTLC > >> on-chain, you need to put the preimage on-chain. And when the HTLC > >> first reaches you, you have no way of predicting the future chain fee. > >> With a large number of uneconomical HTLCs in play, the total BTC > >> exposure could still be very large, so you might want to limit this > >> somewhat. > >> > >> * Note that as long as the sum of HTLCs exceeds the dust limit, one > >> could manifest the output on the transaction. > >> > >> ## The good news > >> With an aggregated HTLC output, the number of HTLCs would no longer > >> impact the commitment transaction size while the channel is open and > >> operational. > >> > >> The marginal cost of claiming an HTLC with a preimage on-chain would > >> be much lower; no new inputs or outputs, only a linear increase in the > >> witness size. With a covenant primitive available, the extra footprint > >> of the timeout and success transactions would no longer exist. > >> > >> Claiming timed out HTLCs could still be made close to constant size > >> (no preimage to present), so no additional on-chain cost with more > >> HTLCs. > >> > >> ## The bad news > >> The most obvious problem is that we would need a new covenant > >> primitive on L1 (see below). However, I think it could be beneficial > >> to start exploring these ideas now in order to guide the L1 effort > >> towards something we could utilize to its fullest on L2. > >> > >> As mentioned, even with a functioning covenant, we don=E2=80=99t escap= e the > >> fact that a preimage needs to go on-chain, pricing out HTLCs at > >> certain fee rates. This is analogous to the dust exposure problem > >> discussed in [6], and makes some sort of limit still required. > >> > >> ### Open question > >> With PTLCs, could one create a compact proof showing that you know the > >> preimage for m-of-n of the satoshis in the output? (some sort of > >> threshold signature). > >> > >> If we could do this we would be able to remove the slot jamming issue > >> entirely; any number of active PTLCs would not change the on-chain > >> cost of claiming them. > >> > >> ## Covenant primitives > >> A recursive covenant is needed to achieve this. Something like OP_CTV > >> and OP_APO seems insufficient, since the number of ways the set of > >> HTLCs could be claimed would cause combinatorial blowup in the number > >> of possible spending transactions. > >> > >> Personally, I=E2=80=99ve found the simple yet powerful properties of > >> OP_CHECKCONTRACTVERIFY [4] together with OP_CAT and amount inspection > >> particularly interesting for the use case, but I=E2=80=99m certain man= y of the > >> other proposals could achieve the same thing. More direct inspection > >> like you get from a proposal like OP_TX[9] would also most likely have > >> the building blocks needed. > >> > >> ### Proof-of-concept > >> I=E2=80=99ve implemented a rough demo** of spending an HTLC output tha= t pays > >> to a script with OP_CHECKCONTRACTVERIFY to achieve this [5]. The idea > >> is to commit to all active HTLCs in a merkle tree, and have the > >> spender provide merkle proofs for the HTLCs to claim, claiming the sum > >> into a new output. The remainder goes back into a new output with the > >> claimed HTLCs removed from the merkle tree. > >> > >> An interesting trick one can do when creating the merkle tree, is > >> sorting the HTLCs by expiry. This means that one in the timeout case > >> claim a subtree of HTLCs using a single merkle proof (and RBF this > >> batched timeout claim as more and more HTLCs expire) reducing the > >> timeout case to constant size witness (or rather logarithmic in the > >> total number of HTLCs). > >> > >> **Consider it an experiment, as it is missing a lot before it could be > >> usable in any real commitment setting. > >> > >> > >> [1] > https://bitcoinops.org/en/topics/channel-jamming-attacks/#htlc-jamming-at= tack > >> [2] https://github.com/lightning/bolts/issues/845 > >> [3] > https://github.com/lightning/bolts/blob/aad959a297ff66946effb165518143be1= 5777dd6/02-peer-protocol.md#rationale-7 > >> [4] > https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2022-November/021= 182.html > >> [5] > https://github.com/halseth/tapsim/blob/b07f29804cf32dce0168ab5bb40558cbb1= 8f2e76/examples/matt/claimpool/script.txt > >> [6] > https://lists.linuxfoundation.org/pipermail/lightning-dev/2021-October/00= 3257.html > >> [7] > https://github.com/lightning/bolts/issues/845#issuecomment-937736734 > >> [8] > https://github.com/lightning/bolts/blob/8a64c6a1cef979b3f0cecb00ba7a48c2d= 28b3588/03-transactions.md?plain=3D1#L333 > >> [9] > https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2022-May/020450.h= tml > >> _______________________________________________ > >> bitcoin-dev mailing list > >> bitcoin-dev@lists.linuxfoundation.org > >> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev > --0000000000006d3f3b060cbc8c92 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Johan,

> Is this a concern though, if we assume there's no revoked state th=
at
> can be broadcast (Eltoo)? Could you share an example of how this would
> be played out by an attacker?

Sure, let's assume no revoked state can be broadcast (Eltoo).

My understanding of the new covenant mechanism is the aggregation or collap=
sing of all HTLC outputs in one or at least 2 outputs (offered / received).
Any spend of an aggregated HTLC "payout" should satisfy the scrip=
t locking condition by presenting a preimage and a signature.
An offerd aggregated HTLC output might collapse a M number of HTLC "pa=
yout", where M is still limited by the max standard transaction relay,=
 among other things.

The offered-to counterparty can claim any subset N of the aggregation M by =
presenting the list of signatures and preimages (How they're feeded to =
the spent script is a covenant implementation detail). However, there is no=
 guarantee that the offered-to counterparty reveal "all" the prei=
mages she is awarded off. Non-spent HTLC outputs are clawback to a remainde=
r subset of M, M'.

I think this partial reveal of HTLC payout preimages still opens the door t=
o replacement cycling attacks.

Let's say you have 5 offered HTLC "payouts" between Alice and=
 Bob aggregated in a single output, 4 of value 0.1 BTC and 1 of value 1 BTC=
. All expire at timelock T.
At T, Alice broadcasts an aggregated HTLC-timeout spend for the 5 HTLC with=
 0.0.1 BTC on-chain fee.

Bob can craft a HTLC-preimage spend of the single offered output spending o=
ne of 0.1 BTC HTLC payout (and revealing its preimage) while burning all th=
e value as fee. This replaces out Alice's honest HTLC-timeout out of ne=
twork mempools, are they're concurrent spend.=C2=A0Bob can repeat this trick as long as ther=
e is HTLC "payout" remaining in the offered set, until he&=
#39;s being able to do a HTLC =
off-chain double-spend of the 1 BTC HTLC "payout".
This stealing gain of the 1 BTC HTLC "payout" covers wha= t has been burned as miners fees to replace cycle out Alice's sequence = of honest HTLC-timeout.
And it should be noted that =
Bob might benefit from network mempools congestion delaying the confirmatio=
n of his malicious low-value high-fee HTLC-preimage transactions.

> I'm not sure what you mean here, could you elaborate?

See https://lists.linuxfoundation.org/pipermail/bitcoin-=
dev/2023-December/022191.html and my answer there.
I think "self-sustained" fees is one only part of the solution, t=
he other part being the sliding delay of the HTLC timelock based on block f=
eerate.
Otherwise, a replacement cycling attacker can always benefit from network m=
empools congestion spontaneously pushing out a malicious cycling transactio=
n out of block templates.

> That sounds possible, but how would you deal with the exponential
> blowup in the number of combinations?

In a taproot-world, "swallow the bullet" in terms of witness size=
 growth in case of non-cooperative closure.
I think this is where introducing an accumulator at the Script level to eff=
iciently test partial set membership would make sense.
Note, exponential blowup is an issue for mass non-coordinated withdrawals o=
f a payment pool too.

Best,
Antoine

Le=C2=A0lun. 11 d=C3=A9c. 2023 =C3=A0=C2=A009:17, Johan= Tor=C3=A5s Halseth <johanth@gmail.= com> a =C3=A9crit=C2=A0:
Hi, Antoine.

> The attack works on legacy channels if the holder (or local) commitmen= t transaction confirms first, the second-stage HTLC claim transaction is fu= lly malleable by the counterparty.

Yes, correct. Thanks for pointing that out!

> I think one of the weaknesses of this approach is the level of malleab= ility still left to the counterparty, where one might burn in miners fees a= ll the HTLC accumulated value promised to the counterparty, and for which t= he preimages have been revealed off-chain.

Is this a concern though, if we assume there's no revoked state that can be broadcast (Eltoo)? Could you share an example of how this would
be played out by an attacker?

> I wonder if a more safe approach, eliminating a lot of competing inter= ests style of mempool games, wouldn't be to segregate HTLC claims in tw= o separate outputs, with full replication of the HTLC lockscripts in both o= utputs, and let a covenant accepts or rejects aggregated claims with satisf= ying witness and chain state condition for time lock.

I'm not sure what you mean here, could you elaborate?

> I wonder if in a PTLC world, you can generate an aggregate curve point= for all the sub combinations of scalar plausible. Unrevealed curve points = in a taproot branch are cheap. It might claim an offered HTLC near-constant= size too.

That sounds possible, but how would you deal with the exponential
blowup in the number of combinations?

Cheers,
Johan


On Tue, Nov 21, 2023 at 3:39=E2=80=AFAM Antoine Riard <antoine.riard@gmail.com>= wrote:
>
> Hi Johan,
>
> Few comments.
>
> ## Transaction recycling
> The transaction recycling attack is made possible by the change made > to HTLC second level transactions for the anchor channel type[8];
> making it possible to add fees to the transaction by adding inputs
> without violating the signature. For the legacy channel type this
> attack was not possible, as all fees were taken from the HTLC outputs<= br> > themselves, and had to be agreed upon by channel counterparties during=
> signing (of course this has its own problems, which is why we wanted > to change it).
>
> The attack works on legacy channels if the holder (or local) commitmen= t transaction confirms first, the second-stage HTLC claim transaction is fu= lly malleable by the counterparty.
>
> See https= ://github.com/lightning/bolts/blob/master/03-transactions.md#offered-htlc-o= utputs (only remote_htlcpubkey required)
>
> Note a replacement cycling attack works in a future package-relay worl= d too.
>
> See test: http= s://github.com/ariard/bitcoin/commit/19d61fa8cf22a5050b51c4005603f43d72f1ef= cf
>
> > The idea of HTLC output aggregation is to collapse all HTLC outpu= ts on
> > the commitment to a single one. This has many benefits (that I=E2= =80=99ll get
> > to), one of them being the possibility to let the spender claim t= he
> > portion of the output that they=E2=80=99re right to, deciding how= much should
> > go to fees. Note that this requires a covenant to be possible. >
> Another advantage of HTLC output aggregation is the reduction of fee-b= umping reserves requirements on channel counterparties, as second-stage HTL= C transactions have common fields (nVersion, nLocktime, ...) *could* be sha= red.
>
> > ## A single HTLC output
> > Today, every forwarded HTLC results in an output that needs to be=
> > manifested on the commitment transaction in order to claw back mo= ney
> > in case of an uncooperative channel counterparty. This puts a lim= it on
> > the number of active HTLCs (in order for the commitment transacti= on to
> > not become too large) which makes it possible to jam the channel = with
> > small amounts of capital [1]. It also turns out that having this = limit
> > be large makes it expensive and complicated to sweep the outputs<= br> > > efficiently [2].
>
> > Instead of having new HTLC outputs manifest for each active
> > forwarding, with covenants on the base layer one could create a s= ingle
> > aggregated output on the commitment. The output amount being the = sum
> > of the active HTLCs (offered and received), alternatively one out= put
> > for received and one for offered. When spending this output, you = would
> > only be entitled to the fraction of the amount corresponding to t= he
> > HTLCs you know the preimage for (received), or that has timed out=
> > (offered).
>
> > ## Impacts to transaction recycling
> > Depending on the capabilities of the covenant available (e.g.
> > restricting the number of inputs to the transaction) the transact= ion
> > spending the aggregated HTLC output can be made self sustained: t= he
> > spender will be able to claim what is theirs (preimage or timeout= ) and
> > send it to whatever output they want, or to fees. The remainder w= ill
> > go back into a covenant restricted output with the leftover HTLCs= .
> > Note that this most likely requires Eltoo in order to not enable = fee
> > siphoning[7].
>
> I think one of the weaknesses of this approach is the level of malleab= ility still left to the counterparty, where one might burn in miners fees a= ll the HTLC accumulated value promised to the counterparty, and for which t= he preimages have been revealed off-chain.
>
> I wonder if a more safe approach, eliminating a lot of competing inter= ests style of mempool games, wouldn't be to segregate HTLC claims in tw= o separate outputs, with full replication of the HTLC lockscripts in both o= utputs, and let a covenant accepts or rejects aggregated claims with satisf= ying witness and chain state condition for time lock.
>
> > ## Impacts to slot jamming
> > With the aggregated output being a reality, it changes the nature= of
> > =E2=80=9Cslot jamming=E2=80=9D [1] significantly. While channel c= apacity must still be
> > reserved for in-flight HTLCs, one no longer needs to allocate a > > commitment output for each up to some hardcoded limit.
>
> > In today=E2=80=99s protocol this limit is 483, and I believe most=
> > implementations default to an even lower limit. This leads to cha= nnel
> > jamming being quite inexpensive, as one can quickly fill a channe= l
> > with small HTLCs, without needing a significant amount of capital= to
> > do so.
>
> > The origins of the 483 slot limits is the worst case commitment s= ize
> > before getting into unstandard territory [3]. With an aggregated<= br> > > output this would no longer be the case, as adding HTLCs would no=
> > longer affect commitment size. Instead, the full on-chain footpri= nt of
> > an HTLC would be deferred until claim time.
>
> > Does this mean one could lift, or even remove the limit for numbe= r of
> > active HTLCs? Unfortunately, the obvious approach doesn=E2=80=99t= seem to get
> > rid of the problem entirely, but mitigates it quite a bit.
>
> Yes, protocol limit of 483 is a long-term limit on the payment through= put of the LN, though as an upper bound we have the dust limits and mempool= fluctuations rendering irrelevant the claim of such aggregated dust output= s. Aggregated claims might give a more dynamic margin of what is a tangible= and trust-minimized HTLC payment.
>
> > ### Slot jamming attack scenario
> > Consider the scenario where an attacker sends a large number of > > non-dust* HTLCs across a channel, and the channel parties enforce= no
> > limit on the number of active HTLCs.
>
> > The number of payments would not affect the size of the commitmen= t
> > transaction at all, only the size of the witness that must be
> > presented when claiming or timing out the HTLCs. This means that = there
> > is still a point at which chain fees get high enough for the HTLC= to
> > be uneconomical to claim. This is no different than in today=E2= =80=99s spec,
> > and such HTLCs will just be stranded on-chain until chain fees > > decrease, at which point there is a race between the success and<= br> > > timeout spends.
>
> > There seems to be no way around this; if you want to claim an HTL= C
> > on-chain, you need to put the preimage on-chain. And when the HTL= C
> > first reaches you, you have no way of predicting the future chain= fee.
> > With a large number of uneconomical HTLCs in play, the total BTC<= br> > > exposure could still be very large, so you might want to limit th= is
> > somewhat.
>
> > * Note that as long as the sum of HTLCs exceeds the dust limit, o= ne
> > could manifest the output on the transaction.
>
> Unless we introduce sliding windows during which the claim periods of = an HTLC can be claimed and freeze accordingly the HTLC-timeout path.
>
> See: https://fc22.ifca.ai/preproceedings/119.pdf=
>
> Bad news: you will need off-chain consensus on the feerate threshold a= t which the sliding windows kick-out among all the routing nodes participat= ing in the HTLC payment path.
>
> > ## The good news
> > With an aggregated HTLC output, the number of HTLCs would no long= er
> > impact the commitment transaction size while the channel is open = and
> > operational.
>
> > The marginal cost of claiming an HTLC with a preimage on-chain wo= uld
> > be much lower; no new inputs or outputs, only a linear increase i= n the
> > witness size. With a covenant primitive available, the extra foot= print
> > of the timeout and success transactions would no longer exist. >
> > Claiming timed out HTLCs could still be made close to constant si= ze
> > (no preimage to present), so no additional on-chain cost with mor= e
> > HTLCs.
>
> I wonder if in a PTLC world, you can generate an aggregate curve point= for all the sub combinations of scalar plausible. Unrevealed curve points = in a taproot branch are cheap. It might claim an offered HTLC near-constant= size too.
>
> > ## The bad news
> > The most obvious problem is that we would need a new covenant
> > primitive on L1 (see below). However, I think it could be benefic= ial
> > to start exploring these ideas now in order to guide the L1 effor= t
> > towards something we could utilize to its fullest on L2.
>
> > As mentioned, even with a functioning covenant, we don=E2=80=99t = escape the
> > fact that a preimage needs to go on-chain, pricing out HTLCs at > > certain fee rates. This is analogous to the dust exposure problem=
> > discussed in [6], and makes some sort of limit still required. >
> Ideally such covenant mechanisms would generalize to the withdrawal ph= ase of payment pools, where dozens or hundreds of participants wish to conf= irm their non-competing withdrawal transactions concurrently. While unlocki= ng preimage or scalar can be aggregated in a single witness, there will sti= ll be a need to verify that each withdrawal output associated with an unloc= king secret is present in the transaction.
>
> Maybe few other L2s are answering this N-inputs-to-M-outputs pattern w= ith advanced locking scripts conditions to satisfy.
>
> > ### Open question
> > With PTLCs, could one create a compact proof showing that you kno= w the
> > preimage for m-of-n of the satoshis in the output? (some sort of<= br> > > threshold signature).
>
> > If we could do this we would be able to remove the slot jamming i= ssue
> > entirely; any number of active PTLCs would not change the on-chai= n
> > cost of claiming them.
>
> See comments above, I think there is a plausible scheme here you just = generate all the point combinations possible, and only reveal the one you n= eed at broadcast.
>
> > ## Covenant primitives
> > A recursive covenant is needed to achieve this. Something like OP= _CTV
> > and OP_APO seems insufficient, since the number of ways the set o= f
> > HTLCs could be claimed would cause combinatorial blowup in the nu= mber
> > of possible spending transactions.
>
> > Personally, I=E2=80=99ve found the simple yet powerful properties= of
> > OP_CHECKCONTRACTVERIFY [4] together with OP_CAT and amount inspec= tion
> > particularly interesting for the use case, but I=E2=80=99m certai= n many of the
> > other proposals could achieve the same thing. More direct inspect= ion
> > like you get from a proposal like OP_TX[9] would also most likely= have
> > the building blocks needed.
>
> As pointed out during the CTV drama and payment pool public discussion= years ago, what would be very useful to tie-break among all covenant const= ructions would be an efficiency simulation framework. Even if the same sema= ntic can be achieved independently by multiple covenants, they certainly do= not have the same performance trade-offs (e.g average and worst-case witne= ss size).
>
> I don't think the blind approach of activating many complex covena= nts at the same time is conservative enough in Bitcoin, where one might des= ign "malicious" L2 contracts, of which the game-theory is not ful= ly understood.
>
> See e.g https://blog.bitmex.com/txwithhold-s= mart-contracts/
>
> > ### Proof-of-concept
> > I=E2=80=99ve implemented a rough demo** of spending an HTLC outpu= t that pays
> > to a script with OP_CHECKCONTRACTVERIFY to achieve this [5]. The = idea
> > is to commit to all active HTLCs in a merkle tree, and have the > > spender provide merkle proofs for the HTLCs to claim, claiming th= e sum
> > into a new output. The remainder goes back into a new output with= the
> > claimed HTLCs removed from the merkle tree.
>
> > An interesting trick one can do when creating the merkle tree, is=
> > sorting the HTLCs by expiry. This means that one in the timeout c= ase
> > claim a subtree of HTLCs using a single merkle proof (and RBF thi= s
> > batched timeout claim as more and more HTLCs expire) reducing the=
> > timeout case to constant size witness (or rather logarithmic in t= he
> > total number of HTLCs).
>
> > **Consider it an experiment, as it is missing a lot before it cou= ld be
> > usable in any real commitment setting.
>
> I think this is an interesting question if more advanced cryptosystems= based on assumptions other than the DL problem could constitute a factor o= f scalability of LN payment throughput by orders of magnitude, by decouplin= g number of off-chain payments from the growth of the on-chain witness size= need to claim them, without lowering in security as with trimmed HTLC due = to dust limits.
>
> Best,
> Antoine
>
> Le jeu. 26 oct. 2023 =C3=A0 20:28, Johan Tor=C3=A5s Halseth via bitcoi= n-dev <bitcoin-dev@lists.linuxfoundation.org> a =C3=A9crit : >>
>> Hi all,
>>
>> After the transaction recycling has spurred some discussion the la= st
>> week or so, I figured it could be worth sharing some research I=E2= =80=99ve
>> done into HTLC output aggregation, as it could be relevant for how= to
>> avoid this problem in a future channel type.
>>
>> TLDR; With the right covenant we can create HTLC outputs that are = much
>> more chain efficient, not prone to tx recycling and harder to jam.=
>>
>> ## Transaction recycling
>> The transaction recycling attack is made possible by the change ma= de
>> to HTLC second level transactions for the anchor channel type[8];<= br> >> making it possible to add fees to the transaction by adding inputs=
>> without violating the signature. For the legacy channel type this<= br> >> attack was not possible, as all fees were taken from the HTLC outp= uts
>> themselves, and had to be agreed upon by channel counterparties du= ring
>> signing (of course this has its own problems, which is why we want= ed
>> to change it).
>>
>> The idea of HTLC output aggregation is to collapse all HTLC output= s on
>> the commitment to a single one. This has many benefits (that I=E2= =80=99ll get
>> to), one of them being the possibility to let the spender claim th= e
>> portion of the output that they=E2=80=99re right to, deciding how = much should
>> go to fees. Note that this requires a covenant to be possible.
>>
>> ## A single HTLC output
>> Today, every forwarded HTLC results in an output that needs to be<= br> >> manifested on the commitment transaction in order to claw back mon= ey
>> in case of an uncooperative channel counterparty. This puts a limi= t on
>> the number of active HTLCs (in order for the commitment transactio= n to
>> not become too large) which makes it possible to jam the channel w= ith
>> small amounts of capital [1]. It also turns out that having this l= imit
>> be large makes it expensive and complicated to sweep the outputs >> efficiently [2].
>>
>> Instead of having new HTLC outputs manifest for each active
>> forwarding, with covenants on the base layer one could create a si= ngle
>> aggregated output on the commitment. The output amount being the s= um
>> of the active HTLCs (offered and received), alternatively one outp= ut
>> for received and one for offered. When spending this output, you w= ould
>> only be entitled to the fraction of the amount corresponding to th= e
>> HTLCs you know the preimage for (received), or that has timed out<= br> >> (offered).
>>
>> ## Impacts to transaction recycling
>> Depending on the capabilities of the covenant available (e.g.
>> restricting the number of inputs to the transaction) the transacti= on
>> spending the aggregated HTLC output can be made self sustained: th= e
>> spender will be able to claim what is theirs (preimage or timeout)= and
>> send it to whatever output they want, or to fees. The remainder wi= ll
>> go back into a covenant restricted output with the leftover HTLCs.=
>> Note that this most likely requires Eltoo in order to not enable f= ee
>> siphoning[7].
>>
>> ## Impacts to slot jamming
>> With the aggregated output being a reality, it changes the nature = of
>> =E2=80=9Cslot jamming=E2=80=9D [1] significantly. While channel ca= pacity must still be
>> reserved for in-flight HTLCs, one no longer needs to allocate a >> commitment output for each up to some hardcoded limit.
>>
>> In today=E2=80=99s protocol this limit is 483, and I believe most<= br> >> implementations default to an even lower limit. This leads to chan= nel
>> jamming being quite inexpensive, as one can quickly fill a channel=
>> with small HTLCs, without needing a significant amount of capital = to
>> do so.
>>
>> The origins of the 483 slot limits is the worst case commitment si= ze
>> before getting into unstandard territory [3]. With an aggregated >> output this would no longer be the case, as adding HTLCs would no<= br> >> longer affect commitment size. Instead, the full on-chain footprin= t of
>> an HTLC would be deferred until claim time.
>>
>> Does this mean one could lift, or even remove the limit for number= of
>> active HTLCs? Unfortunately, the obvious approach doesn=E2=80=99t = seem to get
>> rid of the problem entirely, but mitigates it quite a bit.
>>
>> ### Slot jamming attack scenario
>> Consider the scenario where an attacker sends a large number of >> non-dust* HTLCs across a channel, and the channel parties enforce = no
>> limit on the number of active HTLCs.
>>
>> The number of payments would not affect the size of the commitment=
>> transaction at all, only the size of the witness that must be
>> presented when claiming or timing out the HTLCs. This means that t= here
>> is still a point at which chain fees get high enough for the HTLC = to
>> be uneconomical to claim. This is no different than in today=E2=80= =99s spec,
>> and such HTLCs will just be stranded on-chain until chain fees
>> decrease, at which point there is a race between the success and >> timeout spends.
>>
>> There seems to be no way around this; if you want to claim an HTLC=
>> on-chain, you need to put the preimage on-chain. And when the HTLC=
>> first reaches you, you have no way of predicting the future chain = fee.
>> With a large number of uneconomical HTLCs in play, the total BTC >> exposure could still be very large, so you might want to limit thi= s
>> somewhat.
>>
>> * Note that as long as the sum of HTLCs exceeds the dust limit, on= e
>> could manifest the output on the transaction.
>>
>> ## The good news
>> With an aggregated HTLC output, the number of HTLCs would no longe= r
>> impact the commitment transaction size while the channel is open a= nd
>> operational.
>>
>> The marginal cost of claiming an HTLC with a preimage on-chain wou= ld
>> be much lower; no new inputs or outputs, only a linear increase in= the
>> witness size. With a covenant primitive available, the extra footp= rint
>> of the timeout and success transactions would no longer exist.
>>
>> Claiming timed out HTLCs could still be made close to constant siz= e
>> (no preimage to present), so no additional on-chain cost with more=
>> HTLCs.
>>
>> ## The bad news
>> The most obvious problem is that we would need a new covenant
>> primitive on L1 (see below). However, I think it could be benefici= al
>> to start exploring these ideas now in order to guide the L1 effort=
>> towards something we could utilize to its fullest on L2.
>>
>> As mentioned, even with a functioning covenant, we don=E2=80=99t e= scape the
>> fact that a preimage needs to go on-chain, pricing out HTLCs at >> certain fee rates. This is analogous to the dust exposure problem<= br> >> discussed in [6], and makes some sort of limit still required.
>>
>> ### Open question
>> With PTLCs, could one create a compact proof showing that you know= the
>> preimage for m-of-n of the satoshis in the output? (some sort of >> threshold signature).
>>
>> If we could do this we would be able to remove the slot jamming is= sue
>> entirely; any number of active PTLCs would not change the on-chain=
>> cost of claiming them.
>>
>> ## Covenant primitives
>> A recursive covenant is needed to achieve this. Something like OP_= CTV
>> and OP_APO seems insufficient, since the number of ways the set of=
>> HTLCs could be claimed would cause combinatorial blowup in the num= ber
>> of possible spending transactions.
>>
>> Personally, I=E2=80=99ve found the simple yet powerful properties = of
>> OP_CHECKCONTRACTVERIFY [4] together with OP_CAT and amount inspect= ion
>> particularly interesting for the use case, but I=E2=80=99m certain= many of the
>> other proposals could achieve the same thing. More direct inspecti= on
>> like you get from a proposal like OP_TX[9] would also most likely = have
>> the building blocks needed.
>>
>> ### Proof-of-concept
>> I=E2=80=99ve implemented a rough demo** of spending an HTLC output= that pays
>> to a script with OP_CHECKCONTRACTVERIFY to achieve this [5]. The i= dea
>> is to commit to all active HTLCs in a merkle tree, and have the >> spender provide merkle proofs for the HTLCs to claim, claiming the= sum
>> into a new output. The remainder goes back into a new output with = the
>> claimed HTLCs removed from the merkle tree.
>>
>> An interesting trick one can do when creating the merkle tree, is<= br> >> sorting the HTLCs by expiry. This means that one in the timeout ca= se
>> claim a subtree of HTLCs using a single merkle proof (and RBF this=
>> batched timeout claim as more and more HTLCs expire) reducing the<= br> >> timeout case to constant size witness (or rather logarithmic in th= e
>> total number of HTLCs).
>>
>> **Consider it an experiment, as it is missing a lot before it coul= d be
>> usable in any real commitment setting.
>>
>>
>> [1] https://bi= tcoinops.org/en/topics/channel-jamming-attacks/#htlc-jamming-attack
>> [2] https://github.com/lightning/bolts/issues= /845
>> [3] https://github.com/lightning/bolts/blob/aad959a297= ff66946effb165518143be15777dd6/02-peer-protocol.md#rationale-7
>> [4] https:= //lists.linuxfoundation.org/pipermail/bitcoin-dev/2022-November/021182.html=
>> [5] https://github.com/halseth/tapsim/blob/b07f29804= cf32dce0168ab5bb40558cbb18f2e76/examples/matt/claimpool/script.txt
>> [6] https= ://lists.linuxfoundation.org/pipermail/lightning-dev/2021-October/003257.ht= ml
>> [7] https://github.com/= lightning/bolts/issues/845#issuecomment-937736734
>> [8] https://github.com/lightning/bolts/blob/8a64c6a1= cef979b3f0cecb00ba7a48c2d28b3588/03-transactions.md?plain=3D1#L333
>> [9] https://lis= ts.linuxfoundation.org/pipermail/bitcoin-dev/2022-May/020450.html
>> _______________________________________________
>> bitcoin-dev mailing list
>> bitcoin-dev@lists.linuxfoundation.org
>> https://lists.linuxfoundation= .org/mailman/listinfo/bitcoin-dev
--0000000000006d3f3b060cbc8c92--