Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Fixing a griefing attack on JIT Channels using PTLCs

4 messages, May 9 to 10, 2023. Started by Ben Carman.

ZmnSCPxj (2), Ben Carman, SomberNight

Permalink First message in the Wayback Machine

Ben Carman permalink original

Hi everyone,

I was chatting with Tony Giorgio the other day and he made me aware of a potential griefing attack that is possible today on LSPs that provide Just-In-Time channels.

The attack is very simple, when the LSP receives the payment and then opens a 0-conf channel to the client, the client could not claim the payment thus resulting in the LSP not getting paid and the client getting a free inbound lightning channel. The LSP could double spend the transaction but they still would lose the miner fees and as we are seeing today, that can be very expensive.

I am not sure if this has been proposed before but we can fix this with PTLCs!

Instead of having the LSP just broadcasting the funding transaction to the mempool, they can sign the funding transaction using adaptor signatures locked to the same secret as the invoice. Then when the client wants to claim the funds they can get the funding txid from the LSP, and then do the PTLC dance with the LSP based on using that funding transaction. If it all goes as planned the LSP can give the funding transaction signed using adaptor sigs to the client and the client can then decrypt the signatures and broadcast the transaction. Then the LSP can find the transaction in the mempool and extract the secret they need to claim the payment, thus making claiming the payment and opening the channel atomic so the client can't grief the LSP.

Not sure if this has been talked about before, if not I think we can throw it in the ever-growing pile of "PTLCs fixes this".

Best, benthecarman

SomberNight in reply to Ben Carman permalink original

Hi benthecarman,

Quoted text (1 line)
> the LSP can give the funding transaction signed using adaptor sigs to the client and the client can then decrypt the signatures and broadcast the transaction. Then the LSP can find the transaction in the mempool and extract the secret they need to claim the payment

What if, after the client has the funding transaction locally, it waits for the PTLC held by the LSP to time out, i.e. days, and then (the client) broadcasts the funding transaction? The LSP could then no longer claim the PTLC, and it would have paid for the channel-open.

To prevent this, the LSP would have to actively double-spend the channel funding tx given to the client when the PTLC is close to expiring, and only after getting the conflict mined can the PTLC be failed. This double-spending would cost mining fees of course (arguably the ~same amount as not doing anything and just letting the channel open). Although perhaps the LSP has enough users and high enough traffic that the conflicting tx itself can be something useful, e.g. another channel-open to another user.

ghost43 / SomberNight

------- Original Message ------- On Tuesday, May 9th, 2023 at 19:07, Ben Carman <benthecarman at live.com> wrote:

Quoted text (14 lines)
> Hi everyone,
>
> I was chatting with Tony Giorgio the other day and he made me aware of a potential griefing attack that is possible today on LSPs that provide Just-In-Time channels.
>
> The attack is very simple, when the LSP receives the payment and then opens a 0-conf channel to the client, the client could not claim the payment thus resulting in the LSP not getting paid and the client getting a free inbound lightning channel. The LSP could double spend the transaction but they still would lose the miner fees and as we are seeing today, that can be very expensive.
>
> I am not sure if this has been proposed before but we can fix this with PTLCs!
>
> Instead of having the LSP just broadcasting the funding transaction to the mempool, they can sign the funding transaction using adaptor signatures locked to the same secret as the invoice. Then when the client wants to claim the funds they can get the funding txid from the LSP, and then do the PTLC dance with the LSP based on using that funding transaction. If it all goes as planned the LSP can give the funding transaction signed using adaptor sigs to the client and the client can then decrypt the signatures and broadcast the transaction. Then the LSP can find the transaction in the mempool and extract the secret they need to claim the payment, thus making claiming the payment and opening the channel atomic so the client can't grief the LSP.
>
> Not sure if this has been talked about before, if not I think we can throw it in the ever-growing pile of "PTLCs fixes this".
>
> Best,
> benthecarman
ZmnSCPxj in reply to SomberNight permalink original

Good morning benthecarman and SomberNight,

As noted by SomberNight, PTLCs does not quite fix this, as the client can still wait out the inbound PTLC of the LSP and force the LSP to perform an onchain action to ensure it does not give a channel for free.

Another wrinkle here is that the LSP can attempt to coordinate with a miner (via e.g. full-RBF) to double-spend the funding transaction after the client has broadcasted the signed funding transaction on the mempool (i.e. lets the LSP learn the scalar that unlocks the inbound HTLC). Assuming the LSP uses one large UTXO to fund a smaller channel, the funding transaction has one input, two outputs. The clawback transaction (spending the same UTXO but returning it back to the LSP control) that the LSP coordinates with a miner would be one input, one output, thus having a size advantage. As the funding transaction pays some fixed fee --- whose value presumably is paid for in the JIT channel open via the inbound PTLC that arrives at the LSP --- the clawback transaction can pay the exact same fixed fee, but being smaller by one output, has a better feerate and thus a miner would prefer it.

Either client or the LSP has to move first. The only way they can assure that the other will actually do what they promised is if there is some arbiter who can ensure that the second mover actually performs their move. The default arbiter is the blockchain layer itself, but 0-conf just wants to avoid the blockchain layer for being too slow.

Regards, ZmnSCPxj

Sent with Proton Mail secure email.

------- Original Message ------- On Tuesday, May 9th, 2023 at 9:10 PM, SomberNight via Lightning-dev <lightning-dev at lists.linuxfoundation.org> wrote:

Quoted text (36 lines)
> Hi benthecarman,
>
> > the LSP can give the funding transaction signed using adaptor sigs to the client and the client can then decrypt the signatures and broadcast the transaction. Then the LSP can find the transaction in the mempool and extract the secret they need to claim the payment
>
>
> What if, after the client has the funding transaction locally, it waits for the PTLC held by the LSP to time out, i.e. days, and then (the client) broadcasts the funding transaction? The LSP could then no longer claim the PTLC, and it would have paid for the channel-open.
>
> To prevent this, the LSP would have to actively double-spend the channel funding tx given to the client when the PTLC is close to expiring, and only after getting the conflict mined can the PTLC be failed. This double-spending would cost mining fees of course (arguably the ~same amount as not doing anything and just letting the channel open). Although perhaps the LSP has enough users and high enough traffic that the conflicting tx itself can be something useful, e.g. another channel-open to another user.
>
> ghost43 / SomberNight
>
>
> ------- Original Message -------
> On Tuesday, May 9th, 2023 at 19:07, Ben Carman benthecarman at live.com wrote:
>
>
>
> > Hi everyone,
> >
> > I was chatting with Tony Giorgio the other day and he made me aware of a potential griefing attack that is possible today on LSPs that provide Just-In-Time channels.
> >
> > The attack is very simple, when the LSP receives the payment and then opens a 0-conf channel to the client, the client could not claim the payment thus resulting in the LSP not getting paid and the client getting a free inbound lightning channel. The LSP could double spend the transaction but they still would lose the miner fees and as we are seeing today, that can be very expensive.
> >
> > I am not sure if this has been proposed before but we can fix this with PTLCs!
> >
> > Instead of having the LSP just broadcasting the funding transaction to the mempool, they can sign the funding transaction using adaptor signatures locked to the same secret as the invoice. Then when the client wants to claim the funds they can get the funding txid from the LSP, and then do the PTLC dance with the LSP based on using that funding transaction. If it all goes as planned the LSP can give the funding transaction signed using adaptor sigs to the client and the client can then decrypt the signatures and broadcast the transaction. Then the LSP can find the transaction in the mempool and extract the secret they need to claim the payment, thus making claiming the payment and opening the channel atomic so the client can't grief the LSP.
> >
> > Not sure if this has been talked about before, if not I think we can throw it in the ever-growing pile of "PTLCs fixes this".
> >
> > Best,
> > benthecarman
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
ZmnSCPxj in reply to ZmnSCPxj permalink original

Good morning mailing list, et al.,

Let me explain the various possible mitigations and their drawbacks.

Many of these are either "LSP trusts client" or "client trusts LSP", in the sense that it is possible for the second mover (client in "LSP trusts client"; LSP in "client trusts LSP") to impose costs on, or outright steal from, the first mover.

If you want a trust-minimized solution, you need some kind of third party that both LSP and client agree will actually enforce that the second mover does not cheat or otherwise impose costs on the first mover. This "third party" SHOULD really be the blockchain, meaning you should really be using at least 1-conf and probably 3-conf to avoid reorgs, but *shrug*. (You *could* use Liquid as a third party --- but Liquid is custodial, it just has a federation as a custodian instead of a single entity, you have to trust that the federation does not collude to steal all your funds, or that Blockstream has not installed Something Else (TM) in the HSMs they sold to the federation members.)

Without a trusted third party (with the blockchain, being a decentralized open-source project with strong incentives against censorship, being your standard for trustworthiness), your choices are:

* LSP issues a promise --- a signature committing to a funding output on a funding transaction --- that it will definitely make a 0-conf funding transaction get confirmed before some future target blockheight.
  https://github.com/BitcoinAndLightningLayerSpecs/lsp/pull/24
  If the funding transaction is not confirmed by then, or the output is not the correct `scriptPubKey` and amount, the client reports it publicly and starts a boycott of the LSP.
  * The client refuses to send `channel_ready` (and therefore the HTLC cannot reach the client) until after the LSP issues this promise.
    "LSP trusts client".
  * How often have boycotts actually worked anyway?
* Client waits for the funding transaction to appear on its local mempool before sending `channel_ready`.
  * "LSP trusts client", somewhat, but far weaker than the above; you can argue this is actually "client trusts LSP" and I would agree with you.
  * The LSP can still double-spend the funding transaction with coordination with a miner, as I noted in my critique of benthecarman proposal.
    Mere broadcast is not an assurance of confirmation, we have been saying that about 0-conf for a long time.
  * Not all clients naturally have access to a mempool --- BIP157/158 clients do not necessarily maintain their own mempool, though an Electrum SPV client can query the mempool of the Electrum server.
* benthecarman proposal, as noted in previous post.
  * "client trusts LSP".
* LSP waits for the client to hand over the preimage before broadcasting the funding tx.
  * "client trusts LSP".
  * LSP can skip actual funding tx broadcast once the client has handed over the preimage.
  * Can be implemented in multiple ways that are all equivalent:
    * Outright give the preimage in some bespoke API call.
    * LSP sends the `open_channel` blah blah dance until `channel_ready` exchange, does `update_add_htlc` and irrevocably committed dance, then waits until `update_fulfill_htlc` before broadcasting the funding tx.
  * A client can implement the "client waits for funding tx in its own mempool before preimage" while the LSP implements this "LSP waits for preimage before funding tx broadcast", and both of them will stall waiting for each other LOL ^.^ wahahahahaha deadlock is fun.
    This is why LSPS has to pick one or the other, otherwise we will get incompatibilities between LSPs and clients.

LSPS (Open LSP Specifications group) participants have indicated a desire to prefer "LSP trusts client", because the LSP is a big target for various kinds of out-of-LSPS attacks. For example, a hacker could potentially modify the behavior of an LSP so that the LSP attacks the client, if the "client trusts LSP" model is used. Worse, somebody can ***accuse*** the LSP of actually attacking *some* client, and it can be hard for the LSP to provide substantial evidence that it is NOT attacking the client. (This is why the "promise" scheme I listed first above is valuable --- it is definite proof that the LSP is not attacking the client, if the client is unable to provide the promise as a proof-of-misbehaviour, then the client is just bullshitting and its claim of being cheated can be ignored, assuming of course that people actually believe in the strong cryptographic provisions of the signature scheme (which I might add is the same signature scheme used to secure Bitcoin itself, so... but humans are stupid, which is why AI should replace humans with something better). By the way have I mentioned I am human today?)

However, the only truly "LSP trusts client" scheme that I have figured out is that first scheme where the LSP issues a cryptographically third-party-verifiable promise to get the funding tx confirmed by some later blockheight. This scheme has been controversial even among LSPS participants, however.

Regards, ZmnSCPxj