Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

AMP: Atomic Multi-Path Payments over Lightning

23 messages, Feb 6 to 21, 2018. Started by Olaoluwa Osuntokun.

ZmnSCPxj (4), Rusty Russell (3), Christian Decker (3), Olaoluwa Osuntokun (2), Conner Fromknecht (2), Jim Posen (2), Johan Torås Halseth (2), Corné Plooy (2), +3 more

Permalink First message in the Wayback Machine

Olaoluwa Osuntokun permalink original

Hi Y'all,

A common question I've seen concerning Lightning is: "I have five $2 channels, is it possible for me to *atomically* send $6 to fulfill a payment?". The answer to this question is "yes", provided that the receiver waits to pull all HTLC's until the sum matches their invoice. Typically, one assumes that the receiver will supply a payment hash, and the sender will re-use the payment hash for all streams. This has the downside of payment hash re-use across *multiple* payments (which can already easily be correlated), and also has a failure mode where if the sender fails to actually satisfy all the payment flows, then the receiver can still just pull the monies (and possibly not disperse a service, or w/e).

Conner Fromknecht and I have come up with a way to achieve this over Lightning while (1) not re-using any payment hashes across all payment flows, and (2) adding a *strong* guarantee that the receiver won't be paid until *all* partial payment flows are extended. We call this scheme AMP (Atomic Multi-path Payments). It can be experimented with on Lightning *today* with the addition of a new feature bit to gate this new feature. The beauty of the scheme is that it requires no fundamental changes to the protocol as is now, as the negotiation is strictly *end-to-end* between sender and receiver.

TL;DR: we repurpose some unused space in the onion per-hop payload of the onion blob to signal our protocol (and deliver some protocol-specific data), then use additive secret sharing to ensure that the receiver can't pull the payment until they have enough shares to reconstruct the original pre-image.

Protocol Goals ============== 1. Atomicity: The logical transaction should either succeed or fail in entirety. Naturally, this implies that the receiver should not be unable to settle *any* of the partial payments, until all of them have arrived.

2. Avoid Payment Hash Reuse: The payment preimages validated by the consensus layer should be distinct for each partial payment. Primarily, this helps avoid correlation of the partial payments, and ensures that malicious intermediaries straddling partial payments cannot steal funds.

3. Order Invariance: The protocol should be forgiving to the order in which partial payments arrive at the destination, adding robustness in the face of delays or routing failures.

4. Non-interactive Setup: It should be possible for the sender to perform an AMP without directly coordinating with the receiving node. Predominantly, this means that the *sender* is able to determine the number of partial payments to use for a particular AMP, which makes sense since they will be the one fronting the fees for the cost of this parameter. Plus, we can always turn a non-interactive protocol into an interactive one for the purposes of invoicing.

Protocol Benefits =================

Sending pay payments predominantly over an AMP-like protocol has several clear benefits:

  - Eliminates the constraint that a single path from sender to receiver
    with sufficient directional capacity. This reduces the pressure to have
    larger channels in order to support larger payment flows. As a result,
    the payment graph be very diffused, without sacrificing payment
    utility
  - Reduces strain from larger payments on individual paths, and allows the
    liquidity imbalances to be more diffuse. We expect this to have a
    non-negligible impact on channel longevity. This is due to the fact that
    with usage of AMP, payment flows are typically *smaller* meaning that
    each payment will unbalance a channel to a lesser degree that
    with one giant flow.
  - Potential fee savings for larger payments, contingent on there being a
    super-linear component to routed fees. It's possible that with
    modifications to the fee schedule, it's actually *cheaper* to send
    payments over multiple flows rather than one giant flow.
  - Allows for logical payments larger than the current maximum value of an
    individual payment. Atm we have a (temporarily) limit on the max payment
    size. With AMP, this can be side stepped as each flow can be up the max
    size, with the sum of all flows exceeding the max.
  - Given sufficient path diversity, AMPs may improve the privacy of LN
    Intermediaries are now unaware to how much of the total payment they are
    forwarding, or even if they are forwarding a partial payment at all.
  - Using smaller payments increases the set of possible paths a partial
    payment could have taken, which reduces the effectiveness of static
    analysis techniques involving channel capacities and the plaintext
    values being forwarded.

Protocol Overview ================== This design can be seen as a generalization of the single, non-interactive payment scheme, that uses decoding of extra onion blobs (EOBs?) to encode extra data for the receiver. In that design, the extra data includes a payment preimage that the receiver can use to settle back the payment. EOBs and some method of parsing them are really the only requirement for this protocol to work. Thus, only the sender and receiver need to implement this feature in order for it to function, which can be announced using a feature bit.

First, let's review the current format of the per-hop payload for each node described in BOLT-0004.

┌───────────────┬───────────────────┬────────────────┬───────────────────────┬─────────────────┬─────────────────┐
│Realm (1 byte) │Next Addr (8 bytes)│Amount (8 bytes)│Outgoing CLTV (4
bytes)│Unused (12 bytes)│ HMAC (32 bytes) │
└───────────────┴───────────────────┴────────────────┴───────────────────────┴─────────────────┴─────────────────┘
■────────────────────────────────────────────────────────────────────────────────────────────────────────────────■
                                              ┌─────────────────┐
                                              │65 Bytes Per Hop │
                                              └─────────────────┘

Currently, *each* node gets a 65-byte payload. We use this payload to give each node instructions on *how* to forward a payment. We tell each node: the realm (or chain to forward on), then next node to forward to, the amount to forward (this is where fees are extracted by forwarding out less than in), the outgoing CLTV (allows verification that the prior node didn't modify any values), and finally an HMAC over the entire thing.

Two important points:
  1. We have 12 bytes for each hop that are currently unpurposed and can be
  used by application protocols to signal new interpretation of bytes and
  also deliver additional encrypted+authenticated data to *each* hop.
  2. The protocol currently has a hard limit of 20-hops. With this feature
  we ensure that the packet stays fixed sized during processing in order to
  avoid leaking positional information. Typically most payments won't use
  all 20 hops, as a result, we can use the remaining hops to stuff in *even
  more* data.

Protocol Description ==================== The solution we propose is Atomic Multi-path Payments (AMPs). At a high level, this leverages EOBs to deliver additive shares of a base preimage, from which the payment preimages of partial payments can be derived. The receiver can only construct this value after having received all of the partial payments, satisfying the atomicity constraint.

The basic protocol:

Primitives
==========
Let H be a CRH function.
Let || denote concatenation.
Let ^ denote xor.

Sender Requirements =================== The parameters to the sending procedure are a random identifier ID, the number of partial payments n, and the total payment value V. Assume the sender has some way of dividing V such that V = v_1 + … + v_n.

To begin, the sender builds the base preimage BP, from which n partial preimages will be derived. Next, the sender samples n additive shares s_1, …, s_n, and takes the sum to compute BP = s_1 ^ … ^ s_n.

With the base preimage created, the sender now moves on to constructing the
n partial payments. For each i in [1,n], the sender deterministically
computes the partial preimage r_i = H(BP ||  i), by concatenating the
sequence number i to the base preimage and hashing the result. Afterwards,
it applies H to determine the payment hash to use in the i’th partial
payment as h_i = H(r_i). Note that that with this preimage derivation
scheme, once the payments are pulled each pre-image is distinct and
indistinguishable from any other.

With all of the pieces in place, the sender initiates the i’th payment by constructing a route to the destination with value v_i and payment hash h_i. The tuple (ID, n, s_i) is included in the EOB to be opened by the receiver.

In order to include the three tuple within the per-hop payload for the final destination, we repurpose the _first_ byte of the un-used padding bytes in the payload to signal version 0x01 of the AMP protocol (note this is a PoC outline, we would need to standardize signalling of these 12 bytes to support other protocols). Typically this byte isn't set, so the existence of this means that we're (1) using AMP, and (2) the receiver should consume the _next_ hop as well. So if the payment length is actually 5, the sender tacks on an additional dummy 6th hop, encrypted with the _same_ shared secret for that hop to deliver the e2e encrypted data.

Note, the sender can retry partial payments just as they would normal payments, since they are order invariant, and would be indistinguishable from regular payments to intermediaries in the network.

Receiver Requirements =====================

Upon the arrival of each partial payment, the receiver will iteratively reconstruct BP, and do some bookkeeping to figure out when to settle the partial payments. During this reconstruction process, the receiver does not need to be aware of the order in which the payments were sent, and in fact nothing about the incoming partial payments reveals this information to the receiver, though this can be learned after reconstructing BP.

Each EOB is decoded to retrieve (ID, n, s_i), where i is the unique but unknown index of the incoming partial payment. The receiver has access to persistent key-value store DB that maps ID to (n, c*, BP*), where c* represents the number of partial payments received, BP* is the sum of the received additive shares, and the superscript * denotes that the value is being updated iteratively. c* and BP* both have initial values of 0.

In the basic protocol, the receiver cache’s the first n it sees, and verifies that all incoming partial payments have the same n. The receiver should reject all partial payments if any EOB deviates. Next, the we update our persistent store with DB[ID] = (n, c* + 1, BP* ^ s_i), advancing the reconstruction by one step.

If c* + 1 < n, there are still more packets in flight, so we sit tight.
Otherwise, the receiver assumes all partial payments have arrived, and can
being settling them back. Using the base preimage BP = BP* ^ s_i from our
final iteration, the receiver can re-derive all n partial preimages and
payment hashes, using r_i = H(BP || i) and h_i = H(r_i) simply through
knowledge of n and BP.

Finally, the receiver settles back any outstanding payments that include payment hash h_i using the partial preimage r_i. Each r_i will appear random due to the nature of H, as will it’s corresponding h_i. Thus, each partial payment should appear uncorrelated, and does not reveal that it is part of an AMP nor the number of partial payments used.

Non-interactive to Interactive AMPs ===================================

Sender simply receives an ID and amount from the receiver in an invoice before initiating the protocol. The receiver should only consider the invoice settled if the total amount received in partial payments containing ID matches or exceeds the amount specified in the invoice. With this variant, the receiver is able to map all partial payments to a pre-generated invoice statement.

Additive Shares vs Threshold-Shares ===================================

The biggest reason to use additive shares seems to be atomicity. Threshold shares open the door to some partial payments being settled, even if others are left in flight. Haven’t yet come up with a good reason for using threshold schemes, but there seem to be plenty against it.

Reconstruction of additive shares can be done iteratively, and is win for the storage and computation requirements on the receiving end. If the sender decides to use fewer than n partial payments, the remaining shares could be included in the EOB of the final partial payment to allow the sender to reconstruct sooner. Sender could also optimistically do partial reconstruction on this last aggregate value.

Adaptive AMPs =============

The sender may not always be aware of how many partial payments they wish to send at the time of the first partial payment, at which point the simplified protocol would require n to be chosen. To accommodate, the above scheme can be adapted to handle a dynamically chosen n by iteratively constructing the shared secrets as follows.

Starting with a base preimage BP, the key trick is that the sender remember the difference between the base preimage and the sum of all partial preimages used so far. The relation is described using the following equations:

    X_0 = 0
    X_i = X_{i-1} ^ s_i
    X_n = BP ^ X_{n-1}

where if n=1, X_1 = BP, implying that this is in fact a generalization of the single, non-interactive payment scheme mentioned above. For i=1, ..., n-1, the sender sends s_i in the EOB, and X_n for the n-th share.

Iteratively reconstructing s_1 ^ …. ^ s_{n-1} ^ X_n = BP, allows the
receiver to compute all relevant r_i = H(BP || i) and h_i = H(r_i). Lastly,
the final number of partial payments n could be signaled in the final EOB,
which would also serve as a sentinel value for signaling completion. In
response to DOS vectors stemming from unknown values of n, implementations
could consider advertising a maximum value for n, or adopting some sort of
framing pattern for conveying that more partial payments are on the way.

We can further modify our usage of the per-hop payloads to send (H(BP), s_i) to consume most of the EOB sent from sender to receiver. In this scenario, we'd repurpose the 11-bytes *after* our signalling byte in the unused byte section to store the payment ID (which should be unique for each payment). In the case of a non-interactive payment, this will be unused. While for interactive payments, this will be the ID within the invoice. To deliver this slimmer 2-tuple, we'll use 32-bytes for the hash of the BP, and 32-bytes for the partial pre-image share, leaving an un-used byte in the payload.

Cross-Chain AMPs ================

AMPs can be used to pay a receiver in multiple currencies atomically...which is pretty cool :D

Open Research Questions =======================

The above is a protocol sketch to achieve atomic multi-path payments over Lightning. The details concerning onion blob usage serves as a template that future protocols can draw upon in order to deliver additional data to *any* hop in the route. However, there are still a few open questions before something like this can be feasibly deployed.

1. How does the sender decide how many chunked payments to send, and the size of each payment?

  - Upon a closer examination, this seems to overlap with the task of
    congestion control within TCP. The sender may be able to utilize
    inspired heuristics to gauge: (1) how large the initial payment should
be
    and (2) how many subsequent payments may be required. Note that if the
    first payment succeeds, then the exchange is over in a signal round.
2. How can AMP and HORNET be composed?
  - If we eventually integrate HORNET, then a distinct communications
    sessions can be established to allow the sender+receiver to exchange
    up-to-date partial payment information. This may allow the sender to
more
    accurately size each partial payment.

3. Can the sender's initial strategy be governed by an instance of the Push-relabel max flow algo?

4. How does this mesh with the current max HTLC limit on a commitment?
   - ATM, we have a max limit on the number of active HTLC's on a particular
     commitment transaction. We do this, as otherwise it's possible that the
     transaction is too large, and exceeds standardness w.r.t transaction
     size. In a world where most payments use an AMP-like protocol, then
     overall ant any given instance there will be several pending HTLC's on
     commitments network wise.
     This may incentivize nodes to open more channels in order to support
     the increased commitment space utilization.

Conclusion ==========

We've presented a design outline of how to integrate atomic multi-path payments (AMP) into Lightning. The existence of such a construct allows a sender to atomically split a payment flow amongst several individual payment flows. As a result, larger channels aren't as important as it's possible to utilize one total outbound payment bandwidth to send several channels. Additionally, in order to support the increased load, internal routing nodes are incensed have more active channels. The existence of AMP-like payments may also increase the longevity of channels as there'll be smaller, more numerous payment flows, making it unlikely that a single payment comes across unbalances a channel entirely. We've also showed how one can utilize the current onion packet format to deliver additional data from a sender to receiver, that's still e2e authenticated.

-- Conner && Laolu

ZmnSCPxj in reply to Olaoluwa Osuntokun permalink original

Good morning Laolu,

This is excellent work!

Some minor comments...

Quoted text (5 lines)
> (Atomic Multi-path Payments). It can be experimented with on Lightning
> *today* with the addition of a new feature bit to gate this new
> feature. The beauty of the scheme is that it requires no fundamental changes
> to the protocol as is now, as the negotiation is strictly *end-to-end*
> between sender and receiver.

I think, a `globalfeatures` odd bit could be used for this. As it is end-ot-end, `localfeatures` is not appropriate.

Quoted text (4 lines)
>   - Potential fee savings for larger payments, contingent on there being a
>     super-linear component to routed fees. It's possible that with
>     modifications to the fee schedule, it's actually *cheaper* to send
>     payments over multiple flows rather than one giant flow.

I believe, currently, fees have not this super-linear component. Indeed, the existence of per-hop fees (`fee_base_msat`) means, splitting the payment over multiple flows will be, very likely, more expensive, compared to using a single flow. Tiny roundoffs in computing the proportional fees (`fee_proportional_millionths`) may make smaller flows give a slight fee advantage, but I think the multiplication of per-hop fees will dominate.

Quoted text (4 lines)
>   - Using smaller payments increases the set of possible paths a partial
>     payment could have taken, which reduces the effectiveness of static
>     analysis techniques involving channel capacities and the plaintext
>     values being forwarded.

Strongly agree!

Quoted text (5 lines)
> In order to include the three tuple within the per-hop payload for the final
> destination, we repurpose the _first_ byte of the un-used padding bytes in
> the payload to signal version 0x01 of the AMP protocol (note this is a PoC
> outline, we would need to standardize signalling of these 12 bytes to
> support other protocols).

I believe the `realm` byte is intended for this. Intermediate nodes do not need to understand realm bytes that are understood by other nodes in the route, including the realm bytes understood by the final destination, as intermediate nodes cannot, indeed, read the hop data of other nodes. Thus, you can route over nodes that are unaware of AMP, and only provide an AMP realm byte to the destination node, who, is able to reconstruct this your AMP data as per your algorithm.

Indeed, the `realm` byte controls the interpretation of the rest of the 65-byte packet. If you define, instead, a separate `realm` that is understood by the destination node, you can redefine the entire 64 bytes of the final hop data as you wish.

If we support AMP only at final payees, we can completely redefine the 64 bytes in the final hop data for the new AMP `realm`, and not consume the next hop (which would reduce route length by 1).

(If we want to support multiple routes converging to an intermediate node, then continue routing to a different final node after routes have merged (i.e. A->B->C->D, and A->E->C->D, with the payment being merged by C, who forwards the combination to D), then we need to follow the current hop data format, but I think supporting AMP at final payees is actually enough... AMP at intermediate nodes might not be used often enough by senders for it to matter, as taking advantage of that seems more complex than just asking your routing algo to provide you multiple routes to a destination, which you are probably already doing)

----

Overall, good work I think.

Regards, ZmnSCPxj

Olaoluwa Osuntokun in reply to ZmnSCPxj permalink original

Hi ZmnSCPxj,

Quoted text (1 line)
> This is excellent work!

Thanks!

Quoted text (2 lines)
> I think, a `globalfeatures` odd bit could be used for this.  As it is
> end-ot-end, `localfeatures` is not appropriate.

Yep, it would need to be a global feature bit. In the case that we're sending to a destination which isn't publicly advertised, then perhaps an extension to BOLT-11 could be made to signal receiver support.

Quoted text (1 line)
> I believe, currently, fees have not this super-linear component

Yep they don't. Arguably, we should also have a component that scales according to the proposed CLTV value of the outgoing HTLC. At Scaling Bitcoin Stanford, Aviv Zohar gave a talked titled "How to Charge Lightning" where the authors analyzed the possible evolution of fees on the network (and also suggested adding this super-linear component to extend the lifetime of channels). However, the talk itself focused on a very simple "mega super duper hub" topology. Towards the end he alluded to a forthcoming paper that had more comprehensive analysis of more complex topologies. I look forward to the publication of their finalized work.

Quoted text (3 lines)
> Indeed, the existence of per-hop fees (`fee_base_msat`) means, splitting
> the payment over multiple flows will be, very likely, more expensive,
> compared to using a single flow.

Well it's still to be seen how the fee structure on mainnet emerges once the network is still fully bootstrapped. AFAIK, most running on mainnet atm are using the default fee schedules for their respective implementations. For example, the default fee_base_msat for lnd is 1000 msat (1 satoshi).

Quoted text (1 line)
> I believe the `realm` byte is intended for this.

The realm byte is meant to signal "forward this to the dogecoin channel". ATM, we just default to 0 as "Bitcoin". However, the byte itself only really need significance between the sender and the intermediate node. So there isn't necessarily pressure to have a globally synchronized set of realm bytes.

Quoted text (4 lines)
> Thus, you can route over nodes that are unaware of AMP, and only provide
> an AMP realm byte to the destination node, who, is able to reconstruct
this
> your AMP data as per your algorithm.

Yes, the intermediate nodes don't need to be aware of the end-to-end protocol. For the final hop, there are actually 53 free bytes (before one needs to signal the existence of EOBs):

  * 1 byte realm
  * 8 bytes next addr (all zeroes to signal final dest)
  * 32 bytes hmac (also all zeroes for the final dest)
  * 12 bytes padding

So any combo of these bytes can be used to signal more advanced protocols to the final destination.

A correction from the prior email description:

Quoted text (2 lines)
> We can further modify our usage of the per-hop payloads to send
> (H(BP), s_i) to consume most of the EOB sent from sender to receiver.
This should actually be (H(s_0 || s_1 || ...), s_i). So we still allow them
to check this finger print to see if they have all the final shares, but
don't allow them to preemptively pull all the payments.

-- Laolu

On Mon, Feb 5, 2018 at 11:12 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:

Quoted text (83 lines)
> Good morning Laolu,
>
> This is excellent work!
>
> Some minor comments...
>
>
> (Atomic Multi-path Payments). It can be experimented with on Lightning
> *today* with the addition of a new feature bit to gate this new
> feature. The beauty of the scheme is that it requires no fundamental
> changes
> to the protocol as is now, as the negotiation is strictly *end-to-end*
> between sender and receiver.
>
>
> I think, a `globalfeatures` odd bit could be used for this.  As it is
> end-ot-end, `localfeatures` is not appropriate.
>
>   - Potential fee savings for larger payments, contingent on there being a
>     super-linear component to routed fees. It's possible that with
>     modifications to the fee schedule, it's actually *cheaper* to send
>     payments over multiple flows rather than one giant flow.
>
>
> I believe, currently, fees have not this super-linear component.  Indeed,
> the existence of per-hop fees (`fee_base_msat`) means, splitting the
> payment over multiple flows will be, very likely, more expensive, compared
> to using a single flow.  Tiny roundoffs in computing the proportional fees
> (`fee_proportional_millionths`) may make smaller flows give a slight fee
> advantage, but I think the multiplication of per-hop fees will dominate.
>
>
>   - Using smaller payments increases the set of possible paths a partial
>     payment could have taken, which reduces the effectiveness of static
>     analysis techniques involving channel capacities and the plaintext
>     values being forwarded.
>
>
> Strongly agree!
>
>
> In order to include the three tuple within the per-hop payload for the
> final
> destination, we repurpose the _first_ byte of the un-used padding bytes in
> the payload to signal version 0x01 of the AMP protocol (note this is a PoC
> outline, we would need to standardize signalling of these 12 bytes to
> support other protocols).
>
>
> I believe the `realm` byte is intended for this.  Intermediate nodes do
> not need to understand realm bytes that are understood by other nodes in
> the route, including the realm bytes understood by the final destination,
> as intermediate nodes cannot, indeed, read the hop data of other nodes.
> Thus, you can route over nodes that are unaware of AMP, and only provide an
> AMP realm byte to the destination node, who, is able to reconstruct this
> your AMP data as per your algorithm.
>
> Indeed, the `realm` byte controls the interpretation of the rest of the
> 65-byte packet.  If you define, instead, a separate `realm` that is
> understood by the destination node, you can redefine the entire 64 bytes of
> the final hop data as you wish.
>
> If we support AMP only at final payees, we can completely redefine the 64
> bytes in the final hop data for the new AMP `realm`, and not consume the
> next hop (which would reduce route length by 1).
>
> (If we want to support multiple routes converging to an intermediate node,
> then continue routing to a different final node after routes have merged
> (i.e. A->B->C->D, and A->E->C->D, with the payment being merged by C, who
> forwards the combination to D), then we need to follow the current hop data
> format, but I think supporting AMP at final payees is actually enough...
> AMP at intermediate nodes might not be used often enough by senders for it
> to matter, as taking advantage of that seems more complex than just asking
> your routing algo to provide you multiple routes to a destination, which
> you are probably already doing)
>
> ----
>
> Overall, good work I think.
>
> Regards,
> ZmnSCPxj
>
Conner Fromknecht in reply to Olaoluwa Osuntokun permalink original

Hi ZmnSCPxj and Laolu,

Quoted text (5 lines)
>  Indeed, the existence of per-hop fees (`fee_base_msat`) means, splitting
the
>  payment over multiple flows will be, very likely, more expensive,
compared to
>  using a single flow.

As Laolu pointed out, we have yet to see how fees evolve on mainnet or what will emerge as a sane, default fee schedules. I agree that if the same proportional fee is used across all partial payments, then it could certainly be more expensive.

However, it could also be the case that you were paying a needlessly high proportional fee to begin with, because paths of sufficient capacity to the destination were scarce. In an AMP world, there will be an abundance of channels that can route small, partial payments, which may itself drive down the competitive fee rate for smaller payments. Just a hypothesis, we shall see where supply meets demand!

At the end of the day, the user can always fall back to regular payment if they expect to end up paying more fees using an AMP.

Quoted text (8 lines)
> (If we want to support multiple routes converging to an intermediate node,
> then continue routing to a different final node after routes have merged
(i.e.
> A->B->C->D, and A->E->C->D, with the payment being merged by C, who
forwards
> the combination to D), then we need to follow the current hop data
format, but
> I think supporting AMP at final payees is actually enough...

I think this is an interesting idea, sounds maybe like a recursive/hierarchical AMP? The ability to merge the payments seems like it would result in a decent privacy leak, as I believe an intermediary would have enough evidence to prove that two payments were merged/correlated. Simple traffic analysis would also reveal a discrepancy in the number of incoming and outgoing packets, and possibly other observable differences in routing (some) AMPs vs regular payments.

FWIW the current proposal allows the paths of partial payments to overlap, in such a scenario C would just forward the HTLCs independently. One could send them all along the same path if they desired! I'm assuming the intent here is to try and reduce total fees?

Minor correction^2:

Quoted text (1 line)
> This should actually be (H(s_0 || s_1 || ...), s_i).

This assumes the receiver knows the indexes of each share. Without this knowledge they would have to brute force all orderings to check the fingerprint.

To maintain order invariance on the receiving end, I would propose sending (0, s_i) for the first n-1 partial payments, and then (n, s_i) on the final one. As in the description of the basic AMP scheme, the receiver maintains a persistent count of how many partial payments have been received for ID. If the receiver does not get the last payment last, the receiver just waits until all n have been received before deciding that its reconstructed value is BP.

The receiver can verify they've received the correct BP and n by rederiving
the
partial preimages r_i = H(BP || i) and checking that there are n outstanding
payments, one for each h_i = H(r_i). This also saves the receiving node n
additional hash invocations.

-Conner

On Tue, Feb 6, 2018 at 4:04 PM Olaoluwa Osuntokun <laolu32 at gmail.com> wrote:

Quoted text (167 lines)
> Hi ZmnSCPxj,
>
> > This is excellent work!
>
> Thanks!
>
> > I think, a `globalfeatures` odd bit could be used for this.  As it is
> > end-ot-end, `localfeatures` is not appropriate.
>
> Yep, it would need to be a global feature bit. In the case that we're
> sending to a destination which isn't publicly advertised, then perhaps an
> extension to BOLT-11 could be made to signal receiver support.
>
> > I believe, currently, fees have not this super-linear component
>
> Yep they don't. Arguably, we should also have a component that scales
> according to the proposed CLTV value of the outgoing HTLC. At Scaling
> Bitcoin Stanford, Aviv Zohar gave a talked titled "How to Charge Lightning"
> where the authors analyzed the possible evolution of fees on the network
> (and also suggested adding this super-linear component to extend the
> lifetime of channels).  However, the talk itself focused on a very simple
> "mega super duper hub" topology. Towards the end he alluded to a
> forthcoming
> paper that had more comprehensive analysis of more complex topologies. I
> look forward to the publication of their finalized work.
>
> > Indeed, the existence of per-hop fees (`fee_base_msat`) means, splitting
> > the payment over multiple flows will be, very likely, more expensive,
> > compared to using a single flow.
>
> Well it's still to be seen how the fee structure on mainnet emerges once
> the
> network is still fully bootstrapped. AFAIK, most running on mainnet atm are
> using the default fee schedules for their respective implementations. For
> example, the default fee_base_msat for lnd is 1000 msat (1 satoshi).
>
> > I believe the `realm` byte is intended for this.
>
> The realm byte is meant to signal "forward this to the dogecoin channel".
> ATM, we just default to 0 as "Bitcoin". However, the byte itself only
> really
> need significance between the sender and the intermediate node. So there
> isn't necessarily pressure to have a globally synchronized set of realm
> bytes.
>
> > Thus, you can route over nodes that are unaware of AMP, and only provide
> > an AMP realm byte to the destination node, who, is able to reconstruct
> this
> > your AMP data as per your algorithm.
>
> Yes, the intermediate nodes don't need to be aware of the end-to-end
> protocol. For the final hop, there are actually 53 free bytes (before one
> needs to signal the existence of EOBs):
>
>   * 1 byte realm
>   * 8 bytes next addr (all zeroes to signal final dest)
>   * 32 bytes hmac (also all zeroes for the final dest)
>   * 12 bytes padding
>
> So any combo of these bytes can be used to signal more advanced protocols
> to
> the final destination.
>
>
> A correction from the prior email description:
>
> > We can further modify our usage of the per-hop payloads to send
> > (H(BP), s_i) to consume most of the EOB sent from sender to receiver.
>
> This should actually be (H(s_0 || s_1 || ...), s_i). So we still allow them
> to check this finger print to see if they have all the final shares, but
> don't allow them to preemptively pull all the payments.
>
>
> -- Laolu
>
>
> On Mon, Feb 5, 2018 at 11:12 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>
>> Good morning Laolu,
>>
>> This is excellent work!
>>
>> Some minor comments...
>>
>>
>> (Atomic Multi-path Payments). It can be experimented with on Lightning
>> *today* with the addition of a new feature bit to gate this new
>> feature. The beauty of the scheme is that it requires no fundamental
>> changes
>> to the protocol as is now, as the negotiation is strictly *end-to-end*
>> between sender and receiver.
>>
>>
>> I think, a `globalfeatures` odd bit could be used for this.  As it is
>> end-ot-end, `localfeatures` is not appropriate.
>>
>>   - Potential fee savings for larger payments, contingent on there being a
>>     super-linear component to routed fees. It's possible that with
>>     modifications to the fee schedule, it's actually *cheaper* to send
>>     payments over multiple flows rather than one giant flow.
>>
>>
>> I believe, currently, fees have not this super-linear component.  Indeed,
>> the existence of per-hop fees (`fee_base_msat`) means, splitting the
>> payment over multiple flows will be, very likely, more expensive, compared
>> to using a single flow.  Tiny roundoffs in computing the proportional fees
>> (`fee_proportional_millionths`) may make smaller flows give a slight fee
>> advantage, but I think the multiplication of per-hop fees will dominate.
>>
>>
>>   - Using smaller payments increases the set of possible paths a partial
>>     payment could have taken, which reduces the effectiveness of static
>>     analysis techniques involving channel capacities and the plaintext
>>     values being forwarded.
>>
>>
>> Strongly agree!
>>
>>
>> In order to include the three tuple within the per-hop payload for the
>> final
>> destination, we repurpose the _first_ byte of the un-used padding bytes in
>> the payload to signal version 0x01 of the AMP protocol (note this is a PoC
>> outline, we would need to standardize signalling of these 12 bytes to
>> support other protocols).
>>
>>
>> I believe the `realm` byte is intended for this.  Intermediate nodes do
>> not need to understand realm bytes that are understood by other nodes in
>> the route, including the realm bytes understood by the final destination,
>> as intermediate nodes cannot, indeed, read the hop data of other nodes.
>> Thus, you can route over nodes that are unaware of AMP, and only provide an
>> AMP realm byte to the destination node, who, is able to reconstruct this
>> your AMP data as per your algorithm.
>>
>> Indeed, the `realm` byte controls the interpretation of the rest of the
>> 65-byte packet.  If you define, instead, a separate `realm` that is
>> understood by the destination node, you can redefine the entire 64 bytes of
>> the final hop data as you wish.
>>
>> If we support AMP only at final payees, we can completely redefine the 64
>> bytes in the final hop data for the new AMP `realm`, and not consume the
>> next hop (which would reduce route length by 1).
>>
>> (If we want to support multiple routes converging to an intermediate
>> node, then continue routing to a different final node after routes have
>> merged (i.e. A->B->C->D, and A->E->C->D, with the payment being merged by
>> C, who forwards the combination to D), then we need to follow the current
>> hop data format, but I think supporting AMP at final payees is actually
>> enough... AMP at intermediate nodes might not be used often enough by
>> senders for it to matter, as taking advantage of that seems more complex
>> than just asking your routing algo to provide you multiple routes to a
>> destination, which you are probably already doing)
>>
>> ----
>>
>> Overall, good work I think.
>>
>> Regards,
>> ZmnSCPxj
>>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Jim Posen in reply to Conner Fromknecht permalink original

This is a really neat idea.

This is a question about non-interactive payments in general, but is there any way to get a proof of payment? With regular invoices, knowledge of the preimage serves as cryptographic proof that the payment was delivered.

On Feb 6, 2018 6:26 PM, "Conner Fromknecht" <conner at lightning.engineering> wrote:

Quoted text (269 lines)
>
> Hi ZmnSCPxj and Laolu,
>
> >  Indeed, the existence of per-hop fees (`fee_base_msat`) means,
> splitting the
> >  payment over multiple flows will be, very likely, more expensive,
> compared to
> >  using a single flow.
>
> As Laolu pointed out, we have yet to see how fees evolve on mainnet or
> what will
> emerge as a sane, default fee schedules. I agree that if the same
> proportional
> fee is used across all partial payments, then it could certainly be more
> expensive.
>
> However, it could also be the case that you were paying a needlessly high
> proportional fee to begin with, because paths of sufficient capacity to the
> destination were scarce. In an AMP world, there will be an abundance of
> channels
> that can route small, partial payments, which may itself drive down the
> competitive fee rate for smaller payments. Just a hypothesis, we shall see
> where
> supply meets demand!
>
> At the end of the day, the user can always fall back to regular payment if
> they
> expect to end up paying more fees using an AMP.
>
> > (If we want to support multiple routes converging to an intermediate
> node,
> > then continue routing to a different final node after routes have merged
> (i.e.
> > A->B->C->D, and A->E->C->D, with the payment being merged by C, who
> forwards
> > the combination to D), then we need to follow the current hop data
> format, but
> > I think supporting AMP at final payees is actually enough...
>
> I think this is an interesting idea, sounds maybe like a
> recursive/hierarchical
> AMP? The ability to merge the payments seems like it would result in a
> decent privacy
> leak, as I believe an intermediary would have enough evidence to prove
> that two
> payments were merged/correlated. Simple traffic analysis would also reveal
> a
> discrepancy in the number of incoming and outgoing packets, and possibly
> other
> observable differences in routing (some) AMPs vs regular payments.
>
> FWIW the current proposal allows the paths of partial payments to overlap,
> in such a scenario C would just forward the HTLCs independently. One could
> send
> them all along the same path if they desired! I'm assuming the intent here
> is to
> try and reduce total fees?
>
> Minor correction^2:
>
> > This should actually be (H(s_0 || s_1 || ...), s_i).
>
> This assumes the receiver knows the indexes of each share. Without this
> knowledge they would have to brute force all orderings to check the
> fingerprint.
>
> To maintain order invariance on the receiving end, I would propose sending
> (0, s_i) for the first n-1 partial payments, and then (n, s_i) on the
> final one.
> As in the description of the basic AMP scheme, the receiver maintains a
> persistent count of how many partial payments have been received for ID.
> If the
> receiver does not get the last payment last, the receiver just waits until
> all n
> have been received before deciding that its reconstructed value is BP.
>
> The receiver can verify they've received the correct BP and n by
> rederiving the
> partial preimages r_i = H(BP || i) and checking that there are n
> outstanding
> payments, one for each h_i = H(r_i). This also saves the receiving node n
> additional hash invocations.
>
> -Conner
>
> On Tue, Feb 6, 2018 at 4:04 PM Olaoluwa Osuntokun <laolu32 at gmail.com>
> wrote:
>
>> Hi ZmnSCPxj,
>>
>> > This is excellent work!
>>
>> Thanks!
>>
>> > I think, a `globalfeatures` odd bit could be used for this.  As it is
>> > end-ot-end, `localfeatures` is not appropriate.
>>
>> Yep, it would need to be a global feature bit. In the case that we're
>> sending to a destination which isn't publicly advertised, then perhaps an
>> extension to BOLT-11 could be made to signal receiver support.
>>
>> > I believe, currently, fees have not this super-linear component
>>
>> Yep they don't. Arguably, we should also have a component that scales
>> according to the proposed CLTV value of the outgoing HTLC. At Scaling
>> Bitcoin Stanford, Aviv Zohar gave a talked titled "How to Charge
>> Lightning"
>> where the authors analyzed the possible evolution of fees on the network
>> (and also suggested adding this super-linear component to extend the
>> lifetime of channels).  However, the talk itself focused on a very simple
>> "mega super duper hub" topology. Towards the end he alluded to a
>> forthcoming
>> paper that had more comprehensive analysis of more complex topologies. I
>> look forward to the publication of their finalized work.
>>
>> > Indeed, the existence of per-hop fees (`fee_base_msat`) means, splitting
>> > the payment over multiple flows will be, very likely, more expensive,
>> > compared to using a single flow.
>>
>> Well it's still to be seen how the fee structure on mainnet emerges once
>> the
>> network is still fully bootstrapped. AFAIK, most running on mainnet atm
>> are
>> using the default fee schedules for their respective implementations. For
>> example, the default fee_base_msat for lnd is 1000 msat (1 satoshi).
>>
>> > I believe the `realm` byte is intended for this.
>>
>> The realm byte is meant to signal "forward this to the dogecoin channel".
>> ATM, we just default to 0 as "Bitcoin". However, the byte itself only
>> really
>> need significance between the sender and the intermediate node. So there
>> isn't necessarily pressure to have a globally synchronized set of realm
>> bytes.
>>
>> > Thus, you can route over nodes that are unaware of AMP, and only provide
>> > an AMP realm byte to the destination node, who, is able to reconstruct
>> this
>> > your AMP data as per your algorithm.
>>
>> Yes, the intermediate nodes don't need to be aware of the end-to-end
>> protocol. For the final hop, there are actually 53 free bytes (before one
>> needs to signal the existence of EOBs):
>>
>>   * 1 byte realm
>>   * 8 bytes next addr (all zeroes to signal final dest)
>>   * 32 bytes hmac (also all zeroes for the final dest)
>>   * 12 bytes padding
>>
>> So any combo of these bytes can be used to signal more advanced protocols
>> to
>> the final destination.
>>
>>
>> A correction from the prior email description:
>>
>> > We can further modify our usage of the per-hop payloads to send
>> > (H(BP), s_i) to consume most of the EOB sent from sender to receiver.
>>
>> This should actually be (H(s_0 || s_1 || ...), s_i). So we still allow
>> them
>> to check this finger print to see if they have all the final shares, but
>> don't allow them to preemptively pull all the payments.
>>
>>
>> -- Laolu
>>
>>
>> On Mon, Feb 5, 2018 at 11:12 PM ZmnSCPxj <ZmnSCPxj at protonmail.com> wrote:
>>
>>> Good morning Laolu,
>>>
>>> This is excellent work!
>>>
>>> Some minor comments...
>>>
>>>
>>> (Atomic Multi-path Payments). It can be experimented with on Lightning
>>> *today* with the addition of a new feature bit to gate this new
>>> feature. The beauty of the scheme is that it requires no fundamental
>>> changes
>>> to the protocol as is now, as the negotiation is strictly *end-to-end*
>>> between sender and receiver.
>>>
>>>
>>> I think, a `globalfeatures` odd bit could be used for this.  As it is
>>> end-ot-end, `localfeatures` is not appropriate.
>>>
>>>   - Potential fee savings for larger payments, contingent on there being
>>> a
>>>     super-linear component to routed fees. It's possible that with
>>>     modifications to the fee schedule, it's actually *cheaper* to send
>>>     payments over multiple flows rather than one giant flow.
>>>
>>>
>>> I believe, currently, fees have not this super-linear component.
>>> Indeed, the existence of per-hop fees (`fee_base_msat`) means, splitting
>>> the payment over multiple flows will be, very likely, more expensive,
>>> compared to using a single flow.  Tiny roundoffs in computing the
>>> proportional fees (`fee_proportional_millionths`) may make smaller
>>> flows give a slight fee advantage, but I think the multiplication of
>>> per-hop fees will dominate.
>>>
>>>
>>>   - Using smaller payments increases the set of possible paths a partial
>>>     payment could have taken, which reduces the effectiveness of static
>>>     analysis techniques involving channel capacities and the plaintext
>>>     values being forwarded.
>>>
>>>
>>> Strongly agree!
>>>
>>>
>>> In order to include the three tuple within the per-hop payload for the
>>> final
>>> destination, we repurpose the _first_ byte of the un-used padding bytes
>>> in
>>> the payload to signal version 0x01 of the AMP protocol (note this is a
>>> PoC
>>> outline, we would need to standardize signalling of these 12 bytes to
>>> support other protocols).
>>>
>>>
>>> I believe the `realm` byte is intended for this.  Intermediate nodes do
>>> not need to understand realm bytes that are understood by other nodes in
>>> the route, including the realm bytes understood by the final destination,
>>> as intermediate nodes cannot, indeed, read the hop data of other nodes.
>>> Thus, you can route over nodes that are unaware of AMP, and only provide an
>>> AMP realm byte to the destination node, who, is able to reconstruct this
>>> your AMP data as per your algorithm.
>>>
>>> Indeed, the `realm` byte controls the interpretation of the rest of the
>>> 65-byte packet.  If you define, instead, a separate `realm` that is
>>> understood by the destination node, you can redefine the entire 64 bytes of
>>> the final hop data as you wish.
>>>
>>> If we support AMP only at final payees, we can completely redefine the
>>> 64 bytes in the final hop data for the new AMP `realm`, and not consume the
>>> next hop (which would reduce route length by 1).
>>>
>>> (If we want to support multiple routes converging to an intermediate
>>> node, then continue routing to a different final node after routes have
>>> merged (i.e. A->B->C->D, and A->E->C->D, with the payment being merged by
>>> C, who forwards the combination to D), then we need to follow the current
>>> hop data format, but I think supporting AMP at final payees is actually
>>> enough... AMP at intermediate nodes might not be used often enough by
>>> senders for it to matter, as taking advantage of that seems more complex
>>> than just asking your routing algo to provide you multiple routes to a
>>> destination, which you are probably already doing)
>>>
>>> ----
>>>
>>> Overall, good work I think.
>>>
>>> Regards,
>>> ZmnSCPxj
>>>
>> _______________________________________________
>> Lightning-dev mailing list
>> Lightning-dev at lists.linuxfoundation.org
>> https://www.learnbitcoin.com/archive/lists/lightning-dev
>>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
>
Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (5 lines)
> Hi Y'all,
>
> A common question I've seen concerning Lightning is: "I have five $2
> channels, is it possible for me to *atomically* send $6 to fulfill a
> payment?". The answer to this question is "yes", provided that the receiver

This is awesome! I'm kicking myself for not proposing it :)

Unfortunately, your proposal defines a way to make multipath donations, not multipath payments :(

In other words, you've lost proof of payment, which IMHO is critical.

Fortunately, this can be fairly trivially fixed when we go to scriptless scripts or other equivalent decorrelation mechanism, when I think this mechanism becomes extremely powerful.

Quoted text (4 lines)
>   - Potential fee savings for larger payments, contingent on there being a
>     super-linear component to routed fees. It's possible that with
>     modifications to the fee schedule, it's actually *cheaper* to send
>     payments over multiple flows rather than one giant flow.

This is a stretch. I'd stick with the increased reliability/privacy arguments which are overwhelmingly compelling IMHO.

If I have any important feedback on deeper reading (and after a sccond coffee), I'll send a separate email.

Thanks! Rusty.

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (10 lines)
> Protocol Overview
> ==================
> This design can be seen as a generalization of the single, non-interactive
> payment scheme, that uses decoding of extra onion blobs (EOBs?) to encode
> extra data for the receiver. In that design, the extra data includes a
> payment preimage that the receiver can use to settle back the payment. EOBs
> and some method of parsing them are really the only requirement for this
> protocol to work. Thus, only the sender and receiver need to implement this
> feature in order for it to function, which can be announced using a feature
> bit.

OK, so this proposal conflates two things:

1. split payments.
2. expansion of onion space.
We've got a wiki page for #2 which could probably use some love:
        https://github.com/lightningnetwork/lightning-rfc/wiki/Brainstorming#using-multiple-hops_data-cells-in-the-onion

For the final hop this may not be necessary, as we have 8 unused bytes in `next addr`, giving us 20 free bytes.

But why not simplify the proposal: the payment preimage is the XOR of those 20 bytes (with 12 zero bytes prepended)? And the receiver gives up to 30 seconds(?) to receive all the parts after the first one.

That means the sender gets dynamic resizing (if they want to split a payment further, set one to randomness, and XOR that into the other), the receive has only to remember the combination-so-far.

Cheers, Rusty.

Johan Torås Halseth in reply to Rusty Russell permalink original

An obvious way to make this compatible with proof-of-payment would be to require two hashes to claim the HTLC: the presage from the invoice payment hash (as today) + the new hash introduced here. This would give the sender a receipt after only one of the HTLCs was claimed. Would require changes to the scripts of course. With Schnorr/EC operations this could probably be made more elegant, as mentioned.

- Johan On Wed, Feb 7, 2018 at 18:21, Rusty Russell <rusty at rustcorp.com.au> wrote: Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (23 lines, sent without quote marks)
 > Hi Y'all,
 >
 > A common question I've seen concerning Lightning is: "I have five $2
 > channels, is it possible for me to *atomically* send $6 to fulfill a
 > payment?". The answer to this question is "yes", provided that the
receiver

This is awesome! I'm kicking myself for not proposing it :)

Unfortunately, your proposal defines a way to make multipath donations,
not multipath payments :(

In other words, you've lost proof of payment, which IMHO is critical.

Fortunately, this can be fairly trivially fixed when we go to scriptless
scripts or other equivalent decorrelation mechanism, when I think this
mechanism becomes extremely powerful.

 > - Potential fee savings for larger payments, contingent on there being a
 > super-linear component to routed fees. It's possible that with
 > modifications to the fee schedule, it's actually *cheaper* to send
 > payments over multiple flows rather than one giant flow.

This is a stretch. I'd stick with the increased reliability/privacy
arguments which are overwhelmingly compelling IMHO.

If I have any important feedback on deeper reading (and after a sccond
coffee), I'll send a separate email.

Thanks!
Rusty.
Jim Posen in reply to Johan Torås Halseth permalink original

If using two hashes to deliver the payment while still getting a proof, I'm not sure what that provides above just sending regular lightning payments over multiple routes with one hash. Firstly, if there is a second hash, it would presumably be the same for all routes, making them linkable again, which AMP tries to solve. And secondly, the receiver has no incentive to claim any of the HTLCs before all of them are locked in, because in that case they are releasing the transaction receipt before fully being paid.

On Thu, Feb 8, 2018 at 8:41 AM, Johan Torås Halseth <johanth at gmail.com> wrote:

Quoted text (56 lines)
> An obvious way to make this compatible with proof-of-payment would be to
> require two hashes to claim the HTLC: the presage from the invoice payment
> hash (as today) + the new hash introduced here. This would give the sender
> a receipt after only one of the HTLCs was claimed. Would require changes to
> the scripts of course.
>
> With Schnorr/EC operations this could probably be made more elegant, as
> mentioned.
>
> - Johan
> On Wed, Feb 7, 2018 at 18:21, Rusty Russell <rusty at rustcorp.com.au> wrote:
>
> Olaoluwa Osuntokun <laolu32 at gmail.com> writes:
> > Hi Y'all,
> >
> > A common question I've seen concerning Lightning is: "I have five $2
> > channels, is it possible for me to *atomically* send $6 to fulfill a
> > payment?". The answer to this question is "yes", provided that the
> receiver
>
> This is awesome! I'm kicking myself for not proposing it :)
>
> Unfortunately, your proposal defines a way to make multipath donations,
> not multipath payments :(
>
> In other words, you've lost proof of payment, which IMHO is critical.
>
> Fortunately, this can be fairly trivially fixed when we go to scriptless
> scripts or other equivalent decorrelation mechanism, when I think this
> mechanism becomes extremely powerful.
>
> > - Potential fee savings for larger payments, contingent on there being a
> > super-linear component to routed fees. It's possible that with
> > modifications to the fee schedule, it's actually *cheaper* to send
> > payments over multiple flows rather than one giant flow.
>
> This is a stretch. I'd stick with the increased reliability/privacy
> arguments which are overwhelmingly compelling IMHO.
>
> If I have any important feedback on deeper reading (and after a sccond
> coffee), I'll send a separate email.
>
> Thanks!
> Rusty.
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
>
Johan Torås Halseth in reply to Jim Posen permalink original

Yeah, that is true, it would only give you the atomicity, not the decorrelation. I don’t see how you could get all the same properties using only one hash though. I guess the sender has no incentive to claim any of the payments before all of them have arrived, but you get no guarantee that partial payments cannot be made. Seems hard to do without introducing new primitives. - Johan

On Thu, Feb 8, 2018 at 12:44, Jim Posen <jim.posen at gmail.com> wrote: If using two hashes to deliver the payment while still getting a proof, I'm not sure what that provides above just sending regular lightning payments over multiple routes with one hash. Firstly, if there is a second hash, it would presumably be the same for all routes, making them linkable again, which AMP tries to solve. And secondly, the receiver has no incentive to claim any of the HTLCs before all of them are locked in, because in that case they are releasing the transaction receipt before fully being paid.

On Thu, Feb 8, 2018 at 8:41 AM, Johan Torås Halseth < johanth at gmail.com [johanth at gmail.com] > wrote: An obvious way to make this compatible with proof-of-payment would be to require two hashes to claim the HTLC: the presage from the invoice payment hash (as today) + the new hash introduced here. This would give the sender a receipt after only one of the HTLCs was claimed. Would require changes to the scripts of course. With Schnorr/EC operations this could probably be made more elegant, as mentioned.

- Johan On Wed, Feb 7, 2018 at 18:21, Rusty Russell < rusty at rustcorp.com.au [rusty at rustcorp.com.au] > wrote: Olaoluwa Osuntokun < laolu32 at gmail.com [laolu32 at gmail.com] > writes:

Quoted text (20 lines, sent without quote marks)
> Hi Y'all,
>
> A common question I've seen concerning Lightning is: "I have five $2
> channels, is it possible for me to *atomically* send $6 to fulfill a
> payment?". The answer to this question is "yes", provided that the receiver

This is awesome! I'm kicking myself for not proposing it :)

Unfortunately, your proposal defines a way to make multipath donations,
not multipath payments :(

In other words, you've lost proof of payment, which IMHO is critical.

Fortunately, this can be fairly trivially fixed when we go to scriptless
scripts or other equivalent decorrelation mechanism, when I think this
mechanism becomes extremely powerful.

> - Potential fee savings for larger payments, contingent on there being a
> super-linear component to routed fees. It's possible that with
> modifications to the fee schedule, it's actually *cheaper* to send
> payments over multiple flows rather than one giant flow.

This is a stretch. I'd stick with the increased reliability/privacy
arguments which are overwhelmingly compelling IMHO.

If I have any important feedback on deeper reading (and after a sccond
coffee), I'll send a separate email.

Thanks! Rusty. ______________________________ _________________ Lightning-dev mailing list Lightning-dev at lists. linuxfoundation.org [Lightning-dev at lists.linuxfoundation.org] https://lists.linuxfoundation. org/mailman/listinfo/ lightning-dev [https://www.learnbitcoin.com/archive/lists/lightning-dev]

______________________________ _________________ Lightning-dev mailing list Lightning-dev at lists. linuxfoundation.org [Lightning-dev at lists.linuxfoundation.org] https://lists.linuxfoundation. org/mailman/listinfo/ lightning-dev [https://www.learnbitcoin.com/archive/lists/lightning-dev]

CJP in reply to Olaoluwa Osuntokun permalink original

Can you give a use case for this?

Usually, especially in the common case that a payment is done in exchange for some non-cryptographic asset (e.g. physical goods), there already is some kind of trust between payer and payee. So, if a payment is split non-atomically into smaller transactions, and only a part succeeds, presumably they can cooperatively figure out some way to settle the situation.

I spoke to people of the "interledger" project, and what they are planning to do is to non-atomically split *every* transaction into lots of micro-payments. In fact, they consider it unnecessary to enforce HTLCs with scripts, because their amounts are so small(*). If one micro-payment fails, that just makes them learn that a certain channel is unreliable, and they'll send further payments (and even the remaining part of the same payment) through a different route.

CJP

(*) not worth the extra on-blockchain fee due to the increased tx size.

Olaoluwa Osuntokun schreef op di 06-02-2018 om 05:26 [+0000]:

Quoted text (587 lines)
> Hi Y'all,
>
>
> A common question I've seen concerning Lightning is: "I have five $2
> channels, is it possible for me to *atomically* send $6 to fulfill a
> payment?". The answer to this question is "yes", provided that the
> receiver
> waits to pull all HTLC's until the sum matches their invoice.
> Typically, one
> assumes that the receiver will supply a payment hash, and the sender
> will
> re-use the payment hash for all streams. This has the downside of
> payment
> hash re-use across *multiple* payments (which can already easily be
> correlated), and also has a failure mode where if the sender fails to
> actually satisfy all the payment flows, then the receiver can still
> just
> pull the monies (and possibly not disperse a service, or w/e).
>
>
> Conner Fromknecht and I have come up with a way to achieve this over
> Lightning while (1) not re-using any payment hashes across all payment
> flows, and (2) adding a *strong* guarantee that the receiver won't be
> paid
> until *all* partial payment flows are extended. We call this scheme
> AMP
> (Atomic Multi-path Payments). It can be experimented with on Lightning
> *today* with the addition of a new feature bit to gate this new
> feature. The beauty of the scheme is that it requires no fundamental
> changes
> to the protocol as is now, as the negotiation is strictly *end-to-end*
> between sender and receiver.
>
>
> TL;DR: we repurpose some unused space in the onion per-hop payload of
> the
> onion blob to signal our protocol (and deliver some protocol-specific
> data),
> then use additive secret sharing to ensure that the receiver can't
> pull the
> payment until they have enough shares to reconstruct the original
> pre-image.
>
>
>
>
> Protocol Goals
> ==============
> 1. Atomicity: The logical transaction should either succeed or fail in
> entirety. Naturally, this implies that the receiver should not be
> unable to
> settle *any* of the partial payments, until all of them have arrived.
>
>
> 2. Avoid Payment Hash Reuse: The payment preimages validated by the
> consensus layer should be distinct for each partial payment.
> Primarily,
> this helps avoid correlation of the partial payments, and ensures that
> malicious intermediaries straddling partial payments cannot steal
> funds.
>
>
> 3. Order Invariance: The protocol should be forgiving to the order in
> which
> partial payments arrive at the destination, adding robustness in the
> face of
> delays or routing failures.
>
>
> 4. Non-interactive Setup: It should be possible for the sender to
> perform an
> AMP without directly coordinating with the receiving node.
> Predominantly,
> this means that the *sender* is able to determine the number of
> partial
> payments to use for a particular AMP, which makes sense since they
> will be
> the one fronting the fees for the cost of this parameter. Plus, we can
> always turn a non-interactive protocol into an interactive one for the
> purposes of invoicing.
>
>
>
>
> Protocol Benefits

> =================
>
>
> Sending pay payments predominantly over an AMP-like protocol has
> several
> clear benefits:
>
>
>   - Eliminates the constraint that a single path from sender to
> receiver
>     with sufficient directional capacity. This reduces the pressure to
> have
>     larger channels in order to support larger payment flows. As a
> result,
>     the payment graph be very diffused, without sacrificing payment
>     utility
>
>
>   - Reduces strain from larger payments on individual paths, and
> allows the
>     liquidity imbalances to be more diffuse. We expect this to have a
>     non-negligible impact on channel longevity. This is due to the
> fact that
>     with usage of AMP, payment flows are typically *smaller* meaning
> that
>     each payment will unbalance a channel to a lesser degree that
>     with one giant flow.
>
>
>   - Potential fee savings for larger payments, contingent on there
> being a
>     super-linear component to routed fees. It's possible that with
>     modifications to the fee schedule, it's actually *cheaper* to send
>     payments over multiple flows rather than one giant flow.
>
>
>   - Allows for logical payments larger than the current maximum value
> of an
>     individual payment. Atm we have a (temporarily) limit on the max
> payment
>     size. With AMP, this can be side stepped as each flow can be up
> the max
>     size, with the sum of all flows exceeding the max.
>
>
>   - Given sufficient path diversity, AMPs may improve the privacy of
> LN
>     Intermediaries are now unaware to how much of the total payment
> they are
>     forwarding, or even if they are forwarding a partial payment at
> all.
>
>
>   - Using smaller payments increases the set of possible paths a
> partial
>     payment could have taken, which reduces the effectiveness of
> static
>     analysis techniques involving channel capacities and the plaintext
>     values being forwarded.
>
>
>
>
> Protocol Overview
> ==================
> This design can be seen as a generalization of the single,
> non-interactive
> payment scheme, that uses decoding of extra onion blobs (EOBs?) to
> encode
> extra data for the receiver. In that design, the extra data includes a
> payment preimage that the receiver can use to settle back the payment.
> EOBs
> and some method of parsing them are really the only requirement for
> this
> protocol to work. Thus, only the sender and receiver need to implement
> this
> feature in order for it to function, which can be announced using a
> feature
> bit.
>
>
> First, let's review the current format of the per-hop payload for each
> node
> described in BOLT-0004.
>
>
> ┌───────────────┬───────────────────┬────────────────┬───────────────────────┬─────────────────┬─────────────────┐
> │Realm (1 byte) │Next Addr (8 bytes)│Amount (8 bytes)│Outgoing CLTV (4
> bytes)│Unused (12 bytes)│ HMAC (32 bytes) │
> └───────────────┴───────────────────┴────────────────┴───────────────────────┴─────────────────┴─────────────────┘
> ■────────────────────────────────────────────────────────────────────────────────────────────────────────────────■
>                                               ┌─────────────────┐
>                                               │65 Bytes Per Hop │
>                                               └─────────────────┘
>
>
> Currently, *each* node gets a 65-byte payload. We use this payload to
> give
> each node instructions on *how* to forward a payment. We tell each
> node: the
> realm (or chain to forward on), then next node to forward to, the
> amount to
> forward (this is where fees are extracted by forwarding out less than
> in),
> the outgoing CLTV (allows verification that the prior node didn't
> modify any
> values), and finally an HMAC over the entire thing.
>
>
> Two important points:
>   1. We have 12 bytes for each hop that are currently unpurposed and
> can be
>   used by application protocols to signal new interpretation of bytes
> and
>   also deliver additional encrypted+authenticated data to *each* hop.
>
>
>   2. The protocol currently has a hard limit of 20-hops. With this
> feature
>   we ensure that the packet stays fixed sized during processing in
> order to
>   avoid leaking positional information. Typically most payments won't
> use
>   all 20 hops, as a result, we can use the remaining hops to stuff in
> *even
>   more* data.
>
>
>
>
> Protocol Description
> ====================
> The solution we propose is Atomic Multi-path Payments (AMPs). At a
> high
> level, this leverages EOBs to deliver additive shares of a base
> preimage,
> from which the payment preimages of partial payments can be derived.
> The
> receiver can only construct this value after having received all of
> the
> partial payments, satisfying the atomicity constraint.
>
>
> The basic protocol:

>
>
> Primitives
> ==========
> Let H be a CRH function.
> Let || denote concatenation.
> Let ^ denote xor.

>
>
>
>
> Sender Requirements
> ===================
> The parameters to the sending procedure are a random identifier ID,
> the
> number of partial payments n, and the total payment value V. Assume
> the
> sender has some way of dividing V such that V = v_1 + … + v_n.
>
>
> To begin, the sender builds the base preimage BP, from which n partial
> preimages will be derived. Next, the sender samples n additive shares
> s_1,
> …, s_n, and takes the sum to compute BP = s_1 ^ … ^ s_n.
>
>
> With the base preimage created, the sender now moves on to
> constructing the
> n partial payments. For each i in [1,n], the sender deterministically
> computes the partial preimage r_i = H(BP ||  i), by concatenating the
> sequence number i to the base preimage and hashing the result.
> Afterwards,
> it applies H to determine the payment hash to use in the i’th partial
> payment as h_i = H(r_i). Note that that with this preimage derivation
> scheme, once the payments are pulled each pre-image is distinct and
> indistinguishable from any other.
>
>
> With all of the pieces in place, the sender initiates the i’th payment
> by
> constructing a route to the destination with value v_i and payment
> hash h_i.
> The tuple (ID, n, s_i) is included in the EOB to be opened by the
> receiver.
>
>
> In order to include the three tuple within the per-hop payload for the
> final
> destination, we repurpose the _first_ byte of the un-used padding
> bytes in
> the payload to signal version 0x01 of the AMP protocol (note this is a
> PoC
> outline, we would need to standardize signalling of these 12 bytes to
> support other protocols). Typically this byte isn't set, so the
> existence of
> this means that we're (1) using AMP, and (2) the receiver should
> consume the
> _next_ hop as well. So if the payment length is actually 5, the sender
> tacks
> on an additional dummy 6th hop, encrypted with the _same_ shared
> secret for
> that hop to deliver the e2e encrypted data.
>
>
> Note, the sender can retry partial payments just as they would normal
> payments, since they are order invariant, and would be
> indistinguishable
> from regular payments to intermediaries in the network.

>
>
>
>
> Receiver
Requirements
> =====================
>
>
> Upon the arrival of each partial payment, the receiver will
> iteratively
> reconstruct BP, and do some bookkeeping to figure out when to settle
> the
> partial payments. During this reconstruction process, the receiver
> does not
> need to be aware of the order in which the payments were sent, and in
> fact
> nothing about the incoming partial payments reveals this information
> to the
> receiver, though this can be learned after reconstructing BP.
>
>
> Each EOB is decoded to retrieve (ID, n, s_i), where i is the unique
> but
> unknown index of the incoming partial payment. The receiver has access
> to
> persistent key-value store DB that maps ID to (n, c*, BP*), where c*
> represents the number of partial payments received, BP* is the sum of
> the
> received additive shares, and the superscript * denotes that the value
> is
> being updated iteratively. c* and BP* both have initial values of 0.
>
>
> In the basic protocol, the receiver cache’s the first n it sees, and
> verifies that all incoming partial payments have the same n. The
> receiver
> should reject all partial payments if any EOB deviates.  Next, the we
> update
> our persistent store with DB[ID] = (n, c* + 1, BP* ^ s_i), advancing
> the
> reconstruction by one step.
>
>
> If c* + 1 < n, there are still more packets in flight, so we sit
> tight.
> Otherwise, the receiver assumes all partial payments have arrived, and
> can
> being settling them back. Using the base preimage BP = BP* ^ s_i from
> our
> final iteration, the receiver can re-derive all n partial preimages
> and
> payment hashes, using r_i = H(BP || i) and h_i = H(r_i) simply through
> knowledge of n and BP.
>
>
> Finally, the receiver settles back any outstanding payments that
> include
> payment hash h_i using the partial preimage r_i. Each r_i will appear
> random
> due to the nature of H, as will it’s corresponding h_i. Thus, each
> partial
> payment should appear uncorrelated, and does not reveal that it is
> part of
> an AMP nor the number of partial payments used.
>
>
> Non-interactive to Interactive AMPs
> ===================================
>
>
> Sender simply receives an ID and amount from the receiver in an
> invoice
> before initiating the protocol. The receiver should only consider the
> invoice settled if the total amount received in partial payments
> containing
> ID matches or exceeds the amount specified in the invoice. With this
> variant, the receiver is able to map all partial payments to a
> pre-generated
> invoice statement.
>
>
>
>
> Additive Shares vs Threshold-Shares
> ===================================
>
>
> The biggest reason to use additive shares seems to be atomicity.
> Threshold
> shares open the door to some partial payments being settled, even if
> others
> are left in flight. Haven’t yet come up with a good reason for using
> threshold schemes, but there seem to be plenty against it.
>
>
> Reconstruction of additive shares can be done iteratively, and is win
> for
> the storage and computation requirements on the receiving end. If the
> sender
> decides to use fewer than n partial payments, the remaining shares
> could be
> included in the EOB of the final partial payment to allow the sender
> to
> reconstruct sooner. Sender could also optimistically do partial
> reconstruction on this last aggregate value.
>
>
>
>
> Adaptive AMPs
> =============
>
>
> The sender may not always be aware of how many partial payments they
> wish to
> send at the time of the first partial payment, at which point the
> simplified
> protocol would require n to be chosen. To accommodate, the above
> scheme can
> be adapted to handle a dynamically chosen n by iteratively
> constructing the
> shared secrets as follows.
>
>
> Starting with a base preimage BP, the key trick is that the sender
> remember
> the difference between the base preimage and the sum of all partial
> preimages used so far. The relation is described using the following
> equations:
>
>
>     X_0 = 0

>     X_i = X_{i-1} ^ s_i

>     X_n = BP ^ X_{n-1}
>
>
> where if n=1, X_1 = BP, implying that this is in fact a generalization
> of
> the single, non-interactive payment scheme mentioned above. For
> i=1, ...,
> n-1, the sender sends s_i in the EOB, and  X_n for the n-th share.
>
>
> Iteratively reconstructing s_1 ^ …. ^ s_{n-1} ^ X_n = BP, allows the
> receiver to compute all relevant r_i = H(BP || i) and h_i = H(r_i).
> Lastly,
> the final number of partial payments n could be signaled in the final
> EOB,
> which would also serve as a sentinel value for signaling completion.
> In
> response to DOS vectors stemming from unknown values of n,
> implementations
> could consider advertising a maximum value for n, or adopting some
> sort of
> framing pattern for conveying that more partial payments are on the
> way.
>
>
> We can further modify our usage of the per-hop payloads to send
> (H(BP), s_i) to
> consume most of the EOB sent from sender to receiver. In this
> scenario, we'd
> repurpose the 11-bytes *after* our signalling byte in the unused byte
> section
> to store the payment ID (which should be unique for each payment). In
> the case
> of a non-interactive payment, this will be unused. While for
> interactive
> payments, this will be the ID within the invoice. To deliver this
> slimmer
> 2-tuple, we'll use 32-bytes for the hash of the BP, and 32-bytes for
> the
> partial pre-image share, leaving an un-used byte in the payload.
>
>
>
>
> Cross-Chain AMPs
> ================
>
>
> AMPs can be used to pay a receiver in multiple currencies
> atomically...which
> is pretty cool :D
>
>
>
>
> Open Research Questions
> =======================
>
>
> The above is a protocol sketch to achieve atomic multi-path payments
> over
> Lightning. The details concerning onion blob usage serves as a
> template that
> future protocols can draw upon in order to deliver additional data to
> *any*
> hop in the route. However, there are still a few open questions before
> something like this can be feasibly deployed.
>
>
> 1. How does the sender decide how many chunked payments to send, and
> the
> size of each payment?
>
>
>   - Upon a closer examination, this seems to overlap with the task of
>     congestion control within TCP. The sender may be able to utilize
>     inspired heuristics to gauge: (1) how large the initial payment
> should be
>     and (2) how many subsequent payments may be required. Note that if
> the
>     first payment succeeds, then the exchange is over in a signal
> round.
>
>
> 2. How can AMP and HORNET be composed?
>
>
>   - If we eventually integrate HORNET, then a distinct communications
>     sessions can be established to allow the sender+receiver to
> exchange
>     up-to-date partial payment information. This may allow the sender
> to more
>     accurately size each partial payment.
>
> 3. Can the sender's initial strategy be governed by an instance of the
> Push-relabel max flow algo?
>
>
> 4. How does this mesh with the current max HTLC limit on a commitment?
>
>
>    - ATM, we have a max limit on the number of active HTLC's on a
> particular
>      commitment transaction. We do this, as otherwise it's possible
> that the
>      transaction is too large, and exceeds standardness w.r.t
> transaction
>      size. In a world where most payments use an AMP-like protocol,
> then
>      overall ant any given instance there will be several pending
> HTLC's on
>      commitments network wise.
>
>
>      This may incentivize nodes to open more channels in order to
> support
>      the increased commitment space utilization.
>
>
>
>
> Conclusion
> ==========
>
>
> We've presented a design outline of how to integrate atomic multi-path
> payments (AMP) into Lightning. The existence of such a construct
> allows a
> sender to atomically split a payment flow amongst several individual
> payment
> flows. As a result, larger channels aren't as important as it's
> possible to
> utilize one total outbound payment bandwidth to send several channels.
> Additionally, in order to support the increased load, internal routing
> nodes
> are incensed have more active channels. The existence of AMP-like
> payments
> may also increase the longevity of channels as there'll be smaller,
> more
> numerous payment flows, making it unlikely that a single payment comes
> across unbalances a channel entirely. We've also showed how one can
> utilize
> the current onion packet format to deliver additional data from a
> sender to
> receiver, that's still e2e authenticated.
>
>
>
>
> -- Conner && Laolu
>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
Cezary Dziemian in reply to CJP permalink original

That would be great improvement, if AMP could work this way:

1. I would like to send 0.1 BTC, so I split this to 5 payment 0.02 BTC each + one extra 0.02 BTC payment. 2. When recipient received 6 htlcs, he is able to spend only 5 of them. If recipient receives, only 5 of them, it is still fine, and payment is success.

In such scenario, single route/payment would fail, and payment as whole would still be success. Do you think that would be possible? It could greatly increase reliability of LN payments.

2018-02-09 11:15 GMT+01:00 CJP <cjp at ultimatestunts.nl>:

Quoted text (618 lines)
> Can you give a use case for this?
>
> Usually, especially in the common case that a payment is done in
> exchange for some non-cryptographic asset (e.g. physical goods), there
> already is some kind of trust between payer and payee. So, if a payment
> is split non-atomically into smaller transactions, and only a part
> succeeds, presumably they can cooperatively figure out some way to
> settle the situation.
>
> I spoke to people of the "interledger" project, and what they are
> planning to do is to non-atomically split *every* transaction into lots
> of micro-payments. In fact, they consider it unnecessary to enforce
> HTLCs with scripts, because their amounts are so small(*). If one
> micro-payment fails, that just makes them learn that a certain channel
> is unreliable, and they'll send further payments (and even the remaining
> part of the same payment) through a different route.
>
> CJP
>
> (*) not worth the extra on-blockchain fee due to the increased tx size.
>
> Olaoluwa Osuntokun schreef op di 06-02-2018 om 05:26 [+0000]:
> > Hi Y'all,
> >
> >
> > A common question I've seen concerning Lightning is: "I have five $2
> > channels, is it possible for me to *atomically* send $6 to fulfill a
> > payment?". The answer to this question is "yes", provided that the
> > receiver
> > waits to pull all HTLC's until the sum matches their invoice.
> > Typically, one
> > assumes that the receiver will supply a payment hash, and the sender
> > will
> > re-use the payment hash for all streams. This has the downside of
> > payment
> > hash re-use across *multiple* payments (which can already easily be
> > correlated), and also has a failure mode where if the sender fails to
> > actually satisfy all the payment flows, then the receiver can still
> > just
> > pull the monies (and possibly not disperse a service, or w/e).
> >
> >
> > Conner Fromknecht and I have come up with a way to achieve this over
> > Lightning while (1) not re-using any payment hashes across all payment
> > flows, and (2) adding a *strong* guarantee that the receiver won't be
> > paid
> > until *all* partial payment flows are extended. We call this scheme
> > AMP
> > (Atomic Multi-path Payments). It can be experimented with on Lightning
> > *today* with the addition of a new feature bit to gate this new
> > feature. The beauty of the scheme is that it requires no fundamental
> > changes
> > to the protocol as is now, as the negotiation is strictly *end-to-end*
> > between sender and receiver.
> >
> >
> > TL;DR: we repurpose some unused space in the onion per-hop payload of
> > the
> > onion blob to signal our protocol (and deliver some protocol-specific
> > data),
> > then use additive secret sharing to ensure that the receiver can't
> > pull the
> > payment until they have enough shares to reconstruct the original
> > pre-image.
> >
> >
> >
> >
> > Protocol Goals
> > ==============
> > 1. Atomicity: The logical transaction should either succeed or fail in
> > entirety. Naturally, this implies that the receiver should not be
> > unable to
> > settle *any* of the partial payments, until all of them have arrived.
> >
> >
> > 2. Avoid Payment Hash Reuse: The payment preimages validated by the
> > consensus layer should be distinct for each partial payment.
> > Primarily,
> > this helps avoid correlation of the partial payments, and ensures that
> > malicious intermediaries straddling partial payments cannot steal
> > funds.
> >
> >
> > 3. Order Invariance: The protocol should be forgiving to the order in
> > which
> > partial payments arrive at the destination, adding robustness in the
> > face of
> > delays or routing failures.
> >
> >
> > 4. Non-interactive Setup: It should be possible for the sender to
> > perform an
> > AMP without directly coordinating with the receiving node.
> > Predominantly,
> > this means that the *sender* is able to determine the number of
> > partial
> > payments to use for a particular AMP, which makes sense since they
> > will be
> > the one fronting the fees for the cost of this parameter. Plus, we can
> > always turn a non-interactive protocol into an interactive one for the
> > purposes of invoicing.
> >
> >
> >
> >
> > Protocol Benefits
> > =================
> >
> >
> > Sending pay payments predominantly over an AMP-like protocol has
> > several
> > clear benefits:
> >
> >
> >   - Eliminates the constraint that a single path from sender to
> > receiver
> >     with sufficient directional capacity. This reduces the pressure to
> > have
> >     larger channels in order to support larger payment flows. As a
> > result,
> >     the payment graph be very diffused, without sacrificing payment
> >     utility
> >
> >
> >   - Reduces strain from larger payments on individual paths, and
> > allows the
> >     liquidity imbalances to be more diffuse. We expect this to have a
> >     non-negligible impact on channel longevity. This is due to the
> > fact that
> >     with usage of AMP, payment flows are typically *smaller* meaning
> > that
> >     each payment will unbalance a channel to a lesser degree that
> >     with one giant flow.
> >
> >
> >   - Potential fee savings for larger payments, contingent on there
> > being a
> >     super-linear component to routed fees. It's possible that with
> >     modifications to the fee schedule, it's actually *cheaper* to send
> >     payments over multiple flows rather than one giant flow.
> >
> >
> >   - Allows for logical payments larger than the current maximum value
> > of an
> >     individual payment. Atm we have a (temporarily) limit on the max
> > payment
> >     size. With AMP, this can be side stepped as each flow can be up
> > the max
> >     size, with the sum of all flows exceeding the max.
> >
> >
> >   - Given sufficient path diversity, AMPs may improve the privacy of
> > LN
> >     Intermediaries are now unaware to how much of the total payment
> > they are
> >     forwarding, or even if they are forwarding a partial payment at
> > all.
> >
> >
> >   - Using smaller payments increases the set of possible paths a
> > partial
> >     payment could have taken, which reduces the effectiveness of
> > static
> >     analysis techniques involving channel capacities and the plaintext
> >     values being forwarded.
> >
> >
> >
> >
> > Protocol Overview
> > ==================
> > This design can be seen as a generalization of the single,
> > non-interactive
> > payment scheme, that uses decoding of extra onion blobs (EOBs?) to
> > encode
> > extra data for the receiver. In that design, the extra data includes a
> > payment preimage that the receiver can use to settle back the payment.
> > EOBs
> > and some method of parsing them are really the only requirement for
> > this
> > protocol to work. Thus, only the sender and receiver need to implement
> > this
> > feature in order for it to function, which can be announced using a
> > feature
> > bit.
> >
> >
> > First, let's review the current format of the per-hop payload for each
> > node
> > described in BOLT-0004.
> >
> >
> > ┌───────────────┬───────────────────┬────────────────┬──────
> ─────────────────┬─────────────────┬─────────────────┐
> > │Realm (1 byte) │Next Addr (8 bytes)│Amount (8 bytes)│Outgoing CLTV (4
> > bytes)│Unused (12 bytes)│ HMAC (32 bytes) │
> > └───────────────┴───────────────────┴────────────────┴──────
> ─────────────────┴─────────────────┴─────────────────┘
> > ■───────────────────────────────────────────────────────────
> ─────────────────────────────────────────────────────■
> >                                               ┌─────────────────┐
> >                                               │65 Bytes Per Hop │
> >                                               └─────────────────┘
> >
> >
> > Currently, *each* node gets a 65-byte payload. We use this payload to
> > give
> > each node instructions on *how* to forward a payment. We tell each
> > node: the
> > realm (or chain to forward on), then next node to forward to, the
> > amount to
> > forward (this is where fees are extracted by forwarding out less than
> > in),
> > the outgoing CLTV (allows verification that the prior node didn't
> > modify any
> > values), and finally an HMAC over the entire thing.
> >
> >
> > Two important points:
> >   1. We have 12 bytes for each hop that are currently unpurposed and
> > can be
> >   used by application protocols to signal new interpretation of bytes
> > and
> >   also deliver additional encrypted+authenticated data to *each* hop.
> >
> >
> >   2. The protocol currently has a hard limit of 20-hops. With this
> > feature
> >   we ensure that the packet stays fixed sized during processing in
> > order to
> >   avoid leaking positional information. Typically most payments won't
> > use
> >   all 20 hops, as a result, we can use the remaining hops to stuff in
> > *even
> >   more* data.
> >
> >
> >
> >
> > Protocol Description
> > ====================
> > The solution we propose is Atomic Multi-path Payments (AMPs). At a
> > high
> > level, this leverages EOBs to deliver additive shares of a base
> > preimage,
> > from which the payment preimages of partial payments can be derived.
> > The
> > receiver can only construct this value after having received all of
> > the
> > partial payments, satisfying the atomicity constraint.
> >
> >
> > The basic protocol:
> >
> >
> > Primitives
> > ==========
> > Let H be a CRH function.
> > Let || denote concatenation.
> > Let ^ denote xor.
> >
> >
> >
> >
> > Sender Requirements
> > ===================
> > The parameters to the sending procedure are a random identifier ID,
> > the
> > number of partial payments n, and the total payment value V. Assume
> > the
> > sender has some way of dividing V such that V = v_1 + … + v_n.
> >
> >
> > To begin, the sender builds the base preimage BP, from which n partial
> > preimages will be derived. Next, the sender samples n additive shares
> > s_1,
> > …, s_n, and takes the sum to compute BP = s_1 ^ … ^ s_n.
> >
> >
> > With the base preimage created, the sender now moves on to
> > constructing the
> > n partial payments. For each i in [1,n], the sender deterministically
> > computes the partial preimage r_i = H(BP ||  i), by concatenating the
> > sequence number i to the base preimage and hashing the result.
> > Afterwards,
> > it applies H to determine the payment hash to use in the i’th partial
> > payment as h_i = H(r_i). Note that that with this preimage derivation
> > scheme, once the payments are pulled each pre-image is distinct and
> > indistinguishable from any other.
> >
> >
> > With all of the pieces in place, the sender initiates the i’th payment
> > by
> > constructing a route to the destination with value v_i and payment
> > hash h_i.
> > The tuple (ID, n, s_i) is included in the EOB to be opened by the
> > receiver.
> >
> >
> > In order to include the three tuple within the per-hop payload for the
> > final
> > destination, we repurpose the _first_ byte of the un-used padding
> > bytes in
> > the payload to signal version 0x01 of the AMP protocol (note this is a
> > PoC
> > outline, we would need to standardize signalling of these 12 bytes to
> > support other protocols). Typically this byte isn't set, so the
> > existence of
> > this means that we're (1) using AMP, and (2) the receiver should
> > consume the
> > _next_ hop as well. So if the payment length is actually 5, the sender
> > tacks
> > on an additional dummy 6th hop, encrypted with the _same_ shared
> > secret for
> > that hop to deliver the e2e encrypted data.
> >
> >
> > Note, the sender can retry partial payments just as they would normal
> > payments, since they are order invariant, and would be
> > indistinguishable
> > from regular payments to intermediaries in the network.
> >
> >
> >
> >
> > Receiver Requirements
> > =====================
> >
> >
> > Upon the arrival of each partial payment, the receiver will
> > iteratively
> > reconstruct BP, and do some bookkeeping to figure out when to settle
> > the
> > partial payments. During this reconstruction process, the receiver
> > does not
> > need to be aware of the order in which the payments were sent, and in
> > fact
> > nothing about the incoming partial payments reveals this information
> > to the
> > receiver, though this can be learned after reconstructing BP.
> >
> >
> > Each EOB is decoded to retrieve (ID, n, s_i), where i is the unique
> > but
> > unknown index of the incoming partial payment. The receiver has access
> > to
> > persistent key-value store DB that maps ID to (n, c*, BP*), where c*
> > represents the number of partial payments received, BP* is the sum of
> > the
> > received additive shares, and the superscript * denotes that the value
> > is
> > being updated iteratively. c* and BP* both have initial values of 0.
> >
> >
> > In the basic protocol, the receiver cache’s the first n it sees, and
> > verifies that all incoming partial payments have the same n. The
> > receiver
> > should reject all partial payments if any EOB deviates.  Next, the we
> > update
> > our persistent store with DB[ID] = (n, c* + 1, BP* ^ s_i), advancing
> > the
> > reconstruction by one step.
> >
> >
> > If c* + 1 < n, there are still more packets in flight, so we sit
> > tight.
> > Otherwise, the receiver assumes all partial payments have arrived, and
> > can
> > being settling them back. Using the base preimage BP = BP* ^ s_i from
> > our
> > final iteration, the receiver can re-derive all n partial preimages
> > and
> > payment hashes, using r_i = H(BP || i) and h_i = H(r_i) simply through
> > knowledge of n and BP.
> >
> >
> > Finally, the receiver settles back any outstanding payments that
> > include
> > payment hash h_i using the partial preimage r_i. Each r_i will appear
> > random
> > due to the nature of H, as will it’s corresponding h_i. Thus, each
> > partial
> > payment should appear uncorrelated, and does not reveal that it is
> > part of
> > an AMP nor the number of partial payments used.
> >
> >
> > Non-interactive to Interactive AMPs
> > ===================================
> >
> >
> > Sender simply receives an ID and amount from the receiver in an
> > invoice
> > before initiating the protocol. The receiver should only consider the
> > invoice settled if the total amount received in partial payments
> > containing
> > ID matches or exceeds the amount specified in the invoice. With this
> > variant, the receiver is able to map all partial payments to a
> > pre-generated
> > invoice statement.
> >
> >
> >
> >
> > Additive Shares vs Threshold-Shares
> > ===================================
> >
> >
> > The biggest reason to use additive shares seems to be atomicity.
> > Threshold
> > shares open the door to some partial payments being settled, even if
> > others
> > are left in flight. Haven’t yet come up with a good reason for using
> > threshold schemes, but there seem to be plenty against it.
> >
> >
> > Reconstruction of additive shares can be done iteratively, and is win
> > for
> > the storage and computation requirements on the receiving end. If the
> > sender
> > decides to use fewer than n partial payments, the remaining shares
> > could be
> > included in the EOB of the final partial payment to allow the sender
> > to
> > reconstruct sooner. Sender could also optimistically do partial
> > reconstruction on this last aggregate value.
> >
> >
> >
> >
> > Adaptive AMPs
> > =============
> >
> >
> > The sender may not always be aware of how many partial payments they
> > wish to
> > send at the time of the first partial payment, at which point the
> > simplified
> > protocol would require n to be chosen. To accommodate, the above
> > scheme can
> > be adapted to handle a dynamically chosen n by iteratively
> > constructing the
> > shared secrets as follows.
> >
> >
> > Starting with a base preimage BP, the key trick is that the sender
> > remember
> > the difference between the base preimage and the sum of all partial
> > preimages used so far. The relation is described using the following
> > equations:
> >
> >
> >     X_0 = 0
> >     X_i = X_{i-1} ^ s_i
> >     X_n = BP ^ X_{n-1}
> >
> >
> > where if n=1, X_1 = BP, implying that this is in fact a generalization
> > of
> > the single, non-interactive payment scheme mentioned above. For
> > i=1, ...,
> > n-1, the sender sends s_i in the EOB, and  X_n for the n-th share.
> >
> >
> > Iteratively reconstructing s_1 ^ …. ^ s_{n-1} ^ X_n = BP, allows the
> > receiver to compute all relevant r_i = H(BP || i) and h_i = H(r_i).
> > Lastly,
> > the final number of partial payments n could be signaled in the final
> > EOB,
> > which would also serve as a sentinel value for signaling completion.
> > In
> > response to DOS vectors stemming from unknown values of n,
> > implementations
> > could consider advertising a maximum value for n, or adopting some
> > sort of
> > framing pattern for conveying that more partial payments are on the
> > way.
> >
> >
> > We can further modify our usage of the per-hop payloads to send
> > (H(BP), s_i) to
> > consume most of the EOB sent from sender to receiver. In this
> > scenario, we'd
> > repurpose the 11-bytes *after* our signalling byte in the unused byte
> > section
> > to store the payment ID (which should be unique for each payment). In
> > the case
> > of a non-interactive payment, this will be unused. While for
> > interactive
> > payments, this will be the ID within the invoice. To deliver this
> > slimmer
> > 2-tuple, we'll use 32-bytes for the hash of the BP, and 32-bytes for
> > the
> > partial pre-image share, leaving an un-used byte in the payload.
> >
> >
> >
> >
> > Cross-Chain AMPs
> > ================
> >
> >
> > AMPs can be used to pay a receiver in multiple currencies
> > atomically...which
> > is pretty cool :D
> >
> >
> >
> >
> > Open Research Questions
> > =======================
> >
> >
> > The above is a protocol sketch to achieve atomic multi-path payments
> > over
> > Lightning. The details concerning onion blob usage serves as a
> > template that
> > future protocols can draw upon in order to deliver additional data to
> > *any*
> > hop in the route. However, there are still a few open questions before
> > something like this can be feasibly deployed.
> >
> >
> > 1. How does the sender decide how many chunked payments to send, and
> > the
> > size of each payment?
> >
> >
> >   - Upon a closer examination, this seems to overlap with the task of
> >     congestion control within TCP. The sender may be able to utilize
> >     inspired heuristics to gauge: (1) how large the initial payment
> > should be
> >     and (2) how many subsequent payments may be required. Note that if
> > the
> >     first payment succeeds, then the exchange is over in a signal
> > round.
> >
> >
> > 2. How can AMP and HORNET be composed?
> >
> >
> >   - If we eventually integrate HORNET, then a distinct communications
> >     sessions can be established to allow the sender+receiver to
> > exchange
> >     up-to-date partial payment information. This may allow the sender
> > to more
> >     accurately size each partial payment.
> >
> > 3. Can the sender's initial strategy be governed by an instance of the
> > Push-relabel max flow algo?
> >
> >
> > 4. How does this mesh with the current max HTLC limit on a commitment?
> >
> >
> >    - ATM, we have a max limit on the number of active HTLC's on a
> > particular
> >      commitment transaction. We do this, as otherwise it's possible
> > that the
> >      transaction is too large, and exceeds standardness w.r.t
> > transaction
> >      size. In a world where most payments use an AMP-like protocol,
> > then
> >      overall ant any given instance there will be several pending
> > HTLC's on
> >      commitments network wise.
> >
> >
> >      This may incentivize nodes to open more channels in order to
> > support
> >      the increased commitment space utilization.
> >
> >
> >
> >
> > Conclusion
> > ==========
> >
> >
> > We've presented a design outline of how to integrate atomic multi-path
> > payments (AMP) into Lightning. The existence of such a construct
> > allows a
> > sender to atomically split a payment flow amongst several individual
> > payment
> > flows. As a result, larger channels aren't as important as it's
> > possible to
> > utilize one total outbound payment bandwidth to send several channels.
> > Additionally, in order to support the increased load, internal routing
> > nodes
> > are incensed have more active channels. The existence of AMP-like
> > payments
> > may also increase the longevity of channels as there'll be smaller,
> > more
> > numerous payment flows, making it unlikely that a single payment comes
> > across unbalances a channel entirely. We've also showed how one can
> > utilize
> > the current onion packet format to deliver additional data from a
> > sender to
> > receiver, that's still e2e authenticated.
> >
> >
> >
> >
> > -- Conner && Laolu
> >
> >
> > _______________________________________________
> > Lightning-dev mailing list
> > Lightning-dev at lists.linuxfoundation.org
> > https://www.learnbitcoin.com/archive/lists/lightning-dev
>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
ZmnSCPxj in reply to Cezary Dziemian permalink original

Good morning Cezary,

Quoted text (7 lines)
> That would be great improvement, if AMP could work this way:
>
> 1. I would like to send 0.1 BTC, so I split this to 5 payment 0.02 BTC each + one extra 0.02 BTC payment.
> 2. When recipient received 6 htlcs, he is able to spend only 5 of them.
> If recipient receives, only 5 of them, it is still fine, and payment is success.
>
> In such scenario, single route/payment would fail, and payment as whole would still be success. Do you think that would be possible? It could greatly increase reliability of LN payments.

I will leave it to better mathematicians to answer your direct question, but, my intuition suggests it is not possible as stated.

However, let me propose an alternative AMP method instead.

------

Roughly, we want to proceed this way.

1. When paying: 1.1. Try to pay. 1.2. If it fails, split it into two smaller payments and recurse into 1.

Now we should ensure that the receiver can only receive if it has received all payments, and once it has received all payments, it can claim all payments.

So let me first introduce the below dual:

* A pseudorandom number generator can be represented by its algorithm and the seed.  Alternatively, it can be represented by a stream of numbers.

Now, a stream of numbers has no end, but it does have a start (i.e. the first random number generated by the PRNG from the seed). It is possible to "split" a stream into two streams, by taking the 0th, 2nd, 4th... numbers in one stream, and taking the 1st, 3rd, 5th... numbers in the other stream.

Each such "split" stream can itself be further split into two streams. Split streams can be re-"merged" by interleaving their members to yield the original pre-split stream.

Now, we also want to be able to split a random seed into two seeds. This splitting need not correspond to the stream-split (i.e. the split seeds will NOT generate the split streams); we only need to split seeds to prevent the receiver from claiming partial amounts. This can be done by using another random source to generate a new "seed", and XOR it with the real seed. The split "halves" are then the random number, and seed XOR the random number; the result is two apparently random numbers which, when XORed together, generate the original seed.

Let us now sketch our algorithm:

1. def pay(seed, stream, dest, amount): 1.1. try { r = route(dest, amount, randomstuff); offer_htlc(H(stream[0]), r, seed, stream); 1.2. } catch(PaymentFailure) { sd1, sd2 = split_seed(seed); sr1, sr2 = split_stream(stream); pay(sd1, sr1, dest, amount / 2); pay(sd2, sr2, dest, amount / 2); }

Now notice that the hash we use is H(stream[0]). That is, the first item in the stream of random numbers. Thus our streams do not actually need to give anything more than the first number in a stream. We can represent a "split" stream simply by the index into the original stream. For example, if we have:

    s = original stream
    sl, sr = split_stream(s)
    sll, slr = split_stream(sl)

Then s[0] and sl[0] and sll[0] are simply index 0 into the original stream, sr[0] is index 1, and slr[0] is index 2. We can thus represent streams and their splits by the tuple (seed, index, depth), where depth indicates how many splits the stream has been through. So, for the below:

    s = (seed, 0, 0)
    sl, sr = split_stream(s) = (seed, 0, 1), (seed, 1, 1)
    sll, slr = split_stream(sl) = (seed, 0, 2), (seed, 2, 2)
    split_stream( (seed, index, depth) ) = (seed, index, depth + 1), (seed, index + 2**depth, depth + 1)

Then, for any stream s whose RNG algorithm is PRNG:

   s[0] = (seed, index, _)[0] = PRNG(seed)[index]

Let us now consider how our payment might proceed.

1. First, we generate a random seed, and call pay(seed, (seed, 0, 0), dest, amount) 2. Let us suppose that payment fails for the entire amount. Split the amount into two: 2.1. In one branch we have pay(X, (seed, 0, 1), dest, amount / 2). X is a new random number. 2.2. In other branch we have pay(seed ^ X, (seed, 1, 1), dest, amount / 2). X is the same number as branch 2.1. 2.2.1. Suppose this payment fails. Split it again intow two payments: 2.2.1.1 In one sub-branch we have pay(Y, (seed, 1, 2), dest, amount / 4). 2.2.1.2. In other sub-branch we have pay(seed ^ X ^ Y, (seed, 3, 2), dest, amount / 4).

The receiver receives the branches 2.1, 2.2.1.1, and 2.2.1.2., which provide the seeds:

2.1. => X 2.2.1.1 => Y 2.2.1.2. => seed ^X ^ Y

Xoring all of the above provides X ^ Y ^ seed ^ X ^ Y = seed.

The receiver can claim branch 2.1. by using PRNG(seed)[0], can claim branch 2.2.1.1 using PRNG(seed)[1], and branch 2.2.1.2 using PRNG(seed)[3].

Thus the sender needs only to send the split seed (say 32 bytes) and the index (say 1 byte for up to 8-level splitting into up to 256 payments). The receiver gathers each split seed, XOR them all together to get the original PRNG seed, and runs the PRNG the appropriate number of times to get the preimages of each payment.

(pragmatically we also need some kind of payment ID to differentiate different logical payments from the same sender, and to differentiate it from non-AMP)

The receiver cannot claim partial payments as it cannot determine the original seed until all branches of the payment reach it. Once it has received all branches of the payment, however, it can determine the seed and the preimage of each payment; once it does so it has incentive to get all branches, yielding atomicity.

Regards, ZmnSCPxj

Quoted text (617 lines)
> 2018-02-09 11:15 GMT+01:00 CJP <cjp at ultimatestunts.nl>:
>
>> Can you give a use case for this?
>>
>> Usually, especially in the common case that a payment is done in
>> exchange for some non-cryptographic asset (e.g. physical goods), there
>> already is some kind of trust between payer and payee. So, if a payment
>> is split non-atomically into smaller transactions, and only a part
>> succeeds, presumably they can cooperatively figure out some way to
>> settle the situation.
>>
>> I spoke to people of the "interledger" project, and what they are
>> planning to do is to non-atomically split *every* transaction into lots
>> of micro-payments. In fact, they consider it unnecessary to enforce
>> HTLCs with scripts, because their amounts are so small(*). If one
>> micro-payment fails, that just makes them learn that a certain channel
>> is unreliable, and they'll send further payments (and even the remaining
>> part of the same payment) through a different route.
>>
>> CJP
>>
>> (*) not worth the extra on-blockchain fee due to the increased tx size.
>>
>> Olaoluwa Osuntokun schreef op di 06-02-2018 om 05:26 [+0000]:
>>
>>> Hi Y'all,
>>>
>>>
>>> A common question I've seen concerning Lightning is: "I have five $2
>>> channels, is it possible for me to *atomically* send $6 to fulfill a
>>> payment?". The answer to this question is "yes", provided that the
>>> receiver
>>> waits to pull all HTLC's until the sum matches their invoice.
>>> Typically, one
>>> assumes that the receiver will supply a payment hash, and the sender
>>> will
>>> re-use the payment hash for all streams. This has the downside of
>>> payment
>>> hash re-use across *multiple* payments (which can already easily be
>>> correlated), and also has a failure mode where if the sender fails to
>>> actually satisfy all the payment flows, then the receiver can still
>>> just
>>> pull the monies (and possibly not disperse a service, or w/e).
>>>
>>>
>>> Conner Fromknecht and I have come up with a way to achieve this over
>>> Lightning while (1) not re-using any payment hashes across all payment
>>> flows, and (2) adding a *strong* guarantee that the receiver won't be
>>> paid
>>> until *all* partial payment flows are extended. We call this scheme
>>> AMP
>>> (Atomic Multi-path Payments). It can be experimented with on Lightning
>>> *today* with the addition of a new feature bit to gate this new
>>> feature. The beauty of the scheme is that it requires no fundamental
>>> changes
>>> to the protocol as is now, as the negotiation is strictly *end-to-end*
>>> between sender and receiver.
>>>
>>>
>>> TL;DR: we repurpose some unused space in the onion per-hop payload of
>>> the
>>> onion blob to signal our protocol (and deliver some protocol-specific
>>> data),
>>> then use additive secret sharing to ensure that the receiver can't
>>> pull the
>>> payment until they have enough shares to reconstruct the original
>>> pre-image.
>>>
>>>
>>>
>>>
>>> Protocol Goals
>>> ==============
>>> 1. Atomicity: The logical transaction should either succeed or fail in
>>> entirety. Naturally, this implies that the receiver should not be
>>> unable to
>>> settle *any* of the partial payments, until all of them have arrived.
>>>
>>>
>>> 2. Avoid Payment Hash Reuse: The payment preimages validated by the
>>> consensus layer should be distinct for each partial payment.
>>> Primarily,
>>> this helps avoid correlation of the partial payments, and ensures that
>>> malicious intermediaries straddling partial payments cannot steal
>>> funds.
>>>
>>>
>>> 3. Order Invariance: The protocol should be forgiving to the order in
>>> which
>>> partial payments arrive at the destination, adding robustness in the
>>> face of
>>> delays or routing failures.
>>>
>>>
>>> 4. Non-interactive Setup: It should be possible for the sender to
>>> perform an
>>> AMP without directly coordinating with the receiving node.
>>> Predominantly,
>>> this means that the *sender* is able to determine the number of
>>> partial
>>> payments to use for a particular AMP, which makes sense since they
>>> will be
>>> the one fronting the fees for the cost of this parameter. Plus, we can
>>> always turn a non-interactive protocol into an interactive one for the
>>> purposes of invoicing.
>>>
>>>
>>>
>>>
>>> Protocol Benefits

>>> =================
>>>
>>>
>>> Sending pay payments predominantly over an AMP-like protocol has
>>> several
>>> clear benefits:
>>>
>>>
>>>   - Eliminates the constraint that a single path from sender to
>>> receiver
>>>     with sufficient directional capacity. This reduces the pressure to
>>> have
>>>     larger channels in order to support larger payment flows. As a
>>> result,
>>>     the payment graph be very diffused, without sacrificing payment
>>>     utility
>>>
>>>
>>>   - Reduces strain from larger payments on individual paths, and
>>> allows the
>>>     liquidity imbalances to be more diffuse. We expect this to have a
>>>     non-negligible impact on channel longevity. This is due to the
>>> fact that
>>>     with usage of AMP, payment flows are typically *smaller* meaning
>>> that
>>>     each payment will unbalance a channel to a lesser degree that
>>>     with one giant flow.
>>>
>>>
>>>   - Potential fee savings for larger payments, contingent on there
>>> being a
>>>     super-linear component to routed fees. It's possible that with
>>>     modifications to the fee schedule, it's actually *cheaper* to send
>>>     payments over multiple flows rather than one giant flow.
>>>
>>>
>>>   - Allows for logical payments larger than the current maximum value
>>> of an
>>>     individual payment. Atm we have a (temporarily) limit on the max
>>> payment
>>>     size. With AMP, this can be side stepped as each flow can be up
>>> the max
>>>     size, with the sum of all flows exceeding the max.
>>>
>>>
>>>   - Given sufficient path diversity, AMPs may improve the privacy of
>>> LN
>>>     Intermediaries are now unaware to how much of the total payment
>>> they are
>>>     forwarding, or even if they are forwarding a partial payment at
>>> all.
>>>
>>>
>>>   - Using smaller payments increases the set of possible paths a
>>> partial
>>>     payment could have taken, which reduces the effectiveness of
>>> static
>>>     analysis techniques involving channel capacities and the plaintext
>>>     values being forwarded.
>>>
>>>
>>>
>>>
>>> Protocol Overview
>>> ==================
>>> This design can be seen as a generalization of the single,
>>> non-interactive
>>> payment scheme, that uses decoding of extra onion blobs (EOBs?) to
>>> encode
>>> extra data for the receiver. In that design, the extra data includes a
>>> payment preimage that the receiver can use to settle back the payment.
>>> EOBs
>>> and some method of parsing them are really the only requirement for
>>> this
>>> protocol to work. Thus, only the sender and receiver need to implement
>>> this
>>> feature in order for it to function, which can be announced using a
>>> feature
>>> bit.
>>>
>>>
>>> First, let's review the current format of the per-hop payload for each
>>> node
>>> described in BOLT-0004.
>>>
>>>
>>> ┌───────────────┬───────────────────┬────────────────┬───────────────────────┬─────────────────┬─────────────────┐
>>> │Realm (1 byte) │Next Addr (8 bytes)│Amount (8 bytes)│Outgoing CLTV (4
>>> bytes)│Unused (12 bytes)│ HMAC (32 bytes) │
>>> └───────────────┴───────────────────┴────────────────┴───────────────────────┴─────────────────┴─────────────────┘
>>> ■────────────────────────────────────────────────────────────────────────────────────────────────────────────────■
>>>                                               ┌─────────────────┐
>>>                                               │65 Bytes Per Hop │
>>>                                               └─────────────────┘
>>>
>>>
>>> Currently, *each* node gets a 65-byte payload. We use this payload to
>>> give
>>> each node instructions on *how* to forward a payment. We tell each
>>> node: the
>>> realm (or chain to forward on), then next node to forward to, the
>>> amount to
>>> forward (this is where fees are extracted by forwarding out less than
>>> in),
>>> the outgoing CLTV (allows verification that the prior node didn't
>>> modify any
>>> values), and finally an HMAC over the entire thing.
>>>
>>>
>>> Two important points:
>>>   1. We have 12 bytes for each hop that are currently unpurposed and
>>> can be
>>>   used by application protocols to signal new interpretation of bytes
>>> and
>>>   also deliver additional encrypted+authenticated data to *each* hop.
>>>
>>>
>>>   2. The protocol currently has a hard limit of 20-hops. With this
>>> feature
>>>   we ensure that the packet stays fixed sized during processing in
>>> order to
>>>   avoid leaking positional information. Typically most payments won't
>>> use
>>>   all 20 hops, as a result, we can use the remaining hops to stuff in
>>> *even
>>>   more* data.
>>>
>>>
>>>
>>>
>>> Protocol Description
>>> ====================
>>> The solution we propose is Atomic Multi-path Payments (AMPs). At a
>>> high
>>> level, this leverages EOBs to deliver additive shares of a base
>>> preimage,
>>> from which the payment preimages of partial payments can be derived.
>>> The
>>> receiver can only construct this value after having received all of
>>> the
>>> partial payments, satisfying the atomicity constraint.
>>>
>>>
>>> The basic protocol:

>>>
>>>
>>> Primitives
>>> ==========
>>> Let H be a CRH function.
>>> Let || denote concatenation.
>>> Let ^ denote xor.

>>>
>>>
>>>
>>>
>>> Sender Requirements
>>> ===================
>>> The parameters to the sending procedure are a random identifier ID,
>>> the
>>> number of partial payments n, and the total payment value V. Assume
>>> the
>>> sender has some way of dividing V such that V = v_1 + … + v_n.
>>>
>>>
>>> To begin, the sender builds the base preimage BP, from which n partial
>>> preimages will be derived. Next, the sender samples n additive shares
>>> s_1,
>>> …, s_n, and takes the sum to compute BP = s_1 ^ … ^ s_n.
>>>
>>>
>>> With the base preimage created, the sender now moves on to
>>> constructing the
>>> n partial payments. For each i in [1,n], the sender deterministically
>>> computes the partial preimage r_i = H(BP ||  i), by concatenating the
>>> sequence number i to the base preimage and hashing the result.
>>> Afterwards,
>>> it applies H to determine the payment hash to use in the i’th partial
>>> payment as h_i = H(r_i). Note that that with this preimage derivation
>>> scheme, once the payments are pulled each pre-image is distinct and
>>> indistinguishable from any other.
>>>
>>>
>>> With all of the pieces in place, the sender initiates the i’th payment
>>> by
>>> constructing a route to the destination with value v_i and payment
>>> hash h_i.
>>> The tuple (ID, n, s_i) is included in the EOB to be opened by the
>>> receiver.
>>>
>>>
>>> In order to include the three tuple within the per-hop payload for the
>>> final
>>> destination, we repurpose the _first_ byte of the un-used padding
>>> bytes in
>>> the payload to signal version 0x01 of the AMP protocol (note this is a
>>> PoC
>>> outline, we would need to standardize signalling of these 12 bytes to
>>> support other protocols). Typically this byte isn't set, so the
>>> existence of
>>> this means that we're (1) using AMP, and (2) the receiver should
>>> consume the
>>> _next_ hop as well. So if the payment length is actually 5, the sender
>>> tacks
>>> on an additional dummy 6th hop, encrypted with the _same_ shared
>>> secret for
>>> that hop to deliver the e2e encrypted data.
>>>
>>>
>>> Note, the sender can retry partial payments just as they would normal
>>> payments, since they are order invariant, and would be
>>> indistinguishable
>>> from regular payments to intermediaries in the network.
>>>
>>>
>>>
>>>
>>> Receiver
Requirements
>>> =====================
>>>
>>>
>>> Upon the arrival of each partial payment, the receiver will
>>> iteratively
>>> reconstruct BP, and do some bookkeeping to figure out when to settle
>>> the
>>> partial payments. During this reconstruction process, the receiver
>>> does not
>>> need to be aware of the order in which the payments were sent, and in
>>> fact
>>> nothing about the incoming partial payments reveals this information
>>> to the
>>> receiver, though this can be learned after reconstructing BP.
>>>
>>>
>>> Each EOB is decoded to retrieve (ID, n, s_i), where i is the unique
>>> but
>>> unknown index of the incoming partial payment. The receiver has access
>>> to
>>> persistent key-value store DB that maps ID to (n, c*, BP*), where c*
>>> represents the number of partial payments received, BP* is the sum of
>>> the
>>> received additive shares, and the superscript * denotes that the value
>>> is
>>> being updated iteratively. c* and BP* both have initial values of 0.
>>>
>>>
>>> In the basic protocol, the receiver cache’s the first n it sees, and
>>> verifies that all incoming partial payments have the same n. The
>>> receiver
>>> should reject all partial payments if any EOB deviates.  Next, the we
>>> update
>>> our persistent store with DB[ID] = (n, c* + 1, BP* ^ s_i), advancing
>>> the
>>> reconstruction by one step.
>>>
>>>
>>> If c* + 1 < n, there are still more packets in flight, so we sit
>>> tight.
>>> Otherwise, the receiver assumes all partial payments have arrived, and
>>> can
>>> being settling them back. Using the base preimage BP = BP* ^ s_i from
>>> our
>>> final iteration, the receiver can re-derive all n partial preimages
>>> and
>>> payment hashes, using r_i = H(BP || i) and h_i = H(r_i) simply through
>>> knowledge of n and BP.
>>>
>>>
>>> Finally, the receiver settles back any outstanding payments that
>>> include
>>> payment hash h_i using the partial preimage r_i. Each r_i will appear
>>> random
>>> due to the nature of H, as will it’s corresponding h_i. Thus, each
>>> partial
>>> payment should appear uncorrelated, and does not reveal that it is
>>> part of
>>> an AMP nor the number of partial payments used.
>>>
>>>
>>> Non-interactive to Interactive AMPs
>>> ===================================
>>>
>>>
>>> Sender simply receives an ID and amount from the receiver in an
>>> invoice
>>> before initiating the protocol. The receiver should only consider the
>>> invoice settled if the total amount received in partial payments
>>> containing
>>> ID matches or exceeds the amount specified in the invoice. With this
>>> variant, the receiver is able to map all partial payments to a
>>> pre-generated
>>> invoice statement.
>>>
>>>
>>>
>>>
>>> Additive Shares vs Threshold-Shares
>>> ===================================
>>>
>>>
>>> The biggest reason to use additive shares seems to be atomicity.
>>> Threshold
>>> shares open the door to some partial payments being settled, even if
>>> others
>>> are left in flight. Haven’t yet come up with a good reason for using
>>> threshold schemes, but there seem to be plenty against it.
>>>
>>>
>>> Reconstruction of additive shares can be done iteratively, and is win
>>> for
>>> the storage and computation requirements on the receiving end. If the
>>> sender
>>> decides to use fewer than n partial payments, the remaining shares
>>> could be
>>> included in the EOB of the final partial payment to allow the sender
>>> to
>>> reconstruct sooner. Sender could also optimistically do partial
>>> reconstruction on this last aggregate value.
>>>
>>>
>>>
>>>
>>> Adaptive AMPs
>>> =============
>>>
>>>
>>> The sender may not always be aware of how many partial payments they
>>> wish to
>>> send at the time of the first partial payment, at which point the
>>> simplified
>>> protocol would require n to be chosen. To accommodate, the above
>>> scheme can
>>> be adapted to handle a dynamically chosen n by iteratively
>>> constructing the
>>> shared secrets as follows.
>>>
>>>
>>> Starting with a base preimage BP, the key trick is that the sender
>>> remember
>>> the difference between the base preimage and the sum of all partial
>>> preimages used so far. The relation is described using the following
>>> equations:
>>>
>>>
>>>     X_0 = 0

>>>     X_i = X_{i-1} ^ s_i

>>>     X_n = BP ^ X_{n-1}
>>>
>>>
>>> where if n=1, X_1 = BP, implying that this is in fact a generalization
>>> of
>>> the single, non-interactive payment scheme mentioned above. For
>>> i=1, ...,
>>> n-1, the sender sends s_i in the EOB, and  X_n for the n-th share.
>>>
>>>
>>> Iteratively reconstructing s_1 ^ …. ^ s_{n-1} ^ X_n = BP, allows the
>>> receiver to compute all relevant r_i = H(BP || i) and h_i = H(r_i).
>>> Lastly,
>>> the final number of partial payments n could be signaled in the final
>>> EOB,
>>> which would also serve as a sentinel value for signaling completion.
>>> In
>>> response to DOS vectors stemming from unknown values of n,
>>> implementations
>>> could consider advertising a maximum value for n, or adopting some
>>> sort of
>>> framing pattern for conveying that more partial payments are on the
>>> way.
>>>
>>>
>>> We can further modify our usage of the per-hop payloads to send
>>> (H(BP), s_i) to
>>> consume most of the EOB sent from sender to receiver. In this
>>> scenario, we'd
>>> repurpose the 11-bytes *after* our signalling byte in the unused byte
>>> section
>>> to store the payment ID (which should be unique for each payment). In
>>> the case
>>> of a non-interactive payment, this will be unused. While for
>>> interactive
>>> payments, this will be the ID within the invoice. To deliver this
>>> slimmer
>>> 2-tuple, we'll use 32-bytes for the hash of the BP, and 32-bytes for
>>> the
>>> partial pre-image share, leaving an un-used byte in the payload.
>>>
>>>
>>>
>>>
>>> Cross-Chain AMPs
>>> ================
>>>
>>>
>>> AMPs can be used to pay a receiver in multiple currencies
>>> atomically...which
>>> is pretty cool :D
>>>
>>>
>>>
>>>
>>> Open Research Questions
>>> =======================
>>>
>>>
>>> The above is a protocol sketch to achieve atomic multi-path payments
>>> over
>>> Lightning. The details concerning onion blob usage serves as a
>>> template that
>>> future protocols can draw upon in order to deliver additional data to
>>> *any*
>>> hop in the route. However, there are still a few open questions before
>>> something like this can be feasibly deployed.
>>>
>>>
>>> 1. How does the sender decide how many chunked payments to send, and
>>> the
>>> size of each payment?
>>>
>>>
>>>   - Upon a closer examination, this seems to overlap with the task of
>>>     congestion control within TCP. The sender may be able to utilize
>>>     inspired heuristics to gauge: (1) how large the initial payment
>>> should be
>>>     and (2) how many subsequent payments may be required. Note that if
>>> the
>>>     first payment succeeds, then the exchange is over in a signal
>>> round.
>>>
>>>
>>> 2. How can AMP and HORNET be composed?
>>>
>>>
>>>   - If we eventually integrate HORNET, then a distinct communications
>>>     sessions can be established to allow the sender+receiver to
>>> exchange
>>>     up-to-date partial payment information. This may allow the sender
>>> to more
>>>     accurately size each partial payment.
>>>
>>> 3. Can the sender's initial strategy be governed by an instance of the
>>> Push-relabel max flow algo?
>>>
>>>
>>> 4. How does this mesh with the current max HTLC limit on a commitment?
>>>
>>>
>>>    - ATM, we have a max limit on the number of active HTLC's on a
>>> particular
>>>      commitment transaction. We do this, as otherwise it's possible
>>> that the
>>>      transaction is too large, and exceeds standardness w.r.t
>>> transaction
>>>      size. In a world where most payments use an AMP-like protocol,
>>> then
>>>      overall ant any given instance there will be several pending
>>> HTLC's on
>>>      commitments network wise.
>>>
>>>
>>>      This may incentivize nodes to open more channels in order to
>>> support
>>>      the increased commitment space utilization.
>>>
>>>
>>>
>>>
>>> Conclusion
>>> ==========
>>>
>>>
>>> We've presented a design outline of how to integrate atomic multi-path
>>> payments (AMP) into Lightning. The existence of such a construct
>>> allows a
>>> sender to atomically split a payment flow amongst several individual
>>> payment
>>> flows. As a result, larger channels aren't as important as it's
>>> possible to
>>> utilize one total outbound payment bandwidth to send several channels.
>>> Additionally, in order to support the increased load, internal routing
>>> nodes
>>> are incensed have more active channels. The existence of AMP-like
>>> payments
>>> may also increase the longevity of channels as there'll be smaller,
>>> more
>>> numerous payment flows, making it unlikely that a single payment comes
>>> across unbalances a channel entirely. We've also showed how one can
>>> utilize
>>> the current onion packet format to deliver additional data from a
>>> sender to
>>> receiver, that's still e2e authenticated.
>>>
>>>
>>>
>>>
>>> -- Conner && Laolu
>>>
>>>
>>> _______________________________________________
>>> Lightning-dev mailing list
>>> Lightning-dev at lists.linuxfoundation.org
>>> https://www.learnbitcoin.com/archive/lists/lightning-dev
>>
>> _______________________________________________
>> Lightning-dev mailing list
>> Lightning-dev at lists.linuxfoundation.org
>> https://www.learnbitcoin.com/archive/lists/lightning-dev
Christian Decker in reply to Jim Posen permalink original

Jim Posen <jim.posen at gmail.com> writes:

Quoted text (7 lines)
> If using two hashes to deliver the payment while still getting a proof, I'm
> not sure what that provides above just sending regular lightning payments
> over multiple routes with one hash. Firstly, if there is a second hash, it
> would presumably be the same for all routes, making them linkable again,
> which AMP tries to solve. And secondly, the receiver has no incentive to
> claim any of the HTLCs before all of them are locked in, because in that
> case they are releasing the transaction receipt before fully being paid.

Arguably the second concern is not really an issue, if you allow partial claims you'll end up in a whole lot of trouble. It should always be the case that the payment as whole is atomic, i.e., either the entirety of the payment goes through or none of it, independently of whether it was a singlepath or a multipath payment. This is actually one of the really nice features that was enforced using the simple "just reuse the hash"-mechanism, you always had to wait for the complete payment or you'd risk losing part of it.

Christian Decker in reply to CJP permalink original

CJP <cjp at ultimatestunts.nl> writes:

Quoted text (8 lines)
> Can you give a use case for this?
>
> Usually, especially in the common case that a payment is done in
> exchange for some non-cryptographic asset (e.g. physical goods), there
> already is some kind of trust between payer and payee. So, if a payment
> is split non-atomically into smaller transactions, and only a part
> succeeds, presumably they can cooperatively figure out some way to
> settle the situation.

The scenario that is commonly used in these cases is a merchant that provides a signed invoice "if you pay me X with payment_hash Y I will deliver Z". Now the user performs the payment, learns the payment_key matching the payment_hash, but the merchant refuses to deliver, claiming it didn't get the payment. Now the user can go to a court, present the invoice signed by the merchant, and the proof-of-payment, and force the merchant to honor its commitment.

Corné Plooy in reply to Christian Decker permalink original

I was thinking that, for that use case, a different signed invoice could be formulated, stating

* several payment hashes with their corresponding amounts

* the obligation of signer to deliver Z if all corresponding payment keys are shown

* some terms to handle the case where only a part of the payments was successful, e.g. an obligation to refund

The third item is a bit problematic: in order to distinguish this case from a complete success, the payee would have to prove *absence* of successful transactions, which is hard. Absence of successful transactions can only be declared by the payer, so in order to reliably settle *without* going to court first, the payer should sign a declaration stating that certain transactions were canceled and that the other ones should be refunded. This can be another invoice.

So, the original invoice states:

* several payment hashes with their corresponding amounts

* if all corresponding payment keys are shown: the obligation of <payee> to deliver Z, UNLESS stated otherwise by an invoice signed by <payer>

-- signed by <payee>

But if a payment partially fails, it can be refunded cooperatively with an invoice created by payer:

* declares which of the original payments were successful (with payment keys) and which were not

* replaces the obligation of <payee> to deliver Z with an obligation to refund the successful transactions

* several payment hashes with their corresponding amounts

* if all corresponding payment keys are shown: cancel the obligation of <payee> to refund

-- signed by <payer>

Maybe this can be repeated iteratively if necessary; hopefully the not-yet-settled amount will converge to zero.

Important advantage: this only requires changes to the invoice format, not to the network protocol.

The point is: in this use case, the court is apparently the final point of settlement for invoices, just like the blockchain is for the other channels in the route. IANAL, but I think the "scripting language" accepted by courts is quite flexible, and you can use that to enforce atomicity. With the construction described above, you can either refund cooperatively (and collect evidence that refund has happened), or, if that fails, go to court to enforce settlement there.

CJP

Op 12-02-18 om 10:23 schreef Christian Decker:

Quoted text (20 lines)
> CJP <cjp at ultimatestunts.nl> writes:
>> Can you give a use case for this?
>>
>> Usually, especially in the common case that a payment is done in
>> exchange for some non-cryptographic asset (e.g. physical goods), there
>> already is some kind of trust between payer and payee. So, if a payment
>> is split non-atomically into smaller transactions, and only a part
>> succeeds, presumably they can cooperatively figure out some way to
>> settle the situation.
> The scenario that is commonly used in these cases is a merchant that
> provides a signed invoice "if you pay me X with payment_hash Y I will
> deliver Z". Now the user performs the payment, learns the payment_key
> matching the payment_hash, but the merchant refuses to deliver, claiming
> it didn't get the payment. Now the user can go to a court, present the
> invoice signed by the merchant, and the proof-of-payment, and force the
> merchant to honor its commitment.
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
Christian Decker in reply to Corné Plooy permalink original

Honestly I don't get why we are complicating this so much. We have a system that allows atomic multipath payments using a single secret, and future decorrelation mechanisms allow us to vary the secret in such a way that multiple paths cannot be collated, why introduce a whole set of problems by giving away the atomicity? The same goes for the overpaying and trusting the recipient to only claim the owed amount, there is no need for this. Just pay the exact amount, by deriving secrets from the main secret and make the derivation reproducible by intermediate hops.

Having proof-of-payment be presentable in a court is a nice feature, but it doesn't mean we need to abandon all guarantees we have worked so hard to establish in LN.

Corné Plooy via Lightning-dev <lightning-dev at lists.linuxfoundation.org> writes:

Quoted text (95 lines)
> I was thinking that, for that use case, a different signed invoice could
> be formulated, stating
>
> * several payment hashes with their corresponding amounts
>
> * the obligation of signer to deliver Z if all corresponding payment
> keys are shown
>
> * some terms to handle the case where only a part of the payments was
> successful, e.g. an obligation to refund
>
>
> The third item is a bit problematic: in order to distinguish this case
> from a complete success, the payee would have to prove *absence* of
> successful transactions, which is hard. Absence of successful
> transactions can only be declared by the payer, so in order to reliably
> settle *without* going to court first, the payer should sign a
> declaration stating that certain transactions were canceled and that the
> other ones should be refunded. This can be another invoice.
>
>
> So, the original invoice states:
>
> * several payment hashes with their corresponding amounts
>
> * if all corresponding payment keys are shown: the obligation of <payee>
> to deliver Z, UNLESS stated otherwise by an invoice signed by <payer>
>
> -- signed by <payee>
>
>
> But if a payment partially fails, it can be refunded cooperatively with
> an invoice created by payer:
>
> * declares which of the original payments were successful (with payment
> keys) and which were not
>
> * replaces the obligation of <payee> to deliver Z with an obligation to
> refund the successful transactions
>
> * several payment hashes with their corresponding amounts
>
> * if all corresponding payment keys are shown: cancel the obligation of
> <payee> to refund
>
> -- signed by <payer>
>
>
> Maybe this can be repeated iteratively if necessary; hopefully the
> not-yet-settled amount will converge to zero.
>
>
> Important advantage: this only requires changes to the invoice format,
> not to the network protocol.
>
>
> The point is: in this use case, the court is apparently the final point
> of settlement for invoices, just like the blockchain is for the other
> channels in the route. IANAL, but I think the "scripting language"
> accepted by courts is quite flexible, and you can use that to enforce
> atomicity. With the construction described above, you can either refund
> cooperatively (and collect evidence that refund has happened), or, if
> that fails, go to court to enforce settlement there.
>
>
> CJP
>
>
> Op 12-02-18 om 10:23 schreef Christian Decker:
>> CJP <cjp at ultimatestunts.nl> writes:
>>> Can you give a use case for this?
>>>
>>> Usually, especially in the common case that a payment is done in
>>> exchange for some non-cryptographic asset (e.g. physical goods), there
>>> already is some kind of trust between payer and payee. So, if a payment
>>> is split non-atomically into smaller transactions, and only a part
>>> succeeds, presumably they can cooperatively figure out some way to
>>> settle the situation.
>> The scenario that is commonly used in these cases is a merchant that
>> provides a signed invoice "if you pay me X with payment_hash Y I will
>> deliver Z". Now the user performs the payment, learns the payment_key
>> matching the payment_hash, but the merchant refuses to deliver, claiming
>> it didn't get the payment. Now the user can go to a court, present the
>> invoice signed by the merchant, and the proof-of-payment, and force the
>> merchant to honor its commitment.
>> _______________________________________________
>> Lightning-dev mailing list
>> Lightning-dev at lists.linuxfoundation.org
>> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
ZmnSCPxj in reply to Christian Decker permalink original

Good morning Christian and Corne,

Another idea to consider, is techniques like ZKCP and ZKCSP, which provide atomic access to information in exchange for monetary compensation. Ensuring atomicity of the exchange can be done by providing the information encrypted, a hash of the encryption key, and proofs that the encrypted data is the one desired and that the data was encrypted with the given key; the proof-of-payment is the encryption key, and possession of the encryption key is sufficient to gain access to the information, with no need to bring in legal structures.

(admittedly, ZKCP and ZKCSP are dependent on new cryptography...)

(also, AMP currently cannot provide a proof-of-payment, unlike current payment routing that has proof-of-payment, but that is an eventual design goal that would enable use of ZKC(S)P on-Lightning, assuming we eventually find out that zk-SNARKs and so on are something we can trust)

Regards, ZmnSCPxj

​ Sent with ProtonMail Secure Email. ​

-------- Original Message -------- On February 13, 2018 2:05 AM, Christian Decker <decker.christian at gmail.com> wrote:

Quoted text (92 lines)
>Honestly I don't get why we are complicating this so much. We have a
> system that allows atomic multipath payments using a single secret, and
> future decorrelation mechanisms allow us to vary the secret in such a
> way that multiple paths cannot be collated, why introduce a whole set of
> problems by giving away the atomicity? The same goes for the overpaying
> and trusting the recipient to only claim the owed amount, there is no
> need for this. Just pay the exact amount, by deriving secrets from the
> main secret and make the derivation reproducible by intermediate hops.
>
> Having proof-of-payment be presentable in a court is a nice feature, but
> it doesn't mean we need to abandon all guarantees we have worked so hard
> to establish in LN.
>
> Corné Plooy via Lightning-dev lightning-dev at lists.linuxfoundation.org
>writes:
>
>>I was thinking that, for that use case, a different signed invoice could
>> be formulated, stating
>> - several payment hashes with their corresponding amounts
>>
>> - the obligation of signer to deliver Z if all corresponding payment
>> keys are shown
>>
>> - some terms to handle the case where only a part of the payments was
>> successful, e.g. an obligation to refund
>>The third item is a bit problematic: in order to distinguish this case
>> from a complete success, the payee would have to prove absence of
>> successful transactions, which is hard. Absence of successful
>> transactions can only be declared by the payer, so in order to reliably
>> settle without going to court first, the payer should sign a
>> declaration stating that certain transactions were canceled and that the
>> other ones should be refunded. This can be another invoice.
>>So, the original invoice states:
>> - several payment hashes with their corresponding amounts
>>
>> - if all corresponding payment keys are shown: the obligation of <payee>
>> to deliver Z, UNLESS stated otherwise by an invoice signed by <payer>
>>-- signed by <payee>
>>But if a payment partially fails, it can be refunded cooperatively with
>> an invoice created by payer:
>> - declares which of the original payments were successful (with payment
>> keys) and which were not
>>
>> - replaces the obligation of <payee> to deliver Z with an obligation to
>> refund the successful transactions
>>
>> - several payment hashes with their corresponding amounts
>>
>> - if all corresponding payment keys are shown: cancel the obligation of
>> <payee> to refund
>>-- signed by <payer>
>>Maybe this can be repeated iteratively if necessary; hopefully the
>> not-yet-settled amount will converge to zero.
>>Important advantage: this only requires changes to the invoice format,
>> not to the network protocol.
>>The point is: in this use case, the court is apparently the final point
>> of settlement for invoices, just like the blockchain is for the other
>> channels in the route. IANAL, but I think the "scripting language"
>> accepted by courts is quite flexible, and you can use that to enforce
>> atomicity. With the construction described above, you can either refund
>> cooperatively (and collect evidence that refund has happened), or, if
>> that fails, go to court to enforce settlement there.
>>CJP
>>Op 12-02-18 om 10:23 schreef Christian Decker:
>>>CJP cjp at ultimatestunts.nl writes:
>>>>Can you give a use case for this?
>>>>Usually, especially in the common case that a payment is done in
>>>> exchange for some non-cryptographic asset (e.g. physical goods), there
>>>> already is some kind of trust between payer and payee. So, if a payment
>>>> is split non-atomically into smaller transactions, and only a part
>>>> succeeds, presumably they can cooperatively figure out some way to
>>>> settle the situation.
>>>> The scenario that is commonly used in these cases is a merchant that
>>>> provides a signed invoice "if you pay me X with payment_hash Y I will
>>>> deliver Z". Now the user performs the payment, learns the payment_key
>>>> matching the payment_hash, but the merchant refuses to deliver, claiming
>>>> it didn't get the payment. Now the user can go to a court, present the
>>>> invoice signed by the merchant, and the proof-of-payment, and force the
>>>> merchant to honor its commitment.
>>>>
>>>Lightning-dev mailing list
>>>Lightning-dev at lists.linuxfoundation.org
>>>https://www.learnbitcoin.com/archive/lists/lightning-dev
>>>
>>Lightning-dev mailing list
>>Lightning-dev at lists.linuxfoundation.org
>>https://www.learnbitcoin.com/archive/lists/lightning-dev
>>
>Lightning-dev mailing list
>Lightning-dev at lists.linuxfoundation.org
>https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Conner Fromknecht in reply to ZmnSCPxj permalink original

Hi everyone,

I've seen some discussions over losing proofs of payment in the AMP setting, and wanted to address some lingering concerns I have regarding the soundness of using the current invoicing system to prove payments.

In general, I think we are ascribing too much weight to simply having a preimage and BOLT 11 invoice. The structure of non-interactive payments definitely poses some interesting challenges in adapting the existing invoicing scheme. However, I believe there exist stronger and better means of doing proofs of payment, and would prefer not to tie our hands by assuming this is the best way to approach the problem.

IMHO, the current signed invoice + preimage is a very weak proof of payment. It's the hash equivalent to proving you own a public key by publishing the secret key. There is an assumption that the only way someone could get that preimage is by having made a payment, but this assumption is broken most directly by the proving mechanism. Similarly, any intermediary who acquires an invoice with the appropriate hash could also make this claim since they also have the preimage.

Further, I think it's a mistake to conflate
  1) me being able to present a valid preimage/invoice pair, with
  2) me having received the correct preimage in response to an onion packet
    that I personally crafted for the receiving node in the invoice.

The main issue is that the proof does not bind a specific sender, making statement 1 producible by multiple individuals. I think it would be potentially worthwhile to explore proofs of stronger statements, such as 2, that could utilize the ephemeral keys in the onion packets, or even the onion as a witness, which is more rigidly coupled to having actually completed a payment.

Without any modification to the spec, we can always use something like ZKBoo to prove (w/o trusted setup) knowledge of a preimage without totally revealing it to the verifier. This isn't perfect, but at least gives the sender the option to prove the statement without necessarily giving up the preimage.

TL;DR: I'm not convinced the signed invoice + hash is really a good yardstick by which to measure provability, and I think doing some research into proofs of payment on stronger statements would be incredibly valuable. Therefore, I'm not sure if AMPs really lose this, so much as force us to reconsider what it actually requires to soundly prove a payment to an external verifier.

Best, Conner

On Mon, Feb 12, 2018 at 6:56 PM ZmnSCPxj via Lightning-dev < lightning-dev at lists.linuxfoundation.org> wrote:

Quoted text (130 lines)
> Good morning Christian and Corne,
>
> Another idea to consider, is techniques like ZKCP and ZKCSP, which provide
> atomic access to information in exchange for monetary compensation.
> Ensuring atomicity of the exchange can be done by providing the information
> encrypted, a hash of the encryption key, and proofs that the encrypted data
> is the one desired and that the data was encrypted with the given key; the
> proof-of-payment is the encryption key, and possession of the encryption
> key is sufficient to gain access to the information, with no need to bring
> in legal structures.
>
> (admittedly, ZKCP and ZKCSP are dependent on new cryptography...)
>
> (also, AMP currently cannot provide a proof-of-payment, unlike current
> payment routing that has proof-of-payment, but that is an eventual design
> goal that would enable use of ZKC(S)P on-Lightning, assuming we eventually
> find out that zk-SNARKs and so on are something we can trust)
>
> Regards,
> ZmnSCPxj
>
> ​
> Sent with ProtonMail Secure Email.
> ​
>
> -------- Original Message --------
>  On February 13, 2018 2:05 AM, Christian Decker <
> decker.christian at gmail.com> wrote:
>
> >Honestly I don't get why we are complicating this so much. We have a
> > system that allows atomic multipath payments using a single secret, and
> > future decorrelation mechanisms allow us to vary the secret in such a
> > way that multiple paths cannot be collated, why introduce a whole set of
> > problems by giving away the atomicity? The same goes for the overpaying
> > and trusting the recipient to only claim the owed amount, there is no
> > need for this. Just pay the exact amount, by deriving secrets from the
> > main secret and make the derivation reproducible by intermediate hops.
> >
> > Having proof-of-payment be presentable in a court is a nice feature, but
> > it doesn't mean we need to abandon all guarantees we have worked so hard
> > to establish in LN.
> >
> > Corné Plooy via Lightning-dev lightning-dev at lists.linuxfoundation.org
> >writes:
> >
> >>I was thinking that, for that use case, a different signed invoice could
> >> be formulated, stating
> >> - several payment hashes with their corresponding amounts
> >>
> >> - the obligation of signer to deliver Z if all corresponding payment
> >> keys are shown
> >>
> >> - some terms to handle the case where only a part of the payments was
> >> successful, e.g. an obligation to refund
> >>The third item is a bit problematic: in order to distinguish this case
> >> from a complete success, the payee would have to prove absence of
> >> successful transactions, which is hard. Absence of successful
> >> transactions can only be declared by the payer, so in order to reliably
> >> settle without going to court first, the payer should sign a
> >> declaration stating that certain transactions were canceled and that the
> >> other ones should be refunded. This can be another invoice.
> >>So, the original invoice states:
> >> - several payment hashes with their corresponding amounts
> >>
> >> - if all corresponding payment keys are shown: the obligation of <payee>
> >> to deliver Z, UNLESS stated otherwise by an invoice signed by <payer>
> >>-- signed by <payee>
> >>But if a payment partially fails, it can be refunded cooperatively with
> >> an invoice created by payer:
> >> - declares which of the original payments were successful (with payment
> >> keys) and which were not
> >>
> >> - replaces the obligation of <payee> to deliver Z with an obligation to
> >> refund the successful transactions
> >>
> >> - several payment hashes with their corresponding amounts
> >>
> >> - if all corresponding payment keys are shown: cancel the obligation of
> >> <payee> to refund
> >>-- signed by <payer>
> >>Maybe this can be repeated iteratively if necessary; hopefully the
> >> not-yet-settled amount will converge to zero.
> >>Important advantage: this only requires changes to the invoice format,
> >> not to the network protocol.
> >>The point is: in this use case, the court is apparently the final point
> >> of settlement for invoices, just like the blockchain is for the other
> >> channels in the route. IANAL, but I think the "scripting language"
> >> accepted by courts is quite flexible, and you can use that to enforce
> >> atomicity. With the construction described above, you can either refund
> >> cooperatively (and collect evidence that refund has happened), or, if
> >> that fails, go to court to enforce settlement there.
> >>CJP
> >>Op 12-02-18 om 10:23 schreef Christian Decker:
> >>>CJP cjp at ultimatestunts.nl writes:
> >>>>Can you give a use case for this?
> >>>>Usually, especially in the common case that a payment is done in
> >>>> exchange for some non-cryptographic asset (e.g. physical goods), there
> >>>> already is some kind of trust between payer and payee. So, if a
> payment
> >>>> is split non-atomically into smaller transactions, and only a part
> >>>> succeeds, presumably they can cooperatively figure out some way to
> >>>> settle the situation.
> >>>> The scenario that is commonly used in these cases is a merchant that
> >>>> provides a signed invoice "if you pay me X with payment_hash Y I will
> >>>> deliver Z". Now the user performs the payment, learns the payment_key
> >>>> matching the payment_hash, but the merchant refuses to deliver,
> claiming
> >>>> it didn't get the payment. Now the user can go to a court, present the
> >>>> invoice signed by the merchant, and the proof-of-payment, and force
> the
> >>>> merchant to honor its commitment.
> >>>>
> >>>Lightning-dev mailing list
> >>>Lightning-dev at lists.linuxfoundation.org
> >>>https://www.learnbitcoin.com/archive/lists/lightning-dev
> >>>
> >>Lightning-dev mailing list
> >>Lightning-dev at lists.linuxfoundation.org
> >>https://www.learnbitcoin.com/archive/lists/lightning-dev
> >>
> >Lightning-dev mailing list
> >Lightning-dev at lists.linuxfoundation.org
> >https://www.learnbitcoin.com/archive/lists/lightning-dev
> >
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Corné Plooy in reply to Conner Fromknecht permalink original

Hi Conner,

I do believe proof of payment is an important feature to have, especially for the use case of a payer/payee pair that doesn't completely trust each other, but does have the possibility to go to court.

However, I'm not convinced by what you wrote. I do think a combination of signed invoice + preimage is a reliable proof of payment. Strictly speaking, you are right: it is not so much a proof that they payer *sent* the funds, but it *is* proof that the payee *received* the funds. This is because the only scenario where it makes sense for the payee to reveal the preimage is if it can claim a corresponding incoming HTLC with (at least) the correct amount of funds. Revealing the preimage in any other scenario would be stupid(*), and no amount of cryptography can protect against stupidity. So, when it comes to cryptographic proof, this is about as good as it gets.

Now, about the difference between the payer having sent the funds and the payee having received the funds: I'd argue that it's the second that really matters. If the payer can prove that there is *any* kind of arrangement that ended up with the payee having received the correct amount of funds, that should count as payment. Now, if none of the intermediaries has been stupid, this does imply that the payer ends up on the sending side of the payment, but even if one if the intermediaries has been stupid, why should the payer and payee care? All that matters is that an arrangement has been made to let the payee receive (at least) the correct amount of funds, and that arrangement has been proven to be successful. I consider that proof of payment.

CJP

(*) Stupidity includes being hacked, and anything else that can cause your secrets being used against your own interests.

Op 13-02-18 om 04:29 schreef Conner Fromknecht:

Quoted text (243 lines)
>
> Hi everyone,
>
> I've seen some discussions over losing proofs of payment in the AMP
> setting,
> and wanted to address some lingering concerns I have regarding the
> soundness of using the current invoicing system to prove payments.
>
> In general, I think we are ascribing too much weight to simply having a
> preimage and BOLT 11 invoice. The structure of non-interactive payments
> definitely poses some interesting challenges in adapting the existing
> invoicing
> scheme. However, I believe there exist stronger and better means of doing
> proofs of payment, and would prefer not to tie our hands by assuming
> this is the best way to approach the problem.
>
> IMHO, the current signed invoice + preimage is a very weak proof of
> payment.
> It's the hash equivalent to proving you own a public key by publishing the
> secret key. There is an assumption that the only way someone could get
> that
> preimage is by having made a payment, but this assumption is broken most
> directly by the proving mechanism. Similarly, any intermediary who
> acquires
> an invoice with the appropriate hash could also make this claim since they
> also have the preimage.
>
> Further, I think it's a mistake to conflate
>   1) me being able to present a valid preimage/invoice pair, with
>   2) me having received the correct preimage in response to an onion
> packet
>     that I personally crafted for the receiving node in the invoice.
>
> The main issue is that the proof does not bind a specific sender,
> making statement 1 producible by multiple individuals. I think it would be
> potentially worthwhile to explore proofs of stronger statements, such
> as 2,
> that could utilize the ephemeral keys in the onion packets, or even the
> onion as a witness, which is more rigidly coupled to having actually
> completed a payment.
>
> Without any modification to the spec, we can always use something like
> ZKBoo to prove (w/o trusted setup) knowledge of a preimage without
> totally revealing it to the verifier. This isn't perfect, but at least
> gives the
> sender the option to prove the statement without necessarily giving up
> the preimage.
>
> TL;DR: I'm not convinced the signed invoice + hash is really a good
> yardstick
> by which to measure provability, and I think doing some research into
> proofs
> of payment on stronger statements would be incredibly valuable. Therefore,
> I'm not sure if AMPs really lose this, so much as force us to reconsider
> what it actually requires to soundly prove a payment to an external
> verifier.
>
> Best,
> Conner
>
> On Mon, Feb 12, 2018 at 6:56 PM ZmnSCPxj via Lightning-dev
> <lightning-dev at lists.linuxfoundation.org
> <mailto:lightning-dev at lists.linuxfoundation.org>> wrote:
>
>     Good morning Christian and Corne,
>
>     Another idea to consider, is techniques like ZKCP and ZKCSP, which
>     provide atomic access to information in exchange for monetary
>     compensation.  Ensuring atomicity of the exchange can be done by
>     providing the information encrypted, a hash of the encryption key,
>     and proofs that the encrypted data is the one desired and that the
>     data was encrypted with the given key; the proof-of-payment is the
>     encryption key, and possession of the encryption key is sufficient
>     to gain access to the information, with no need to bring in legal
>     structures.
>
>     (admittedly, ZKCP and ZKCSP are dependent on new cryptography...)
>
>     (also, AMP currently cannot provide a proof-of-payment, unlike
>     current payment routing that has proof-of-payment, but that is an
>     eventual design goal that would enable use of ZKC(S)P
>     on-Lightning, assuming we eventually find out that zk-SNARKs and
>     so on are something we can trust)
>
>     Regards,
>     ZmnSCPxj
>
>     ​
>     Sent with ProtonMail Secure Email.
>     ​
>
>     -------- Original Message --------
>      On February 13, 2018 2:05 AM, Christian Decker
>     <decker.christian at gmail.com <mailto:decker.christian at gmail.com>>
>     wrote:
>
>     >Honestly I don't get why we are complicating this so much. We have a
>     > system that allows atomic multipath payments using a single
>     secret, and
>     > future decorrelation mechanisms allow us to vary the secret in
>     such a
>     > way that multiple paths cannot be collated, why introduce a
>     whole set of
>     > problems by giving away the atomicity? The same goes for the
>     overpaying
>     > and trusting the recipient to only claim the owed amount, there
>     is no
>     > need for this. Just pay the exact amount, by deriving secrets
>     from the
>     > main secret and make the derivation reproducible by intermediate
>     hops.
>     >
>     > Having proof-of-payment be presentable in a court is a nice
>     feature, but
>     > it doesn't mean we need to abandon all guarantees we have worked
>     so hard
>     > to establish in LN.
>     >
>     > Corné Plooy via Lightning-dev
>     lightning-dev at lists.linuxfoundation.org
>     <mailto:lightning-dev at lists.linuxfoundation.org>
>     >writes:
>     >
>     >>I was thinking that, for that use case, a different signed
>     invoice could
>     >> be formulated, stating
>     >> - several payment hashes with their corresponding amounts
>     >>
>     >> - the obligation of signer to deliver Z if all corresponding
>     payment
>     >> keys are shown
>     >>
>     >> - some terms to handle the case where only a part of the
>     payments was
>     >> successful, e.g. an obligation to refund
>     >>The third item is a bit problematic: in order to distinguish
>     this case
>     >> from a complete success, the payee would have to prove absence of
>     >> successful transactions, which is hard. Absence of successful
>     >> transactions can only be declared by the payer, so in order to
>     reliably
>     >> settle without going to court first, the payer should sign a
>     >> declaration stating that certain transactions were canceled and
>     that the
>     >> other ones should be refunded. This can be another invoice.
>     >>So, the original invoice states:
>     >> - several payment hashes with their corresponding amounts
>     >>
>     >> - if all corresponding payment keys are shown: the obligation
>     of <payee>
>     >> to deliver Z, UNLESS stated otherwise by an invoice signed by
>     <payer>
>     >>-- signed by <payee>
>     >>But if a payment partially fails, it can be refunded
>     cooperatively with
>     >> an invoice created by payer:
>     >> - declares which of the original payments were successful (with
>     payment
>     >> keys) and which were not
>     >>
>     >> - replaces the obligation of <payee> to deliver Z with an
>     obligation to
>     >> refund the successful transactions
>     >>
>     >> - several payment hashes with their corresponding amounts
>     >>
>     >> - if all corresponding payment keys are shown: cancel the
>     obligation of
>     >> <payee> to refund
>     >>-- signed by <payer>
>     >>Maybe this can be repeated iteratively if necessary; hopefully the
>     >> not-yet-settled amount will converge to zero.
>     >>Important advantage: this only requires changes to the invoice
>     format,
>     >> not to the network protocol.
>     >>The point is: in this use case, the court is apparently the
>     final point
>     >> of settlement for invoices, just like the blockchain is for the
>     other
>     >> channels in the route. IANAL, but I think the "scripting language"
>     >> accepted by courts is quite flexible, and you can use that to
>     enforce
>     >> atomicity. With the construction described above, you can
>     either refund
>     >> cooperatively (and collect evidence that refund has happened),
>     or, if
>     >> that fails, go to court to enforce settlement there.
>     >>CJP
>     >>Op 12-02-18 om 10:23 schreef Christian Decker:
>     >>>CJP cjp at ultimatestunts.nl <mailto:cjp at ultimatestunts.nl> writes:
>     >>>>Can you give a use case for this?
>     >>>>Usually, especially in the common case that a payment is done in
>     >>>> exchange for some non-cryptographic asset (e.g. physical
>     goods), there
>     >>>> already is some kind of trust between payer and payee. So, if
>     a payment
>     >>>> is split non-atomically into smaller transactions, and only a
>     part
>     >>>> succeeds, presumably they can cooperatively figure out some
>     way to
>     >>>> settle the situation.
>     >>>> The scenario that is commonly used in these cases is a
>     merchant that
>     >>>> provides a signed invoice "if you pay me X with payment_hash
>     Y I will
>     >>>> deliver Z". Now the user performs the payment, learns the
>     payment_key
>     >>>> matching the payment_hash, but the merchant refuses to
>     deliver, claiming
>     >>>> it didn't get the payment. Now the user can go to a court,
>     present the
>     >>>> invoice signed by the merchant, and the proof-of-payment, and
>     force the
>     >>>> merchant to honor its commitment.
>     >>>>
>     >>>Lightning-dev mailing list
>     >>>Lightning-dev at lists.linuxfoundation.org
>     <mailto:Lightning-dev at lists.linuxfoundation.org>
>     >>>https://www.learnbitcoin.com/archive/lists/lightning-dev
>     >>>
>     >>Lightning-dev mailing list
>     >>Lightning-dev at lists.linuxfoundation.org
>     <mailto:Lightning-dev at lists.linuxfoundation.org>
>     >>https://www.learnbitcoin.com/archive/lists/lightning-dev
>     >>
>     >Lightning-dev mailing list
>     >Lightning-dev at lists.linuxfoundation.org
>     <mailto:Lightning-dev at lists.linuxfoundation.org>
>     >https://www.learnbitcoin.com/archive/lists/lightning-dev
>     >
>
>     _______________________________________________
>     Lightning-dev mailing list
>     Lightning-dev at lists.linuxfoundation.org
>     <mailto:Lightning-dev at lists.linuxfoundation.org>
>     https://www.learnbitcoin.com/archive/lists/lightning-dev
>
>
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
ZmnSCPxj in reply to Corné Plooy permalink original

Good morning Corne and Conner,

Ignoring the practical matters that Corne rightly brings up, I think, it is possible to use ZKCP to provide a "stronger" proof-of-payment in the sense that Conner is asking for.

All that is needed is to create a message (possibly in some standard language) indicating the payment amount and whatever commitment the payee claims to have for this payment, have the payee securely sign the message, and encrypt them. The encryption key used is hashed and is used as the payment hash for a standard BOLT11. Together with the standard BOLT11 the payee provides the encrypted message and signature to the payer in some secure communication channel that is end-to-end encrypted (so that only the payer can receive the encrypted message).

(additionally zk-SNARKs attesting to correct operation of the parsing and encryption of the message, as well as the hashing of the encryption key, will be needed)

In order to claim the payment on-Lightning, the payee provides the encryption key (as it is the preimage for the payment hash). Standard LN routing protocols then propagate this encryption key back to the payer.

As only the payer received the encrypted message, only the payer can decrypt that message using the payment preimage, even if the preimage was propagated to multiple hops (and may very well have been published onchain in case a hop resolved a channel onchain).

Regards, ZmnSCPxj

-------- Original Message -------- On February 13, 2018 10:33 AM, Corné Plooy via Lightning-dev <lightning-dev at lists.linuxfoundation.org> wrote:

Quoted text (279 lines)
>Hi Conner,
>
>
> I do believe proof of payment is an important feature to have,
> especially for the use case of a payer/payee pair that doesn't
> completely trust each other, but does have the possibility to go to court.
>
>
> However, I'm not convinced by what you wrote. I do think a combination
> of signed invoice + preimage is a reliable proof of payment. Strictly
> speaking, you are right: it is not so much a proof that they payer
>sent the funds, but it is proof that the payee received the funds.
> This is because the only scenario where it makes sense for the payee to
> reveal the preimage is if it can claim a corresponding incoming HTLC
> with (at least) the correct amount of funds. Revealing the preimage in
> any other scenario would be stupid(), and no amount of cryptography can
> protect against stupidity. So, when it comes to cryptographic proof,
> this is about as good as it gets.
>
>
> Now, about the difference between the payer having sent the funds and
> the payee having received the funds: I'd argue that it's the second that
> really matters. If the payer can prove that there is any kind of
> arrangement that ended up with the payee having received the correct
> amount of funds, that should count as payment. Now, if none of the
> intermediaries has been stupid, this does imply that the payer ends up
> on the sending side of the payment, but even if one if the
> intermediaries has been stupid, why should the payer and payee care? All
> that matters is that an arrangement has been made to let the payee
> receive (at least) the correct amount of funds, and that arrangement has
> been proven to be successful. I consider that proof of payment.
>
>
> CJP
>
>
> () Stupidity includes being hacked, and anything else that can cause
> your secrets being used against your own interests.
>
>
> Op 13-02-18 om 04:29 schreef Conner Fromknecht:
>>Hi everyone,
>>I've seen some discussions over losing proofs of payment in the AMP
>> setting,
>> and wanted to address some lingering concerns I have regarding the
>> soundness of using the current invoicing system to prove payments.
>>In general, I think we are ascribing too much weight to simply having a
>> preimage and BOLT 11 invoice. The structure of non-interactive payments
>> definitely poses some interesting challenges in adapting the existing
>> invoicing
>> scheme. However, I believe there exist stronger and better means of doing
>> proofs of payment, and would prefer not to tie our hands by assuming
>> this is the best way to approach the problem.
>>IMHO, the current signed invoice + preimage is a very weak proof of
>> payment.
>> It's the hash equivalent to proving you own a public key by publishing the
>> secret key. There is an assumption that the only way someone could get
>> that
>> preimage is by having made a payment, but this assumption is broken most
>> directly by the proving mechanism. Similarly, any intermediary who
>> acquires
>> an invoice with the appropriate hash could also make this claim since they
>> also have the preimage.
>>Further, I think it's a mistake to conflate
>>   1) me being able to present a valid preimage/invoice pair, with
>>   2) me having received the correct preimage in response to an onion
>> packet
>>     that I personally crafted for the receiving node in the invoice.
>>
>> The main issue is that the proof does not bind a specific sender,
>> making statement 1 producible by multiple individuals. I think it would be
>> potentially worthwhile to explore proofs of stronger statements, such
>> as 2,
>> that could utilize the ephemeral keys in the onion packets, or even the
>> onion as a witness, which is more rigidly coupled to having actually
>> completed a payment.
>>Without any modification to the spec, we can always use something like
>> ZKBoo to prove (w/o trusted setup) knowledge of a preimage without
>> totally revealing it to the verifier. This isn't perfect, but at least
>> gives the
>> sender the option to prove the statement without necessarily giving up
>> the preimage.
>>TL;DR: I'm not convinced the signed invoice + hash is really a good
>> yardstick
>> by which to measure provability, and I think doing some research into
>> proofs
>> of payment on stronger statements would be incredibly valuable. Therefore,
>> I'm not sure if AMPs really lose this, so much as force us to reconsider
>> what it actually requires to soundly prove a payment to an external
>> verifier.
>>Best,
>> Conner
>>On Mon, Feb 12, 2018 at 6:56 PM ZmnSCPxj via Lightning-dev
>> <lightning-dev at lists.linuxfoundation.org
>>mailto:lightning-dev at lists.linuxfoundation.org> wrote:
>>Good morning Christian and Corne,
>>
>>Another idea to consider, is techniques like ZKCP and ZKCSP, which
>>provide atomic access to information in exchange for monetary
>>compensation.  Ensuring atomicity of the exchange can be done by
>>providing the information encrypted, a hash of the encryption key,
>>and proofs that the encrypted data is the one desired and that the
>>data was encrypted with the given key; the proof-of-payment is the
>>encryption key, and possession of the encryption key is sufficient
>>to gain access to the information, with no need to bring in legal
>>structures.
>>
>>(admittedly, ZKCP and ZKCSP are dependent on new cryptography...)
>>
>>(also, AMP currently cannot provide a proof-of-payment, unlike
>>current payment routing that has proof-of-payment, but that is an
>>eventual design goal that would enable use of ZKC(S)P
>>on-Lightning, assuming we eventually find out that zk-SNARKs and
>>so on are something we can trust)
>>
>>Regards,
>>ZmnSCPxj
>>
>>​
>>Sent with ProtonMail Secure Email.
>>​
>>
>>-------- Original Message --------
>> On February 13, 2018 2:05 AM, Christian Decker
>><decker.christian at gmail.com <mailto:decker.christian at gmail.com>>
>>wrote:
>>
>>>Honestly I don't get why we are complicating this so much. We have a
>>> system that allows atomic multipath payments using a single
>>secret, and
>>> future decorrelation mechanisms allow us to vary the secret in
>>such a
>>> way that multiple paths cannot be collated, why introduce a
>>whole set of
>>> problems by giving away the atomicity? The same goes for the
>>overpaying
>>> and trusting the recipient to only claim the owed amount, there
>>is no
>>> need for this. Just pay the exact amount, by deriving secrets
>>from the
>>> main secret and make the derivation reproducible by intermediate
>>hops.
>>>
>>> Having proof-of-payment be presentable in a court is a nice
>>feature, but
>>> it doesn't mean we need to abandon all guarantees we have worked
>>so hard
>>> to establish in LN.
>>>
>>> Corné Plooy via Lightning-dev
>>lightning-dev at lists.linuxfoundation.org
>><mailto:lightning-dev at lists.linuxfoundation.org>
>>>writes:
>>>
>>>>I was thinking that, for that use case, a different signed
>>invoice could
>>>> be formulated, stating
>>>> - several payment hashes with their corresponding amounts
>>>>
>>>> - the obligation of signer to deliver Z if all corresponding
>>payment
>>>> keys are shown
>>>>
>>>> - some terms to handle the case where only a part of the
>>payments was
>>>> successful, e.g. an obligation to refund
>>>>The third item is a bit problematic: in order to distinguish
>>this case
>>>> from a complete success, the payee would have to prove absence of
>>>> successful transactions, which is hard. Absence of successful
>>>> transactions can only be declared by the payer, so in order to
>>reliably
>>>> settle without going to court first, the payer should sign a
>>>> declaration stating that certain transactions were canceled and
>>that the
>>>> other ones should be refunded. This can be another invoice.
>>>>So, the original invoice states:
>>>> - several payment hashes with their corresponding amounts
>>>>
>>>> - if all corresponding payment keys are shown: the obligation
>>of <payee>
>>>> to deliver Z, UNLESS stated otherwise by an invoice signed by
>><payer>
>>>>-- signed by <payee>
>>>>But if a payment partially fails, it can be refunded
>>cooperatively with
>>>> an invoice created by payer:
>>>> - declares which of the original payments were successful (with
>>payment
>>>> keys) and which were not
>>>>
>>>> - replaces the obligation of <payee> to deliver Z with an
>>obligation to
>>>> refund the successful transactions
>>>>
>>>> - several payment hashes with their corresponding amounts
>>>>
>>>> - if all corresponding payment keys are shown: cancel the
>>obligation of
>>>> <payee> to refund
>>>>-- signed by <payer>
>>>>Maybe this can be repeated iteratively if necessary; hopefully the
>>>> not-yet-settled amount will converge to zero.
>>>>Important advantage: this only requires changes to the invoice
>>format,
>>>> not to the network protocol.
>>>>The point is: in this use case, the court is apparently the
>>final point
>>>> of settlement for invoices, just like the blockchain is for the
>>other
>>>> channels in the route. IANAL, but I think the "scripting language"
>>>> accepted by courts is quite flexible, and you can use that to
>>enforce
>>>> atomicity. With the construction described above, you can
>>either refund
>>>> cooperatively (and collect evidence that refund has happened),
>>or, if
>>>> that fails, go to court to enforce settlement there.
>>>>CJP
>>>>Op 12-02-18 om 10:23 schreef Christian Decker:
>>>>>CJP cjp at ultimatestunts.nl <mailto:cjp at ultimatestunts.nl> writes:
>>>>>>Can you give a use case for this?
>>>>>>Usually, especially in the common case that a payment is done in
>>>>>> exchange for some non-cryptographic asset (e.g. physical
>>goods), there
>>>>>> already is some kind of trust between payer and payee. So, if
>>a payment
>>>>>> is split non-atomically into smaller transactions, and only a
>>part
>>>>>> succeeds, presumably they can cooperatively figure out some
>>way to
>>>>>> settle the situation.
>>>>>> The scenario that is commonly used in these cases is a
>>merchant that
>>>>>> provides a signed invoice "if you pay me X with payment_hash
>>Y I will
>>>>>> deliver Z". Now the user performs the payment, learns the
>>payment_key
>>>>>> matching the payment_hash, but the merchant refuses to
>>deliver, claiming
>>>>>> it didn't get the payment. Now the user can go to a court,
>>present the
>>>>>> invoice signed by the merchant, and the proof-of-payment, and
>>force the
>>>>>> merchant to honor its commitment.
>>>>>>
>>>>>Lightning-dev mailing list
>>>>>Lightning-dev at lists.linuxfoundation.org
>><mailto:Lightning-dev at lists.linuxfoundation.org>
>>>>>https://www.learnbitcoin.com/archive/lists/lightning-dev
>>>>>
>>>>Lightning-dev mailing list
>>>>Lightning-dev at lists.linuxfoundation.org
>><mailto:Lightning-dev at lists.linuxfoundation.org>
>>>>https://www.learnbitcoin.com/archive/lists/lightning-dev
>>>>
>>>Lightning-dev mailing list
>>>Lightning-dev at lists.linuxfoundation.org
>><mailto:Lightning-dev at lists.linuxfoundation.org>
>>>https://www.learnbitcoin.com/archive/lists/lightning-dev
>>>
>>
>>_______________________________________________
>>Lightning-dev mailing list
>>Lightning-dev at lists.linuxfoundation.org
>><mailto:Lightning-dev at lists.linuxfoundation.org>
>>https://www.learnbitcoin.com/archive/lists/lightning-dev
>>
>>
>>Lightning-dev mailing list
>>Lightning-dev at lists.linuxfoundation.org
>>https://www.learnbitcoin.com/archive/lists/lightning-dev
>>
>
>
>Lightning-dev mailing list
>Lightning-dev at lists.linuxfoundation.org
>https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Rusty Russell in reply to Conner Fromknecht permalink original

Conner Fromknecht <conner at lightning.engineering> writes:

Quoted text (7 lines)
> IMHO, the current signed invoice + preimage is a very weak proof of payment.
> It's the hash equivalent to proving you own a public key by publishing the
> secret key. There is an assumption that the only way someone could get that
> preimage is by having made a payment, but this assumption is broken most
> directly by the proving mechanism. Similarly, any intermediary who acquires
> an invoice with the appropriate hash could also make this claim since they
> also have the preimage.

Agreed.

Quoted text (11 lines)
> Further, I think it's a mistake to conflate
>   1) me being able to present a valid preimage/invoice pair, with
>   2) me having received the correct preimage in response to an onion packet
>     that I personally crafted for the receiving node in the invoice.
>
> The main issue is that the proof does not bind a specific sender,
> making statement 1 producible by multiple individuals. I think it would be
> potentially worthwhile to explore proofs of stronger statements, such as 2,
> that could utilize the ephemeral keys in the onion packets, or even the
> onion as a witness, which is more rigidly coupled to having actually
> completed a payment.

Yes; this places more emphasis on the invoice's precision, eg. "I will ship X to Y".

In practice, as we move to payment decorrelation the proof-of-payment does half of what you suggest: only the initial payer has the necessary proof, but it's still open-kimono if they reveal it.

Using some kind of point-supplied-in-onion to tweak result might help here (handwave?!) since you can prove you know the secret for the point easily without revealing it, and then AMP is simply an aggregation of tweaks.

Quoted text (7 lines)
> TL;DR: I'm not convinced the signed invoice + hash is really a good
> yardstick
> by which to measure provability, and I think doing some research into proofs
> of payment on stronger statements would be incredibly valuable. Therefore,
> I'm not sure if AMPs really lose this, so much as force us to reconsider
> what it actually requires to soundly prove a payment to an external
> verifier.

Proof-of-payment is a unique lightning property, which I think is terribly underrated (because we're used to not having it). Our actions so far have been to boltser this (hence BOLT11), and I'd hate to see us discard it for convenience: I fear we'd never get it back!

Fortunately I think we *can* have our cake and eat it too...

Thanks, Rusty.

Anthony Towns in reply to ZmnSCPxj permalink original

On Tue, Feb 13, 2018 at 09:23:37AM -0500, ZmnSCPxj via Lightning-dev wrote:

Quoted text (4 lines)
> Good morning Corne and Conner,
> Ignoring the practical matters that Corne rightly brings up, I think,
> it is possible to use ZKCP to provide a "stronger" proof-of-payment in
> the sense that Conner is asking for.

I think Schnorr scriptless scripts work for this (assuming HTLC payment hashes are ECC points rather than SHA256 hashes). In particular:

 - Alice agrees to pay Bob $5 for a coffee.
 - Bob calculates a lightning payment hash preimage r, and payment hash
   R=r*G. Bob also prepares a receipt message, saying "I've been paid $5
   to give Alice a coffee", and calculates a partial Schnorr signature
   of this receipt (n a signature nonce, N=n*G, s=n+H(R+N,B,receipt)*b),
   and sends Alice (R, N, s)
 - Alice verfies the partial signature:
      s*G = N + H(R+N,B,receipt)*B
 - Alice pays over lightning conditional on receiving the preimage r of R.
 - Alice then has a valid signature of the receipt, signed by Bob:
      (R+N, r+s)

The benefit over just getting a hash preimage, is that you can use this to prove that you paid Bob, rather than Carol or Dave, at some later date, including to a third party (a small-claims court, tax authorities, a KYC/AML audit?).

The nice part is you get that just by doing some negotiation at the start, it's not something the lightning protocol needs to handle at all (beyond switching to ECC points for payment hashes).

Quoted text (6 lines)
> -------- Original Message --------
>  On February 13, 2018 10:33 AM, Corné Plooy via Lightning-dev <lightning-dev at lists.linuxfoundation.org> wrote:
> >Hi Conner,
> > I do believe proof of payment is an important feature to have,
> > especially for the use case of a payer/payee pair that doesn't
> > completely trust each other, but does have the possibility to go to court.

Cheers, aj