Return-Path: Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id CDCD1C0039; Tue, 21 Nov 2023 02:40:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id A0ECC401CE; Tue, 21 Nov 2023 02:40:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A0ECC401CE 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=ALCzjOdz 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 QTDy3xhmo4a9; Tue, 21 Nov 2023 02:39:58 +0000 (UTC) Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by smtp4.osuosl.org (Postfix) with ESMTPS id 54A06401BA; Tue, 21 Nov 2023 02:39:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 54A06401BA Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-35af64a180eso7339205ab.1; Mon, 20 Nov 2023 18:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700534397; x=1701139197; darn=lists.linuxfoundation.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=2D48U+KmOO5cIRtFUMxXkMxXrry96RWek2apAKKXGGU=; b=ALCzjOdzkjIvs+7myjl15LswNj1g8/Y5a4P3fqsl+d8EB3bn418vaAXue2vZbzs9BL duw6FmptOMLsVnRcvTbDkB+rObLMWG6I7tlslQUTzubQfJrPtu+NukuBsvxZqa9JlWM4 3dpbALOuTue1QnbsUR4EFYrdcrphmdcWmyrwCcGzwgCd5NEszRQ6CchyPb+mRXUylDo5 IjQ3GNWQstbiT4f44duvegMJ2HWuSAyI1aUMgSG0j8FUbVj/WH09lePOIV+ahOrmWCSW xydvqx7Vze3okSDizm25Hm24KfQUAXjrVqD3WF7ijn0Qloxw9lbVFeGqZf5vm1rVP2ll KU8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700534397; x=1701139197; h=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=2D48U+KmOO5cIRtFUMxXkMxXrry96RWek2apAKKXGGU=; b=UIeQ6mqvQ0tp3X4g3Ttv9VBPHPWmnddqM1QoCHLkq+50Md2rjLL8Ij/Q05oqt0zZNl Oec3D/44Tc1bj7te1kHtP3Rk0hda8X7MVlTF3nnflmwgriZ7Yi2rXciCMpbEYR1CJln4 rqC+6dzS5KB5W9/F/utpJ2ZdF9zlsDDkCPZhWdn6yMIpZa68lyOAhsU2iv4XFdhRno8X GcsASpjw53eCFTl3dWFbhCbSdzjo7QNBhF0ia+htkjhjJgSXv1f+qmSmLAKMix+U1xDp q7vEl4ckrDoVOmG8Iaso0cxGMPYcy7QI1XGVQgoqYPToDHFOnPUbqjoi772TES5maEjV emmQ== X-Gm-Message-State: AOJu0Yz+Bv/Tmp4sLzGyEFjbwqv9RQ33aug+NklDzVcceqxSQUBDRyRu Ar0qDaqbNmRdSAzfaRJr+ezqvAnsaVEMqp1S8We4UPnMfZf0QRG7 X-Google-Smtp-Source: AGHT+IFn39KAEcIWmm5wWoBhF0jr2+5ATAbZXBn7ZZckzFzS5yOq6sZBLmjNJ1QhxbByIjCeutq9ktAmPV+t+DYpwtc= X-Received: by 2002:a92:3314:0:b0:35a:b399:555a with SMTP id a20-20020a923314000000b0035ab399555amr9937339ilf.10.1700534397112; Mon, 20 Nov 2023 18:39:57 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Antoine Riard Date: Tue, 21 Nov 2023 02:39:45 +0000 Message-ID: To: =?UTF-8?Q?Johan_Tor=C3=A5s_Halseth?= , Bitcoin Protocol Discussion , "lightning-dev\\\\@lists.linuxfoundation.org" Content-Type: multipart/alternative; boundary="000000000000ab1685060aa084dc" X-Mailman-Approved-At: Tue, 21 Nov 2023 11:26:28 +0000 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: Tue, 21 Nov 2023 02:40:01 -0000 --000000000000ab1685060aa084dc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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-h= tlc-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/19d61fa8cf22a5050b51c4005603f43d72= f1efcf > 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 sh= ould > 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 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]. I think one of the weaknesses of this approach is the level of malleability still left to the counterparty, where one might burn in miners 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 both 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 capacity = 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. 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 and mempool fluctuations rendering irrelevant the claim of such aggregated dust 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 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 sp= ec, > 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 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 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 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. 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 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 escape t= he > 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 with 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 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. 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 many o= f 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. 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 same 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 at the same time is conservative enough in Bitcoin, where one might design "malicious" L2 contracts, of which the game-theory is not fully understood. 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 that p= ays > 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. 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 decoupling 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=99v= e > 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 sh= ould > 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 capacity = 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 sp= ec, > 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 escape t= he > 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 many o= f 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 that p= ays > 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 > --000000000000ab1685060aa084dc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Johan,

Few comments.

<= /div>
## Transaction recycling
The transaction recycling attack is m= ade possible by the change made
to HTLC second level transactions for th= e anchor channel type[8];
making it possible to add fees to the transact= ion by adding inputs
without violating the signature. For the legacy cha= nnel type this
attack was not possible, as all fees were taken from the = HTLC outputs
themselves, and had to be agreed upon by channel counterpar= ties during
signing (of course this has its own problems, which is why w= e wanted
to change it).

The attack works on= legacy channels if the holder (or local) commitment transaction confirms f= irst, the second-stage HTLC claim transaction is fully malleable by the cou= nterparty.


Note a= replacement cycling attack works in a future package-relay world too.


> The idea of HTLC output aggregation is to collapse all= HTLC outputs on
> the commitment to a single one. This has many bene= fits (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.

Another a= dvantage of HTLC output aggregation is the reduction of fee-bumping reserve= s 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 commi= tment transaction in order to claw back money
> in case of an uncoope= rative channel counterparty. This puts a limit on
> the number of act= ive HTLCs (in order for the commitment transaction to
> not become to= o large) which makes it possible to jam the channel with
> small amou= nts of capital [1]. It also turns out that having this limit
> be lar= ge makes it expensive and complicated to sweep the outputs
> efficien= tly [2].

> Instead of having new HTLC outputs manifest for each a= ctive
> forwarding, with covenants on the base layer one could create= a single
> aggregated output on the commitment. The output amount be= ing the sum
> of the active HTLCs (offered and received), alternative= ly one output
> for received and one for offered. When spending this = output, you would
> only be entitled to the fraction of the amount co= rresponding to the
> HTLCs you know the preimage for (received), or t= hat 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 trans= action
> spending the aggregated HTLC output can be made self sustain= ed: the
> spender will be able to claim what is theirs (preimage or t= imeout) and
> send it to whatever output they want, or to fees. The r= emainder will
> go back into a covenant restricted output with the le= ftover 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 l= eft to the counterparty, where one might burn in miners fees all the HTLC a= ccumulated value promised to the counterparty, and for which the preimages = have been revealed off-chain.

I wonder if a more s= afe approach, eliminating a lot of competing interests style of mempool gam= es, wouldn't be to segregate HTLC claims in two separate outputs, with = full replication of the HTLC lockscripts in both outputs, and let a covenan= t accepts or rejects aggregated claims with satisfying witness and chain st= ate condition for time lock.

> ## Impacts to sl= ot jamming
> With the aggregated output being a reality, it changes t= he nature of
> =E2=80=9Cslot jamming=E2=80=9D [1] significantly. Whil= e channel capacity 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 signifi= cant 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 l= onger be the case, as adding HTLCs would no
> longer affect commitmen= t size. Instead, the full on-chain footprint of
> an HTLC would be de= ferred until claim time.

> Does this mean one could lift, or even= remove the limit for number of
> active HTLCs? Unfortunately, the ob= vious approach doesn=E2=80=99t seem to get
> rid of the problem entir= ely, but mitigates it quite a bit.

Yes, protoc= ol limit of 483 is a long-term limit on the payment throughput of the LN, t= hough as an upper bound we have the dust limits and mempool fluctuations re= ndering irrelevant the claim of such aggregated dust outputs. Aggregated cl= aims might give a more dynamic margin of what is a tangible and trust-minim= ized HTLC payment.

> ### Slot jamming attack sc= enario
> Consider the scenario where an attacker sends a large number= of
> non-dust* HTLCs across a channel, and the channel parties enfor= ce no
> limit on the number of active HTLCs.

> The number o= f payments would not affect the size of the commitment
> transaction = at all, only the size of the witness that must be
> presented when cl= aiming or timing out the HTLCs. This means that there
> is still a po= int at which chain fees get high enough for the HTLC to
> be uneconom= ical to claim. This is no different than in today=E2=80=99s spec,
> a= nd such HTLCs will just be stranded on-chain until chain fees
> decre= ase, 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 c= laim an HTLC
> on-chain, you need to put the preimage on-chain. And w= hen the HTLC
> first reaches you, you have no way of predicting the f= uture chain fee.
> With a large number of uneconomical HTLCs in play,= the total BTC
> exposure could still be very large, so you might wan= t to limit this
> somewhat.

> * Note that as long as the su= m 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 an HTLC can be claimed and freeze= accordingly the HTLC-timeout path.


Bad news: you will need o= ff-chain consensus on the feerate threshold at which the sliding windows ki= ck-out among all the routing nodes participating in the HTLC payment path.<= /div>

> ## The good news
> With an aggregated H= TLC output, the number of HTLCs would no longer
> impact the commitme= nt transaction size while the channel is open and
> operational.
<= br>> The marginal cost of claiming an HTLC with a preimage on-chain woul= d
> be much lower; no new inputs or outputs, only a linear increase i= n the
> witness size. With a covenant primitive available, the extra = footprint
> of the timeout and success transactions would no longer e= xist.

> Claiming timed out HTLCs could still be made close to con= stant size
> (no preimage to present), so no additional on-chain cost= with more
> HTLCs.

I wonder if in a PTL= C world, you can generate an aggregate curve point for all the sub combinat= ions of scalar plausible. Unrevealed curve points in a taproot branch are c= heap. 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 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 covena= nt, 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 t= o the dust exposure problem
> discussed in [6], and makes some sort o= f 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 wit= hdrawal transactions concurrently. While unlocking preimage or scalar can b= e aggregated in a single witness, there will still be a need to verify that= each withdrawal output associated with an unlocking secret is present in t= he transaction.

Maybe few other L2s are answering = this N-inputs-to-M-outputs pattern with advanced locking scripts conditions= to satisfy.

> ### Open question
> With P= TLCs, could one create a compact proof showing that you know the
> pr= eimage for m-of-n of the satoshis in the output? (some sort of
> thre= shold signature).

> If we could do this we would be able to remov= e the slot jamming issue
> entirely; any number of active PTLCs would= not change the on-chain
> cost of claiming them.

<= /div>
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_CHECKCON= TRACTVERIFY [4] together with OP_CAT and amount inspection
> particul= arly interesting for the use case, but I=E2=80=99m certain many of the
&= gt; 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 point= ed out during the CTV drama and payment pool public discussion years ago, w= hat would be very useful to tie-break among all covenant constructions woul= d be an efficiency simulation framework. Even if the same semantic can be a= chieved independently by multiple covenants, they certainly do not have the= same performance trade-offs (e.g average and worst-case witness size).=C2= =A0

I don't think the blind approach of activa= ting many complex covenants at the same time is conservative enough in Bitc= oin, where one might design "malicious" L2 contracts, of which th= e game-theory is not fully understood.


&g= t; ### Proof-of-concept
> I=E2=80=99ve implemented a rough demo** of = spending an HTLC output that pays
> to a script with OP_CHECKCONTRACT= VERIFY to achieve this [5]. The idea
> is to commit to all active HTL= Cs in a merkle tree, and have the
> spender provide merkle proofs for= the HTLCs to claim, claiming the sum
> into a new output. The remain= der 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 o= ne in the timeout case
> claim a subtree of HTLCs using a single merk= le proof (and RBF this
> batched timeout claim as more and more HTLCs= expire) reducing the
> timeout case to constant size witness (or rat= her logarithmic in the
> total number of HTLCs).

> **Consid= er it an experiment, as it is missing a lot before it could be
> usab= le in any real commitment setting.

I think thi= s is an interesting question if more advanced cryptosystems based on assump= tions other than the DL problem could constitute a factor of scalability of= LN payment throughput by orders of magnitude, by decoupling number of off-= chain payments from the growth of the on-chain witness size need to claim t= hem, without lowering in security as with trimmed HTLC due to dust limits.<= /div>

Best,
Antoine

Le=C2=A0jeu. 26 oct.= 2023 =C3=A0=C2=A020:28, Johan Tor=C3=A5s Halseth via bitcoin-dev <bitcoin-dev@lists.linux= foundation.org> a =C3=A9crit=C2=A0:
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<= br> 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 g= et
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 shou= ld
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 capacity mu= st 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 g= et
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 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.

### 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 many 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 that pay= s
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-attack
[2] https://github.com/lightning/bolts/issues/845 [3] https://github.com/lightning/bolts/blob/aad959a297ff66946ef= fb165518143be15777dd6/02-peer-protocol.md#rationale-7
[4] https://lists.l= inuxfoundation.org/pipermail/bitcoin-dev/2022-November/021182.html
[5] https://github.com/halseth/tapsim/blob/b07f29804cf32dce01= 68ab5bb40558cbb18f2e76/examples/matt/claimpool/script.txt
[6] https://lists.= linuxfoundation.org/pipermail/lightning-dev/2021-October/003257.html [7] https://github.com/lightning= /bolts/issues/845#issuecomment-937736734
[8] https://github.com/lightning/bolts/blob/8a64c6a1cef979b3f= 0cecb00ba7a48c2d28b3588/03-transactions.md?plain=3D1#L333
[9] https://lists.linuxf= oundation.org/pipermail/bitcoin-dev/2022-May/020450.html
_______________________________________________
bitcoin-dev mailing list
= bitcoin-dev@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mail= man/listinfo/bitcoin-dev
--000000000000ab1685060aa084dc--