Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

A proposal for up-front payments.

44 messages, Nov 5, 2019, to Mar 9, 2020. Started by Rusty Russell.

Rusty Russell (13), Anthony Towns (8), Joost Jager (7), ZmnSCPxj (5), Yaacov Akiba Slama (3), Orfeas Stefanos Thyfronitis Litos (3), Bastien TEINTURIER (2), Olaoluwa Osuntokun, +2 more

Permalink First message in the Wayback Machine

Rusty Russell permalink original

Hi all,

        It's been widely known that we're going to have to have up-front
payments for msgs eventually, to avoid Type 2 spam (I think of Type 1
link-local, Type 2 though multiple nodes, and Type 3 liquidity-using
spam).
        Since both Offers and Joost's WhatSat are looking at sending
messages, it's time to float actual proposals.  I've been trying to come
up with something for several years now, so thought I'd present the best
I've got in the hope that others can improve on it.
1. New feature bit, extended messages, etc.
2. Adding an HTLC causes a *push* of a number of msat on
   commitment_signed (new field), and a hash.
3. Failing/succeeding an HTLC returns some of those msat, and a count
   and preimage (new fields).

How many msat can you take for forwarding? That depends on you presenting a series of preimages (which chain into a final hash given in the HTLC add), which you get by decoding the onion. You get to keep 50 msat[1] per preimage you present[2].

So, how many preimages does the user have to give to have you forward the payment? That depends. The base rate is 16 preimages, but subtract one for each leading 4 zero bits of the SHA256(blockhash | hmac) of the onion. The blockhash is the hash of the block specified in the onion: reject if it's not in the last 3 blocks[3].

This simply adds some payment noise, while allowing a hashcash style tradeoff of sats for work.

The final node gets some variable number of preimages, which adds noise. It should take all and subtract from the minimum required invoice amount on success, or take some random number on failure.

This leaks some forward information, and makes an explicit tradeoff for the sender between amount spent and privacy, but it's the best I've been able to come up with.

Thoughts? Rusty.

[1] If we assume $1 per GB, $10k per BTC and 64k messages, we get about
    655msat per message.  Flat pricing for simplicity; we're trying to
    prevent spam, not create a spam market.
[2] Actually, a number and a single preimage; you can check this is
    indeed the n'th preimage.
[3] This reduces incentive to grind the damn things in advance, though
    maybe that's dumb?  We can also use a shorter hash (siphash?), or
    even truncated SHA256 (128 bits).
ZmnSCPxj in reply to Rusty Russell permalink original

Good morning Rusty,

Is this intended to be enforceable onchain if a channel is dropped onchain while a message is being routed? By a vague sense of the description, it seems to me, it would require a complicated SCRIPT (or multiple tiny 50-msatoshi UTXOs) to enforce onchain.

Also, it is not exactly clear to me, the mechanism you are proposing in detail. Can you give a motivating example, for example in a route from ZmnSCPxj, through Rusty, to my imaginary friend YAIjbOJa (who is not in fact me)?

Regards, ZmnSCPxj

Quoted text (57 lines)
> Hi all,
>
> It's been widely known that we're going to have to have up-front
> payments for msgs eventually, to avoid Type 2 spam (I think of Type 1
> link-local, Type 2 though multiple nodes, and Type 3 liquidity-using
> spam).
>
> Since both Offers and Joost's WhatSat are looking at sending
> messages, it's time to float actual proposals. I've been trying to come
> up with something for several years now, so thought I'd present the best
> I've got in the hope that others can improve on it.
>
> 1.  New feature bit, extended messages, etc.
> 2.  Adding an HTLC causes a push of a number of msat on
>     commitment_signed (new field), and a hash.
>
> 3.  Failing/succeeding an HTLC returns some of those msat, and a count
>     and preimage (new fields).
>
>     How many msat can you take for forwarding? That depends on you
>     presenting a series of preimages (which chain into a final hash given in
>     the HTLC add), which you get by decoding the onion. You get to keep 50
>     msat[1] per preimage you present[2].
>
>     So, how many preimages does the user have to give to have you forward
>     the payment? That depends. The base rate is 16 preimages, but subtract
>     one for each leading 4 zero bits of the SHA256(blockhash | hmac) of the
>     onion. The blockhash is the hash of the block specified in the onion:
>     reject if it's not in the last 3 blocks[3].
>
>     This simply adds some payment noise, while allowing a hashcash style
>     tradeoff of sats for work.
>
>     The final node gets some variable number of preimages, which adds noise.
>     It should take all and subtract from the minimum required invoice amount
>     on success, or take some random number on failure.
>
>     This leaks some forward information, and makes an explicit tradeoff for
>     the sender between amount spent and privacy, but it's the best I've been
>     able to come up with.
>
>     Thoughts?
>     Rusty.
>
>     [1] If we assume $1 per GB, $10k per BTC and 64k messages, we get about
>     655msat per message. Flat pricing for simplicity; we're trying to
>     prevent spam, not create a spam market.
>     [2] Actually, a number and a single preimage; you can check this is
>     indeed the n'th preimage.
>     [3] This reduces incentive to grind the damn things in advance, though
>     maybe that's dumb? We can also use a shorter hash (siphash?), or
>     even truncated SHA256 (128 bits).
>
>
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
Rusty Russell in reply to ZmnSCPxj permalink original

ZmnSCPxj <ZmnSCPxj at protonmail.com> writes:

Quoted text (1 line)
> Good morning Rusty,

Hi ZmnSCPxj!

Quoted text (2 lines)
> Is this intended to be enforceable onchain if a channel is dropped onchain while a message is being routed?
> By a vague sense of the description, it seems to me, it would require a complicated SCRIPT (or multiple tiny 50-msatoshi UTXOs) to enforce onchain.

No, it's done as a simple subtraction from direct to-local and to-remote payments. Enforcement is by peer closing the channel, which you wouldn't do over a few msat.

Quoted text (4 lines)
> Also, it is not exactly clear to me, the mechanism you are proposing in detail.
> Can you give a motivating example, for example in a route from
> ZmnSCPxj, through Rusty, to my imaginary friend YAIjbOJa (who is not
> in fact me)?

Sure: for simplicity I'm sending a 0-value HTLC.

ZmnSCPxj has balance 10000msat in channel with Rusty, who has 1000msat in the channel with YAIjbOJa.

Rusty prepares a nonce, AAAAA and hashes it 25 times = ZZZZZ.

ZmnSCPxj prepares the onion, but adds extra fields (see below). He then sends the HTLC to Rusty, but also sends ZZZZZ, and 25x50 msat (ie. those fields are in the update_add_htlc msg). His balance with Rusty is now 8750msat (ie. 25x50 to Rusty).

Rusty decrypts the onion, reads the prepay field: it says 14, LLLLL. Rusty checks: the hash of the onion & block (or something) does indeed have the top 8 bits clear, so the cost is in fact 16 - 8/2 == 14. He then hashes LLLLL 14 times, and yes, it's ZZZZZ as ZmnSCPxj said it should be.

So Rusty takes the 14x50 as prepayment, and forwards the HTLC as normal to YAIjbOJa, along with LLLLL and 11x50msat. His balance with YAIjbOJa is now 450msat.

YAIjbOJa decrypts the onion. And it says 10,BBBBB. YAIjbOJa checks that hashing BBBBB 10 times does indeed give LLLLL. Now it takes the 11x50 msat, and fulfils the HTLC. It replies to Rusty with 10,BBBBB in the update_fulfill_htlc message, returning the (implicit) 1x50msat; Rusty's balance with YAIjbOJa is now 500msat.

Rusty checks that BBBBB hashed 10 times gives LLLLL. Now it returns 24,BBBBB to ZmnSCPxj with the update_fulfill_htlc, demonstrating to ZmnSCPxj that he's entitled to it, and (implicity) returning 1x50msat to ZmnSCPxj, so their balance is now 8800msat.

Now let's look at attacks:

1. Rusty steals the funds and doesn't return them.  ZmnSCPxj closes
   channel, having lost 26x50msat.
2, YAIjbOJa steals the funds and doesn't return them.  Rusty closes
   the channel, having lost 11x50msat.
3. ZmnSCPxj doesn't put correct preimages in, or too few, or other
   malformation.  If it's Rusty's onion, he won't forward it and will
   give an error.  If it's YAIjbOJa who rejects it, Rusty returns all
   but the 14x50msat he has preimages for.

Obviously Rusty needs some upper limit on how much he'll pay out, to avoid infinite exposure (say limit the total exposure to 10,000 sats).

A reasonable limit for each HTLC would be 20 hops x 16 x 50msat == 16sat. Even with no other limits, with 486 HTLCs in flight each way, that's only 15456 satoshis. You'll probably lament the channel closure more.

Hope that helps! Rusty.

Quoted text (57 lines)
>> Hi all,
>>
>> It's been widely known that we're going to have to have up-front
>> payments for msgs eventually, to avoid Type 2 spam (I think of Type 1
>> link-local, Type 2 though multiple nodes, and Type 3 liquidity-using
>> spam).
>>
>> Since both Offers and Joost's WhatSat are looking at sending
>> messages, it's time to float actual proposals. I've been trying to come
>> up with something for several years now, so thought I'd present the best
>> I've got in the hope that others can improve on it.
>>
>> 1.  New feature bit, extended messages, etc.
>> 2.  Adding an HTLC causes a push of a number of msat on
>>     commitment_signed (new field), and a hash.
>>
>> 3.  Failing/succeeding an HTLC returns some of those msat, and a count
>>     and preimage (new fields).
>>
>>     How many msat can you take for forwarding? That depends on you
>>     presenting a series of preimages (which chain into a final hash given in
>>     the HTLC add), which you get by decoding the onion. You get to keep 50
>>     msat[1] per preimage you present[2].
>>
>>     So, how many preimages does the user have to give to have you forward
>>     the payment? That depends. The base rate is 16 preimages, but subtract
>>     one for each leading 4 zero bits of the SHA256(blockhash | hmac) of the
>>     onion. The blockhash is the hash of the block specified in the onion:
>>     reject if it's not in the last 3 blocks[3].
>>
>>     This simply adds some payment noise, while allowing a hashcash style
>>     tradeoff of sats for work.
>>
>>     The final node gets some variable number of preimages, which adds noise.
>>     It should take all and subtract from the minimum required invoice amount
>>     on success, or take some random number on failure.
>>
>>     This leaks some forward information, and makes an explicit tradeoff for
>>     the sender between amount spent and privacy, but it's the best I've been
>>     able to come up with.
>>
>>     Thoughts?
>>     Rusty.
>>
>>     [1] If we assume $1 per GB, $10k per BTC and 64k messages, we get about
>>     655msat per message. Flat pricing for simplicity; we're trying to
>>     prevent spam, not create a spam market.
>>     [2] Actually, a number and a single preimage; you can check this is
>>     indeed the n'th preimage.
>>     [3] This reduces incentive to grind the damn things in advance, though
>>     maybe that's dumb? We can also use a shorter hash (siphash?), or
>>     even truncated SHA256 (128 bits).
>>
>>
>> Lightning-dev mailing list
>> Lightning-dev at lists.linuxfoundation.org
>> https://www.learnbitcoin.com/archive/lists/lightning-dev
Anthony Towns in reply to Rusty Russell permalink original

On Tue, Nov 05, 2019 at 07:56:45PM +1030, Rusty Russell wrote:

Quoted text (3 lines)
> Sure: for simplicity I'm sending a 0-value HTLC.
> ZmnSCPxj has balance 10000msat in channel with Rusty, who has 1000msat
> in the channel with YAIjbOJa.

Alice, Bob and Carol sure seem simpler than Zmn YAI and Rusty...

Quoted text (2 lines)
> Rusty prepares a nonce, AAAAA and hashes it 25 times = ZZZZZ.
> ZmnSCPxj prepares the onion, but adds extra fields (see below).

It would have made more sense to me for Alice (Zmn) to generate the nonce, hash it, and prepare the onion, so that the nonce is revealed to Dave (Rusty) if/when the message ever actually reaches its destination. Otherwise Rusty has to send AAAAA to Zmn already so that Zmn can prepare the onion?

Quoted text (10 lines)
> He then
> sends the HTLC to Rusty, but also sends ZZZZZ, and 25x50 msat (ie. those
> fields are in the update_add_htlc msg).  His balance with Rusty is now
> 8750msat (ie. 25x50 to Rusty).
>
> Rusty decrypts the onion, reads the prepay field: it says 14, LLLLL.
> Rusty checks: the hash of the onion & block (or something) does indeed
> have the top 8 bits clear, so the cost is in fact 16 - 8/2 == 14.  He
> then hashes LLLLL 14 times, and yes, it's ZZZZZ as ZmnSCPxj said it
> should be.

I'm not sure why lucky hashing should result in a discount? You're giving a linear discount for exponentially more luck in hashing which also seems odd.

You've only got two nonce choices -- the initial AAAA and the depth that you tell Bob and Carol to hash to as steps in the route; so the incentive there seems to be to do a large depth, so you might hash AAAA 1000 times, and figure that you'll find a leading eight 0's once in the first 256 entries, then another by the time you get up to 512, and another by the time you get to 768, which gets you discounts on three intermediaries. But the cost there is that your intermediaries collectively have to do the same amount of hashing you did, so it's not proof-of-work, because it's as hard to verify as it is to generate.

I think you could just make the scheme be:

  Alice sends HTLC(k,v) + 1250 msat to Bob
  Bob unwraps the onion and forwards HTLC(k,v) + 500 msat to Carol
  Carol unwraps the onion and forwards HTLC(k,v) + 250 msat to Dave
  Dave redeems the HTLC, claims an extra 300 msat and refunds 200 msat to Carol
  Carol redeems the HTLC and refunds 200 msat to Bob
  Bob redeems the HTLC and refunds 200 msat to Alice

If there's a failure, Alice loses the 1250 msat, and someone in the path steals the funds. You could make the accountable by having Alice also provide "Hash(AAAA, refund=200)" to everyone, encoding AAAA in the onion to Dave, and then each hop reveals AAAA and refunds 200msat to demonstrate their honesty.

Does that miss anything that all the hashing achieves?

I think the idea here is that you're paying tiny amounts for the bandwidth, which when it's successful does in fact pay for the bandwidth; and when it's unsuccessful results in a channel closure, which makes it unprofitable to cheat the system, but doesn't change the economics of lightning much overall because channel closures can happen anytime anyway. I think that approach makes sense.

Cheers, aj

Olaoluwa Osuntokun in reply to Rusty Russell permalink original

Hi Rusty,

Agreed w.r.t the need for prepaid HTLCS, I've been mulling over other alternatives for a few years now, and none of them seems to resolve the series of routing related incentive issues that prepaid HTLCs would.

Quoted text (2 lines)
> Since both Offers and Joost's WhatSat are looking at sending messages,
> it's time to float actual proposals.

IMO both should just be done over HORNET, so we don't need introduce a new set of internal protocol level messages whenever we have some new control/signalling need. Instead, we'd have a control/signal channel (give me routes, invoices, sign this, etc), and a payment channel (HTLCs as used today).

Quoted text (2 lines)
> 2. Adding an HTLC causes a *push* of a number of msat on commitment_signed
> (new field), and a hash.

The prepay amount should be signalled in the update add message instead. This lets HTLCs carry a heterogeneous set of prepay amounts. In addition, we need a new onion field as well to signal the incoming amount the node _should_ have received (allows them to detect deviations in the sender's intended route).

Quoted text (2 lines)
> 3. Failing/succeeding an HTLC returns some of those msat, and a count and
> preimage (new fields).

Failing shouldn't return the prepay amount, otherwise extending long lived HTLCs then cancelling them at the last minute is still costless. This costlessness of _adding_ an HTLC to a _remote_ commitment is IMO, the biggest incentive flaw that exists today in the greater routing network.

Quoted text (1 line)
>  You get to keep 50 msat[1] per preimage you present[2].

We should avoid introducing any new constants to the protocol, as they're typically dreamed up independent of any empirical lessons learned from deployment.

On the topic of the prepay cost, the channel update message should be extended to allow nodes to signal prepay costs similar to the way we handle regular payment success fees. In order to eliminate a number of costless attacks possible today on the routing network, nodes should also be able to signal a new coefficient used to _scale_ the prepay fee as a function of the CLTV value of the incoming HTLC. With this addition, senders need to pay to _add_ an HTLC to a remote commitment transaction (fixed base cost), then also need to pay a variable rate that scales with the duration of the proposed outgoing CLTV value (senders ofc don't prepay to themselves). Once we introduce this, loop attacks and the like are no longer free to launch, and nodes can dynamically respond to congestion in the network by raising their prepay prices.

-- Laolu

On Mon, Nov 4, 2019 at 6:25 PM Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (56 lines)
> Hi all,
>
>         It's been widely known that we're going to have to have up-front
> payments for msgs eventually, to avoid Type 2 spam (I think of Type 1
> link-local, Type 2 though multiple nodes, and Type 3 liquidity-using
> spam).
>
>         Since both Offers and Joost's WhatSat are looking at sending
> messages, it's time to float actual proposals.  I've been trying to come
> up with something for several years now, so thought I'd present the best
> I've got in the hope that others can improve on it.
>
> 1. New feature bit, extended messages, etc.
> 2. Adding an HTLC causes a *push* of a number of msat on
>    commitment_signed (new field), and a hash.
> 3. Failing/succeeding an HTLC returns some of those msat, and a count
>    and preimage (new fields).
>
> How many msat can you take for forwarding?  That depends on you
> presenting a series of preimages (which chain into a final hash given in
> the HTLC add), which you get by decoding the onion.  You get to keep 50
> msat[1] per preimage you present[2].
>
> So, how many preimages does the user have to give to have you forward
> the payment?  That depends.  The base rate is 16 preimages, but subtract
> one for each leading 4 zero bits of the SHA256(blockhash | hmac) of the
> onion.  The blockhash is the hash of the block specified in the onion:
> reject if it's not in the last 3 blocks[3].
>
> This simply adds some payment noise, while allowing a hashcash style
> tradeoff of sats for work.
>
> The final node gets some variable number of preimages, which adds noise.
> It should take all and subtract from the minimum required invoice amount
> on success, or take some random number on failure.
>
> This leaks some forward information, and makes an explicit tradeoff for
> the sender between amount spent and privacy, but it's the best I've been
> able to come up with.
>
> Thoughts?
> Rusty.
>
> [1] If we assume $1 per GB, $10k per BTC and 64k messages, we get about
>     655msat per message.  Flat pricing for simplicity; we're trying to
>     prevent spam, not create a spam market.
> [2] Actually, a number and a single preimage; you can check this is
>     indeed the n'th preimage.
> [3] This reduces incentive to grind the damn things in advance, though
>     maybe that's dumb?  We can also use a shorter hash (siphash?), or
>     even truncated SHA256 (128 bits).
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Rusty Russell in reply to Anthony Towns permalink original

Anthony Towns <aj at erisian.com.au> writes:

Quoted text (6 lines)
> On Tue, Nov 05, 2019 at 07:56:45PM +1030, Rusty Russell wrote:
>> Sure: for simplicity I'm sending a 0-value HTLC.
>> ZmnSCPxj has balance 10000msat in channel with Rusty, who has 1000msat
>> in the channel with YAIjbOJa.
>
> Alice, Bob and Carol sure seem simpler than Zmn YAI and Rusty...

Agreed, I should not have directly answered the q.

Quoted text (8 lines)
>> Rusty prepares a nonce, AAAAA and hashes it 25 times = ZZZZZ.
>> ZmnSCPxj prepares the onion, but adds extra fields (see below).
>
> It would have made more sense to me for Alice (Zmn) to generate
> the nonce, hash it, and prepare the onion, so that the nonce is
> revealed to Dave (Rusty) if/when the message ever actually reaches its
> destination. Otherwise Rusty has to send AAAAA to Zmn already so that
> Zmn can prepare the onion?

The entire point is to pay *up-front*, though, to prevent spam.

Bob/ZmnSCPxj doesn't prepare anything in the onion. They get handed the last hash directly: Alice is saying "I'll pay you 50msat for each preimage you can give me leading to this hash".

Quoted text (12 lines)
>> He then
>> sends the HTLC to Rusty, but also sends ZZZZZ, and 25x50 msat (ie. those
>> fields are in the update_add_htlc msg).  His balance with Rusty is now
>> 8750msat (ie. 25x50 to Rusty).
>>
>> Rusty decrypts the onion, reads the prepay field: it says 14, LLLLL.
>> Rusty checks: the hash of the onion & block (or something) does indeed
>> have the top 8 bits clear, so the cost is in fact 16 - 8/2 == 14.  He
>> then hashes LLLLL 14 times, and yes, it's ZZZZZ as ZmnSCPxj said it
>> should be.
>
> I'm not sure why lucky hashing should result in a discount?

Because the PoW adds noise to the amounts, otherwise the path length is trivially exposed, esp in the failure case. It's weak protection though.

Quoted text (2 lines)
> You're giving a linear discount for exponentially more luck in hashing
> which also seems odd.

Because you really want some actual payment, not just PoW. Botnets are really good at PoW, less good at sending msats. And the PoW is hard to calibrate (I guessed: real numbers will be necessary)/

Quoted text (2 lines)
> You've only got two nonce choices -- the initial AAAA and the depth
> that you tell Bob and Carol to hash to as steps in the route;

No, the sphinx construction allows for grinding, that was my intent here. The prepay hashes are independent.

Quoted text (11 lines)
> I think you could just make the scheme be:
>
>   Alice sends HTLC(k,v) + 1250 msat to Bob
>   Bob unwraps the onion and forwards HTLC(k,v) + 500 msat to Carol
>   Carol unwraps the onion and forwards HTLC(k,v) + 250 msat to Dave
>   Dave redeems the HTLC, claims an extra 300 msat and refunds 200 msat to Carol
>   Carol redeems the HTLC and refunds 200 msat to Bob
>   Bob redeems the HTLC and refunds 200 msat to Alice
>
> If there's a failure, Alice loses the 1250 msat, and someone in the
> path steals the funds.

This example confuses me.

So, you're charging 250msat per hop? Why is Bob taking 750? Does Carol now know Dave is the last hop?

Does Alice lose everything on any routing failure?

If so, that is strong incentive for Alice to reduce path-length privacy by keeping payments minimal, which I was really trying to avoid.

Quoted text (6 lines)
> You could make the accountable by having Alice
> also provide "Hash(AAAA, refund=200)" to everyone, encoding AAAA in the
> onion to Dave, and then each hop reveals AAAA and refunds 200msat to
> demonstrate their honesty.
>
> Does that miss anything that all the hashing achieves?

It does nothing if Carol is the one who can't route.

Quoted text (5 lines)
> I think the idea here is that you're paying tiny amounts for the
> bandwidth, which when it's successful does in fact pay for the bandwidth;
> and when it's unsuccessful results in a channel closure, which makes it
> unprofitable to cheat the system, but doesn't change the economics of
> lightning much overall because channel closures can happen anytime anyway.

Not at all. You can still fail to route, and still get paid. You can't steal *more* money without channel closure though.

Quoted text (4 lines)
> I think that approach makes sense.
>
> Cheers,
> aj

Cheers, Rusty.

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (15 lines)
> Hi Rusty,
>
> Agreed w.r.t the need for prepaid HTLCS, I've been mulling over other
> alternatives for a few years now, and none of them seems to resolve the
> series of routing related incentive issues that prepaid HTLCs would.
>
>> Since both Offers and Joost's WhatSat are looking at sending messages,
>> it's time to float actual proposals.
>
> IMO both should just be done over HORNET, so we don't need introduce a new
> set of internal protocol level messages whenever we have some new
> control/signalling need. Instead, we'd have a control/signal channel (give
> me
> routes, invoices, sign this, etc), and a payment channel (HTLCs as used
> today).

I'm not so sure, as I don't think we're going to actually use each one more than once or twice?

I mean, we could stream movies through LN, but I think that's an added service, which would be best done by HORNET.

Quoted text (8 lines)
>> 2. Adding an HTLC causes a *push* of a number of msat on commitment_signed
>> (new field), and a hash.
>
> The prepay amount should be signalled in the update add message instead.
> This lets HTLCs carry a heterogeneous set of prepay amounts. In addition, we
> need a new onion field as well to signal the incoming amount the node
> _should_ have received (allows them to detect deviations in the sender's
> intended route).

Sorry, brain fart: it's a new field in the update_add_htlc of course.

I just, um, added that to make sure you were all reading carefully! :_

Quoted text (7 lines)
>> 3. Failing/succeeding an HTLC returns some of those msat, and a count and
>> preimage (new fields).
>
> Failing shouldn't return the prepay amount, otherwise extending long lived
> HTLCs then cancelling them at the last minute is still costless. This
> costlessness of _adding_ an HTLC to a _remote_ commitment is IMO, the
> biggest incentive flaw that exists today in the greater routing network.

No, that's type (liquidity) 3 spam, which needs a completely different solution.

Definitely needs fixing, but up-front fees don't do it (except in the case where you might want to indicate you're *going* to have a long-held HTLC, where you'd pay additional up-front, but that's future work).

Quoted text (5 lines)
>>  You get to keep 50 msat[1] per preimage you present[2].
>
> We should avoid introducing any new constants to the protocol, as they're
> typically dreamed up independent of any empirical lessons learned from
> deployment.

OTOH, we should avoid creating more complex knobs for users, since the complexity of the protocol is becoming unmanagable. I think we did this too much with v1, so instead of getting empirical data we got defaults which in practice are unspecified specifications.

I like a flat value to start, since it's easy to implement and deploy.

Quoted text (6 lines)
> On the topic of the prepay cost, the channel update message should be
> extended to allow nodes to signal prepay costs similar to the way we handle
> regular payment success fees. In order to eliminate a number of costless
> attacks possible today on the routing network, nodes should also be able to
> signal a new coefficient used to _scale_ the prepay fee as a function of the
> CLTV value of the incoming HTLC.

... and HTLC amount, surely? That becomes a pretty complex tuning parameter.

I think we should directly target type 3 spam through a separate mechanism (as discussed previously). This is just to prevent quantity of messages.

Quoted text (7 lines)
> With this addition, senders need to pay to
> _add_ an HTLC to a remote commitment transaction (fixed base cost), then
> also need to pay a variable rate that scales with the duration of the
> proposed outgoing CLTV value (senders ofc don't prepay to themselves).  Once
> we introduce this, loop attacks and the like are no longer free to launch,
> and nodes can dynamically respond to congestion in the network by raising
> their prepay prices.

I disagree; you should signal with normal fees, not prepay. Otherwise we're increasing fees at a time that success rates are lowering, which makes the incentive misalightment far more promiment :(

Cheers, Rusty.

Joost Jager in reply to Rusty Russell permalink original

In my opinion, the prepayment should be a last resort. It does take away some of the attractiveness of the Lightning Network. Especially if you need to make many payment attempts over long routes, the tiny prepays do add up. For a $10 payment, it's probably nothing to worry about. But for micro-payments this can become prohibitively expensive. And it is exactly the micro-payment use case where Lightning outshines other payment systems. A not yet imagined micro-payment based service could even be the launchpad to world domination. So I think we should be very careful with interfering with that potential.

Isn't spam something that can also be addressed by using rate limits for failures? If all relevant nodes on the network employ rate limits, they can isolate the spammer and diminish their disruptive abilities. If a node sees that its outgoing htlc packets stack up, it can reduce the incoming flow on the channels where the htlcs originate from. Large routing nodes could agree with their peers on service levels that define these rate limits.

Joost

On Tue, Nov 5, 2019 at 3:25 AM Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (56 lines)
> Hi all,
>
>         It's been widely known that we're going to have to have up-front
> payments for msgs eventually, to avoid Type 2 spam (I think of Type 1
> link-local, Type 2 though multiple nodes, and Type 3 liquidity-using
> spam).
>
>         Since both Offers and Joost's WhatSat are looking at sending
> messages, it's time to float actual proposals.  I've been trying to come
> up with something for several years now, so thought I'd present the best
> I've got in the hope that others can improve on it.
>
> 1. New feature bit, extended messages, etc.
> 2. Adding an HTLC causes a *push* of a number of msat on
>    commitment_signed (new field), and a hash.
> 3. Failing/succeeding an HTLC returns some of those msat, and a count
>    and preimage (new fields).
>
> How many msat can you take for forwarding?  That depends on you
> presenting a series of preimages (which chain into a final hash given in
> the HTLC add), which you get by decoding the onion.  You get to keep 50
> msat[1] per preimage you present[2].
>
> So, how many preimages does the user have to give to have you forward
> the payment?  That depends.  The base rate is 16 preimages, but subtract
> one for each leading 4 zero bits of the SHA256(blockhash | hmac) of the
> onion.  The blockhash is the hash of the block specified in the onion:
> reject if it's not in the last 3 blocks[3].
>
> This simply adds some payment noise, while allowing a hashcash style
> tradeoff of sats for work.
>
> The final node gets some variable number of preimages, which adds noise.
> It should take all and subtract from the minimum required invoice amount
> on success, or take some random number on failure.
>
> This leaks some forward information, and makes an explicit tradeoff for
> the sender between amount spent and privacy, but it's the best I've been
> able to come up with.
>
> Thoughts?
> Rusty.
>
> [1] If we assume $1 per GB, $10k per BTC and 64k messages, we get about
>     655msat per message.  Flat pricing for simplicity; we're trying to
>     prevent spam, not create a spam market.
> [2] Actually, a number and a single preimage; you can check this is
>     indeed the n'th preimage.
> [3] This reduces incentive to grind the damn things in advance, though
>     maybe that's dumb?  We can also use a shorter hash (siphash?), or
>     even truncated SHA256 (128 bits).
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Anthony Towns in reply to Rusty Russell permalink original

On Wed, Nov 06, 2019 at 10:43:23AM +1030, Rusty Russell wrote:

Quoted text (8 lines)
> >> Rusty prepares a nonce, AAAAA and hashes it 25 times = ZZZZZ.
> >> ZmnSCPxj prepares the onion, but adds extra fields (see below).
> > It would have made more sense to me for Alice (Zmn) to generate
> > the nonce, hash it, and prepare the onion, so that the nonce is
> > revealed to Dave (Rusty) if/when the message ever actually reaches its
> > destination. Otherwise Rusty has to send AAAAA to Zmn already so that
> > Zmn can prepare the onion?
> The entire point is to pay *up-front*, though, to prevent spam.

Hmm, I'm not sure I see the point of paying upfront but not unconditionally -- you already commit the funds as part of the HTLC, and if you're refunding some of them, you kind-of have to keep them reserved or you risk finalising the HTLC causing a failure because you don't have enough msats spare to do the refund?

If you refund on routing failure, why wouldn't a spammer just add a fake "Ezekiel" at the end of the route after Dave, so that the HTLCs always fail and all the fees are returned?

Quoted text (3 lines)
> Bob/ZmnSCPxj doesn't prepare anything in the onion.  They get handed the
> last hash directly: Alice is saying "I'll pay you 50msat for each
> preimage you can give me leading to this hash".

So my example was Alice paying Dave via Bob and Carol (so Alice/Bob, Bob/Carol, Carol/Dave being the individual channels).

What you wrote to Zmn says "Rusty decrypts the onion, reads the prepay field: it says 14, LLLL." but Alice doesn't know anything other than ZZZZ so can't put LLLL in the onion?

Are you using Hornet so that every intermediary can communicate a nonce back to the source of the route? If not, "Rusty" generating the nonce seems like you're informing Rusty that you're actually the origin of the HTLC, and not just innocently forwarding it along; if so, it seems like you have independent nonces at each step, rather than AAAA/BBBB/LLLL/ZZZZ in a direct chain.

Quoted text (4 lines)
> > I'm not sure why lucky hashing should result in a discount?
> Because the PoW adds noise to the amounts, otherwise the path length is
> trivially exposed, esp in the failure case.  It's weak protection
> though.

With a linear/exponential relationship you just get "half the time it's 1 unit, 25% of the time it's 2 units, 12% of the time it's 3 units", so I don't think that's adding much noise?

Quoted text (4 lines)
> > You've only got two nonce choices -- the initial AAAA and the depth
> > that you tell Bob and Carol to hash to as steps in the route;
> No, the sphinx construction allows for grinding, that was my intent
> here.  The prepay hashes are independent.

Oh, because you're also xoring with the onion packet, right, I see.

Quoted text (5 lines)
> > I think you could just make the scheme be:
> >   Alice sends HTLC(k,v) + 1250 msat to Bob
> >   Bob unwraps the onion and forwards HTLC(k,v) + 500 msat to Carol
> >   Carol unwraps the onion and forwards HTLC(k,v) + 250 msat to Dave
> >   Dave redeems the HTLC, claims an extra 300 msat and refunds 200 msat to Carol

The math here doesn't add up. Let's assume I meant:

  Bob keeps 500 sat, forwards 750 sat
  Carol keeps 250 sat, forwards 500 sat
  Dave keeps 300 sat, refunds 200 sat
Quoted text (6 lines)
> >   Carol redeems the HTLC and refunds 200 msat to Bob
> >   Bob redeems the HTLC and refunds 200 msat to Alice
> >
> > If there's a failure, Alice loses the 1250 msat, and someone in the
> > path steals the funds.
> This example confuses me.

Well, that makes us even at least? :)

Quoted text (2 lines)
> So, you're charging 250msat per hop?  Why is Bob taking 750?  Does Carol
> now know Dave is the last hop?

No, Alice is choosing to pay 500, 250 and 300 msat to Bob, Carol and Dave respectively, as part of setting up the onion, and picks those numbers via some magic algo trading off privacy and cost.

Quoted text (1 line)
> Does Alice lose everything on any routing failure?

That was my thought yeah; it seems weird to pay upfront but expect a refund on failure -- the HTLC funds are already committed upfront and refunded on failure.

Quoted text (2 lines)
> If so, that is strong incentive for Alice to reduce path-length privacy
> by keeping payments minimal, which I was really trying to avoid.

Assuming v is much larger than 1250msat, and 1250 msat is much lower than the cost to Bob of losing the channel with Alice, I don't think that's a problem. 1250msat pays for 125kB of bandwdith under your assumptions I think?

Quoted text (2 lines)
> > Does that miss anything that all the hashing achieves?
> It does nothing if Carol is the one who can't route.

If Carol can't route, then ideally she just refunds all the money and everyone's happy.

If Carol tries to steal, then she can keep 750 msat instead of 250 msat. This doesn't give any way for Bob to prove Carol cheated on him though; but Bob could just refund the 1250 msat and write the 750 msat off as a loss of dealing with cheaters like Carol.

Cheers, aj

Rusty Russell in reply to Anthony Towns permalink original

Anthony Towns <aj at erisian.com.au> writes:

Quoted text (15 lines)
> On Wed, Nov 06, 2019 at 10:43:23AM +1030, Rusty Russell wrote:
>> >> Rusty prepares a nonce, AAAAA and hashes it 25 times = ZZZZZ.
>> >> ZmnSCPxj prepares the onion, but adds extra fields (see below).
>> > It would have made more sense to me for Alice (Zmn) to generate
>> > the nonce, hash it, and prepare the onion, so that the nonce is
>> > revealed to Dave (Rusty) if/when the message ever actually reaches its
>> > destination. Otherwise Rusty has to send AAAAA to Zmn already so that
>> > Zmn can prepare the onion?
>> The entire point is to pay *up-front*, though, to prevent spam.
>
> Hmm, I'm not sure I see the point of paying upfront but not
> unconditionally -- you already commit the funds as part of the HTLC,
> and if you're refunding some of them, you kind-of have to keep them
> reserved or you risk finalising the HTLC causing a failure because you
> don't have enough msats spare to do the refund?

? These are upfront an unconditional. I'm confused. You pay per HTLC added (or, in future, to send a message).

What part was unclear here?

Alice pays X to Bob. Bob gives X-<num-preimages> back to Alice. Bob gets preimages from the onion, and from Carol etc.

This happens independent of HTLC success or failure.

Quoted text (10 lines)
>> Bob/ZmnSCPxj doesn't prepare anything in the onion.  They get handed the
>> last hash directly: Alice is saying "I'll pay you 50msat for each
>> preimage you can give me leading to this hash".
>
> So my example was Alice paying Dave via Bob and Carol (so Alice/Bob,
> Bob/Carol, Carol/Dave being the individual channels).
>
> What you wrote to Zmn says "Rusty decrypts the onion, reads the prepay
> field: it says 14, LLLL." but Alice doesn't know anything other than
> ZZZZ so can't put LLLL in the onion?

Alice created the onion. Alice knows all the preimages, since she created the chain AAAAA....ZZZZZ.

Quoted text (8 lines)
>> > I'm not sure why lucky hashing should result in a discount?
>> Because the PoW adds noise to the amounts, otherwise the path length is
>> trivially exposed, esp in the failure case.  It's weak protection
>> though.
>
> With a linear/exponential relationship you just get "half the time it's
> 1 unit, 25% of the time it's 2 units, 12% of the time it's 3 units", so
> I don't think that's adding much noise?

It depends how much people are prepared to grind, doesn't it?

Quoted text (34 lines)
>> > You've only got two nonce choices -- the initial AAAA and the depth
>> > that you tell Bob and Carol to hash to as steps in the route;
>> No, the sphinx construction allows for grinding, that was my intent
>> here.  The prepay hashes are independent.
>
> Oh, because you're also xoring with the onion packet, right, I see.
>
>> > I think you could just make the scheme be:
>> >   Alice sends HTLC(k,v) + 1250 msat to Bob
>> >   Bob unwraps the onion and forwards HTLC(k,v) + 500 msat to Carol
>> >   Carol unwraps the onion and forwards HTLC(k,v) + 250 msat to Dave
>> >   Dave redeems the HTLC, claims an extra 300 msat and refunds 200 msat to Carol
>
> The math here doesn't add up. Let's assume I meant:
>
>   Bob keeps 500 sat, forwards 750 sat
>   Carol keeps 250 sat, forwards 500 sat
>   Dave keeps 300 sat, refunds 200 sat
>
>> >   Carol redeems the HTLC and refunds 200 msat to Bob
>> >   Bob redeems the HTLC and refunds 200 msat to Alice
>> >
>> > If there's a failure, Alice loses the 1250 msat, and someone in the
>> > path steals the funds.
>> This example confuses me.
>
> Well, that makes us even at least? :)
>
>> So, you're charging 250msat per hop?  Why is Bob taking 750?  Does Carol
>> now know Dave is the last hop?
>
> No, Alice is choosing to pay 500, 250 and 300 msat to Bob, Carol and
> Dave respectively, as part of setting up the onion, and picks those
> numbers via some magic algo trading off privacy and cost.

OK.

Quoted text (5 lines)
>> Does Alice lose everything on any routing failure?
>
> That was my thought yeah; it seems weird to pay upfront but expect a
> refund on failure -- the HTLC funds are already committed upfront and
> refunded on failure.

AFAICT you have to overpay, since anything else is very revealing of path length. Which kind of implies a refund, I think.

Quoted text (7 lines)
>> If so, that is strong incentive for Alice to reduce path-length privacy
>> by keeping payments minimal, which I was really trying to avoid.
>
> Assuming v is much larger than 1250msat, and 1250 msat is much lower than
> the cost to Bob of losing the channel with Alice, I don't think that's
> a problem. 1250msat pays for 125kB of bandwdith under your assumptions
> I think?

That's irrelevant? Since retries are common, it's natural for Alice to want to minimize losses. If she's going to lose everything on any failure, she'll pay the minimum amount, which exposes her path length trivially.

Thus my attempt to try to reduce the lossage. I think.

Quoted text (5 lines)
>> > Does that miss anything that all the hashing achieves?
>> It does nothing if Carol is the one who can't route.
>
> If Carol can't route, then ideally she just refunds all the money and
> everyone's happy.

That tells Bob clearly that Carol failed. If Carol claims a variable amount, it's less obvious (though still pretty bad).

Quoted text (4 lines)
> If Carol tries to steal, then she can keep 750 msat instead of 250 msat.
> This doesn't give any way for Bob to prove Carol cheated on him though;
> but Bob could just refund the 1250 msat and write the 750 msat off as a
> loss of dealing with cheaters like Carol.

What actually happens is that Carol sends a signature on a commitment which Bob does't agree with (since he expected his money back). They go onchain.

Now Bob is out the total he fwd to Carol, but he's probably more annoyed at losing the channel.

Cheers, Rusty.

Rusty Russell in reply to Joost Jager permalink original

Joost Jager <joost.jager at gmail.com> writes:

Quoted text (9 lines)
> In my opinion, the prepayment should be a last resort. It does take away
> some of the attractiveness of the Lightning Network. Especially if you need
> to make many payment attempts over long routes, the tiny prepays do add up.
> For a $10 payment, it's probably nothing to worry about. But for
> micro-payments this can become prohibitively expensive. And it is exactly
> the micro-payment use case where Lightning outshines other payment systems.
> A not yet imagined micro-payment based service could even be the launchpad
> to world domination. So I think we should be very careful with interfering
> with that potential.

I completely agree, yeah. And maybe we'll never need it, but it's one of my main concerns for the network.

Quoted text (3 lines)
> Isn't spam something that can also be addressed by using rate limits for
> failures? If all relevant nodes on the network employ rate limits, they can
> isolate the spammer and diminish their disruptive abilities.

Sure, once the spammer has jammed up the network, he'll be stopped. So will everyone else. Conner had a proposal like this which didn't work, IIRC.

Quoted text (4 lines)
> If a node sees that its outgoing htlc packets stack up, it can reduce
> the incoming flow on the channels where the htlcs originate
> from. Large routing nodes could agree with their peers on service
> levels that define these rate limits.

Unfortunately, if we *don't* address this, then the network will defend itself with the simple tactic of deanonymizing payments.

And every other solution I've seen ends up the same way :(

Cheers, Rusty.

Anthony Towns in reply to Rusty Russell permalink original

On Thu, Nov 07, 2019 at 02:56:51PM +1030, Rusty Russell wrote:

Quoted text (5 lines)
> > What you wrote to Zmn says "Rusty decrypts the onion, reads the prepay
> > field: it says 14, LLLL." but Alice doesn't know anything other than
> > ZZZZ so can't put LLLL in the onion?
> Alice created the onion.  Alice knows all the preimages, since she
> created the chain AAAAA....ZZZZZ.

In your reply to Zmn, it was Rusty (Bob) preparing the nonce and creating the chain AAAA...ZZZZ -- so I was lost as to what you were proposing...

Here's what I now think you're saying, which I think mostly hangs together:

Alice sends a HTLC with hash X and value V to Dave via Bob then Carol

Alice generates a nonce AAAA, and calculates H^25(AAAA) = ZZZZ.

Alice creates an onion, and sends the HTLC to Bob, revealing ZZZZ and 6,TTTT to Bob, along with 2500 msat (25 for the hashing ops between AAAA and ZZZZ, and *100 for round numbers). Bob calculates "6" is a fair price.

Bob checks H^6(TTTT)=ZZZZ. If not, Bob refunds the 2500 msat, and fails the HTLC immediately. Otherwise, Bob passes the onion on to Carol, with 1900 msat and TTTT; Carol unwraps the onion revealing 15,EEEE. Carol calcualtes "15" is a fair price.

Carol checks H^15(EEEE)=TTTT, and fails the route if not, refunding 1900msat to Bob. Otherwise, Carol passes the onion on to Dave, with 400 msat and EEEE. Dave unwraps the onion, revealing 2,CCCC, so can claim 200 msat as well as the HTLC amount, etc.

After the successful route, Dave passes 2,CCCC and 200msat back to Carol, who validates and continues passing things back.

If Carol instead passes, say, 3,CCCC back, then she also has to refund 300msat to avoid Bob closing the channel, which would be fine, because Bob can just pass that back too -- Carol's the only one losing money in that case.

If Carol wants to close the channel anyway and collect the HTLC on chain, then Bob's situation is:

   channel with Alice: +2500 msat
   channel with Carol: -1900 msat , -fees , -HTLC funds

If Carol isn't cooperative, Bob only definitely knows TTTT, so to keep the channel open with Alice, has to refund 1900msat, so:

   channel with Alice:  +600 msat , +HTLC funds
   channel with Carol: -1900 msat , -fees , -HTLC funds

(or Bob could keep the 2500 msat at the cost of Alice closing the channel too:

   channel with Alice: +2500 msat , -fees , +HTLC funds
   channel with Carol: -1900 msat , -fees , -HTLC funds
)

So Bob and either keep the channel open but is out 1300 msat because of Carol, or can gain 600 msat at the cost of closing the channel with Alice?

As far as the "fair price" goes, the spitballed formula is "16 - X/4" where X is number of zero bits in some PoW-y thing. The proposal is the thing is SHA256(blockhash|revealedonion) which works, and (I think) means each step is individually grindable.

I think an alternative would be to use the prepayment hashes themselves, so you generate the nonce AAAA as the value you'll send to Dave then hash it repeatedly to get BBBB..QQQQ, then check if pow(AAAA,BBBB) has 60 leading zero bits or pow(AAAA,CCCC) has 56 leading zero bits etc. If you made pow(a,b) be SHA256(a,b,shared-onion-key) I think it'd preserve privacy, but also mean you can't meaningfully grind unfairly cheap routing except for very short paths?

If you don't grind and just go by luck, the average number of hashes per hop is ~15.93 (if I got my maths right), so you should be able to estimate path length pretty accurate by dividing claimed prepaid funds by 15.93*25msat or whatever. If everyone grinds at each level independently, I think you'd just subtract maybe 6 hops from that, but the maths would mostly stay the same?

Though I think you could obfusticate that pretty well by moving some of the value from the HTLC into the prepayment -- you'd risk losing that extra value if the payment made it all the way to the recipient but they declined the HTLC that way though.

Quoted text (6 lines)
> >> Does Alice lose everything on any routing failure?
> > That was my thought yeah; it seems weird to pay upfront but expect a
> > refund on failure -- the HTLC funds are already committed upfront and
> > refunded on failure.
> AFAICT you have to overpay, since anything else is very revealing of
> path length.  Which kind of implies a refund, I think.

I guess you'd want to pay for a path length of about 20 whether the path is actually 17, 2, 10 or 5. But a path length of 20 is just paying for bandwidth for maybe 200kB of total traffic which at $1/GB is 2% of 1 cent, which doesn't seem that worth refunding (except for really tiny micropayments, where paying for payment bandwidth might not be feasible at all).

If you're buying a $2 coffee and paying 500ppm in regular fees per hop with 5 hops, then each routing attempt increases your fees by 4%, which seems pretty easy to ignore to me.

Cheers, aj

Joost Jager in reply to Rusty Russell permalink original
Quoted text (10 lines)
>
> > Isn't spam something that can also be addressed by using rate limits for
> > failures? If all relevant nodes on the network employ rate limits, they
> can
> > isolate the spammer and diminish their disruptive abilities.
>
> Sure, once the spammer has jammed up the network, he'll be stopped.  So
> will everyone else.  Conner had a proposal like this which didn't work,
> IIRC.
>

Do you have ref to this proposal?

Imagine the following setup: a network of nodes that trust each other (as far as spam is concerned) applies a 100 htlc/sec rate limit to the channels between themselves. Channels to untrusted nodes get a rate of only 1 htlc/sec. Assuming the spammer isn't a trusted node, they can only spam at 1 htlc/s and won't jam up the network?

lisa neigut in reply to Joost Jager permalink original
Quoted text (1 line)
> Imagine the following setup: a network of nodes that trust each other

The goal of this pre-payment proposal is to remove the need for trusted parties.

On Thu, Nov 7, 2019 at 07:38 Joost Jager <joost.jager at gmail.com> wrote:

Quoted text (22 lines)
> > Isn't spam something that can also be addressed by using rate limits for
>> > failures? If all relevant nodes on the network employ rate limits, they
>> can
>> > isolate the spammer and diminish their disruptive abilities.
>>
>> Sure, once the spammer has jammed up the network, he'll be stopped.  So
>> will everyone else.  Conner had a proposal like this which didn't work,
>> IIRC.
>>
>
> Do you have ref to this proposal?
>
> Imagine the following setup: a network of nodes that trust each other (as
> far as spam is concerned) applies a 100 htlc/sec rate limit to the channels
> between themselves. Channels to untrusted nodes get a rate of only 1
> htlc/sec. Assuming the spammer isn't a trusted node, they can only spam at
> 1 htlc/s and won't jam up the network?
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Joost Jager in reply to lisa neigut permalink original

On Thu, Nov 7, 2019 at 3:36 PM lisa neigut <niftynei at gmail.com> wrote:

Quoted text (5 lines)
> > Imagine the following setup: a network of nodes that trust each other
>
> The goal of this pre-payment proposal is to remove the need for trusted
> parties
>

Trust isn't the right word. It is a level of service that you provide to your peers. If nodes are cognizant of the fact that the level of service they receive goes down if they forward spam, they will be careful on the incoming side. Require peers to build up a reputation before increasing the inbound limits that apply to the channels with them.

Yaacov Akiba Slama in reply to Joost Jager permalink original

On 07/11/2019 16:43, Joost Jager wrote:

Quoted text (15 lines)
> On Thu, Nov 7, 2019 at 3:36 PM lisa neigut <niftynei at gmail.com
> <mailto:niftynei at gmail.com>> wrote:
>
>     > Imagine the following setup: a network of nodes that trust each
>     other
>
>     The goal of this pre-payment proposal is to remove the need for
>     trusted parties
>
>
> Trust isn't the right word. It is a level of service that you provide
> to your peers. If nodes are cognizant of the fact that the level of
> service they receive goes down if they forward spam, they will be
> careful on the incoming side. Require peers to build up a reputation
> before increasing the inbound limits that apply to the channels with them.

We can learn from the current situation in emails, that a system based on reputation tends to concentrate the power in the hands of few big and strong actors (gmail and co). If we have from the beginning a mechanism to fight against spam by paying to send message, we can perhaps have a really distributed system which cannot be censured.

Rusty Russell in reply to Anthony Towns permalink original

Anthony Towns <aj at erisian.com.au> writes:

Quoted text (9 lines)
> On Thu, Nov 07, 2019 at 02:56:51PM +1030, Rusty Russell wrote:
>> > What you wrote to Zmn says "Rusty decrypts the onion, reads the prepay
>> > field: it says 14, LLLL." but Alice doesn't know anything other than
>> > ZZZZ so can't put LLLL in the onion?
>> Alice created the onion.  Alice knows all the preimages, since she
>> created the chain AAAAA....ZZZZZ.
>
> In your reply to Zmn, it was Rusty (Bob) preparing the nonce and creating
> the chain AAAA...ZZZZ -- so I was lost as to what you were proposing...

Oops. Don't trust that Rusty guy, let's stick with Alice.

[ Snip summary, which is correct ]

Quoted text (24 lines)
> As far as the "fair price" goes, the spitballed formula is "16 - X/4"
> where X is number of zero bits in some PoW-y thing. The proposal is
> the thing is SHA256(blockhash|revealedonion) which works, and (I think)
> means each step is individually grindable.
>
> I think an alternative would be to use the prepayment hashes themselves,
> so you generate the nonce AAAA as the value you'll send to Dave then
> hash it repeatedly to get BBBB..QQQQ, then check if pow(AAAA,BBBB) has
> 60 leading zero bits or pow(AAAA,CCCC) has 56 leading zero bits etc.
> If you made pow(a,b) be SHA256(a,b,shared-onion-key) I think it'd
> preserve privacy, but also mean you can't meaningfully grind unfairly
> cheap routing except for very short paths?
>
> If you don't grind and just go by luck, the average number of hashes
> per hop is ~15.93 (if I got my maths right), so you should be able to
> estimate path length pretty accurate by dividing claimed prepaid funds by
> 15.93*25msat or whatever. If everyone grinds at each level independently,
> I think you'd just subtract maybe 6 hops from that, but the maths would
> mostly stay the same?
>
> Though I think you could obfusticate that pretty well by moving
> some of the value from the HTLC into the prepayment -- you'd risk losing
> that extra value if the payment made it all the way to the recipient but
> they declined the HTLC that way though.

Yeah, and doesn't help obscure in the in-the-middle failure case unf. Which is really bad with current payment_hash since you can spot multiple attempts so easily. Hence my attempt to roll in some PoW to obscure the amounts.

The ideal prepay range would be wider, so you can believably have payments between 16 and 4 per hop, say. But if I can grind it I'll naturally restrict the range to the lower end, and if it's ungrindable (eg. based on nodeid and payment_hash or recent block hash) then everyone on the path knows what it so too.

So, hashcash here is better than nothing, but still not very good.

Quoted text (17 lines)
>> >> Does Alice lose everything on any routing failure?
>> > That was my thought yeah; it seems weird to pay upfront but expect a
>> > refund on failure -- the HTLC funds are already committed upfront and
>> > refunded on failure.
>> AFAICT you have to overpay, since anything else is very revealing of
>> path length.  Which kind of implies a refund, I think.
>
> I guess you'd want to pay for a path length of about 20 whether the
> path is actually 17, 2, 10 or 5. But a path length of 20 is just paying
> for bandwidth for maybe 200kB of total traffic which at $1/GB is 2% of
> 1 cent, which doesn't seem that worth refunding (except for really tiny
> micropayments, where paying for payment bandwidth might not be feasible
> at all).
>
> If you're buying a $2 coffee and paying 500ppm in regular fees per hop
> with 5 hops, then each routing attempt increases your fees by 4%, which
> seems pretty easy to ignore to me.

True, but ideally we'd have lots of noise even if people are trying to minimize fees (which, if they're sending messages rather than payments, they might).

Cheers, Rusty.

Rusty Russell in reply to Joost Jager permalink original

Joost Jager <joost.jager at gmail.com> writes:

Quoted text (17 lines)
>>
>> > Isn't spam something that can also be addressed by using rate limits for
>> > failures? If all relevant nodes on the network employ rate limits, they
>> can
>> > isolate the spammer and diminish their disruptive abilities.
>>
>> Sure, once the spammer has jammed up the network, he'll be stopped.  So
>> will everyone else.  Conner had a proposal like this which didn't work,
>> IIRC.
>
> Do you have ref to this proposal?
>
> Imagine the following setup: a network of nodes that trust each other (as
> far as spam is concerned) applies a 100 htlc/sec rate limit to the channels
> between themselves. Channels to untrusted nodes get a rate of only 1
> htlc/sec. Assuming the spammer isn't a trusted node, they can only spam at
> 1 htlc/s and won't jam up the network?

Damn, I searched for it but all the obvious keywords turned up blank. Conner CC'd in case he remembers the discussion and I'm not imagining it?

Anyway, if there are 100 nodes in the network I can still open a channel to each one and jam it up immediately. And that's not even assuming I play nice until you trust me, then attack or get taken over.

Cheers, Rusty.

Anthony Towns in reply to Rusty Russell permalink original

On Fri, Nov 08, 2019 at 01:08:04PM +1030, Rusty Russell wrote:

Quoted text (2 lines)
> Anthony Towns <aj at erisian.com.au> writes:
> [ Snip summary, which is correct ]

Huzzah!

This correlates all the hops in a payment when the route reaches its end (due to the final preimage getting propogated back for everyone to justify the funds they claim). Maybe solvable by converting from hashes to ECC as the trapdoor function?

The refund amount propogating back also reveals the path, probably. Could that be obfusticated by somehow paying each intermediate node both as the funds go out and come back, so the refund decreases on the way back?

Oh, can we make the amounts work like the onion, where it stays constant? So:

  Alice wants to pay Dave via Bob, Carol. Bob gets 700 msat, Carol gets
  400 msat, Dave gets 300 msat, and Alice gets 100 msat refunded.
  Success:
    Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
    Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
    Carol forwards 1500 msat to Dave  (-1500, 0, 0, +1500)
    Dave refunds 1200 msat to Carol   (-1500, 0, +1200, +300)
    Carol refunds 800 msat to Bob     (-1500, +800, +400, +300)
    Bob refunds 100 msat to Alice     (-1400, +700, +400, +300)
  Clean routing failure at Carol/Dave:
    Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
    Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
    Carol says Dave's not talking
    Carol refunds 1100 msat to Bob    (-1500, +1100, +400, 0)
    Bob refunds 400 msat to Alice     (-1100, +700, +400, 0)

I think that breaks the correlation pretty well, so you just need a decent way of obscuring path length?

In the uncooperative routing failure case, I wonder if using an ECC trapdoor and perhaps scriptless scripts, you could make it so Carol doesn't even get an updated state without revealing the preimage...

Cheers, aj

Joost Jager in reply to Yaacov Akiba Slama permalink original
Quoted text (16 lines)
>
> >     The goal of this pre-payment proposal is to remove the need for
> >     trusted parties
> >
> > Trust isn't the right word. It is a level of service that you provide
> > to your peers. If nodes are cognizant of the fact that the level of
> > service they receive goes down if they forward spam, they will be
> > careful on the incoming side. Require peers to build up a reputation
> > before increasing the inbound limits that apply to the channels with
> them.

We can learn from the current situation in emails, that a system based
> on reputation tends to concentrate the power in the hands of few big and
> strong actors (gmail and co). If we have from the beginning a mechanism
> to fight against spam by paying to send message, we can perhaps have a
> really distributed system which cannot be censured.
>

Can you elaborate on this a bit further? If you consider rate limiting to be a form of censoring, then you can still censor if there is a prepay.

I am not too familiar with the current state of email servers, to what extent power is concentrated now and how that evolution translates to Lightning. One difference is that afaik emails don't traverse a path through multiple mail "nodes". Another is that inboxes of users are very centralized (gmail and co).

What does that undesired situation exactly look like in the Lightning Network if nodes would enforce rate limits based on how they rate their direct peers?

Joost

Joost Jager in reply to Rusty Russell permalink original
Quoted text (28 lines)
>
> >> > Isn't spam something that can also be addressed by using rate limits
> for
> >> > failures? If all relevant nodes on the network employ rate limits,
> they
> >> can
> >> > isolate the spammer and diminish their disruptive abilities.
> >>
> >> Sure, once the spammer has jammed up the network, he'll be stopped.  So
> >> will everyone else.  Conner had a proposal like this which didn't work,
> >> IIRC.
> >
> > Do you have ref to this proposal?
> >
> > Imagine the following setup: a network of nodes that trust each other (as
> > far as spam is concerned) applies a 100 htlc/sec rate limit to the
> channels
> > between themselves. Channels to untrusted nodes get a rate of only 1
> > htlc/sec. Assuming the spammer isn't a trusted node, they can only spam
> at
> > 1 htlc/s and won't jam up the network?
>
> Damn, I searched for it but all the obvious keywords turned up blank.
> Conner CC'd in case he remembers the discussion and I'm not imagining it?
>
> Anyway, if there are 100 nodes in the network I can still open a channel
> to each one and jam it up immediately.  And that's not even assuming I
> play nice until you trust me, then attack or get taken over.

At least it has gotten (100 times?) more difficult. I think it is hard to say upfront how good or bad this setup would work. But I agree that prepay deters spam in a more fundamental way.

Besides the argument that I brought up earlier of potentially killing micro-payment-based use cases with prepay, there is also another concern. It is nothing new, but could be interesting to look at it in the light of prepayments.

It is currently possible to jam a channel with very limited resources. If you hold 483 htlcs on a channel, it has become unusable for up to the cltv limit. Let's say for 1000 blocks. If you allow a route that ping pongs back and forth on the channel (let's say 8 times back and forth), you only need to send 60 htlcs of the minimum amount for the route to jam the channel completely. With min htlc policies of 1 sat, that will lock up only 60 sats of the attacker (assuming no routing fees).

Let's say the wumbo channel has a capacity of 1 btc. Locking up 1 btc for 1000 blocks (~1 week) and assuming a time value of 4% per annum, the cost to the routing node is: 1 * (1.04 ^ (1/52)) - 1 = 75,000 sats.

How much prepay would you need to prevent this? I don't think the 50 msat would cut it.

I know this is the liquidity-using class of spam, but if prepay cannot prevent this I think it is better to first address this class. And once there is solution for that, see whether the other classes of spam are still possible.

Joost

Yaacov Akiba Slama in reply to Joost Jager permalink original
Yaacov Akiba Slama in reply to Joost Jager permalink original

[Sorry: re-sending again in plain text]

On 08/11/2019 16:15, Joost Jager wrote:

Quoted text (26 lines)
>
>     >     The goal of this pre-payment proposal is to remove the need for
>     >     trusted parties
>     >
>     > Trust isn't the right word. It is a level of service that you
>     provide
>     > to your peers. If nodes are cognizant of the fact that the level of
>     > service they receive goes down if they forward spam, they will be
>     > careful on the incoming side. Require peers to build up a
>     reputation
>     > before increasing the inbound limits that apply to the channels
>     with them.
>
>     We can learn from the current situation in emails, that a system
>     based
>     on reputation tends to concentrate the power in the hands of few
>     big and
>     strong actors (gmail and co). If we have from the beginning a
>     mechanism
>     to fight against spam by paying to send message, we can perhaps
>     have a
>     really distributed system which cannot be censured.
>
>
> Can you elaborate on this a bit further? If you consider rate limiting
> to be a form of censoring, then you can still censor if there is a prepay.

There are situations when lot of people need to send each other lot of messages in a small period of time, in protests for instance. In this case, people are ready to pay a little to communicate. It's true that they can be censored even when paying for messaging, but in this case, it's a voluntary (and politic) decision. But when using a rate limiting mechanism, it's an economic decision with politic implications.

Quoted text (4 lines)
>
> I am not too familiar with the current state of email servers, to what
> extent power is concentrated now and how that evolution translates to
> Lightning.

Currently, if you install a smtp server in you home computer or in a server you rent and you try to send an email to someone with an email from any big provider, it will be marked as spam, because you need to have a good "reputation". And if you try to send so called "marketing" emails, you'll be marked as spammer even if the same emails sent by big providers are not rejected. This is the effect of using any reputation system. The path from reputation to propaganda is very short.

Quoted text (3 lines)
> One difference is that afaik emails don't traverse a path through
> multiple mail "nodes". Another is that inboxes of users are very
> centralized (gmail and co).

I can imagine a system where people who want to use the messaging system based on Lightning will have to open a channel to big nodes in order to be able to reach their recipient. In this case, those big nodes can censor as they want because they have access to a lot of metadata.

Rusty Russell in reply to Anthony Towns permalink original

Anthony Towns <aj at erisian.com.au> writes:

Quoted text (10 lines)
> On Fri, Nov 08, 2019 at 01:08:04PM +1030, Rusty Russell wrote:
>> Anthony Towns <aj at erisian.com.au> writes:
>> [ Snip summary, which is correct ]
>
> Huzzah!
>
> This correlates all the hops in a payment when the route reaches its end
> (due to the final preimage getting propogated back for everyone to justify
> the funds they claim). Maybe solvable by converting from hashes to ECC
> as the trapdoor function?

I hadn't thought of this, but yes, once we've eliminated the trivial preimage correlation w/scriptless scripts it'd be a shame to reintroduce it here.

We need an accumulator with some strange properties though:

1. Alice provides tokens and a base accumulator.
2. Bob et. al can add these tokens to the accumulator.
3. They can tell if invalid tokens have been added to the accumulator.
4. They can tell how many tokens (alt: each token has a value and they
   can tell the value sum) have been added.
5. They can't tell what tokens have been added (unless they know all
   the tokens, which is trivial).

Any ideas?

Quoted text (18 lines)
> The refund amount propogating back also reveals the path, probably.
> Could that be obfusticated by somehow paying each intermediate node
> both as the funds go out and come back, so the refund decreases on the
> way back?
>
> Oh, can we make the amounts work like the onion, where it stays constant?
> So:
>
>   Alice wants to pay Dave via Bob, Carol. Bob gets 700 msat, Carol gets
>   400 msat, Dave gets 300 msat, and Alice gets 100 msat refunded.
>
>   Success:
>     Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
>     Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
>     Carol forwards 1500 msat to Dave  (-1500, 0, 0, +1500)
>     Dave refunds 1200 msat to Carol   (-1500, 0, +1200, +300)
>     Carol refunds 800 msat to Bob     (-1500, +800, +400, +300)
>     Bob refunds 100 msat to Alice     (-1400, +700, +400, +300)

Or, on success, upfront payment is fully refunded or not refunded at all (since they get paid by normal fees)? Either way, no data leak for that case.

Quoted text (9 lines)
>   Clean routing failure at Carol/Dave:
>     Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
>     Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
>     Carol says Dave's not talking
>     Carol refunds 1100 msat to Bob    (-1500, +1100, +400, 0)
>     Bob refunds 400 msat to Alice     (-1100, +700, +400, 0)
>
> I think that breaks the correlation pretty well, so you just need a
> decent way of obscuring path length?

I don't see how this breaks correlation?

Quoted text (3 lines)
> In the uncooperative routing failure case, I wonder if using an ECC
> trapdoor and perhaps scriptless scripts, you could make it so Carol
> doesn't even get an updated state without revealing the preimage...

I'm not sure. We can make it so Carol has Bob's preimage(s), etc, so that the node which fails doesn't get paid. I initially thought this would just make people pair up (fake) nodes, but it's probably not worth it since their path would be less-selected in that case.

Cheers, Rusty.

Bastien TEINTURIER in reply to Rusty Russell permalink original

I think there's another alternative than upfront payments to prevent spam, which is maybe less controversial (but potentially less effective as well - to be investigated).

Why not adapt what has been done with email spam and PoW/merkle puzzles? The high-level idea would be that the sender must solve a small PoW puzzle *for each intermediate * *node *and communicate the solution in the onion. There are many ways we could do that (a new field in each intermediate hop, grinding an HMAC prefix, etc) so before going into specifics I only wanted to submit the high-level idea. What's neat with this is that it's simple, doesn't leak any privacy, and avoids having to create a node reputation system.

We fight spam by forcing the sender to use some resources (instead of sats). Maybe this idea has already been proposed and broken, if that's the case I'd love to see the discussion if someone can surface it.

Cheers, Bastien

Le lun. 11 nov. 2019 à 00:32, Rusty Russell <rusty at rustcorp.com.au> a écrit :

Quoted text (80 lines)
> Anthony Towns <aj at erisian.com.au> writes:
> > On Fri, Nov 08, 2019 at 01:08:04PM +1030, Rusty Russell wrote:
> >> Anthony Towns <aj at erisian.com.au> writes:
> >> [ Snip summary, which is correct ]
> >
> > Huzzah!
> >
> > This correlates all the hops in a payment when the route reaches its end
> > (due to the final preimage getting propogated back for everyone to
> justify
> > the funds they claim). Maybe solvable by converting from hashes to ECC
> > as the trapdoor function?
>
> I hadn't thought of this, but yes, once we've eliminated the trivial
> preimage correlation w/scriptless scripts it'd be a shame to reintroduce
> it here.
>
> We need an accumulator with some strange properties though:
>
> 1. Alice provides tokens and a base accumulator.
> 2. Bob et. al can add these tokens to the accumulator.
> 3. They can tell if invalid tokens have been added to the accumulator.
> 4. They can tell how many tokens (alt: each token has a value and they
>    can tell the value sum) have been added.
> 5. They can't tell what tokens have been added (unless they know all
>    the tokens, which is trivial).
>
> Any ideas?
>
> > The refund amount propogating back also reveals the path, probably.
> > Could that be obfusticated by somehow paying each intermediate node
> > both as the funds go out and come back, so the refund decreases on the
> > way back?
> >
> > Oh, can we make the amounts work like the onion, where it stays constant?
> > So:
> >
> >   Alice wants to pay Dave via Bob, Carol. Bob gets 700 msat, Carol gets
> >   400 msat, Dave gets 300 msat, and Alice gets 100 msat refunded.
> >
> >   Success:
> >     Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
> >     Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
> >     Carol forwards 1500 msat to Dave  (-1500, 0, 0, +1500)
> >     Dave refunds 1200 msat to Carol   (-1500, 0, +1200, +300)
> >     Carol refunds 800 msat to Bob     (-1500, +800, +400, +300)
> >     Bob refunds 100 msat to Alice     (-1400, +700, +400, +300)
>
> Or, on success, upfront payment is fully refunded or not refunded at all
> (since they get paid by normal fees)?  Either way, no data leak for that
> case.
>
> >   Clean routing failure at Carol/Dave:
> >     Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
> >     Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
> >     Carol says Dave's not talking
> >     Carol refunds 1100 msat to Bob    (-1500, +1100, +400, 0)
> >     Bob refunds 400 msat to Alice     (-1100, +700, +400, 0)
> >
> > I think that breaks the correlation pretty well, so you just need a
> > decent way of obscuring path length?
>
> I don't see how this breaks correlation?
>
> > In the uncooperative routing failure case, I wonder if using an ECC
> > trapdoor and perhaps scriptless scripts, you could make it so Carol
> > doesn't even get an updated state without revealing the preimage...
>
> I'm not sure.  We can make it so Carol has Bob's preimage(s), etc, so
> that the node which fails doesn't get paid.  I initially thought this
> would just make people pair up (fake) nodes, but it's probably not worth
> it since their path would be less-selected in that case.
>
> Cheers,
> Rusty.
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Pierre in reply to Bastien TEINTURIER permalink original
Quoted text (1 line)
> The high-level idea would be that the sender must solve a small PoW puzzle

<insert meme: "Yo dawg I heard you like pow systems..." >

ZmnSCPxj in reply to Bastien TEINTURIER permalink original

Good morning Bastien,

Quoted text (14 lines)
> I think there's another alternative than upfront payments to prevent spam, which is maybe less
> controversial (but potentially less effective as well - to be investigated).
>
> Why not adapt what has been done with email spam and PoW/merkle puzzles?
> The high-level idea would be that the sender must solve a small PoW puzzle for each intermediate
> node and communicate the solution in the onion.
> There are many ways we could do that (a new field in each intermediate hop, grinding an HMAC
> prefix, etc) so before going into specifics I only wanted to submit the high-level idea.
> What's neat with this is that it's simple, doesn't leak any privacy, and avoids having to create a
> node reputation system.
>
> We fight spam by forcing the sender to use some resources (instead of sats).
> Maybe this idea has already been proposed and broken, if that's the case I'd love to see the
> discussion if someone can surface it.

This imposes a cost that varies depending on how specialized your hardware is at generating proof-of-work.

At a certain point-of-view, one can argue that directly paying with millisatoshis for each hop (whether it fails to forward or not) has the same cost on the sender (replace the consumption of energy to compute proof-of-work with a payment or burning of funds instead), and at least does not prejudice against sender hardware that is not specialized at generating proof-of-work.

Thus I would argue that, given we already have a system that bases an economic token on top of proof-of-work, every use of proof-of-work today (other than to power Bitcoin itself, as Bitcoin cannot support itself) can instead be done by using Bitcoins to impose this economic cost.

All economic costs resolve to energy (economic tokens represent "right-to-consume-energy", by the simple technique of purchasing energy), thus requiring a fee is equivalent to requiring proof-of-work, incentive-wise. The drawback is that proof-of-work is cheaper for specialized hardware (as well as specialized setups for getting more energy at cheaper costs).

As hardware specialization for the specific Lightning-Network-proof-of-work arises, we will find that to practically limit spam, intermediate nodes will have to increase and increase the threshold for accepting proof-of-work, as spammers are going to switch to the more-specialized hardware. This leads to certain kinds of hardware (older mobile phones, older workstations, etc.) being unable to practically use the Lightning Network due to the increased proof-of-work threshold. Eventually, services will arise where datacenters of specialized hardware are rented out to Lighning Network nodes for a fee in exchange for a proof-of-work to be used on a route --- datacenters that may very well end up becoming kingmakers capable of allowing or suppressing certain economic activities. This ends up being indirect and loses a good amount of privacy. It is better to simply impose *some* cost on the sender that it pays directly, than to use a mechanism that inherently leads to specialization.

Regards, ZmnSCPxj

Quoted text (84 lines)
>
> Cheers,
> Bastien
>
> Le lun. 11 nov. 2019 à 00:32, Rusty Russell <rusty at rustcorp.com.au> a écrit :
>
> > Anthony Towns <aj at erisian.com.au> writes:
> > > On Fri, Nov 08, 2019 at 01:08:04PM +1030, Rusty Russell wrote:
> > >> Anthony Towns <aj at erisian.com.au> writes:
> > >> [ Snip summary, which is correct ]
> > >
> > > Huzzah!
> > >
> > > This correlates all the hops in a payment when the route reaches its end
> > > (due to the final preimage getting propogated back for everyone to justify
> > > the funds they claim). Maybe solvable by converting from hashes to ECC
> > > as the trapdoor function?
> >
> > I hadn't thought of this, but yes, once we've eliminated the trivial
> > preimage correlation w/scriptless scripts it'd be a shame to reintroduce
> > it here.
> >
> > We need an accumulator with some strange properties though:
> >
> > 1. Alice provides tokens and a base accumulator.
> > 2. Bob et. al can add these tokens to the accumulator.
> > 3. They can tell if invalid tokens have been added to the accumulator.
> > 4. They can tell how many tokens (alt: each token has a value and they
> >    can tell the value sum) have been added.
> > 5. They can't tell what tokens have been added (unless they know all
> >    the tokens, which is trivial).
> >
> > Any ideas?
> >
> > > The refund amount propogating back also reveals the path, probably.
> > > Could that be obfusticated by somehow paying each intermediate node
> > > both as the funds go out and come back, so the refund decreases on the
> > > way back?
> > >
> > > Oh, can we make the amounts work like the onion, where it stays constant?
> > > So:
> > >
> > >   Alice wants to pay Dave via Bob, Carol. Bob gets 700 msat, Carol gets
> > >   400 msat, Dave gets 300 msat, and Alice gets 100 msat refunded.
> > >
> > >   Success:
> > >     Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
> > >     Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
> > >     Carol forwards 1500 msat to Dave  (-1500, 0, 0, +1500)
> > >     Dave refunds 1200 msat to Carol   (-1500, 0, +1200, +300)
> > >     Carol refunds 800 msat to Bob     (-1500, +800, +400, +300)
> > >     Bob refunds 100 msat to Alice     (-1400, +700, +400, +300)
> >
> > Or, on success, upfront payment is fully refunded or not refunded at all
> > (since they get paid by normal fees)?  Either way, no data leak for that
> > case.
> >
> > >   Clean routing failure at Carol/Dave:
> > >     Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
> > >     Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
> > >     Carol says Dave's not talking
> > >     Carol refunds 1100 msat to Bob    (-1500, +1100, +400, 0)
> > >     Bob refunds 400 msat to Alice     (-1100, +700, +400, 0)
> > >
> > > I think that breaks the correlation pretty well, so you just need a
> > > decent way of obscuring path length?
> >
> > I don't see how this breaks correlation?
> >
> > > In the uncooperative routing failure case, I wonder if using an ECC
> > > trapdoor and perhaps scriptless scripts, you could make it so Carol
> > > doesn't even get an updated state without revealing the preimage...
> >
> > I'm not sure.  We can make it so Carol has Bob's preimage(s), etc, so
> > that the node which fails doesn't get paid.  I initially thought this
> > would just make people pair up (fake) nodes, but it's probably not worth
> > it since their path would be less-selected in that case.
> >
> > Cheers,
> > Rusty.
> > _______________________________________________
> > Lightning-dev mailing list
> > Lightning-dev at lists.linuxfoundation.org
> > https://www.learnbitcoin.com/archive/lists/lightning-dev
Bastien TEINTURIER in reply to ZmnSCPxj permalink original

While I agree with most of your points, I think there are subtleties to explore before completely rejecting the idea.

Quoted text (4 lines)
every use of proof-of-work today (other than to power Bitcoin itself, as
> Bitcoin cannot support itself) can instead be done by using Bitcoins to
> impose this economic cost.
>

That is philosophically true, but the complexity of integrating that small PoW into Lightning is much lower than the complexity of integrating **fair, un-gameable** upfront payments. And not all PoW is born equal: there are a lot of PoW schemes that have different trade-offs than Bitcoin mining (think ASIC-resistance such as variants of Cuckoo Cycle).

Another key point is that creating ASICs for this PoW is fundamentally different from creating ASICs for mining a crypto-currency. Solving this PoW doesn't earn you any money: it merely allows you to spam to temporarily disrupt the network. Since this PoW isn't used in any consensus, we can change the spam PoW algorithm anytime we want, making all previous ASICs obsolete. So it's not obvious to me that anyone would find it viable to invest in creating such ASICs.

Quoted text (6 lines)
As hardware specialization for the specific Lightning-Network-proof-of-work
> arises, we will find that to practically limit spam, intermediate nodes
> will have to increase and increase the threshold for accepting
> proof-of-work, as spammers are going to switch to the more-specialized
> hardware.
>

That's where I think it can be more subtle than what you describe (I may be wrong though as predicting future behavior is hard).

Since I'm ruling out ASICs, we're only dealing with "normal" hardware bottlenecks (cpu/ram). That means attackers are not playing at a completely different scale than normal users. The cost for attackers to generate an amount of spam mimicking N normal users will then be somewhat linear in N (to be investigated further). That's exactly the same result as upfront payments, where an attacker can still spam like he's N users if he's ready to pay a cost linear in N.

I'm slightly playing devil's advocate for the PoW proposal because I think it's worth exploring more, even if we eventually abandon it. Maybe you're right and it won't be as effective to fight spam as upfront payments: but right now with the arguments I've seen on this thread, I'm not yet convinced of that.

Cheers, Bastien

Orfeas Stefanos Thyfronitis Litos in reply to ZmnSCPxj permalink original

Good morning ZmnSCPxj,

Quoted text (1 line)
> requiring a fee is equivalent to requiring proof-of-work, incentive-wise.

Not necessarily, given that 1) there is a finite bitcoin supply but an eventually infinite PoW supply (relevant in the unlikely case fees are burned) 2) sats are transferrable, whereas PoW isn't (relevant in the case fees are paid)

On the other hand, there exists this paper with the fancy name that claims using PoW for spam prevention in the context of email (the original context in which PoW was discovered) is ineffective due to the high per-message PoW required to beat spam [0]. Therefore we have to see whether this paper applies to LN as well before going down that road.

Spam prevention in an unauthenticated system is much more complex than it seems at first, because it boils down to avoiding the Sybil attack, (one of) the most difficult problem(s) in such systems. A (traditional) reputation system in essence enables authentication (eww), per-message PoW might be too expensive, and per-message fees seem to have incentives issues and are kind of misaligned with LN's aims.

Maybe I've missed something, but what makes spam in LN a bigger problem than it is in every other p2p network out there? Why won't traditional bad activity thresholds do the job?

I don't think spam is something that will be completely wiped out, only contained. LN should provide for many orthogonal spam prevention measures (local tunable activity thresholds, gossipable reputation systems (eww), per-message fees, per-message PoW) with sensible defaults to allow users to experiment and choose what is best for them, but that may lead to unacceptable protocol and UI complexity. What a tradeoff...

Best, Orfeas

[0] https://www.cl.cam.ac.uk/~rnc1/proofwork.pdf
Rusty Russell in reply to Bastien TEINTURIER permalink original

Bastien TEINTURIER <bastien at acinq.fr> writes:

Quoted text (5 lines)
> I think there's another alternative than upfront payments to prevent spam,
> which is maybe less
> controversial (but potentially less effective as well - to be investigated).
>
> Why not adapt what has been done with email spam and PoW/merkle puzzles?

If we can't come up with an untracable scheme, this is what we'll have to do (i.e. remove the sats component).

Unfortunately botnets are really good at generating these. That was always the hashcash flaw (which is why it was never actually used).

Using a dynamic level is possible, too, so it gets harder in case we're being spam attacked.

Cheers, Rusty.

Quoted text (103 lines)
> The high-level idea would be that the sender must solve a small PoW puzzle *for
> each intermediate *
> *node *and communicate the solution in the onion.
> There are many ways we could do that (a new field in each intermediate hop,
> grinding an HMAC
> prefix, etc) so before going into specifics I only wanted to submit the
> high-level idea.
> What's neat with this is that it's simple, doesn't leak any privacy, and
> avoids having to create a
> node reputation system.
>
> We fight spam by forcing the sender to use some resources (instead of sats).
> Maybe this idea has already been proposed and broken, if that's the case
> I'd love to see the
> discussion if someone can surface it.
>
>
> Cheers,
> Bastien
>
> Le lun. 11 nov. 2019 à 00:32, Rusty Russell <rusty at rustcorp.com.au> a
> écrit :
>
>> Anthony Towns <aj at erisian.com.au> writes:
>> > On Fri, Nov 08, 2019 at 01:08:04PM +1030, Rusty Russell wrote:
>> >> Anthony Towns <aj at erisian.com.au> writes:
>> >> [ Snip summary, which is correct ]
>> >
>> > Huzzah!
>> >
>> > This correlates all the hops in a payment when the route reaches its end
>> > (due to the final preimage getting propogated back for everyone to
>> justify
>> > the funds they claim). Maybe solvable by converting from hashes to ECC
>> > as the trapdoor function?
>>
>> I hadn't thought of this, but yes, once we've eliminated the trivial
>> preimage correlation w/scriptless scripts it'd be a shame to reintroduce
>> it here.
>>
>> We need an accumulator with some strange properties though:
>>
>> 1. Alice provides tokens and a base accumulator.
>> 2. Bob et. al can add these tokens to the accumulator.
>> 3. They can tell if invalid tokens have been added to the accumulator.
>> 4. They can tell how many tokens (alt: each token has a value and they
>>    can tell the value sum) have been added.
>> 5. They can't tell what tokens have been added (unless they know all
>>    the tokens, which is trivial).
>>
>> Any ideas?
>>
>> > The refund amount propogating back also reveals the path, probably.
>> > Could that be obfusticated by somehow paying each intermediate node
>> > both as the funds go out and come back, so the refund decreases on the
>> > way back?
>> >
>> > Oh, can we make the amounts work like the onion, where it stays constant?
>> > So:
>> >
>> >   Alice wants to pay Dave via Bob, Carol. Bob gets 700 msat, Carol gets
>> >   400 msat, Dave gets 300 msat, and Alice gets 100 msat refunded.
>> >
>> >   Success:
>> >     Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
>> >     Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
>> >     Carol forwards 1500 msat to Dave  (-1500, 0, 0, +1500)
>> >     Dave refunds 1200 msat to Carol   (-1500, 0, +1200, +300)
>> >     Carol refunds 800 msat to Bob     (-1500, +800, +400, +300)
>> >     Bob refunds 100 msat to Alice     (-1400, +700, +400, +300)
>>
>> Or, on success, upfront payment is fully refunded or not refunded at all
>> (since they get paid by normal fees)?  Either way, no data leak for that
>> case.
>>
>> >   Clean routing failure at Carol/Dave:
>> >     Alice forwards 1500 msat to Bob   (-1500, +1500, 0, 0)
>> >     Bob forwards 1500 msat to Carol   (-1500, 0, +1500, 0)
>> >     Carol says Dave's not talking
>> >     Carol refunds 1100 msat to Bob    (-1500, +1100, +400, 0)
>> >     Bob refunds 400 msat to Alice     (-1100, +700, +400, 0)
>> >
>> > I think that breaks the correlation pretty well, so you just need a
>> > decent way of obscuring path length?
>>
>> I don't see how this breaks correlation?
>>
>> > In the uncooperative routing failure case, I wonder if using an ECC
>> > trapdoor and perhaps scriptless scripts, you could make it so Carol
>> > doesn't even get an updated state without revealing the preimage...
>>
>> I'm not sure.  We can make it so Carol has Bob's preimage(s), etc, so
>> that the node which fails doesn't get paid.  I initially thought this
>> would just make people pair up (fake) nodes, but it's probably not worth
>> it since their path would be less-selected in that case.
>>
>> Cheers,
>> Rusty.
>> _______________________________________________
>> Lightning-dev mailing list
>> Lightning-dev at lists.linuxfoundation.org
>> https://www.learnbitcoin.com/archive/lists/lightning-dev
>>
ZmnSCPxj in reply to Bastien TEINTURIER permalink original

Good morning Bastien,

Quoted text (16 lines)
> While I agree with most of your points, I think there are subtleties to explore before
> completely rejecting the idea.
>
> > every use of proof-of-work today (other than to power Bitcoin itself, as Bitcoin cannot support itself) can instead be done by using Bitcoins to impose this economic cost.
>
> That is philosophically true, but the complexity of integrating that small PoW into Lightning
> is much lower than the complexity of integrating *fair, un-gameable* upfront payments.
> And not all PoW is born equal: there are a lot of PoW schemes that have different trade-offs
> than Bitcoin mining (think ASIC-resistance such as variants of Cuckoo Cycle).
>
> Another key point is that creating ASICs for this PoW is fundamentally different from creating
> ASICs for mining a crypto-currency. Solving this PoW doesn't earn you any money: it merely
> allows you to spam to temporarily disrupt the network.
> Since this PoW isn't used in any consensus, we can change the spam PoW algorithm anytime
> we want, making all previous ASICs obsolete.
> So it's not obvious to me that anyone would find it viable to invest in creating such ASICs.

https://github.com/libbitcoin/libbitcoin-system/wiki/Proof-of-Work-Fallacy

While it is true that we do not need consensus at the Lightning layer, we still require that senders are compatible with intermediate nodes to the extent that they use intermediate nodes. Thus a PoW change here would require that intermediate nodes reject older PoW (that is the entire point) while senders must be prepared to provide either the old PoW algorithm or the new one (as arbitrary intermediate nodes may not update immediately).

Specialization will arise to the extent that we design the system to allow it. In this case, specialized PoW-providers will be paid in order to provide PoW that will be presented to intermediate nodes. Far better to just pay intermediate nodes directly and remove this additional friction.

Quoted text (8 lines)
>
> > As hardware specialization for the specific Lightning-Network-proof-of-work arises, we will find that to practically limit spam, intermediate nodes will have to increase and increase the threshold for accepting proof-of-work, as spammers are going to switch to the more-specialized hardware.
>
> That's where I think it can be more subtle than what you describe (I may be wrong though as
> predicting future behavior is hard).
>
> Since I'm ruling out ASICs, we're only dealing with "normal" hardware bottlenecks (cpu/ram).
> That means attackers are not playing at a completely different scale than normal users.

How many botnets does a normal user control?

Quoted text (4 lines)
> The cost for attackers to generate an amount of spam mimicking N normal users will then be
> somewhat linear in N (to be investigated further).
> That's exactly the same result as upfront payments, where an attacker can still spam like
> he's N users if he's ready to pay a cost linear in N.

Then just use upfront payments.

Quoted text (7 lines)
> > requiring a fee is equivalent to requiring proof-of-work, incentive-wise.
>
> Not necessarily, given that
> 1) there is a finite bitcoin supply but an eventually infinite PoW
> supply (relevant in the unlikely case fees are burned)
> 2) sats are transferrable, whereas PoW isn't (relevant in the case fees
> are paid)

Not actually. Again, let me point out that PoW can be *bought*, that is precisely what Bitcoin blockchain layer does. And the blockchain layer PoW is bought with two things: fees and subsidies (inflation). Thus PoW, being purchaseable, is incentive-wise equivalent to paying somebody to spend electricity (possibly with efficiencies at scale). Just cut the middleman.

Regards, ZmnSCPxj

Orfeas Stefanos Thyfronitis Litos in reply to ZmnSCPxj permalink original

Hi ZmnSCPxj,

Quoted text (13 lines)
>>> requiring a fee is equivalent to requiring proof-of-work, incentive-wise.
>>
>> Not necessarily, given that
>> 1) there is a finite bitcoin supply but an eventually infinite PoW
>> supply (relevant in the unlikely case fees are burned)
>> 2) sats are transferrable, whereas PoW isn't (relevant in the case fees
>> are paid)
>
> Not actually.
> Again, let me point out that PoW can be *bought*, that is precisely what Bitcoin blockchain layer does.
> And the blockchain layer PoW is bought with two things: fees and subsidies (inflation).
> Thus PoW, being purchaseable, is incentive-wise equivalent to paying somebody to spend electricity (possibly with efficiencies at scale).
> Just cut the middleman.

I wasn't clear enough, sorry for that. I agree that in general PoW can be bought. However if I understand this particular PoW proposal correctly, a brand-new PoW has to be created for each intermediary. These PoWs cannot be reused by the intermediary for later payments (or for anything else).

I will now show that there exist spam-prevention schemes that differ only on whether the payer gives sats or PoWs to intermediaries, such that economically rational agents are incentivized to cheat in the case of sats but not so in the case of PoWs. This proves that fees are *not* equivalent to PoWs incentive-wise.

In our model, an intermediary can follow one of three possible
strategies (we make the assumption that other strategies are strictly
dominated by one of the three). Each strategy results in different
resource utilization and proceeds from fees.
  (A) do nothing. This results in resources_A = 0 and sats_A = 0
  (B) play honestly. resources_B < 0 (negative because they constitute
an operating cost) and sats_B = anti_spam_fee + routing_fee
  (C) mount a plausibly deniable attack. Here resources_C < 0 and sats_C
= anti_spam_fee.
We assume that resources_C > resources_B + routing_fee (1).

In case intermediaries receive PoWs as an anti-spam measure, it is anti_spam_fee = 0 which means that resources_C + sats_C < 0 = resources_A + sats_A, therefore strategy C is strictly dominated by A. (The fact that A also strictly dominates B is an interesting observation, but beside the point for the argument made.)

OTOH, in the case of anti-spam sats, it is anti_spam_fee > 0. Therefore we have resources_C + sats_C > resources_B + sats_B (using (1)) and for a big enough anti_spam_fee, it is resources_C + sats_C > 0, therefore strategy C strictly dominates both A and B.

In other words, by just changing whether we use anti-spam PoWs or fees, we change the economically rational behavior.

I apologize for the previous ambiguity and I hope this has made my argument clearer.

Best, Orfeas

ZmnSCPxj in reply to Orfeas Stefanos Thyfronitis Litos permalink original

Good morning Orfeas,

Quoted text (59 lines)
> Hi ZmnSCPxj,
>
> > > > requiring a fee is equivalent to requiring proof-of-work, incentive-wise.
> > >
> > > Not necessarily, given that
> > >
> > > 1.  there is a finite bitcoin supply but an eventually infinite PoW
> > >     supply (relevant in the unlikely case fees are burned)
> > >
> > > 2.  sats are transferrable, whereas PoW isn't (relevant in the case fees
> > >     are paid)
> > >
> >
> > Not actually.
> > Again, let me point out that PoW can be bought, that is precisely what Bitcoin blockchain layer does.
> > And the blockchain layer PoW is bought with two things: fees and subsidies (inflation).
> > Thus PoW, being purchaseable, is incentive-wise equivalent to paying somebody to spend electricity (possibly with efficiencies at scale).
> > Just cut the middleman.
>
> I wasn't clear enough, sorry for that. I agree that in general PoW can
> be bought. However if I understand this particular PoW proposal
> correctly, a brand-new PoW has to be created for each intermediary.
> These PoWs cannot be reused by the intermediary for later payments (or
> for anything else).
>
> I will now show that there exist spam-prevention schemes that differ
> only on whether the payer gives sats or PoWs to intermediaries, such
> that economically rational agents are incentivized to cheat in the case
> of sats but not so in the case of PoWs. This proves that fees are not
> equivalent to PoWs incentive-wise.
>
> In our model, an intermediary can follow one of three possible
> strategies (we make the assumption that other strategies are strictly
> dominated by one of the three). Each strategy results in different
> resource utilization and proceeds from fees.
> (A) do nothing. This results in resources_A = 0 and sats_A = 0
> (B) play honestly. resources_B < 0 (negative because they constitute
> an operating cost) and sats_B = anti_spam_fee + routing_fee
> (C) mount a plausibly deniable attack. Here resources_C < 0 and sats_C
> = anti_spam_fee.
> We assume that resources_C > resources_B + routing_fee (1).
>
> In case intermediaries receive PoWs as an anti-spam measure, it is
> anti_spam_fee = 0 which means that resources_C + sats_C < 0 =
> resources_A + sats_A, therefore strategy C is strictly dominated by A.
> (The fact that A also strictly dominates B is an interesting
> observation, but beside the point for the argument made.)
>
> OTOH, in the case of anti-spam sats, it is anti_spam_fee > 0. Therefore
> we have resources_C + sats_C > resources_B + sats_B (using (1)) and for
> a big enough anti_spam_fee, it is resources_C + sats_C > 0, therefore
>
> strategy C strictly dominates both A and B.
>
> In other words, by just changing whether we use anti-spam PoWs or fees,
> we change the economically rational behavior.
>
> I apologize for the previous ambiguity and I hope this has made my
> argument clearer.

This can be made "the same" by any of the following methods:

* Burning the up-front fees.
* Locking the up-front fees for a time, then reverting them to the original sender.

Fees and PoW are equivalent. The artificial difference here is that in the PoW case, the PoW cannot be reused by the intermediate node. Then we only need to make the up front fees also not reusable by the intermediate node, which can be done by either of the above. I believe the latter would be more palatable: you pay fees, part of which is just there to prove you are not spamming the network, and which will be returned to you after a few days. Or just provably burn the funds by sending it to a P2WSH containing `OP_RETURN "ZmnSCPxj is not an AI"`.

This lets us get around having to *design* a PoW, which devs have to change every few months to get around the inevitable ASIC targeting the algorithm, and just lets us reuse existing mechanisms (i.e. Bitcoin). The same thing is used in spam prevention in defiads, for example -- the money backing an advertisement is locked, and this justifies the propagation of the advertisement as long as the money remains locked in the UTXO.

Regards, ZmnSCPxj

Orfeas Stefanos Thyfronitis Litos in reply to ZmnSCPxj permalink original

Hello ZmnSCPxj,

Quoted text (3 lines)
> This can be made "the same" by any of the following methods:
>
> * Burning the up-front fees.

This would impose a hard maximum of 21 * 10^6 * 10^8 global lifetime hops, and a much lower practical one. PoW OTOH doesn't impose such limits. Hence different dynamics.

Quoted text (1 line)
> * Locking the up-front fees for a time, then reverting them to the original sender.
This means that I can burst-spam today, wait until unlock, repeat. If the PoW scheme somehow enforces fresh PoWs (e.g. by needing (nonce || recent block hash) as proof), I can't do this attack.
Quoted text (1 line)
> Fees and PoW are equivalent.

If by "equivalent" you mean "a drop-in replacement", then I hope the subtle differences above and the previous discussion show that this is not the case. If by "equivalent" you mean (a formal version of) "for any scheme that uses PoWs, there exists a fee-based scheme with the same incentives and large-scale dynamics", then that's a very strong claim of which I would love to see a proof (and a formal statement).

This is not to say that I believe PoWs are the solution to spam, just that they warrant separate investigation from fees.

Best, Orfeas

Joost Jager in reply to Rusty Russell permalink original

Hi all,

Within our team, we've been discussing the subject of preventing liquidity-consuming spam (aka channel jamming) further. One idea came up that I think is worth sharing.

Previous prepay ideas were based on the sender paying something up-front in case the htlc causes grief on the network. This however leaves the sender vulnerable to nodes stealing that up-front payment.

Consider what is probably the worst known channel jamming attack: an attacker sends minimum sized htlcs to fill up the limited number of commitment slots of channels along the route. Those htlcs will be held as long as possible by the receiving node (that is also controlled by the attacker). The hold time per htlc doesn't even need to be very long, because a fresh htlc can be launched to immediately re-occupy a slot after it opens up again.

The cost to the network of this attack is mostly dependent on the capacity of the channels used. The bigger the capacity, the more funds are locked up if a sufficient number of minimum sized htlcs are pending. The size of the up-front payment likely needs to be proportional to this cost.

This means that for small htlcs, the up-front payment requirements may very well be exceeding the htlc amount and routing fees paid by far. At that point, a routing node may decide to steal the up-front payment rather than earn the routing fee in an honest way.

A different way of mitigating this is to reverse the direction in which the bond is paid. So instead of paying to offer an htlc, nodes need to pay to receive an htlc. This sounds counterintuitive, but for the described jamming attack there is also an attacker node at the end of the route. The attacker still pays. The advantage is that for legitimate senders, there is no up-front payment that can be stolen.

How this would work is that channel peers charge each other for the time that the other party holds an htlc. So if node A extends an htlc to node B, node B will pay node A amount x per minute of hold time. If node B doesn't pay (doesn't hold up the contract), A will close the channel. It can be a running balance between A and B that materializes as a single htlc per channel on the commitment transaction.

As long as node B forwards the htlc swiftly to node C, the dfiference (the actual cost) between what B needs to pay A and what B receives from C will be tiny. Only when the htlc reaches the attacker node, or any other node on the network that is (unintentionally) mishaving for some reason, the delta starts to increase quickly for that node. The cost is borne by the node that should bear it.

This would also fix concerns that have been voiced around hodl invoices. With the reverse bond payment as described above, hodling nodes will pay for the cost of their actions.

Many details skipped over, but interested to hear opinions on the viability of this variation of up-front payments.

Joost

On Tue, Nov 5, 2019 at 3:25 AM Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (56 lines)
> Hi all,
>
>         It's been widely known that we're going to have to have up-front
> payments for msgs eventually, to avoid Type 2 spam (I think of Type 1
> link-local, Type 2 though multiple nodes, and Type 3 liquidity-using
> spam).
>
>         Since both Offers and Joost's WhatSat are looking at sending
> messages, it's time to float actual proposals.  I've been trying to come
> up with something for several years now, so thought I'd present the best
> I've got in the hope that others can improve on it.
>
> 1. New feature bit, extended messages, etc.
> 2. Adding an HTLC causes a *push* of a number of msat on
>    commitment_signed (new field), and a hash.
> 3. Failing/succeeding an HTLC returns some of those msat, and a count
>    and preimage (new fields).
>
> How many msat can you take for forwarding?  That depends on you
> presenting a series of preimages (which chain into a final hash given in
> the HTLC add), which you get by decoding the onion.  You get to keep 50
> msat[1] per preimage you present[2].
>
> So, how many preimages does the user have to give to have you forward
> the payment?  That depends.  The base rate is 16 preimages, but subtract
> one for each leading 4 zero bits of the SHA256(blockhash | hmac) of the
> onion.  The blockhash is the hash of the block specified in the onion:
> reject if it's not in the last 3 blocks[3].
>
> This simply adds some payment noise, while allowing a hashcash style
> tradeoff of sats for work.
>
> The final node gets some variable number of preimages, which adds noise.
> It should take all and subtract from the minimum required invoice amount
> on success, or take some random number on failure.
>
> This leaks some forward information, and makes an explicit tradeoff for
> the sender between amount spent and privacy, but it's the best I've been
> able to come up with.
>
> Thoughts?
> Rusty.
>
> [1] If we assume $1 per GB, $10k per BTC and 64k messages, we get about
>     655msat per message.  Flat pricing for simplicity; we're trying to
>     prevent spam, not create a spam market.
> [2] Actually, a number and a single preimage; you can check this is
>     indeed the n'th preimage.
> [3] This reduces incentive to grind the damn things in advance, though
>     maybe that's dumb?  We can also use a shorter hash (siphash?), or
>     even truncated SHA256 (128 bits).
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Anthony Towns in reply to Joost Jager permalink original

On Tue, Feb 18, 2020 at 10:23:29AM +0100, Joost Jager wrote:

Quoted text (5 lines)
> A different way of mitigating this is to reverse the direction in which the
> bond is paid. So instead of paying to offer an htlc, nodes need to pay to
> receive an htlc. This sounds counterintuitive, but for the described jamming
> attack there is also an attacker node at the end of the route. The attacker
> still pays.

I think this makes a lot of sense. I think the way it would end up working is that the further the route extends, the greater the payments are, so:

  A -> B   : B sends A 1msat per minute
  A -> B -> C : C sends B 2msat per minute, B forwards 1msat/min to A
  A -> B -> C -> D : D sends C 3 msat, etc
  A -> B -> C -> D -> E : E sends D 4 msat, etc

so each node is receiving +1 msat/minute, except for the last one, who's paying n msat/minute, where n is the number of hops to have gotten up to the last one. There's the obvious privacy issue there, with fairly obvious ways to fudge around it, I think.

But that's rational, because that last node can either (a) collect the payment, covering their cost; or (b) forward the payment, at which point they'll start collecting funds rather than paying them; or (c) cancel the payment releasing all the locked up funds all the way back.

I think it might make sense for the payments to have a grace period -- ie, "if you keep this payment open longer than 20 seconds, you have to start paying me x msat/minute, but if it fulfills or cancels before then, it's all good".

I'm not sure if there needs to be any enforcement for this beyond "this peer isn't obeying the protocol, so I'm going to close the channel"; not even sure it's something that needs to be negotiated as part of payment routing -- it could just be something each peer does for HTLCs on their channels? If that can be made to work, it doesn't need much crypto or bitcoin consensus changes, or even much deployment coordination, all of which would be awesome.

I think at $10k/BTC then 1msat is about the fair price for locking up $5 worth of BTC (so 50k sat) for 1 minute at a 1% pa interest rate, fwiw.

Maybe this opens up some sort of an attack where a peer lies about the time to make the "per minute" go faster, but if msats-per-minute is the units, not sure that really matters.

Maybe this also implies a different protocol for HTLC forwarding, something like:

  1. A sends the HTLC onion packet to B
  2. B decrypts it, makes sure it makes sense
  3. B sends a half-signed updated channel state back to A
  4. A accepts it, and forwards the other half-signed channel update to B

so that at any point before (4) Alice can say "this is taking too long, I'll start losing money" and safely abort the HTLC she was forwarding to Bob to avoid paying fees; while only after (4) can she start the time on expecting Bob to start paying fees that she'll forward back. That means 1.5 round-trips before Bob can really forward the HTLC on to Carol; but maybe it's parallelisable, so Bob/Carol could start at (1) as soon as Alice/Bob has finished (2).

Cheers aj

ZmnSCPxj in reply to Anthony Towns permalink original

Good morning Joost and aj,

A thought that arises here is, what happens if I have forwarded a payment, then the outgoing channel is dropped onchain and that peer disconnects from me?

Since the onchain HTLC might have a timelock of, say, a few hundred blocks from now, the outgoing peer can claim it up until the timelock. If the peer does not claim it, I cannot claim it in my incoming as well. I also cannot safely fail my incoming, as the outgoing peer can still claim it until the timelock expires.

Am I liable for paying the encumbrance fee in this situation? How do I charge the next node the encumbrance fee myself if it has dropped the channel onchain and disconnected from me?

Regards, ZmnSCPxj

Quoted text (69 lines)
> On Tue, Feb 18, 2020 at 10:23:29AM +0100, Joost Jager wrote:
>
> > A different way of mitigating this is to reverse the direction in which the
> > bond is paid. So instead of paying to offer an htlc, nodes need to pay to
> > receive an htlc. This sounds counterintuitive, but for the described jamming
> > attack there is also an attacker node at the end of the route. The attacker
> > still pays.
>
> I think this makes a lot of sense. I think the way it would end up working
> is that the further the route extends, the greater the payments are, so:
>
> A -> B : B sends A 1msat per minute
> A -> B -> C : C sends B 2msat per minute, B forwards 1msat/min to A
> A -> B -> C -> D : D sends C 3 msat, etc
> A -> B -> C -> D -> E : E sends D 4 msat, etc
>
> so each node is receiving +1 msat/minute, except for the last one, who's
> paying n msat/minute, where n is the number of hops to have gotten up to
> the last one. There's the obvious privacy issue there, with fairly
> obvious ways to fudge around it, I think.
>
> But that's rational, because that last node can either (a) collect the
> payment, covering their cost; or (b) forward the payment, at which point
> they'll start collecting funds rather than paying them; or (c) cancel
> the payment releasing all the locked up funds all the way back.
>
> I think it might make sense for the payments to have a grace period --
> ie, "if you keep this payment open longer than 20 seconds, you have to
> start paying me x msat/minute, but if it fulfills or cancels before
> then, it's all good".
>
> I'm not sure if there needs to be any enforcement for this beyond "this
> peer isn't obeying the protocol, so I'm going to close the channel"; not
> even sure it's something that needs to be negotiated as part of payment
> routing -- it could just be something each peer does for HTLCs on their
> channels? If that can be made to work, it doesn't need much crypto or
> bitcoin consensus changes, or even much deployment coordination, all of
> which would be awesome.
>
> I think at $10k/BTC then 1msat is about the fair price for locking up $5
> worth of BTC (so 50k sat) for 1 minute at a 1% pa interest rate, fwiw.
>
> Maybe this opens up some sort of an attack where a peer lies about the
> time to make the "per minute" go faster, but if msats-per-minute is the
> units, not sure that really matters.
>
> Maybe this also implies a different protocol for HTLC forwarding,
> something like:
>
> 1.  A sends the HTLC onion packet to B
> 2.  B decrypts it, makes sure it makes sense
> 3.  B sends a half-signed updated channel state back to A
> 4.  A accepts it, and forwards the other half-signed channel update to B
>
>     so that at any point before (4) Alice can say "this is taking too long,
>     I'll start losing money" and safely abort the HTLC she was forwarding to
>     Bob to avoid paying fees; while only after (4) can she start the time on
>     expecting Bob to start paying fees that she'll forward back. That means
>     1.5 round-trips before Bob can really forward the HTLC on to Carol;
>     but maybe it's parallelisable, so Bob/Carol could start at (1) as soon
>     as Alice/Bob has finished (2).
>
>     Cheers
>     aj
>
>
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
Anthony Towns in reply to ZmnSCPxj permalink original

On Thu, Feb 20, 2020 at 03:42:39AM +0000, ZmnSCPxj wrote:

Quoted text (5 lines)
> A thought that arises here is, what happens if I have forwarded a payment, then the outgoing channel is dropped onchain and that peer disconnects from me?
>
> Since the onchain HTLC might have a timelock of, say, a few hundred blocks from now, the outgoing peer can claim it up until the timelock.
> If the peer does not claim it, I cannot claim it in my incoming as well.
> I also cannot safely fail my incoming, as the outgoing peer can still claim it until the timelock expires.

Suppose the channel state looks like:

  Bob's balance:   $150
  Carol's balance: $500
  Bob to Carol:     $50, hash X, timelock +2016 blocks

The pre-signed close transaction will have already deducted maybe $1 in fees, say 50c from each balance.

At 5% pa, that's $50*0.05*2/52, so about 10 cents worth of "holding" fees, so that seems like it's worth just committing to up-front, ie:

  Bob's balance:   $149.60 (-.50+.10)
  Carol's balance: $499.40 (-.50-.10)
  Bob to Carol:     $50, hash X, timelock +2016 blocks
  Fees:              $1

And that seems necessary anyway: if the channel does drop to the chain, then the HTLC can't be cancelled, so if it never confirms, Bob will have had to pay, say, 9.5c to Alice waiting for the timeout, and can then immediately cancel the HTLC with Alice allowing it to finish unwinding.

So I think the idea would be not to accept a (rate, amount, timelock) tuple for an incoming HTLC unless the rate*amount*timelock product is substantially less than what you're putting towards the blockchain fees anyway, as otherwise you've got bad incentives for the other guy to drop to the chain.

Note the rate increases with number of hops, so if it's 1% pa per hop, the 11th peer will be emitting 10% pa. I think that's probably okay, because BTC's deflationary nature probably means you don't need to earn much interest on it, and you can naturally choose the rate dynamically based on how many HTLCs you currently have open and how much of your channel funds are being used up by the HTLC?

Also, you'd presumably update your channel state every hundred blocks, reducing the 10c by half a cent or so each time, so you could have your risk reduce. Maybe there could be some way of bumping the timelock across a HTLC path so that the risk is capped, but if the HTLC is still being paid for it doesn't have to be cancelled?

Cheers, aj

Rusty Russell in reply to Anthony Towns permalink original

Anthony Towns <aj at erisian.com.au> writes:

Quoted text (19 lines)
> On Tue, Feb 18, 2020 at 10:23:29AM +0100, Joost Jager wrote:
>> A different way of mitigating this is to reverse the direction in which the
>> bond is paid. So instead of paying to offer an htlc, nodes need to pay to
>> receive an htlc. This sounds counterintuitive, but for the described jamming
>> attack there is also an attacker node at the end of the route. The attacker
>> still pays.
>
> I think this makes a lot of sense. I think the way it would end up working
> is that the further the route extends, the greater the payments are, so:
>
>   A -> B   : B sends A 1msat per minute
>   A -> B -> C : C sends B 2msat per minute, B forwards 1msat/min to A
>   A -> B -> C -> D : D sends C 3 msat, etc
>   A -> B -> C -> D -> E : E sends D 4 msat, etc
>
> so each node is receiving +1 msat/minute, except for the last one, who's
> paying n msat/minute, where n is the number of hops to have gotten up to
> the last one. There's the obvious privacy issue there, with fairly
> obvious ways to fudge around it, I think.

Yes, it needs to scale with distance to work at all. However, it has the same problems with other upfront schemes: how does E know to send 4msat per minute?

Quoted text (4 lines)
> I think it might make sense for the payments to have a grace period --
> ie, "if you keep this payment open longer than 20 seconds, you have to
> start paying me x msat/minute, but if it fulfills or cancels before
> then, it's all good".

But whatever the grace period, I can just rely on knowing that B is in Australia (with a 1 second HTLC commit time) to make that node bleed satoshis. I can send A->B->C, and have C fail the htlc after 19 seconds for free. But B has to send 1msat to A. B can't blame A or C, since this attack could come from further away, too.

This attack always seems possible. Are you supposed to pay immediately to fail an HTLC? That makes for a trivial attack, so I guess not.

And if there is a grace period, I can just gum up the network with lots of slow-but-not-slow-enough HTLCs.

Quoted text (15 lines)
> Maybe this also implies a different protocol for HTLC forwarding,
> something like:
>
>   1. A sends the HTLC onion packet to B
>   2. B decrypts it, makes sure it makes sense
>   3. B sends a half-signed updated channel state back to A
>   4. A accepts it, and forwards the other half-signed channel update to B
>
> so that at any point before (4) Alice can say "this is taking too long,
> I'll start losing money" and safely abort the HTLC she was forwarding to
> Bob to avoid paying fees; while only after (4) can she start the time on
> expecting Bob to start paying fees that she'll forward back. That means
> 1.5 round-trips before Bob can really forward the HTLC on to Carol;
> but maybe it's parallelisable, so Bob/Carol could start at (1) as soon
> as Alice/Bob has finished (2).

We added a ping-before-commit[1] to avoid the case where B has disconnected and we don't know yet; we have to assume an HTLC is stuck once we send commitment_signed. This would be a formalization of that, but I don't think it's any better?

There's an old proposal to fast-fail HTLCs: Bob sends an new message "I would fail this HTLC once it's committed, here's the error" and if Alice gets it before she sends the commitment_signed, she sends a new "unadd_htlc" message first. This theoretically allows Bob to do the same: optimistically forward it, and unadd it if Alice doesn't commit with it in time.[2]

Cheers, Rusty.

[1] Technically, if we haven't seen any traffic from the peer in the
    last 30 seconds, we send a ping and wait.
[2] This seems like a speedup, but it only is if someone fails the HTLC.
    We still need to send the commitment_signed back and forth (w/
    revoke and ack) before committing to it in the next hop.
Anthony Towns in reply to Rusty Russell permalink original

On Fri, Feb 21, 2020 at 12:35:20PM +1030, Rusty Russell wrote:

Quoted text (13 lines)
> > I think the way it would end up working
> > is that the further the route extends, the greater the payments are, so:
> >   A -> B   : B sends A 1msat per minute
> >   A -> B -> C : C sends B 2msat per minute, B forwards 1msat/min to A
> >   A -> B -> C -> D : D sends C 3 msat, etc
> >   A -> B -> C -> D -> E : E sends D 4 msat, etc
> > so each node is receiving +1 msat/minute, except for the last one, who's
> > paying n msat/minute, where n is the number of hops to have gotten up to
> > the last one. There's the obvious privacy issue there, with fairly
> > obvious ways to fudge around it, I think.
> Yes, it needs to scale with distance to work at all.  However, it has
> the same problems with other upfront schemes: how does E know to send
> 4msat per minute?

D tells it "if you want this HTLC, you'll need to pay 4msat/minute after the grace period of 65 seconds". Which also means A as the originator can also choose whatever fees they like. The only consequence of choosing too high a fee is that it's more likely one of the intermediate nodes will say "screw that!" and abort the HTLC before it gets to the destination.

Quoted text (9 lines)
> > I think it might make sense for the payments to have a grace period --
> > ie, "if you keep this payment open longer than 20 seconds, you have to
> > start paying me x msat/minute, but if it fulfills or cancels before
> > then, it's all good".
> But whatever the grace period, I can just rely on knowing that B is in
> Australia (with a 1 second HTLC commit time) to make that node bleed
> satoshis.  I can send A->B->C, and have C fail the htlc after 19
> seconds for free.  But B has to send 1msat to A.  B can't blame A or C,
> since this attack could come from further away, too.

So A gives B a grace period of 35 seconds, B deducts 5 seconds processing time and 10 seconds for latency, so gives C a grace period of 20 seconds; C rejects after 19 seconds, and B still has 15 seconds to notify A before he has to start paying fees. Same setup as decreasing timelocks when forwarding HTLCs.

Quoted text (2 lines)
> And if there is a grace period, I can just gum up the network with lots
> of slow-but-not-slow-enough HTLCs.

Well, it reduces the "gum up the network for <timeout> blocks" to "gum up the network for <grace period> seconds", which seems like a pretty big win. I think if you had 20 hops each with a 1 minute grace period, and each channel had a max_accepted_htlcs of 30, you'd need 25 HTLCs per second to block 1000 channels (so 2.7% of the 36k channels 1ml reports), so at the very least, successfully performing this attack would be demonstrating lightning's solved bitcoin's transactions-per-second limitation?

I think you could do better by having the acceptable grace period be dynamic: both (a) requiring a shorter grace period the more funds a HTLC locks up, which stops a single HTLC from gumming up the channel, and (b) requiring a shorter grace period the more active HTLCs you have (or, the more active HTLCs you have that are in the grace period, perhaps). That way if the network is loaded, you're prioritising more efficient routes (or at least ones that are willing to pay their way), and if it's under attack, you're dynamically increasing the resources needed to maintain the attack.

Anyway, that's my hot take; not claiming it's a perfect solution or final answer, rather that this still seems worth brainstorming out.

My feeling is that this might interact nicely with the sender-initiated upfront fee. Like, you could replace a grace period of 30 seconds at 2msat/minute by always charging 2msat/minute but doing a forward payment of 1msat. But at this point I can't keep it all in my head at once to figure out something that really makes sense.

Quoted text (17 lines)
> > Maybe this also implies a different protocol for HTLC forwarding,
> > something like:
> >   1. A sends the HTLC onion packet to B
> >   2. B decrypts it, makes sure it makes sense
> >   3. B sends a half-signed updated channel state back to A
> >   4. A accepts it, and forwards the other half-signed channel update to B
> > so that at any point before (4) Alice can say "this is taking too long,
> > I'll start losing money" and safely abort the HTLC she was forwarding to
> > Bob to avoid paying fees; while only after (4) can she start the time on
> > expecting Bob to start paying fees that she'll forward back. That means
> > 1.5 round-trips before Bob can really forward the HTLC on to Carol;
> > but maybe it's parallelisable, so Bob/Carol could start at (1) as soon
> > as Alice/Bob has finished (2).
> We added a ping-before-commit[1] to avoid the case where B has disconnected
> and we don't know yet; we have to assume an HTLC is stuck once we send
> commitment_signed.  This would be a formalization of that, but I don't
> think it's any better?

I don't think it's any better as things stand, but with the "B pays A holding fees" I think it becomes necessary. If you've got a route A->B->C then from B's perspective I think it currently looks like:

  A->B: here's a HTLC, locked in
  B->C: ping
  C->B: pong!
  B->C: updated commitment with HTLC locked in
  C->B: *silence*

at which point the best B can do is unilaterally close the B/C channel with their pre-HTLC commitment, but they still have to wait for that to confirm before they can safely cancel the HTLC with A, and that will likely take more than whatever the grace period is, so B will be losing money on holding fees.

Whereas:

  A->B: here's a HTLC, locked in
  B->C: HTLC proposal
  C->B: sure: updated commitment with HTLC locked in
  B->C: great, corresponding updated commitment, plus revocation
  C->B: revocation

means that if C goes silent before B receives a new commitment, B can cancel the HTLC with A with no risk (B can publish the old commitment still even if the new arrives later, and C can only publish the pre-HTLC commitment), and if C goes silent after B receives the new commitment, B can drop the new commitment to the blockchain and pay A's fees out of it.

Quoted text (2 lines)
> There's an old proposal to fast-fail HTLCs: Bob sends an new message "I
> would fail this HTLC once it's committed, here's the error"

Yeah, you could do "B->C: proposal, C->B: no way!" instead of "sure" to fast fail the above too.

And I think something like that's necessary (at least with my view of how this "keep the HTLC open" payment would work), otherwise B could send C a "1 microsecond grace period, rate of 3e11 msat/minute, HTLC for 100 sat, timeout of 2016 blocks" and if C couldn't reject it immediately would owe B 50c per millisecond it took to cancel.

Cheers, aj

Rusty Russell in reply to Anthony Towns permalink original

Anthony Towns <aj at erisian.com.au> writes:

Quoted text (12 lines)
> On Fri, Feb 21, 2020 at 12:35:20PM +1030, Rusty Russell wrote:
>> And if there is a grace period, I can just gum up the network with lots
>> of slow-but-not-slow-enough HTLCs.
>
> Well, it reduces the "gum up the network for <timeout> blocks" to "gum
> up the network for <grace period> seconds", which seems like a pretty
> big win. I think if you had 20 hops each with a 1 minute grace period,
> and each channel had a max_accepted_htlcs of 30, you'd need 25 HTLCs per
> second to block 1000 channels (so 2.7% of the 36k channels 1ml reports),
> so at the very least, successfully performing this attack would be
> demonstrating lightning's solved bitcoin's transactions-per-second
> limitation?

But the comparison here is not with the current state, but with the "best previous proposal we have", which is:

1. Charge an up-front fee for accepting any HTLC.
2. Will hang-up after grace period unless you either prove a channel
   close, or gain another grace period by decrypting onion.

(There was is an obvious extension to this, where you pay another HTLC first which covers the (larger) up-front fee for the "I know the next HTLC is going to take a long time").

That proposal is simpler, and covers this case quite nicely.

Quoted text (20 lines)
> at which point the best B can do is unilaterally close the B/C channel
> with their pre-HTLC commitment, but they still have to wait for that to
> confirm before they can safely cancel the HTLC with A, and that will
> likely take more than whatever the grace period is, so B will be losing
> money on holding fees.
>
> Whereas:
>
>   A->B: here's a HTLC, locked in
>
>   B->C: HTLC proposal
>   C->B: sure: updated commitment with HTLC locked in
>   B->C: great, corresponding updated commitment, plus revocation
>   C->B: revocation
>
> means that if C goes silent before B receives a new commitment, B can
> cancel the HTLC with A with no risk (B can publish the old commitment
> still even if the new arrives later, and C can only publish the pre-HTLC
> commitment), and if C goes silent after B receives the new commitment, B
> can drop the new commitment to the blockchain and pay A's fees out of it.

Interesting; this adds a trip, but not in latency (since C can still count on the HTLC being locked in at step 3).

I don't see how it helps B though? It still ends up paying A, and C doesn't pay anything?

It forces a liveness check of C, but TBH I dread rewriting the state machine for this when we can just ping like we do now.

Quoted text (11 lines)
>> There's an old proposal to fast-fail HTLCs: Bob sends an new message "I
>> would fail this HTLC once it's committed, here's the error"
>
> Yeah, you could do "B->C: proposal, C->B: no way!" instead of "sure" to
> fast fail the above too.
>
> And I think something like that's necessary (at least with my view of how
> this "keep the HTLC open" payment would work), otherwise B could send C a
> "1 microsecond grace period, rate of 3e11 msat/minute, HTLC for 100 sat,
> timeout of 2016 blocks" and if C couldn't reject it immediately would
> owe B 50c per millisecond it took to cancel.

Well, surely grace period (and penalty rate) are either fixed in the protocol or negotiated up-front, not per-HTLC.

Cheers, Rusty.

Anthony Towns in reply to Rusty Russell permalink original

On Mon, Feb 24, 2020 at 01:29:36PM +1030, Rusty Russell wrote:

Quoted text (18 lines)
> Anthony Towns <aj at erisian.com.au> writes:
> > On Fri, Feb 21, 2020 at 12:35:20PM +1030, Rusty Russell wrote:
> >> And if there is a grace period, I can just gum up the network with lots
> >> of slow-but-not-slow-enough HTLCs.
> > Well, it reduces the "gum up the network for <timeout> blocks" to "gum
> > up the network for <grace period> seconds", which seems like a pretty
> > big win. I think if you had 20 hops each with a 1 minute grace period,
> > and each channel had a max_accepted_htlcs of 30, you'd need 25 HTLCs per
> > second to block 1000 channels (so 2.7% of the 36k channels 1ml reports),
> > so at the very least, successfully performing this attack would be
> > demonstrating lightning's solved bitcoin's transactions-per-second
> > limitation?
> But the comparison here is not with the current state, but with the
> "best previous proposal we have", which is:
>
> 1. Charge an up-front fee for accepting any HTLC.
> 2. Will hang-up after grace period unless you either prove a channel
>    close, or gain another grace period by decrypting onion.

In general I don't really like comparing ideas that are still in brainstorming mode; it's never clear whether there are unavoidable pitfalls in one or the other that won't become clear until they're actually implemented...

Specifically, I'm not a fan of either channel closes or peeling the onion -- the former causes problems if you're trying to route across sidechains or have lightning as a third layer above channel factories or similar, and I'm not convinced even within Bitcoin "proving a channel close" is that meaningful, and passing around decrypted onions seems like it opens up privacy attacks.

Aside from those philosophical complaints, seems to me the simplest attack would be:

  * route 1000s of HTLCs from your node A1 to your node A2 via different,
    long paths, using up the total channel capacity of your A1/A2 nodes,
    with long timeouts
  * have A2 offer up a transaction claiming that was the channel
    close to A3; make it a real thing if necessary, but it's probably
    fake-able
  * then leave the HTLCs open until they time out, using up capacity
    from all the nodes in your 1000s of routes. For every satoshi of
    yours that's tied up, you should be able to tie up 10-20sat of other
    people's funds

That increases the cost of the attack by one on-chain transaction per timeout period, and limits the attack surface by how many transactions you can get started/completed within whatever the grace period is, but it doesn't seem a lot better than what we have today, unless onchain fees go up a lot.

(If the up-front fee is constant, then A1 paid a fee, and A2 collected a fee so it's a net wash; if it's not constant then you've got a lot of hassle making it work with any privacy I think)

Quoted text (9 lines)
> >   A->B: here's a HTLC, locked in
> >   B->C: HTLC proposal
> >   C->B: sure: updated commitment with HTLC locked in
> >   B->C: great, corresponding updated commitment, plus revocation
> >   C->B: revocation
> Interesting; this adds a trip, but not in latency (since C can still
> count on the HTLC being locked in at step 3).
> I don't see how it helps B though?  It still ends up paying A, and C
> doesn't pay anything?

The updated commitment has C paying B onchain; if B doesn't receive that by the time the grace period's about over, B can cancel the HTLC with A, and then there's statemachine complexity for B to cancel it with C if C comes alive again a little later.

Quoted text (2 lines)
> It forces a liveness check of C, but TBH I dread rewriting the state
> machine for this when we can just ping like we do now.

I'd be surprised if making musig work doesn't require a dread rewrite of the state machine as well, and then there's PTLCs and eltoo...

Quoted text (11 lines)
> >> There's an old proposal to fast-fail HTLCs: Bob sends an new message "I
> >> would fail this HTLC once it's committed, here's the error"
> > Yeah, you could do "B->C: proposal, C->B: no way!" instead of "sure" to
> > fast fail the above too.
> > And I think something like that's necessary (at least with my view of how
> > this "keep the HTLC open" payment would work), otherwise B could send C a
> > "1 microsecond grace period, rate of 3e11 msat/minute, HTLC for 100 sat,
> > timeout of 2016 blocks" and if C couldn't reject it immediately would
> > owe B 50c per millisecond it took to cancel.
> Well, surely grace period (and penalty rate) are either fixed in the
> protocol or negotiated up-front, not per-HTLC.

I think the "keep open rate" should depend on how many nodes have already been in the route (the more hops it's gone through, the more funds/channels you're tying up by holding onto the HTLC, so the more you should pay), while the grace period should depend on how many nodes there are still to go in the route (it needs to be higher to let each of those nodes deduct their delta from it). So I think you *should* expect those to change per HTLC than you're forwarding, as those factors will be different for different HTLCs.

Cheers, aj

Rusty Russell in reply to Anthony Towns permalink original

Anthony Towns <aj at erisian.com.au> writes:

Quoted text (19 lines)
> Aside from those philosophical complaints, seems to me the simplest
> attack would be:
>
>   * route 1000s of HTLCs from your node A1 to your node A2 via different,
>     long paths, using up the total channel capacity of your A1/A2 nodes,
>     with long timeouts
>   * have A2 offer up a transaction claiming that was the channel
>     close to A3; make it a real thing if necessary, but it's probably
>     fake-able
>   * then leave the HTLCs open until they time out, using up capacity
>     from all the nodes in your 1000s of routes. For every satoshi of
>     yours that's tied up, you should be able to tie up 10-20sat of other
>     people's funds
>
> That increases the cost of the attack by one on-chain transaction per
> timeout period, and limits the attack surface by how many transactions
> you can get started/completed within whatever the grace period is, but
> it doesn't seem a lot better than what we have today, unless onchain
> fees go up a lot.

Interestingly, I think your "reverse commitment signing" proposal would mean the close tx will have the HTLC within it, so this attack is not possible? (Modulo handling dust HTLCs, which won't show up in the commitment tx).

Previously I suggested the node simply send a (signed) list of up to N additional HTLCs (this reduces batching to N, so make it at least 16). This is gossiped, and if you get conflicting versions, the channel break is considered invalid, so (as always) the previous channel has to break.

Quoted text (14 lines)
>> >   A->B: here's a HTLC, locked in
>> >   B->C: HTLC proposal
>> >   C->B: sure: updated commitment with HTLC locked in
>> >   B->C: great, corresponding updated commitment, plus revocation
>> >   C->B: revocation
>> Interesting; this adds a trip, but not in latency (since C can still
>> count on the HTLC being locked in at step 3).
>> I don't see how it helps B though?  It still ends up paying A, and C
>> doesn't pay anything?
>
> The updated commitment has C paying B onchain; if B doesn't receive that
> by the time the grace period's about over, B can cancel the HTLC with A,
> and then there's statemachine complexity for B to cancel it with C if
> C comes alive again a little later.

I thought C paid per unit time, so it wouldn't pay up-front? You're suggesting it pays the max in the commitment, and then it gets some back in the normal case of things going right?

Quoted text (5 lines)
>> It forces a liveness check of C, but TBH I dread rewriting the state
>> machine for this when we can just ping like we do now.
>
> I'd be surprised if making musig work doesn't require a dread rewrite
> of the state machine as well, and then there's PTLCs and eltoo...

Hmm, PTLCs and eltoo don't. Musig requires some mods to the protocol, but the state machine changes are trivial.

Quoted text (20 lines)
>> >> There's an old proposal to fast-fail HTLCs: Bob sends an new message "I
>> >> would fail this HTLC once it's committed, here's the error"
>> > Yeah, you could do "B->C: proposal, C->B: no way!" instead of "sure" to
>> > fast fail the above too.
>> > And I think something like that's necessary (at least with my view of how
>> > this "keep the HTLC open" payment would work), otherwise B could send C a
>> > "1 microsecond grace period, rate of 3e11 msat/minute, HTLC for 100 sat,
>> > timeout of 2016 blocks" and if C couldn't reject it immediately would
>> > owe B 50c per millisecond it took to cancel.
>> Well, surely grace period (and penalty rate) are either fixed in the
>> protocol or negotiated up-front, not per-HTLC.
>
> I think the "keep open rate" should depend on how many nodes have
> already been in the route (the more hops it's gone through, the more
> funds/channels you're tying up by holding onto the HTLC, so the more
> you should pay), while the grace period should depend on how many nodes
> there are still to go in the route (it needs to be higher to let each of
> those nodes deduct their delta from it). So I think you *should* expect
> those to change per HTLC than you're forwarding, as those factors will
> be different for different HTLCs.

In theory, but I could lie about both, and it's very undesirable to communicate these things anyway. I think it might make it worse, not better, than having a fixed (per-msat?) rate.

Cheers, Rusty.

Joost Jager in reply to Anthony Towns permalink original

On Thu, Feb 20, 2020 at 4:22 AM Anthony Towns <aj at erisian.com.au> wrote:

Quoted text (23 lines)
> On Tue, Feb 18, 2020 at 10:23:29AM +0100, Joost Jager wrote:
> > A different way of mitigating this is to reverse the direction in which
> the
> > bond is paid. So instead of paying to offer an htlc, nodes need to pay to
> > receive an htlc. This sounds counterintuitive, but for the described
> jamming
> > attack there is also an attacker node at the end of the route. The
> attacker
> > still pays.
>
> I think this makes a lot of sense. I think the way it would end up working
> is that the further the route extends, the greater the payments are, so:
>
>   A -> B   : B sends A 1msat per minute
>   A -> B -> C : C sends B 2msat per minute, B forwards 1msat/min to A
>   A -> B -> C -> D : D sends C 3 msat, etc
>   A -> B -> C -> D -> E : E sends D 4 msat, etc
>
> so each node is receiving +1 msat/minute, except for the last one, who's
> paying n msat/minute, where n is the number of hops to have gotten up to
> the last one. There's the obvious privacy issue there, with fairly
> obvious ways to fudge around it, I think.
>

Yes, that is definitely a good point. Otherwise the attacker can hold the htlc at the end of the route and pay the hold fee to its predecessor. The hold fee will propagate back to the first node (and increase along the way). The first node is also owned by the attacker. Meaning there again is no cost for the attacker to jam the channel.

In the mean time, I've been jamming channels on testnet myself. See what pathfinding changes are needed to do it efficiently and check out the effect. There was the expected outcome of a channel being jammed for as long as I wanted. But I also learned something else:

Traversing a path takes time, especially if the path is optimized for maximum length and contains loops. In particular when some of the nodes and/or network connections are slow, the total round-trip from the sender point of view can get seriously long. Even if the final node immediately fails the htlc, the nodes at the start of the path still see their outgoing htlcs being held for quite some time.

What this means is that the channel jamming attack can also be executed without the attacker controlling the final node. The attacker can construct long routes for which it doesn't matter where they end. Suppose it takes 1 minute for the htlc to be released again on the channel that is targeted (the round trip from the targeted channel to the final node). The attacker just needs to launch htlcs at a rate higher than one per minute to (eventually) saturate the channel. In my experiment, I launched many htlcs concurrently, which seemed to make the total latency even longer. Probably because those htlcs then start competing for limited resources at the route hops.

This variation does require more action from the attacker. They need to keep refreshing htlcs that return back to them. Therefore it may be easier to address this with some form of rate limiting, although that has its own downsides.

Joost