Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Onion Routing Spec

37 messages, Jul 25 to Oct 24, 2016. Started by Christian Decker.

Olaoluwa Osuntokun (13), Christian Decker (12), Rusty Russell (11), Joseph Poon

Permalink First message in the Wayback Machine

Christian Decker permalink original

Hi all,

I took the liberty of taking apart Olaoluwa's Sphinx implementation and I came up with a spec draft that I'd like to propose [1]. It should roughly be Sphinx, pinning down the various key-generation and stream generation algorithms, and adding a per-hop payload.

The per-hop payload is used to give instructions to individual hops, i.e., how many coins to forward to the next hop. This means that the end-to-end payload, i.e., the message in the Sphinx protocol, is currently unused and could be omitted.

The payloads are currently fixed size (20 bytes per-hop and 1024 bytes for end-to-end payload) to avoid making messages collatable by their size. However, they could easily be made variable should we decide that sending mostly empty messages is wasteful.

The spec is implemented in Go [2] and in C [3]. The Go version is an adaptation of Olaoluwa's implementation, with some minor speedups, removing some duplicate information, stripping the header, and switching to ChaCha20 for stream generation and encryption. I also added a small commandline tool that allows you to write packets to stdout so that we can feed an onion generated by the C version to the Go implementation and vice-versa :-)

Feedback is very welcome. If people like the draft I'll create pull-requests for the spec and the implementations, but I'd like to keep the discussion on the mailing list :-)

Cheers, Christian

[1] https://github.com/cdecker/lightning-rfc/blob/master/bolts/onion-protocol.md [2] https://github.com/cdecker/lightning-onion/tree/chacha20 [3] https://github.com/cdecker/lightning/tree/chacha20

Olaoluwa Osuntokun in reply to Christian Decker permalink original

Hi Christian, welcome to the mailing list!

Excellent work! I've been meaning to re-visit my implementation since I finished it last October but have been busy tending to other lnd related items. Thanks for the cleanups and optimizations you've added to my initial Sphinx implementation. Once we've finished fleshing out the initial specification, I'd be happy to get those changes merged!

I've taken a look at the diff against the existing implementation, plus the current spec draft. I'd say the current spec draft is the *clearest* description of Sphinx I've encountered, especially the padding bits. IMO, the notation within the paper describing how to construct+process the mix-header is rather opaque.

I see you've modified the encryption scheme of the end-to-end payload, switching from the arbitrary block-size block cipher (LIONESS) to purely a stream cipher (ChaCha20). Initially I was under the impression that this might compromise one of the security arguments of the scheme, but on closer inspection this is perfectly fine if one extends the header MAC to the entire payload as you've done. If one was staying true to the original construction, then this would eliminate the possibility of Single-Use Reply Blocks (SURB's) since the sender would be unable to construct the reply mix-header as she would be unaware of they responder's message. It's clear to me now that a MAC covering the end-to-end payload was omitted in the original version since the proof of computational indistinguishability of replies vs responses depends on the structure+processing being identical for both messages types. However I don't see us having any use for SURB's so this is an excellent change. Additionally, modifications to the end-to-end payload will instantly cause packet corruption, stopping invalid packets from propagating through the network.

I really like the addition of the per-hop payload! It's a change to the original construction that I've seriously considered proposing. Such a payload should prove to be very useful in the future for information such as: limits on the per-hop absolute timeout, fee information, etc.

The addition of a version byte is also very welcome. This'll streamline future modifications we may make to the mix-header format in the future, such as increasing the size of the per-hop payload, or switching to an alternative format to encoding the "next hop" address.

The current draft doesn't specify the processor's action in the scenario that they're unable to locate the next hop node within their local routing table. Just to be explicit, I think a final paragraph should be inserted under the "Packet Forwarding" section detailing the abort procedure.

Quoted text (2 lines)
> However, they could easily be made variable should we decide that sending
> mostly empty messages is wasteful.

I strongly think we should maintain the size uniformity of the packet throughout processing, changes in payload size between hop can give away information w.r.t a node's position within the route.

We might want to consider dropping the end-to-end payload altogether though. I can't really think of a clear use case for the e2e payload within our specific application. That would save us 1k bytes, reducing the size of the full mix-header to 1234 bytes. Accounting for the additional fields within an HTLC "add" message, plus some additional overhead, this should keep us below typical MTU sizes, avoiding fragmentation of HTLC "add" messages.

Quoted text (2 lines)
> This specification is limited to version 0 packets and the structure of
> future version may change. The receiving node then splits the packet into

its

Quoted text (1 line)
> fields.

Packets with a non-zero version byte should be immediately rejected, as well as packets which aren't *exactly* 2258 bytes (or 1234 bytes if we drop the e2e payload).

Quoted text (3 lines)
> The resulting HMAC is compared with the HMAC from the packet. Should the
> computed HMAC and the HMAC from the packet differ then the node MUST abort
> processing and report a route failure.

Perhaps we should explicitly specify that the HMAC equality check MUST be performed without leaking timing information (constant time comparison)? I can't think of a precise potential vulnerability otherwise since the scheme uses an encrypt-then-MAC construction with a semantically secure encryption scheme. I don't see any clear downsides in specifying that the comparison be made in constant.

Quoted text (1 line)
> The sender computes a route {n_1, ..., n_{r-1}, n_r}, where n_1 is a peer

of

Quoted text (1 line)
> the sender and n_r is the recipient.

In order to eliminate ambiguity, I think this should be more explicit, specifying that "n_1" is a *direct neighbor* of the sender

Quoted text (4 lines)
> A special HMAC value of 20 0x00 bytes indicates that the currently
> processing hop is the intended recipient and that the packet should not be
> forwarded. At this point the end-to-end payload is fully decrypted and the
> route has terminated.

It seems that with the current construction, then the "next hop" address will also be zero bytes if a packet processor is the last hop in the route. Alternatively, if the sender is aware that the receiver is actually a "virtual channel", then an additional address could be used instead of the zero-address to facilitate de-multiplexing at the last hop to the destination virtual channel.

Quoted text (1 line)
> In the pocessing phase the secret is the node's private key...

Typo here, it should read "In the processing phase..."

I think two key onion-routing related aspects are under specified within the current draft: replay protection, and key rotation. Although we might want to place details concerning key rotation in a separate document covering the initial routing protocol as the two are closely related.

First, lets talk replay protection. The current draft specifies that:

Quoted text (1 line)
> The node MUST keep a log of previously used shared secrets. Should the

shared

Quoted text (1 line)
> secret already be in the log it MUST abort processing the packet and

report a

Quoted text (2 lines)
> route failure, since this is likely a replay attack, otherwise the shared
> secret is added to the log

This is definitely necessary, however as dictated this would require nodes to allocate a potentially *unbounded* amount of storage to the shared secret "seen" log. I think we can allow nodes to periodically truncate this log by adding an additional session time stamp to the mix-header, either placed directly after the version byte, or within the per-hop payload.

With this absolute timestamp, each entry within the "seen" log becomes a two-tuple: the shared secret itself, and the corresponding timestamp specified within the mix-header. Before the absolute timestamp has passed, the entry within the log remains, and mix-headers received with duplicated shared secret are rejected. If we enforce an upper bound on the "session lifetime", then nodes can periodically prune this log, discarding obsolete shared secrets. Once an entry has been pruned, although a node may not know if a shared secret is being duplicated, they can reject expired sessions according to the timestamp achieving a similar affect.

Reasonable session times may be something around 30-minutes to an hour or two.

With this scheme, I think that we can achieve near perfect replay protection without unbounded storage.

On to the second aspect: key rotation. Ignoring the possible time-stamped log solution, the (possibly) only other way to allow nodes to prune their shared secret log is to periodically rotate keys. Once a node rotates a key, it can safely delete its *entire* previous shared secret log, as replay attacks will fail on the HMAC check. Independent of replay attack prevention, key rotation is useful in order to provide a degree of forward secrecy. Without key rotation, when a node is compromised by the adversary (assuming the node keeps *all* prior mix-headers), the adversary learns of the next-node within the route, and also the per-hop payload for the compromised node. With key rotation, assuming the prior keys are deleted, then the adversary is only able to decrypt partially ciphertexts from the current epoch.

So then a question arises: how do we perform key rotation within the network globally with loose synchronization? I say loose synchronization since if rotations aren't synchronized to a degree, then the payments of source nodes may fail as an intermediate hop is unable to process the packet since it used an obsolete onion key. Therefore published onion keys should come in pairs (with overlapping lifetimes), and also be authenticated by a node's identity key.

A key rotation scheme might look something like the following:
    * A node publishes two keys, along with a block hash of a block beyond a
      "safe" re-org distance, and a signature (under the identity pubkey)
      covering the advertisement.
    * The first key is intended for use until N blocks after the specified
      block hash, with nodes switching to the second key afterwards.
    * At the N/2 point, the original node publishes a new advertisement with
      the second key from the original advertisement listed as the "first"
key,
      and a new fresh quasi-ephemeral onion key. The original node performs
      this rotation at intervals at the mid-point of expiration of the
oldest
      key.
    * Nodes who receive this new advertisement (aware of the previous)
record
      this as the node's next rotation key. Nodes who receive this
      advertisement, unaware of the previous treat this as the node's
initial
      pair of quasi-ephemeral onion keys.

With this scheme, rotations are synchronized very loosely, perhaps in the timespan of half-days, days, etc. There is a new cost however, when processing packets, a node must attempt to derive the shared secret with both active onion keys. Alternatively, instead of block hashes, we can use some other time based beacon as a switch over point in order to accommodate peers on multiple blockchains.

I'll take a few more passes through the current draft spec, as well are your commits in your fork of my original implementation, following up with any other questions/comments.

-- Laolu

On Mon, Jul 25, 2016 at 9:23 AM Christian Decker <decker.christian at gmail.com> wrote:

Quoted text (40 lines)
> Hi all,
>
> I took the liberty of taking apart Olaoluwa's Sphinx implementation and I
> came up with a spec draft that I'd like to propose [1]. It should roughly
> be Sphinx, pinning down the various key-generation and stream generation
> algorithms, and adding a per-hop payload.
>
> The per-hop payload is used to give instructions to individual hops, i.e.,
> how many coins to forward to the next hop. This means that the end-to-end
> payload, i.e., the message in the Sphinx protocol, is currently unused and
> could be omitted.
>
> The payloads are currently fixed size (20 bytes per-hop and 1024 bytes for
> end-to-end payload) to avoid making messages collatable by their size.
> However, they could easily be made variable should we decide that sending
> mostly empty messages is wasteful.
>
> The spec is implemented in Go [2] and in C [3]. The Go version is an
> adaptation of Olaoluwa's implementation, with some minor speedups, removing
> some duplicate information, stripping the header, and switching to ChaCha20
> for stream generation and encryption. I also added a small commandline tool
> that allows you to write packets to stdout so that we can feed an onion
> generated by the C version to the Go implementation and vice-versa :-)
>
> Feedback is very welcome. If people like the draft I'll create
> pull-requests for the spec and the implementations, but I'd like to keep
> the discussion on the mailing list :-)
>
> Cheers,
> Christian
>
> [1]
> https://github.com/cdecker/lightning-rfc/blob/master/bolts/onion-protocol.md
> [2] https://github.com/cdecker/lightning-onion/tree/chacha20
> [3] https://github.com/cdecker/lightning/tree/chacha20
> _______________________________________________
> 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 (14 lines)
>> A special HMAC value of 20 0x00 bytes indicates that the currently
>> processing hop is the intended recipient and that the packet should not be
>> forwarded. At this point the end-to-end payload is fully decrypted and the
>> route has terminated.
>
> It seems that with the current construction, then the "next hop" address
> will
> also be zero bytes if a packet processor is the last hop in the route.
> Alternatively, if the sender is aware that the receiver is actually a
> "virtual
> channel", then an additional address could be used instead of the
> zero-address
> to facilitate de-multiplexing at the last hop to the destination virtual
> channel.

Hmm, I think we should combine the "header" and "per-hop payload" into a single 40 byte field. They're not meaningfully distinct for lightning, AFAICT.

And I think we should add/steal at least one byte for "realm". 0 = terminal. 1 = bitcoin lightning. 2 = TBA. etc.

Obviously we should specify the layout when type = 0 (ignore) and 1 (hash160(nexthop-pubkey) + 8-byte-amount-to-fwd + 12-ignored).

That allows us to extend the protocol incompatibly (add a new realm) or compatibly (add semantics to those ignored sections).

Quoted text (15 lines)
> First, lets talk replay protection. The current draft specifies that:
>
>> The node MUST keep a log of previously used shared secrets. Should the
> shared
>> secret already be in the log it MUST abort processing the packet and
> report a
>> route failure, since this is likely a replay attack, otherwise the shared
>> secret is added to the log
>
> This is definitely necessary, however as dictated this would require nodes
> to
> allocate a potentially *unbounded* amount of storage to the shared secret
> "seen" log. I think we can allow nodes to periodically truncate this log by
> adding an additional session time stamp to the mix-header, either placed
> directly after the version byte, or within the per-hop payload.

Let's tease this out a bit more; thinking about replays from the PoV of one layer higher. We can't simply deny multiple HTLCs with the same r hash, since that allows an attacker to probe the network to see where an HTLC went (note that in the longer run, it's in a node's short-term economic interest to allow this, which is why rhash is troubling).

If we switch from hash/preimage to the privkeys with point addition scheme (which has other benefits) this is no longer an issue and we can simply refuse to accept two HTLCs with the same pubkey.

Though the idea of using a "comms" key signed by our "peer" key which we rotate every N minutes/hours is appealing for forward secrecy and minimal peer-key exposure reasons, as Laolu says.

Cheers, Rusty.

Christian Decker in reply to Olaoluwa Osuntokun permalink original

Sending to the mailing list since Laolu pointed out I only sent my reply to him. Sorry for that.

On Sat, Jul 30, 2016, 15:25 Christian Decker <decker.christian at gmail.com> wrote:

Quoted text (453 lines)
> On Wed, Jul 27, 2016 at 8:14 PM Olaoluwa Osuntokun <laolu32 at gmail.com>
> wrote:
>
>> Hi Christian, welcome to the mailing list!
>>
> Hi Laolu,
>
> glad to be here :-)
>
>>
>> Excellent work! I've been meaning to re-visit my implementation since I
>> finished it last October but have been busy tending to other lnd related
>> items.
>> Thanks for the cleanups and optimizations you've added to my initial
>> Sphinx
>> implementation. Once we've finished fleshing out the initial
>> specification, I'd
>> be happy to get those changes merged!
>>
>> I've taken a look at the diff against the existing implementation, plus
>> the
>> current spec draft. I'd say the current spec draft is the *clearest*
>> description of Sphinx I've encountered, especially the padding bits. IMO,
>> the
>> notation within the paper describing how to construct+process the
>> mix-header is
>> rather opaque.
>>
> Actually, your implementation helped a lot in getting a clear picture of
> how Sphinx is supposed to work, so thanks for taking the time to implement
> the paper in the first place. Glad you like my writeup, hopefully it is as
> clear to new implementors as well :-)
>
>>
>> I see you've modified the encryption scheme of the end-to-end payload,
>> switching from the arbitrary block-size block cipher (LIONESS) to purely a
>> stream cipher (ChaCha20). Initially I was under the impression that this
>> might
>> compromise one of the security arguments of the scheme, but on closer
>> inspection this is perfectly fine if one extends the header MAC to the
>> entire
>> payload as you've done. If one was staying true to the original
>> construction,
>> then this would eliminate the possibility of Single-Use Reply Blocks
>> (SURB's)
>> since the sender would be unable to construct the reply mix-header as she
>> would
>> be unaware of they responder's message. It's clear to me now that a MAC
>> covering
>> the end-to-end payload was omitted in the original version since the
>> proof of
>> computational indistinguishability of replies vs responses depends on the
>> structure+processing being identical for both messages types. However I
>> don't
>> see us having any use for SURB's so this is an excellent change.
>> Additionally,
>> modifications to the end-to-end payload will instantly cause packet
>> corruption,
>> stopping invalid packets from propagating through the network.
>>
>
> I'm going back and forth about including the payloads in the header HMAC.
> I think we have three options here:
>
>  1) Include the payload in the header HMAC computation
>  2) Include an additional set of HMACs for the payload that can be checked
> at each hop
>  3) Just use an encryption scheme that also verifies the integrity, e.g.,
> ChaCha20-Poly1305, on the last hop and normal ChaCha20 on all preceeding
> hops.
>
> The first option is small, and it discards tampered packets as soon as the
> next hop checks its HMAC. The downside is indeed that we lose a lot of
> flexibility. Besides losing the ability to provide a SURB to the final
> recipient, we also lose the ability to do anonymous rendezvous meetings,
> where the final recipient provides half of the route in the form of a
> precompiled header (something that Hornet is using).
>
> The second option is quite costly just to have the drop-early feature. It
> would add 400 bytes to each packet, assuming 20 byte HMACs and 20 hops. On
> the other hand forwarding a packet to the final recipient when we could
> discard it early is quite costly since each hop locks up some funds in the
> form of an associated HTLC.
>
> The third option is just the case in which we'd forward the packet to the
> final recipient, which can then decide whether the payload was tampered
> with or not. Costly in terms of HTLCs being created and funds being locked
> up, but hopefully they'd be released again immediately.
>
> Both the per-hop checkable schemes, combined with nodes signing the
> packets they forward, would give us the ability to identify misbehaving
> nodes and denounce them: if we receive a packet we check the integrity and
> if it doesn't match then we can prove to others that the node forwarded
> something broken with its signature, or it did not check the packet itself.
>
>
>> I really like the addition of the per-hop payload! It's a change to the
>> original construction that I've seriously considered proposing. Such a
>> payload
>> should prove to be very useful in the future for information such as:
>> limits on
>> the per-hop absolute timeout, fee information, etc.
>>
>> The addition of a version byte is also very welcome. This'll streamline
>> future
>> modifications we may make to the mix-header format in the future, such as
>> increasing the size of the per-hop payload, or switching to an alternative
>> format to encoding the "next hop" address.
>>
>
> Good idea, the next hop address basically does just have to make sense to
> the node processing the packet, so maybe we can use some form of short tag
> or index to specify which existing channel to use, instead of using the
> globally unique address.
>
>>
>> The current draft doesn't specify the processor's action in the scenario
>> that
>> they're unable to locate the next hop node within their local routing
>> table.
>> Just to be explicit, I think a final paragraph should be inserted under
>> the
>> "Packet Forwarding" section detailing the abort procedure.
>>
>
> Good catch, I'll amend the spec to specify that unroutable packets are
> dropped and the sender signaled.
>
>>
>>
>> > However, they could easily be made variable should we decide that
>> sending
>> > mostly empty messages is wasteful.
>>
>> I strongly think we should maintain the size uniformity of the packet
>> throughout processing, changes in payload size between hop can give away
>> information w.r.t a node's position within the route.
>>
>> We might want to consider dropping the end-to-end payload altogether
>> though. I
>> can't really think of a clear use case for the e2e payload within our
>> specific
>> application.  That would save us 1k bytes, reducing the size of the full
>> mix-header to 1234 bytes. Accounting for the additional fields within an
>> HTLC
>> "add" message, plus some additional overhead, this should keep us below
>> typical
>> MTU sizes, avoiding fragmentation of HTLC "add" messages.
>>
>
> There is a tradeoff between small packets and keeping the size uniform. I
> think we could bucketize sizes, e.g., have multiples of 32 bytes or 64
> bytes for the fields, to have packets with similar sized payloads have the
> same packet size. That would allow us to also drop the e2e payload by
> setting a size of 0, and still be able to forward it, should we ever find a
> use for it.
>
>>
>> > This specification is limited to version 0 packets and the structure of
>> > future version may change. The receiving node then splits the packet
>> into its
>> > fields.
>>
>> Packets with a non-zero version byte should be immediately rejected, as
>> well as
>> packets which aren't *exactly* 2258 bytes (or 1234 bytes if we drop the
>> e2e
>> payload).
>>
>
> I don't think we need a size check: the fixed size actually allows us to
> serialize directly on the wire, without a size prefix, so if we read less
> than 2258 bytes then we simply continue reading, if we read more, then we
> crossed a packet boundary and ought to split. But maybe that is mixing
> transport layer and packet specification?
>
>>
>> > The resulting HMAC is compared with the HMAC from the packet. Should the
>> > computed HMAC and the HMAC from the packet differ then the node MUST
>> abort
>> > processing and report a route failure.
>>
>> Perhaps we should explicitly specify that the HMAC equality check MUST be
>> performed without leaking timing information (constant time comparison)? I
>> can't think of a precise potential vulnerability otherwise since the
>> scheme
>> uses an encrypt-then-MAC construction with a semantically secure
>> encryption
>> scheme. I don't see any clear downsides in specifying that the comparison
>> be
>> made in constant.
>>
>
> I don't see a chance of this being used either, each secret key used in
> the HMAC computation is used just once. But better be safe than sorry. I'll
> add it to the spec.
>
>>
>> > The sender computes a route {n_1, ..., n_{r-1}, n_r}, where n_1 is a
>> peer of
>> > the sender and n_r is the recipient.
>>
>> In order to eliminate ambiguity, I think this should be more explicit,
>> specifying that "n_1" is a *direct neighbor* of the sender
>>
>> Amended and clarified that a peer is a direct neighbor in the overlay
> network.
>
>
>> > A special HMAC value of 20 0x00 bytes indicates that the currently
>> > processing hop is the intended recipient and that the packet should not
>> be
>> > forwarded. At this point the end-to-end payload is fully decrypted and
>> the
>> > route has terminated.
>>
>> It seems that with the current construction, then the "next hop" address
>> will
>> also be zero bytes if a packet processor is the last hop in the route.
>> Alternatively, if the sender is aware that the receiver is actually a
>> "virtual
>> channel", then an additional address could be used instead of the
>> zero-address
>> to facilitate de-multiplexing at the last hop to the destination virtual
>> channel.
>>
>
> Sounds good, I thought I'd use the HMAC to signal so we still have the
> first 20 bytes free to use, adding a de-multiplexing address might be one
> use.
>
>>
>> > In the pocessing phase the secret is the node's private key...
>>
>> Typo here, it should read "In the processing phase..."
>>
>> I think two key onion-routing related aspects are under specified within
>> the
>> current draft: replay protection, and key rotation. Although we might
>> want to
>> place details concerning key rotation in a separate document covering the
>> initial routing protocol as the two are closely related.
>>
>> First, lets talk replay protection. The current draft specifies that:
>>
>> > The node MUST keep a log of previously used shared secrets. Should the
>> shared
>> > secret already be in the log it MUST abort processing the packet and
>> report a
>> > route failure, since this is likely a replay attack, otherwise the
>> shared
>> > secret is added to the log
>>
>> This is definitely necessary, however as dictated this would require
>> nodes to
>> allocate a potentially *unbounded* amount of storage to the shared secret
>> "seen" log. I think we can allow nodes to periodically truncate this log
>> by
>> adding an additional session time stamp to the mix-header, either placed
>> directly after the version byte, or within the per-hop payload.
>>
>> With this absolute timestamp, each entry within the "seen" log becomes a
>> two-tuple: the shared secret itself, and the corresponding timestamp
>> specified
>> within the mix-header. Before the absolute timestamp has passed, the entry
>> within the log remains, and mix-headers received with duplicated shared
>> secret
>> are rejected. If we enforce an upper bound on the "session lifetime", then
>> nodes can periodically prune this log, discarding obsolete shared secrets.
>> Once an entry has been pruned, although a node may not know if a shared
>> secret
>> is being duplicated, they can reject expired sessions according to the
>> timestamp achieving a similar affect.
>>
>> Reasonable session times may be something around 30-minutes to an hour or
>> two.
>>
>> With this scheme, I think that we can achieve near perfect replay
>> protection
>> without unbounded storage.
>>
>
> We have to be careful when using timestamps in the packet as it makes
> individual hops collatable. One solution is again to bucketize timestamps
> included in the packet such that we have enough packets with the same
> timestamps to avoid having an attacker associate individual hops in a
> route. The alternative is to have a blinded timestamp per hop, i.e., in the
> routing info, but that automatically blows the size up to 20x. So my
> proposal would be to include a timestamp rounded up to the closest hour and
> have a sliding window of accepted timestamps of +/- 1 hour, remembering the
> secrets for that period and rejecting anything that is too far in the
> future or too far in the past. The more coarse the bigger the less likely
> an attacker is to guess which packets belong to the same route, but the
> more storage is required on the node's side.
>
>>
>> On to the second aspect: key rotation. Ignoring the possible time-stamped
>> log
>> solution, the (possibly) only other way to allow nodes to prune their
>> shared
>> secret log is to periodically rotate keys. Once a node rotates a key, it
>> can
>> safely delete its *entire* previous shared secret log, as replay attacks
>> will
>> fail on the HMAC check. Independent of replay attack prevention, key
>> rotation
>> is useful in order to provide a degree of forward secrecy. Without key
>> rotation, when a node is compromised by the adversary (assuming the node
>> keeps
>> *all* prior mix-headers), the adversary learns of the next-node within the
>> route, and also the per-hop payload for the compromised node. With key
>> rotation, assuming the prior keys are deleted, then the adversary is only
>> able
>> to decrypt partially ciphertexts from the current epoch.
>>
>> So then a question arises: how do we perform key rotation within the
>> network
>> globally with loose synchronization? I say loose synchronization since if
>> rotations aren't synchronized to a degree, then the payments of source
>> nodes
>> may fail as an intermediate hop is unable to process the packet since it
>> used an
>> obsolete onion key. Therefore published onion keys should come in pairs
>> (with
>> overlapping lifetimes), and also be authenticated by a node's identity
>> key.
>>
>> A key rotation scheme might look something like the following:
>>     * A node publishes two keys, along with a block hash of a block
>> beyond a
>>       "safe" re-org distance, and a signature (under the identity pubkey)
>>       covering the advertisement.
>>     * The first key is intended for use until N blocks after the specified
>>       block hash, with nodes switching to the second key afterwards.
>>     * At the N/2 point, the original node publishes a new advertisement
>> with
>>       the second key from the original advertisement listed as the
>> "first" key,
>>       and a new fresh quasi-ephemeral onion key. The original node
>> performs
>>       this rotation at intervals at the mid-point of expiration of the
>> oldest
>>       key.
>>     * Nodes who receive this new advertisement (aware of the previous)
>> record
>>       this as the node's next rotation key. Nodes who receive this
>>       advertisement, unaware of the previous treat this as the node's
>> initial
>>       pair of quasi-ephemeral onion keys.
>>
>> With this scheme, rotations are synchronized very loosely, perhaps in the
>> timespan of half-days, days, etc. There is a new cost however, when
>> processing
>> packets, a node must attempt to derive the shared secret with both active
>> onion
>> keys. Alternatively, instead of block hashes, we can use some other time
>> based
>> beacon as a switch over point in order to accommodate peers on multiple
>> blockchains.
>>
>
> I like the loosely synched approach very much, but do we need explicit
> announcements at all? We could just use the announced key, i.e., the one
> that participated in the channel setup, as a root key for HD key
> derivation. The derivation path could then be based on floor(blockheight /
> 144) so that we rotate keys every day, and don't need any additional
> communication to announce new public keys. The switchover can be a bit
> messy, but we could just accept both old and new keys for a period around
> switchover and try both, or add the date in the packet, which would anyway
> be common to all packets on that day.
>
> A downside of using HD key derivation is that, should the root key be
> compromised then we cannot switch keys to new ones without a teardown, but
> in that case we'd be in a world of pain anyway since these keys allow
> spending the node's coins :-) Not adding the date allows us to switch keys
> quicker and each node could announce its own rotation period, to keep local
> storage low, but it adds some more computation as we determine the intended
> public key by trial and error.
>
>>
>> I'll take a few more passes through the current draft spec, as well are
>> your
>> commits in your fork of my original implementation, following up with any
>> other
>> questions/comments.
>>
>> I'm also trying to figure out how to enable intermediate nodes to reply
> to a packet, e.g., if capacities are insufficient or the next node is
> unreachable, by recycling the routing info. Currently we'd probably forward
> reply along the HTLC path associated with the forward path over the
> encrypted channel.
>
> So far I had no luck trying to build a return path into the header while
> forwarding. Maybe we could continue blinding the ephemeral key on the
> return path, and have a mechanism to tell the node the total blinding
> factor along the path so that it can encrypt something in the routing info
> for the return path? That would neatly combine Hornet and Sphinx,
> eliminating the initial roundtrip to setup forwarding segments.
>
> Thanks again for the detailed feedback, looking forward to read your
> thoughts on this :-)
>
> Cheers,
> Christian
>
> -- Laolu
>>
>>
>> On Mon, Jul 25, 2016 at 9:23 AM Christian Decker <
>> decker.christian at gmail.com> wrote:
>>
>>> Hi all,
>>>
>>> I took the liberty of taking apart Olaoluwa's Sphinx implementation and
>>> I came up with a spec draft that I'd like to propose [1]. It should roughly
>>> be Sphinx, pinning down the various key-generation and stream generation
>>> algorithms, and adding a per-hop payload.
>>>
>>> The per-hop payload is used to give instructions to individual hops,
>>> i.e., how many coins to forward to the next hop. This means that the
>>> end-to-end payload, i.e., the message in the Sphinx protocol, is currently
>>> unused and could be omitted.
>>>
>>> The payloads are currently fixed size (20 bytes per-hop and 1024 bytes
>>> for end-to-end payload) to avoid making messages collatable by their size.
>>> However, they could easily be made variable should we decide that
>>> sending mostly empty messages is wasteful.
>>>
>>> The spec is implemented in Go [2] and in C [3]. The Go version is an
>>> adaptation of Olaoluwa's implementation, with some minor speedups, removing
>>> some duplicate information, stripping the header, and switching to ChaCha20
>>> for stream generation and encryption. I also added a small commandline tool
>>> that allows you to write packets to stdout so that we can feed an onion
>>> generated by the C version to the Go implementation and vice-versa :-)
>>>
>>> Feedback is very welcome. If people like the draft I'll create
>>> pull-requests for the spec and the implementations, but I'd like to keep
>>> the discussion on the mailing list :-)
>>>
>>> Cheers,
>>> Christian
>>>
>>> [1]
>>> https://github.com/cdecker/lightning-rfc/blob/master/bolts/onion-protocol.md
>>> [2] https://github.com/cdecker/lightning-onion/tree/chacha20
>>> [3] https://github.com/cdecker/lightning/tree/chacha20
>>>
>> _______________________________________________
>>> Lightning-dev mailing list
>>> Lightning-dev at lists.linuxfoundation.org
>>> https://www.learnbitcoin.com/archive/lists/lightning-dev
>>>
>>
Olaoluwa Osuntokun in reply to Christian Decker permalink original
Quoted text (5 lines)
> I'm going back and forth about including the payloads in the header HMAC.
I
> think we have three options here:
>
> 1) Include the payload in the header HMAC computation

I'd say personally, I prefer the first option. This results in "fail fast" behavior w.r.t packet forwarding, and additionally adds the smallest overhead.

Quoted text (4 lines)
> we also lose the ability to do anonymous rendezvous meetings, where the
final
> recipient provides half of the route in the form of a precompiled header
> (something that Hornet is using).

It doesn't appear that we loose the ability to do rendezvous routing if we follow through with the first option. The final recipient can still provide a precompiled header which is the e2e payload sent from the source to the rendezvous node. As the source knows the exact nested mix-header when sending, it can still be protected under the mix-header wide MAC.

Additionally, in order to hide the next-hop after the rendezvous node from the source node, the destination can wrap the nested header in a layer of encryption, decryptable only by the rendezvous node.

Quoted text (7 lines)
> Both the per-hop checkable schemes, combined with nodes signing the
packets
> they forward, would give us the ability to identify misbehaving nodes and
> denounce them: if we receive a packet we check the integrity and if it
doesn't
> match then we can prove to others that the node forwarded something broken
> with its signature, or it did not check the packet itself.

Great observation. However, it seems like this is currently out of scope (the implications of "denouncing" a node") and should be re-visited at a future time when we brainstorm some sort of "reputation" scheme.

Quoted text (9 lines)
> There is a tradeoff between small packets and keeping the size uniform. I
think
> we could bucketize sizes, e.g., have multiples of 32 bytes or 64 bytes
for the
> fields, to have packets with similar sized payloads have the same packet
size.
> That would allow us to also drop the e2e payload by setting a size of 0,
and
> still be able to forward it, should we ever find a use for it.
Good point, we may have uses for non-uniform sizes as far as mix-headers in
the
future. So with this, then it appears there may be 3 types of mix-header
formats:
  1. Regular. Meaning no e2e payload, weighing in at 1234 bytes.
  2. Extended. Meaning bearing the e2e payload with a size of 2468 bytes.
  3. Rendezvous. Which nests another mix-header within the end-to-end
payload,
     with a size which is double that of the regular.

If we like this taxonomy, then we may want to reserve the first 2 version bytes within the draft. A version 0 packet would encompass processing the first two types, while a version 1 packet denotes that this is a rendezvous packet. The rendezvous case needs to be distinct as it modifies the processing/forwarding at the final hop.

Alternatively, we can use solely a version of 0 in the initial spec, with the final hop checking if the [1:34] bytes of the payload (if one is present) are a point on the curve. If so, this triggers the rendezvous forwarding, with the mid-point node processing the packet again as normal, completing the rendezvous route.

Quoted text (2 lines)
> We have to be careful when using timestamps in the packet as it makes
individual hops collatable.

Excellent observation. Assuming we roll out a reasonably efficient solution for the collatable HTLC R-values across hops, naively selecting timestamps would present another correlation vector.

Quoted text (7 lines)
> So my proposal would be to include a timestamp rounded up to the closest
hour
> and have a sliding window of accepted timestamps of +/- 1 hour,
remembering the
> secrets for that period and rejecting anything that is too far in the
future or
> too far in the past.

This seems reasonable, also the size of the sliding window can easily be tuned in the future should we find it too large or small.

Quoted text (3 lines)
> The more coarse the bigger the less likely an attacker is to guess which
> packets belong to the same route, but the more storage is required on the
> node's side.

Yep, there's a clear trade off between the window size of the accepted timestamps, and a node's storage overhead. We can tune this value to a ballpark estimate of the number of HTLCs/sec a large node with high frequency bi-directional throughput may forward at peak times.

Let's say a HFB (High-Frequency Bitcoin) node on the network at peak forwards 5k HTLC's per second: (5000/sec * 32 bytes) * 3600 sec = 576MB, if nodes are required to wait 1 hour between log prunings, and 288MB if we use a 30-minute interval. Even with such a high throughput value, that seems reasonable.

Quoted text (7 lines)
> We could just use the announced key, i.e., the one that participated in
the
> channel setup, as a root key for HD key derivation. The derivation path
could
> then be based on floor(blockheight / 144) so that we rotate keys every
day, and
> don't need any additional communication to announce new public keys.

Great suggestion! However, I think instead of directly using the key which participated in the channel setup, we'd use a new independent key as the root for this HD onion derivation. This new independent key would then be authenticated via a signature of a schnorr multi-sign of the channel multi-sig key and the node's identity key (or alternatively two sigs). This safeguards against the compromise of one of the derived private keys leading to compromise of the master root HD priv key which would allow possibly stealing a node's coins. Additionally, a node can switch keys more easily, avoiding a channel tear down.

However, the HD Onion Key approach can potentially cancel out the forward secrecy benefits. If an attacker gains access to the root HD pubkey, along with any of the child derived onion keys, then they can compute the root privkey. This allows the attacker to derive all the child priv keys, giving them the ability to decrypt all mix-headers encrypted since the HD Onion Key was published.

I think we can patch this exploit by adding some precomputation for each
node,
and introducing an intermediate onion derivation point. Assuming we rotate
every 144+ (1 day) blocks, then using the HD Onion PrivKey, each node
pre-generates 365 (or a smaller batch size) keys. Then, generates an
independent "onion derivation" key. The OD key then combined with each of
the
child onion keys, produces the final child onion key (C_i = final onion key,
B_i = intermediate child key, A = OD):
    * C_i = B_i + A

After the precomputation, the OD key (A) should be *destroyed*. If so, even if an attacker gains access to one of the intermediate child onion keys, they're unable to derive the final child onion key as the OD key has been destroyed. This safeguards the forward secrecy of the scheme in the face of the HD root+child exploit. As before, in the case of a root/child compromise the original node can simply authenticate a new HD Onion Key.

So perhaps we can combine the two approaches, publishing a blockhash (buried under a "safe" re-org depth), along with an authenticated HD root pubkey. With this new scheme we're able to push key rotation out to the edges in a non-interactive manner. Having the blockhash as an anchor will reduce the amount of guessing required by a node to fetch the correct onion key.

Quoted text (5 lines)
> I'm also trying to figure out how to enable intermediate nodes to reply
to a
> packet, e.g., if capacities are insufficient or the next node is
unreachable,
> by recycling the routing info.

Yeah I've also attempted to tackle this issue a bit myself. The inclusion of onion routing certainly makes certain classes of failures harder to reconcile. There has been a bit of discussion of this in the past, at the time called "unrolling the onion". In a similar vein it's also more difficult to ascribe blame node's which directly cause a payment to fail.

One of my naive ideas was to include a "backwards" mix-header within each node's per-hop payload (though I hadn't included the per-hop payload in my mental model at the time), however this would result in a quadratic blow up space complexity parametrized by our max-hop limit. Essentially, we'd include a SURB within the mix-header for each hop in the route.

Quoted text (8 lines)
> Maybe we could continue blinding the ephemeral key on the return path, and
> have a mechanism to tell the node the total blinding factor along the
path so
> that it can encrypt something in the routing info for the return path?
That
> would neatly combine Hornet and Sphinx, eliminating the initial roundtrip
to
> setup forwarding segments.

Could you elaborate on this a bit more? It seems that this alone is insufficient to allow "backwards" replies to the source w/o revealing the source's identity.

It seems the primary question is: how can we re-use the information present at a hop, post-processing to reply to the sender without an additional round trip? If we can solve this, then we can greatly increase the robustness of onion routing within the network. I think they may be worth spinning some cycles on, although I don't consider it blocking w.r.t the initial specification.

-- Laolu

Olaoluwa Osuntokun in reply to Rusty Russell permalink original
Quoted text (3 lines)
> Hmm, I think we should combine the "header" and "per-hop payload" into a
> single 40 byte field.  They're not meaningfully distinct for lightning,
> AFAICT.

It's not clear to me what we gain by squashing the header (hop's ephemeral key, MAC, next hop) and the per-hop payload (amount to forward, possibly an allowed CLTV range, etc) into a single blob. I think the extensibility features are the same regardless.

Quoted text (2 lines)
> And I think we should add/steal at least one byte for "realm".  0 =
> terminal.  1 = bitcoin lightning.  2 = TBA. etc.

What does "terminal" represent in this context?

I don't think we need an equivalent of Bitcoin's "net magic" bytes within the onion blob itself, as I'd imagine that the onion blob would be encapsulated within a fixed-length field within the "htlcAdd" message. The "htlcAdd" message would then have a header similar to Bitcoin's, in which the "net magic" bytes would be placed.

Quoted text (6 lines)
> We can't simply deny multiple HTLCs with the same r hash, since that
allows an
> attacker to probe the network to see where an HTLC went (note that in the
> longer run, it's in a node's short-term economic interest to allow this,
which
> is why rhash is troubling).

We wouldn't deny multiple HTLC's with the same r hash. We'd deny a packet with a shared secret we've already seen, meaning one that we've processed before. A node could still forward multiple HTLC's with identical r-hashes (perhaps due to having to fragment a payment due to insufficient link-capacity), these HTLC's would have distinct (indistinguishable) onion packets.

(as a side note: I think we should establish some better terminology than r-hash, or H)

Quoted text (4 lines)
> If we switch from hash/preimage to the privkeys with point addition scheme
> (which has other benefits) this is no longer an issue and we can simply
refuse
> to accept two HTLCs with the same pubkey.

The point addition derivation (P2CH style) scheme only applies to revocations. It's not clear to me how one can switch to priv/pub key based HTLC's without modifying Bitcoin Script. At the moment, we're unable to guarantee/force key disclosure with Script's current capabilities.

-- Laolu

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (11 lines)
>> Hmm, I think we should combine the "header" and "per-hop payload" into a
>> single 40 byte field.  They're not meaningfully distinct for lightning,
>> AFAICT.
>
> It's not clear to me what we gain by squashing the header (hop's ephemeral
> key,
> MAC, next hop) and the per-hop payload (amount to forward, possibly an
> allowed
> CLTV range, etc) into a single blob. I think the extensibility features are
> the
> same regardless.

Ephemeral key and mac make sense as a header, but it's fairly easy to image a different next hop address format for different networks. See also "realm byte" below.

Thus I'm suggesting a format like:

  [ephemeral key] [mac] [realm] [per-realm-information]

Per-realm-information is next-hop, amount, etc.

Quoted text (4 lines)
>> And I think we should add/steal at least one byte for "realm".  0 =
>> terminal.  1 = bitcoin lightning.  2 = TBA. etc.
>
> What does "terminal" represent in this context?

You're right; "Terminus" aka "you're the final hop", rather than using magic HMAC value.

Quoted text (8 lines)
> I don't think we need an equivalent of Bitcoin's "net magic" bytes within
> the
> onion blob itself, as I'd imagine that the onion blob would be encapsulated
> within a fixed-length field within the "htlcAdd" message. The "htlcAdd"
> message
> would then have a header similar to Bitcoin's, in which the "net magic"
> bytes
> would be placed.

An explicit network byte makes sense since we could eventually have multiple networks (atomic cross-chain exchange). While node keys are network globally unique (thus the exchange is *implied* by the next hop), it's nice to be explicit.

We need some flag for the terminal node anyway, so it makes sense IMHO to expand it.

Quoted text (11 lines)
>> We can't simply deny multiple HTLCs with the same r hash, since that
> allows an
>> attacker to probe the network to see where an HTLC went (note that in the
>> longer run, it's in a node's short-term economic interest to allow this,
> which
>> is why rhash is troubling).
>
> We wouldn't deny multiple HTLC's with the same r hash. We'd deny a packet
> with
> a shared secret we've already seen, meaning one that we've processed
> before.

Sorry, I was unclear: We're agreeing. I was clarifying why an alternative approach to replay avoidance (using r hash uniqueness) doesn't work.

Quoted text (2 lines)
> (as a side note: I think we should establish some better terminology than
> r-hash, or H)

Ergh, yes!

Strawman proposal:
1) HTLC-hash and HTLC-preimage? (aha H-hash & H-preimage).
2) committx-hash and committx-preimage (C-hash / C-preimage) for the
   commitment transaction revocation?

That avoids R altogether, which is overloaded...

Quoted text (11 lines)
>> If we switch from hash/preimage to the privkeys with point addition scheme
>> (which has other benefits) this is no longer an issue and we can simply
> refuse
>> to accept two HTLCs with the same pubkey.
>
> The point addition derivation (P2CH style) scheme only applies to
> revocations.
>
> It's not clear to me how one can switch to priv/pub key based HTLC's without
> modifying Bitcoin Script. At the moment, we're unable to guarantee/force key
> disclosure with Script's current capabilities.

Yeah, it was easy to miss; it's buried deep in a thread (see the "alternative approach"):

        https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/better-privacy-with-snarks#m-b54ec279

Basically, you force r-value reuse in signatures to reveal the private key. The script to do this would be pretty big though, involving two other keys, three signatures and three OP_CHECKMULTISIG.

And AFAIK nobody has actually written such a script...

Cheers, Rusty.

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (9 lines)
>> I'm going back and forth about including the payloads in the header HMAC.
> I
>> think we have three options here:
>>
>> 1) Include the payload in the header HMAC computation
>
> I'd say personally, I prefer the first option. This results in "fail fast"
> behavior w.r.t packet forwarding, and additionally adds the smallest
> overhead.

Agreed. I worry about forwarding corrupted packets leading to the ability for malicious nodes to probe routes.

Quoted text (17 lines)
>> we also lose the ability to do anonymous rendezvous meetings, where the
> final
>> recipient provides half of the route in the form of a precompiled header
>> (something that Hornet is using).
>
> It doesn't appear that we loose the ability to do rendezvous routing if we
> follow through with the first option. The final recipient can still provide
> a
> precompiled header which is the e2e payload sent from the source to the
> rendezvous node. As the source knows the exact nested mix-header when
> sending,
> it can still be protected under the mix-header wide MAC.
>
> Additionally, in order to hide the next-hop after the rendezvous node from
> the
> source node, the destination can wrap the nested header in a layer of
> encryption, decryptable only by the rendezvous node.

In practice, you can do this one level up: simply agree with a rendevous node that a given H-hash is to be fwded to you. Then direct the payer to the rendevous node.

So I don't think it's worth any complexity in the routing protocol.

Quoted text (25 lines)
>> There is a tradeoff between small packets and keeping the size uniform. I
> think
>> we could bucketize sizes, e.g., have multiples of 32 bytes or 64 bytes
> for the
>> fields, to have packets with similar sized payloads have the same packet
> size.
>> That would allow us to also drop the e2e payload by setting a size of 0,
> and
>> still be able to forward it, should we ever find a use for it.
>
> Good point, we may have uses for non-uniform sizes as far as mix-headers in
> the
> future. So with this, then it appears there may be 3 types of mix-header
> formats:
>   1. Regular. Meaning no e2e payload, weighing in at 1234 bytes.
>   2. Extended. Meaning bearing the e2e payload with a size of 2468 bytes.
>   3. Rendezvous. Which nests another mix-header within the end-to-end
> payload,
>      with a size which is double that of the regular.
>
> If we like this taxonomy, then we may want to reserve the first 2 version
> bytes
> within the draft. A version 0 packet would encompass processing the first
> two
> types, while a version 1 packet denotes that this is a rendezvous packet.

Keep it simple; let's just support regular for now. Nodes will have to broadcast what extensions they support, and this can be used for extended formats later. Including ones we *didn't* think of yet...

Quoted text (36 lines)
>> We have to be careful when using timestamps in the packet as it makes
> individual hops collatable.
>
> Excellent observation. Assuming we roll out a reasonably efficient solution
> for
> the collatable HTLC R-values across hops, naively selecting timestamps would
> present another correlation vector.
>
>> So my proposal would be to include a timestamp rounded up to the closest
> hour
>> and have a sliding window of accepted timestamps of +/- 1 hour,
> remembering the
>> secrets for that period and rejecting anything that is too far in the
> future or
>> too far in the past.
>
> This seems reasonable, also the size of the sliding window can easily be
> tuned
> in the future should we find it too large or small.
>
>> The more coarse the bigger the less likely an attacker is to guess which
>> packets belong to the same route, but the more storage is required on the
>> node's side.
>
> Yep, there's a clear trade off between the window size of the accepted
> timestamps, and a node's storage overhead. We can tune this value to a
> ballpark
> estimate of the number of HTLCs/sec a large node with high frequency
> bi-directional throughput may forward at peak times.
>
> Let's say a HFB (High-Frequency Bitcoin) node on the network at peak
> forwards
> 5k HTLC's per second: (5000/sec * 32 bytes) * 3600 sec = 576MB, if nodes are
> required to wait 1 hour between log prunings, and 288MB if we use a
> 30-minute
> interval. Even with such a high throughput value, that seems reasonable.

I think we're over-designing. How about: daily key rotation (which we want anywat), remember all onions for current and previous key.

Remember: if we switch from C-hash to C-point, then it's simpler: we only need to guard against retransmissions for *unresolved* htlcs. If someone retransmits an HTLC for which we already know the C-point value, they risk us redeeming it immediately and not forwarding at all.

(We need to remember all previous HTLCs anyway, so off the top of my head checking this is not too hard...).

Quoted text (28 lines)
>> We could just use the announced key, i.e., the one that participated in
> the
>> channel setup, as a root key for HD key derivation. The derivation path
> could
>> then be based on floor(blockheight / 144) so that we rotate keys every
> day, and
>> don't need any additional communication to announce new public keys.
>
> Great suggestion! However, I think instead of directly using the key which
> participated in the channel setup, we'd use a new independent key as the
> root
> for this HD onion derivation. This new independent key would then be
> authenticated via a signature of a schnorr multi-sign of the channel
> multi-sig
> key and the node's identity key (or alternatively two sigs). This safeguards
> against the compromise of one of the derived private keys leading to
> compromise
> of the master root HD priv key which would allow possibly stealing a node's
> coins. Additionally, a node can switch keys more easily, avoiding a channel
> tear down.
>
> However, the HD Onion Key approach can potentially cancel out the forward
> secrecy benefits. If an attacker gains access to the root HD pubkey, along
> with
> any of the child derived onion keys, then they can compute the root privkey.
> This allows the attacker to derive all the child priv keys, giving them the
> ability to decrypt all mix-headers encrypted since the HD Onion Key was
> published.

Broadcasting new node keys (up to?) once a day is probably fine. Perhaps include a validity time range with each key, so you can spot if you're missing one. Recommend allowing 12 hours overlap or something.

It'd be great to avoid it, but that seems complex enough to push to a future spec.

To summarize the keys for each node:

1. channel key: bitcoin key used to sign commitment txs.  One per channel.
2. id key: used to tie channels together ("I own these channels").  Signed
   by channel keys (or could use OP_RETURN, but that's a bit spammy), and
   signs channel keys.
3. comms key: rotated key for onion messages.  Signed by id key.
4. (various ephemeral keys for inter-node comms).

id and comms keys don't have to be bitcoin keys; could be Schnorr. But not much point AFIACT: the big win is making the channel keys (ie. bitcoin) use Schnorr so they can all compactly sign the id key.

Quoted text (9 lines)
>> I'm also trying to figure out how to enable intermediate nodes to reply
> to a
>> packet, e.g., if capacities are insufficient or the next node is
> unreachable,
>> by recycling the routing info.
>
> Yeah I've also attempted to tackle this issue a bit myself. The inclusion of
> onion routing certainly makes certain classes of failures harder to
> reconcile.

Yeah, this one's troubling. In particular, it'd be nice to prove that a node is misbehaving:

(1) When a node gives a fail message, we want to be able to publish it
    to prove (eg) it's lying about its fees.  That means that the
    failure msg needs to be tied to the request so both can be
    published.
(2) If a node corrupts a fail message on return, we want to prove that.
Caveats:
1.  We don't want to expose the source of fail message (ie. leak
    the route).
2.  Ideally the proof can be published in a way which minimizes data
    exposure for the originator.
Quoted text (4 lines)
> If we can solve this, then we can greatly increase the robustness of onion
> routing within the network. I think they may be worth spinning some cycles
> on,
> although I don't consider it blocking w.r.t the initial specification.

I look forward to what you come up with!

Yay! Rusty.

Christian Decker in reply to Olaoluwa Osuntokun permalink original

On Thu, Aug 4, 2016 at 8:24 PM Olaoluwa Osuntokun <laolu32 at gmail.com> wrote:

Quoted text (28 lines)
> > I'm going back and forth about including the payloads in the header
> HMAC. I
> > think we have three options here:
> >
> > 1) Include the payload in the header HMAC computation
>
> I'd say personally, I prefer the first option. This results in "fail fast"
> behavior w.r.t packet forwarding, and additionally adds the smallest
> overhead.
>
> > we also lose the ability to do anonymous rendezvous meetings, where the
> final
> > recipient provides half of the route in the form of a precompiled header
> > (something that Hornet is using).
>
> It doesn't appear that we loose the ability to do rendezvous routing if we
> follow through with the first option. The final recipient can still
> provide a
> precompiled header which is the e2e payload sent from the source to the
> rendezvous node. As the source knows the exact nested mix-header when
> sending,
> it can still be protected under the mix-header wide MAC.
>
> Additionally, in order to hide the next-hop after the rendezvous node from
> the
> source node, the destination can wrap the nested header in a layer of
> encryption, decryptable only by the rendezvous node.
>

Sounds good, however I'm not clear on how the final recipient can provide a precompiled valid header with the HMACs that include the per-hop payloads and the end-to-end payload without knowing them upfront.

Quoted text (16 lines)
>
> > Both the per-hop checkable schemes, combined with nodes signing the
> packets
> > they forward, would give us the ability to identify misbehaving nodes and
> > denounce them: if we receive a packet we check the integrity and if it
> doesn't
> > match then we can prove to others that the node forwarded something
> broken
> > with its signature, or it did not check the packet itself.
>
> Great observation. However, it seems like this is currently out of scope
> (the
> implications of "denouncing" a node") and should be re-visited at a future
> time
> when we brainstorm some sort of "reputation" scheme.
>

Happy to shelve the idea for now, I'll add it to my future-topics list :-)

Quoted text (41 lines)
>
> > There is a tradeoff between small packets and keeping the size uniform.
> I think
> > we could bucketize sizes, e.g., have multiples of 32 bytes or 64 bytes
> for the
> > fields, to have packets with similar sized payloads have the same packet
> size.
> > That would allow us to also drop the e2e payload by setting a size of 0,
> and
> > still be able to forward it, should we ever find a use for it.
>
> Good point, we may have uses for non-uniform sizes as far as mix-headers
> in the
> future. So with this, then it appears there may be 3 types of mix-header
> formats:
>   1. Regular. Meaning no e2e payload, weighing in at 1234 bytes.
>   2. Extended. Meaning bearing the e2e payload with a size of 2468 bytes.
>   3. Rendezvous. Which nests another mix-header within the end-to-end
> payload,
>      with a size which is double that of the regular.
>
> If we like this taxonomy, then we may want to reserve the first 2 version
> bytes
> within the draft. A version 0 packet would encompass processing the first
> two
> types, while a version 1 packet denotes that this is a rendezvous packet.
> The
> rendezvous case needs to be distinct as it modifies the
> processing/forwarding
> at the final hop.
>
> Alternatively, we can use solely a version of 0 in the initial spec, with
> the
> final hop checking if the [1:34] bytes of the payload (if one is present)
> are a
> point on the curve.  If so, this triggers the rendezvous forwarding, with
> the
> mid-point node processing the packet again as normal, completing the
> rendezvous
> route.
>

Enumerating types of packets sounds like a good tradeoff between flexibility and packet size. However size and semantics are orthogonal and keeping them separate might be a cleaner choice.

I'd prefer having a rendezvous scheme that merges the two ends of the route in a seamless way, which should not be too hard to do, unless we keep the per-hop checkable HMACs.

Quoted text (40 lines)
>
> > We have to be careful when using timestamps in the packet as it makes
> individual hops collatable.
>
> Excellent observation. Assuming we roll out a reasonably efficient
> solution for
> the collatable HTLC R-values across hops, naively selecting timestamps
> would
> present another correlation vector.
>
> > So my proposal would be to include a timestamp rounded up to the closest
> hour
> > and have a sliding window of accepted timestamps of +/- 1 hour,
> remembering the
> > secrets for that period and rejecting anything that is too far in the
> future or
> > too far in the past.
>
> This seems reasonable, also the size of the sliding window can easily be
> tuned
> in the future should we find it too large or small.
>
> > The more coarse the bigger the less likely an attacker is to guess which
> > packets belong to the same route, but the more storage is required on the
> > node's side.
>
> Yep, there's a clear trade off between the window size of the accepted
> timestamps, and a node's storage overhead. We can tune this value to a
> ballpark
> estimate of the number of HTLCs/sec a large node with high frequency
> bi-directional throughput may forward at peak times.
>
> Let's say a HFB (High-Frequency Bitcoin) node on the network at peak
> forwards
> 5k HTLC's per second: (5000/sec * 32 bytes) * 3600 sec = 576MB, if nodes
> are
> required to wait 1 hour between log prunings, and 288MB if we use a
> 30-minute
> interval. Even with such a high throughput value, that seems reasonable.
>

Do we need both a timestamped backlog of secrets and key-rotation? If we get the key rotation quick enough it's probably sufficient to simply keep all secrets for the current key, especially if we use bloom-filters to store the seen secrets.

Quoted text (61 lines)
> > We could just use the announced key, i.e., the one that participated in
> the
> > channel setup, as a root key for HD key derivation. The derivation path
> could
> > then be based on floor(blockheight / 144) so that we rotate keys every
> day, and
> > don't need any additional communication to announce new public keys.
>
> Great suggestion! However, I think instead of directly using the key which
> participated in the channel setup, we'd use a new independent key as the
> root
> for this HD onion derivation. This new independent key would then be
> authenticated via a signature of a schnorr multi-sign of the channel
> multi-sig
> key and the node's identity key (or alternatively two sigs). This
> safeguards
> against the compromise of one of the derived private keys leading to
> compromise
> of the master root HD priv key which would allow possibly stealing a node's
> coins. Additionally, a node can switch keys more easily, avoiding a channel
> tear down.
>
> However, the HD Onion Key approach can potentially cancel out the forward
> secrecy benefits. If an attacker gains access to the root HD pubkey, along
> with
> any of the child derived onion keys, then they can compute the root
> privkey.
> This allows the attacker to derive all the child priv keys, giving them the
> ability to decrypt all mix-headers encrypted since the HD Onion Key was
> published.
>
> I think we can patch this exploit by adding some precomputation for each
> node,
> and introducing an intermediate onion derivation point. Assuming we rotate
> every 144+ (1 day) blocks, then using the HD Onion PrivKey, each node
> pre-generates 365 (or a smaller batch size) keys. Then, generates an
> independent "onion derivation" key. The OD key then combined with each of
> the
> child onion keys, produces the final child onion key (C_i = final onion
> key,
> B_i = intermediate child key, A = OD):
>     * C_i = B_i + A
>
> After the precomputation, the OD key (A) should be *destroyed*. If so,
> even if
> an attacker gains access to one of the intermediate child onion keys,
> they're
> unable to derive the final child onion key as the OD key has been
> destroyed.
> This safeguards the forward secrecy of the scheme in the face of the HD
> root+child exploit. As before, in the case of a root/child compromise the
> original node can simply authenticate a new HD Onion Key.
>
> So perhaps we can combine the two approaches, publishing a blockhash
> (buried
> under a "safe" re-org depth), along with an authenticated HD root pubkey.
> With
> this new scheme we're able to push key rotation out to the edges in a
> non-interactive manner. Having the blockhash as an anchor will reduce the
> amount of guessing required by a node to fetch the correct onion key.
>

That's a great idea, I hadn't thought about forward secrecy. I like the non-interactive nature of the scheme, since we'll be communicating enough, even without every node broadcasting new keys upon switch. Potentially there is also a way to define your own key-rotation period with the channel establishment announcement so that low-memory devices can switch at a higher rate, trading memory savings for slightly higher fail rates.

Quoted text (45 lines)
>
> > I'm also trying to figure out how to enable intermediate nodes to reply
> to a
> > packet, e.g., if capacities are insufficient or the next node is
> unreachable,
> > by recycling the routing info.
>
> Yeah I've also attempted to tackle this issue a bit myself. The inclusion
> of
> onion routing certainly makes certain classes of failures harder to
> reconcile.
> There has been a bit of discussion of this in the past, at the time called
> "unrolling the onion". In a similar vein it's also more difficult to
> ascribe blame node's which directly cause a payment to fail.
>
> One of my naive ideas was to include a "backwards" mix-header within each
> node's per-hop payload (though I hadn't included the per-hop payload in my
> mental model at the time), however this would result in a quadratic blow up
> space complexity parametrized by our max-hop limit. Essentially, we'd
> include
> a SURB within the mix-header for each hop in the route.
>
> > Maybe we could continue blinding the ephemeral key on the return path,
> and
> > have a mechanism to tell the node the total blinding factor along the
> path so
> > that it can encrypt something in the routing info for the return path?
> That
> > would neatly combine Hornet and Sphinx, eliminating the initial
> roundtrip to
> > setup forwarding segments.
>
> Could you elaborate on this a bit more? It seems that this alone is
> insufficient to allow "backwards" replies to the source w/o revealing the
> source's identity.
>
> It seems the primary question is: how can we re-use the information
> present at
> a hop, post-processing to reply to the sender without an additional round
> trip?
> If we can solve this, then we can greatly increase the robustness of onion
> routing within the network. I think they may be worth spinning some cycles
> on,
> although I don't consider it blocking w.r.t the initial specification.
>

I don't think this is a high priority issue for the routing spec since we have to keep the HTLC information around anyway. I was thinking along sending a factor along with the header that'd tell each hop that the next time they see this packet it'll have the current ephemeral key blinded by this factor. The hop could then compute its shared secret and write routing info into its position in the header before rotating it to the back. The factor would then be divided by the blinding factor applied to the ephemeral key before forwarding it to the next hop. On the return path the ephemeral key is what we precomputed and we can decrypt the info we stored in the header before.

So far all my attempts either did not work or were leaking too much information about shared secrets or blinding factors. But then again I'm stuck at Crypto 101 :-)

Cheers, Christian

Quoted text (4 lines)
>
> -- Laolu
>
>
Olaoluwa Osuntokun in reply to Rusty Russell permalink original

Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (9 lines)
> Ephemeral key and mac make sense as a header, but it's fairly easy
> to image a different next hop address format for different networks.
> See also "realm byte" below.
>
> Thus I'm suggesting a format like:
>
>  [ephemeral key] [mac] [realm] [per-realm-information]
>
>  Per-realm-information is next-hop, amount, etc.

In order to maintain the security properties of the onion blob, each onion blob is required to be the exact same length. Therefore, the amount of bytes allocated for the "next-hop" address needs to be uniform. In my mind, the next-hop" field should just be an opaque blob (at the specification level) with no further explicit meaning. Nodes residing on various chains will parse the address accordingly (they might be using a different curve, etc).

With this said, I fail to see what we gain by making the current chain-boundary explicit (within the onion blob's mix-header).

Quoted text (9 lines)
> An explicit network byte makes sense since we could eventually have
multiple
> networks (atomic cross-chain exchange).  While node keys are network
globally
> unique (thus the exchange is *implied* by the next hop), it's nice to be
> explicit.
>
> We need some flag for the terminal node anyway, so it makes sense IMHO
> to expand it.

Sure, but the explicit network byte should be within the main p2p message header rather than the header for the onion blob itself. When crossing chains, nodes will properly set the net magic in the outer message header.

Also we don't need to allocate an additional byte for the terminal node in any case. The terminal node can either be identified by the null-MAC, or null-nexthop (if that isn't being used to dispatch into virtual channels).

Quoted text (6 lines)
> Strawman proposal:
> 1) HTLC-hash and HTLC-preimage? (aha H-hash & H-preimage).
> 2) committx-hash and committx-preimage (C-hash / C-preimage) for the
>   commitment transaction revocation?
>
> That avoids R altogether, which is overloaded...

Sounds good to me!

-- Laolu

Olaoluwa Osuntokun in reply to Christian Decker permalink original

Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (5 lines)
> In practice, you can do this one level up: simply agree with a rendevous
> node that a given H-hash is to be fwded to you.  Then direct the payer
> to the rendevous node.
>
> So I don't think it's worth any complexity in the routing protocol.

Nevermind, I forgot that the nested header (assuming its the e2e payload) would be wrapped in layers on onion encryption. So the hop *after* the rendevous node is hidden from pre-rendevous node anyway :)

Quoted text (3 lines)
> Keep it simple; let's just support regular for now.  Nodes will have to
> broadcast what extensions they support, and this can be used for
> extended formats later.  Including ones we *didn't* think of yet...

Sure. Additionally, as Christian pointed out further down in the thread, ideally we shoud aim to seamlessly integrate rendevous routing. If possible, we should keep all onion packets indistinguishable from each other.

Quoted text (2 lines)
> I think we're over-designing.  How about: daily key rotation (which we
> want anywat), remember all onions for current and previous key.

Yeah only daily key rotation should be sufficient. It seems that we need either timestamps, or key rotation, not both.

Quoted text (2 lines)
> It'd be great to avoid it, but that seems complex enough to push to a
> future spec.

Agreed. When I first brought up key rotation eariler in the thread, I noted it might be better if it were deferred to a future spec. Nevertheless, the I've found the resulting discussion very valuable.

Quoted text (1 line)
> id and comms keys don't have to be bitcoin keys; could be Schnorr.

The EC Schnorr construction would likely use Bitcoin's curve, so there's no meaningful distinction there. We're currently constrainted to ECDSA within Bitcoin, but can freely use EC Schnorr within the network if the space savings are desirable (as you pointed out).

Christian Decker <decker.christian at gmail.com> writes:

Quoted text (9 lines)
> Sounds good, however I'm not clear on how the final recipient can provide
a
> precompiled valid header with the HMACs that include the per-hop payloads
> and the end-to-end payload without knowing them upfront.
>
> I'd prefer having a rendezvous scheme that merges the two ends of the
route
> in a seamless way, which should not be too hard to do, unless we keep the
> per-hop checkable HMACs.

Ahh, I see what you mean now. You're correct, it seems that we may be forced to drop the per-hop HMAC in order to enable seamless rendevous routing.

Quoted text (4 lines)
> Do we need both a timestamped backlog of secrets and key-rotation? If we
> get the key rotation quick enough it's probably sufficient to simply keep
> all secrets for the current key, especially if we use bloom-filters to
> store the seen secrets.

Yeah, it seems that key rotation alone is much simpler than the timestamped log of secrets. So the key rotation alone should suffice.

-- Laolu

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (19 lines)
> Rusty Russell <rusty at rustcorp.com.au> wrote:
>> Ephemeral key and mac make sense as a header, but it's fairly easy
>> to image a different next hop address format for different networks.
>> See also "realm byte" below.
>>
>> Thus I'm suggesting a format like:
>>
>>  [ephemeral key] [mac] [realm] [per-realm-information]
>>
>>  Per-realm-information is next-hop, amount, etc.
>
> In order to maintain the security properties of the onion blob, each onion
> blob
> is required to be the exact same length. Therefore, the amount of bytes
> allocated for the "next-hop" address needs to be uniform. In my mind, the
> next-hop" field should just be an opaque blob (at the specification level)
> with
> no further explicit meaning. Nodes residing on various chains will parse the
> address accordingly (they might be using a different curve, etc).

Kind of. We need some identifier to know, as nodes may straddle chains.

Quoted text (18 lines)
> With this said, I fail to see what we gain by making the current
> chain-boundary
> explicit (within the onion blob's mix-header).
>
>> An explicit network byte makes sense since we could eventually have
> multiple
>> networks (atomic cross-chain exchange).  While node keys are network
> globally
>> unique (thus the exchange is *implied* by the next hop), it's nice to be
>> explicit.
>>
>> We need some flag for the terminal node anyway, so it makes sense IMHO
>> to expand it.
>
> Sure, but the explicit network byte should be within the main p2p message
> header rather than the header for the onion blob itself. When crossing
> chains,
> nodes will properly set the net magic in the outer message header.

Some node will have to straddle two chains, right? So you'd route A -> B -> C as normal, and C is (say) litecoin (B straddles both). You really want the onion to be explicit that this transfer to litecoin is what the sender intended. Or some sidechain.

Now, we'd hope nobody would screw this up, but I think it's worth flagging since the sender really should know it's changing chains.

Quoted text (4 lines)
> Also we don't need to allocate an additional byte for the terminal node in
> any
> case. The terminal node can either be identified by the null-MAC, or
> null-nexthop (if that isn't being used to dispatch into virtual channels).

That implies there's a final hop in the packet which is unused? I believe strongly we want a realm byte, so I think it makes more sense to overload it for this.

Quoted text (8 lines)
>> Strawman proposal:
>> 1) HTLC-hash and HTLC-preimage? (aha H-hash & H-preimage).
>> 2) committx-hash and committx-preimage (C-hash / C-preimage) for the
>>   commitment transaction revocation?
>>
>> That avoids R altogether, which is overloaded...
>
> Sounds good to me!

I shall try to use those consistently from now on!

Thanks, Rusty.

Christian Decker in reply to Rusty Russell permalink original

On Sat, Aug 13, 2016 at 07:34:02PM +0930, Rusty Russell wrote:

Quoted text (49 lines)
> Olaoluwa Osuntokun <laolu32 at gmail.com> writes:
> > Rusty Russell <rusty at rustcorp.com.au> wrote:
> >> Ephemeral key and mac make sense as a header, but it's fairly easy
> >> to image a different next hop address format for different networks.
> >> See also "realm byte" below.
> >>
> >> Thus I'm suggesting a format like:
> >>
> >>  [ephemeral key] [mac] [realm] [per-realm-information]
> >>
> >>  Per-realm-information is next-hop, amount, etc.
> >
> > In order to maintain the security properties of the onion blob, each onion
> > blob
> > is required to be the exact same length. Therefore, the amount of bytes
> > allocated for the "next-hop" address needs to be uniform. In my mind, the
> > next-hop" field should just be an opaque blob (at the specification level)
> > with
> > no further explicit meaning. Nodes residing on various chains will parse the
> > address accordingly (they might be using a different curve, etc).
>
> Kind of.  We need some identifier to know, as nodes may straddle chains.
>
> > With this said, I fail to see what we gain by making the current
> > chain-boundary
> > explicit (within the onion blob's mix-header).
> >
> >> An explicit network byte makes sense since we could eventually have
> > multiple
> >> networks (atomic cross-chain exchange).  While node keys are network
> > globally
> >> unique (thus the exchange is *implied* by the next hop), it's nice to be
> >> explicit.
> >>
> >> We need some flag for the terminal node anyway, so it makes sense IMHO
> >> to expand it.
> >
> > Sure, but the explicit network byte should be within the main p2p message
> > header rather than the header for the onion blob itself. When crossing
> > chains,
> > nodes will properly set the net magic in the outer message header.
>
> Some node will have to straddle two chains, right?  So you'd route A ->
> B -> C as normal, and C is (say) litecoin (B straddles both).  You
> really want the onion to be explicit that this transfer to litecoin is
> what the sender intended.  Or some sidechain.
>
> Now, we'd hope nobody would screw this up, but I think it's worth
> flagging since the sender really should know it's changing chains.

I agree that the realm byte is a sensible addition. To trigger this we would need to have multiple channels, on different chains, using the same identifiers between two nodes. Only in this case we'd have an ambiguity where to transfer the funds. Assuming we have the route A -> B => C, where => indicates two channels, one in litecoin and one in bitcoin, and both channels use the same identity for C. Then the instruction to forward 0.01 units to C is ambiguous, as it could be denominated in either litecoin or bitcoin.

While not dangerous it is rather unfortunate as it results in guesswork. It is not dangerous because if A transferred litecoin to B then B will (hopefully) never forward a higher value to C using bitcoin, and if it were bitcoin then the final recipient would not sign off an inferior amount than what he expected.

To prevent this we could make it a policy to never re-use identities for multiple channels, but someone will surely get it wrong at some point :-)

I was thinking that it'd be stored in the per-hop payload, along with the instructions for the hop, which is why I did not specify it, but I'm happy to add it, should it make things clearer.

Quoted text (9 lines)
>
> > Also we don't need to allocate an additional byte for the terminal node in
> > any
> > case. The terminal node can either be identified by the null-MAC, or
> > null-nexthop (if that isn't being used to dispatch into virtual channels).
>
> That implies there's a final hop in the packet which is unused?  I
> believe strongly we want a realm byte, so I think it makes more sense to
> overload it for this.

Indeed the last hop's routing information is all zeroes and the per-hop payload is currently unused (as the node does not forward anything). If we use the terminal identifier we can shave the 40 bytes routing info off the packet, provided the node checks the terminal byte in the per-hop payload before attempting anything with the routing info which'd be garbage, i.e., encrypted fillers by the first hop.

Cheers, Christian

Christian Decker in reply to Olaoluwa Osuntokun permalink original

On Fri, Aug 12, 2016 at 06:00:34PM +0000, Olaoluwa Osuntokun wrote:

Quoted text (40 lines)
> Rusty Russell <rusty at rustcorp.com.au> wrote:
> > In practice, you can do this one level up: simply agree with a rendevous
> > node that a given H-hash is to be fwded to you.  Then direct the payer
> > to the rendevous node.
> >
> > So I don't think it's worth any complexity in the routing protocol.
>
> Nevermind, I forgot that the nested header (assuming its the e2e payload)
> would be wrapped in layers on onion encryption. So the hop *after* the
> rendevous node is hidden from pre-rendevous node anyway :)
>
> > Keep it simple; let's just support regular for now.  Nodes will have to
> > broadcast what extensions they support, and this can be used for
> > extended formats later.  Including ones we *didn't* think of yet...
>
> Sure. Additionally, as Christian pointed out further down in the thread,
> ideally we shoud aim to seamlessly integrate rendevous routing. If possible,
> we should keep all onion packets indistinguishable from each other.
>
> > I think we're over-designing.  How about: daily key rotation (which we
> > want anywat), remember all onions for current and previous key.
>
> Yeah only daily key rotation should be sufficient. It seems that we need
> either timestamps, or key rotation, not both.
>
> > It'd be great to avoid it, but that seems complex enough to push to a
> > future spec.
>
> Agreed. When I first brought up key rotation eariler in the thread, I noted
> it
> might be better if it were deferred to a future spec. Nevertheless, the
> I've found the resulting discussion very valuable.
>
> > id and comms keys don't have to be bitcoin keys; could be Schnorr.
>
> The EC Schnorr construction would likely use Bitcoin's curve, so there's no
> meaningful distinction there. We're currently constrainted to ECDSA within
> Bitcoin, but can freely use EC Schnorr within the network if the space
> savings
> are desirable (as you pointed out).

IDs only have to make sense to the receiving node, so the node may actually broadcast a short identifier with the channel announcement that uniquely identifies the channel to it (index, establishment timestamp, ...). So it could be aything besides the globally unique EC pubkey.

Quoted text (16 lines)
>
>
> Christian Decker <decker.christian at gmail.com> writes:
> > Sounds good, however I'm not clear on how the final recipient can provide
> a
> > precompiled valid header with the HMACs that include the per-hop payloads
> > and the end-to-end payload without knowing them upfront.
> >
> > I'd prefer having a rendezvous scheme that merges the two ends of the
> route
> > in a seamless way, which should not be too hard to do, unless we keep the
> > per-hop checkable HMACs.
>
> Ahh, I see what you mean now. You're correct, it seems that we may be forced
> to drop the per-hop HMAC in order to enable seamless rendevous routing.
>

Kind of sad, I know, but we may be able to save them with an interactive protocol: the endpoints of the route negotiate a rendezvous node, then the sender builds his half of the path, computes the ephemeral key at the rendezvous point and sends it to the final recipient which finalizes the route construction. But maybe I'm overthinking it, at this point the payload could just be sent out-of-band :-)

Quoted text (10 lines)
> > Do we need both a timestamped backlog of secrets and key-rotation? If we
> > get the key rotation quick enough it's probably sufficient to simply keep
> > all secrets for the current key, especially if we use bloom-filters to
> > store the seen secrets.
>
> Yeah, it seems that key rotation alone is much simpler than the timestamped
> log
> of secrets. So the key rotation alone should suffice.
>
> -- Laolu

Perfect, that seems like a clean and simple solution to the shared secret storage problem. Noting this does for a future spec :-)

Cheers, Christian

Olaoluwa Osuntokun in reply to Rusty Russell permalink original

Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (9 lines)
> Some node will have to straddle two chains, right?  So you'd route A ->
> B -> C as normal, and C is (say) litecoin (B straddles both).  You
> really want the onion to be explicit that this transfer to litecoin is
> what the sender intended.  Or some sidechain.
>
> Now, we'd hope nobody would screw this up, but I think it's worth
> flagging since the sender really should know it's changing chains.
>
> Ahh, I'm starting to see your point now.

Agreed that it doesn't hurt to allocate an extra byte in order to make the chain transitions *explicit*. Alternatively, (instead of modifying the header) we can simply allocate the first byte of the per-hop payload for this purpose.

-- Laolu

Olaoluwa Osuntokun in reply to Christian Decker permalink original

Christian Decker <decker.christian at gmail.com> wrote:

Quoted text (22 lines)
> > Now, we'd hope nobody would screw this up, but I think it's worth
> > flagging since the sender really should know it's changing chains.
>
> I agree that the realm byte is a sensible addition. To trigger this we
> would need to have multiple channels, on different chains, using the
> same identifiers between two nodes. Only in this case we'd have an
> ambiguity where to transfer the funds. Assuming we have the route A ->
> B => C, where => indicates two channels, one in litecoin and one in
> bitcoin, and both channels use the same identity for C. Then the
> instruction to forward 0.01 units to C is ambiguous, as it could be
> denominated in either litecoin or bitcoin.
>
> While not dangerous it is rather unfortunate as it results in
> guesswork. It is not dangerous because if A transferred litecoin to B
> then B will (hopefully) never forward a higher value to C using
> bitcoin, and if it were bitcoin then the final recipient would not
> sign off an inferior amount than what he expected.
>
> To prevent this we could make it a policy to never re-use identities
> for multiple channels, but someone will surely get it wrong at some
> point :-)
>

Great example; I hadn't considered this particular case before. It's clear to me now that we should eliminate this potential ambiguity by making the chain of the target link for each hop along the route explicit.

Quoted text (5 lines)
I was thinking that it'd be stored in the per-hop payload, along with
> the instructions for the hop, which is why I did not specify it, but
> I'm happy to add it, should it make things clearer.
>
>

I think the byte specifying the target realm should be protected under a MAC, as forwarding to the correct realm may be critical in order for the payment to succeed. Therefore, if we retain the MAC for the per-hop payload then it can be placed there, otherwise they header may need to extended by a byte in order to place the realm information there.

-- Laolu -- Laolu

Christian Decker in reply to Olaoluwa Osuntokun permalink original

On Tue, Aug 16, 2016 at 04:54:32AM +0000, Olaoluwa Osuntokun wrote:

Quoted text (12 lines)
> > I was thinking that it'd be stored in the per-hop payload, along with
> > the instructions for the hop, which is why I did not specify it, but
> > I'm happy to add it, should it make things clearer.
> >
> >
> I think the byte specifying the target realm should be protected under a
> MAC, as forwarding to the correct realm may be critical in order for the
> payment to succeed. Therefore, if we retain the MAC for the per-hop payload
> then it can be placed there, otherwise they header may need to extended by
> a byte in order to place the realm information there.
>
> -- Laolu

Good catch! We need to make sure that the integrity of the per-hop payload is protected at all costs. The per-hop payloads were introduced to provide intermediate hops with instructions on what to do, i.e., how many coins to forward, so if we can't guarantee their integrity it could result in exploits. An attacker could for example instruct an intermediate hop to forward more, in the hopes of collecting it further down the line.

A mitigating fact may be that a node will forward at most the amount it received, minus its fee, limiting this to a fee-shaving attack. But if we can find a way to fix it, that would be great.

So it would appear we cannot drop the payloads from the MAC after all, which makes stitching routes difficult in the case of rendezvous. The interactive protocol I outlined before may still works, but it is rather ugly as it deviates from the invoice pattern, i.e., the final recipient gives the necessary information for the transfer in a single bundle.

Cheers, Christian

Rusty Russell in reply to Christian Decker permalink original

Christian Decker <decker.christian at gmail.com> writes:

Quoted text (14 lines)
> I agree that the realm byte is a sensible addition. To trigger this we
> would need to have multiple channels, on different chains, using the
> same identifiers between two nodes. Only in this case we'd have an
> ambiguity where to transfer the funds. Assuming we have the route A ->
> B => C, where => indicates two channels, one in litecoin and one in
> bitcoin, and both channels use the same identity for C. Then the
> instruction to forward 0.01 units to C is ambiguous, as it could be
> denominated in either litecoin or bitcoin.
>
> While not dangerous it is rather unfortunate as it results in
> guesswork. It is not dangerous because if A transferred litecoin to B
> then B will (hopefully) never forward a higher value to C using
> bitcoin, and if it were bitcoin then the final recipient would not
> sign off an inferior amount than what he expected.

Worse case: C is a charity, accepting donations. A's software screwed up and didn't realize C was litecoin, not bitcoin. B collects a huge fee, C gets tiny donation.

Cheers, Rusty.

Christian Decker in reply to Rusty Russell permalink original

On Wed, Aug 17, 2016 at 07:53:03PM +0930, Rusty Russell wrote:

Quoted text (19 lines)
> Christian Decker <decker.christian at gmail.com> writes:
> > I agree that the realm byte is a sensible addition. To trigger this we
> > would need to have multiple channels, on different chains, using the
> > same identifiers between two nodes. Only in this case we'd have an
> > ambiguity where to transfer the funds. Assuming we have the route A ->
> > B => C, where => indicates two channels, one in litecoin and one in
> > bitcoin, and both channels use the same identity for C. Then the
> > instruction to forward 0.01 units to C is ambiguous, as it could be
> > denominated in either litecoin or bitcoin.
> >
> > While not dangerous it is rather unfortunate as it results in
> > guesswork. It is not dangerous because if A transferred litecoin to B
> > then B will (hopefully) never forward a higher value to C using
> > bitcoin, and if it were bitcoin then the final recipient would not
> > sign off an inferior amount than what he expected.
>
> Worse case: C is a charity, accepting donations.  A's software screwed
> up and didn't realize C was litecoin, not bitcoin.  B collects a huge
> fee, C gets tiny donation.

True, that's a dangerous scenario. If the recipient does not know the intended amount and accepts anything then fee-shaving is very profitable. In general I'm a bit concerned about rhash re-use, after all today it's not uncommon to just publish a bitcoin address, people might be tempted to do the same in Lightning.

Cheers, Christian

Rusty Russell in reply to Christian Decker permalink original

Christian Decker <decker.christian at gmail.com> writes:

Quoted text (24 lines)
> On Wed, Aug 17, 2016 at 07:53:03PM +0930, Rusty Russell wrote:
>> Christian Decker <decker.christian at gmail.com> writes:
>> > I agree that the realm byte is a sensible addition. To trigger this we
>> > would need to have multiple channels, on different chains, using the
>> > same identifiers between two nodes. Only in this case we'd have an
>> > ambiguity where to transfer the funds. Assuming we have the route A ->
>> > B => C, where => indicates two channels, one in litecoin and one in
>> > bitcoin, and both channels use the same identity for C. Then the
>> > instruction to forward 0.01 units to C is ambiguous, as it could be
>> > denominated in either litecoin or bitcoin.
>> >
>> > While not dangerous it is rather unfortunate as it results in
>> > guesswork. It is not dangerous because if A transferred litecoin to B
>> > then B will (hopefully) never forward a higher value to C using
>> > bitcoin, and if it were bitcoin then the final recipient would not
>> > sign off an inferior amount than what he expected.
>>
>> Worse case: C is a charity, accepting donations.  A's software screwed
>> up and didn't realize C was litecoin, not bitcoin.  B collects a huge
>> fee, C gets tiny donation.
>
> True, that's a dangerous scenario. If the recipient does not know the
> intended amount and accepts anything then fee-shaving is very
> profitable.

Which creates a subtle requirement: even the terminal onion should include an amount.

Quoted text (3 lines)
> In general I'm a bit concerned about rhash re-use, after
> all today it's not uncommon to just publish a bitcoin address, people
> might be tempted to do the same in Lightning.

Hmm, maybe we should implement the code to steal such re-sends? Or more generously, fail it. That would prevent this from becoming a habit, at least.

Related: I can't seem to figure out why we're so concerned with onion reuse? It seems if a node were to retransmit the same onion runs this same risk.

Thanks, Rusty.

Joseph Poon in reply to Rusty Russell permalink original

On Fri, Aug 19, 2016 at 10:26:31AM +0930, Rusty Russell wrote:

Quoted text (9 lines)
> >> > While not dangerous it is rather unfortunate as it results in
> >> > guesswork. It is not dangerous because if A transferred litecoin to B
> >> > then B will (hopefully) never forward a higher value to C using
> >> > bitcoin, and if it were bitcoin then the final recipient would not
> >> > sign off an inferior amount than what he expected.
> >>
> >> Worse case: C is a charity, accepting donations.  A's software screwed
> >> up and didn't realize C was litecoin, not bitcoin.  B collects a huge
> >> fee, C gets tiny donation.

Yeah, for sure, I agree with y'all. By default, there should be a requirement that the amount is pre-negotiated by the sender and the recipient (pay-to-contract, etc.)

Sufficient percentages of senders to a charity should be interested in getting a receipt to prove funds were sent to a charity that I don't think pre-sending it without generating a proof shouldn't be a normal case. By default, I don't think clients should even send funds until they have a signed receipt before cross-chain is supported for safety.

However, I'm not too concerned with cross-chain. As long as there's some identifier between each hop, I suspect that should be sufficient. Is the intent of the realm byte to indicate protocols? I think it's reasonable to have some kind of byte for identifying the message (e.g. using this as a transport layer for other things), but I think there should already be sufficient information for cross-chain, presuming pay-to-contract.

Quoted text (6 lines)
> > True, that's a dangerous scenario. If the recipient does not know the
> > intended amount and accepts anything then fee-shaving is very
> > profitable.
>
> Which creates a subtle requirement: even the terminal onion should
> include an amount.

This may not fully solve the problem, since if one presumes that the second-to-last hop is malicious, they can re-create a new onion blob (presuming consistent hashes for each hop, of course).

There may be a requirement from deriving the fee amount for the last hop, though.

Quoted text (7 lines)
> > In general I'm a bit concerned about rhash re-use, after
> > all today it's not uncommon to just publish a bitcoin address, people
> > might be tempted to do the same in Lightning.
>
> Hmm, maybe we should implement the code to steal such re-sends?  Or more
> generously, fail it.  That would prevent this from becoming a habit, at
> least.

Either way seems practical for some nodes -- I presume if a small percentage of nodes redeem without forwarding, then basically nobody would re-use. Not sure if "steal" is the right word, though.

Olaoluwa Osuntokun in reply to Joseph Poon permalink original

Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (3 lines)
> Which creates a subtle requirement: even the terminal onion should
include an
> amount.

With the current draft specification, all hops receive a per-hop payload (unless we're now abandoning the payload for the final hop due to the "terminal" byte?). This behavior isn't changed for the final hop, so they also extract a payload once they process the onion packet.

Christian Decker <decker.christian at gmail.com> wrote:

Quoted text (3 lines)
> If the recipient does not know the intended amount and accepts anything
then
> fee-shaving is very profitable.

In my mind (although it seems to be handled with the current onion-packet format), this is an issue which should be resolved/negotiated at a higher level. Ignoring the possibility of using the network as a general messaging layer (which seems a bit ambitious, plus brings up DoS concerns), the sender/receiver should have already negotiated all the details of the payment. If the receiver communicated the target r-hash, then they should also be aware of the associated value to be paid out with reveal of the corresponding r-preimage. Joseph's description fits by current thought model.

Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (3 lines)
> Related: I can't seem to figure out why we're so concerned with onion
reuse?
> It seems if a node were to retransmit the same onion runs this same risk.

One might say that the concern is a bit "academic" in nature. In theory, within a mix-net (sending emails/messages, not HTLC's), an adversary shouldn't be able to re-inject an arbitrary previously processed packet thereby causing node to process and forward the packet as normal. If they're able to do this, then in conjunction with several nodes participating within the network, the adversary may be able to partially (worse, even fully) re-construct the original path by observing how the replays propagate throughout the network.

However, practically, we're currently building something that more resembles an onion routing network rather than a mix-net. Additionally, as all communication links are end-to-end encrypted+authenticated, in reality, the only party able to attempt to replay packet within the network are nodes whom have directly received+processes the onion packet in the past. In our particular context, assuming the onion packet is encapsulated within the message that adds a new HTLC, then an attempt to replay would be foolish as if one assumes nodes remember all r-preimages, then the first hop would just immediately pull the funds (as Rusty points out).

Joseph Poon <joseph at lightning.network> wrote:

Quoted text (3 lines)
> This may not fully solve the problem, since if one presumes that the
> second-to-last hop is malicious, they can re-create a new onion blob
> (presuming consistent hashes for each hop, of course).

First, *all* hops receive a per-hop payload which ideally would includes details such as payment, time-lock value, etc. Second, this is only possible if Bob (the second-to-last hop), *knows* that they are in fact, the second-to-last hop *and* already knows all identities following them within the route. Otherwise, the route will fail as Bob is unable to construct a new fully valid onion packet.

Even in the case that Bob if able to do this, it shouldn't affect the payment as a whole assuming Dave (the final receiver) knows the value he's expecting for each particular r-hash (as you detailed earlier).

-- Laolu

Rusty Russell in reply to Joseph Poon permalink original

Joseph Poon <joseph at lightning.network> writes:

Quoted text (14 lines)
> On Fri, Aug 19, 2016 at 10:26:31AM +0930, Rusty Russell wrote:
>> >> > While not dangerous it is rather unfortunate as it results in
>> >> > guesswork. It is not dangerous because if A transferred litecoin to B
>> >> > then B will (hopefully) never forward a higher value to C using
>> >> > bitcoin, and if it were bitcoin then the final recipient would not
>> >> > sign off an inferior amount than what he expected.
>> >>
>> >> Worse case: C is a charity, accepting donations.  A's software screwed
>> >> up and didn't realize C was litecoin, not bitcoin.  B collects a huge
>> >> fee, C gets tiny donation.
>
> Yeah, for sure, I agree with y'all. By default, there should be a
> requirement that the amount is pre-negotiated by the sender and the
> recipient (pay-to-contract, etc.)

Yes, as your point below makes clear; not agreeing on an amount is susceptible to theft by prior hops:

Quoted text (3 lines)
> This may not fully solve the problem, since if one presumes that the
> second-to-last hop is malicious, they can re-create a new onion blob
> (presuming consistent hashes for each hop, of course).

Great catch. Oops...

Quoted text (7 lines)
>> Hmm, maybe we should implement the code to steal such re-sends?  Or more
>> generously, fail it.  That would prevent this from becoming a habit, at
>> least.
>
> Either way seems practical for some nodes -- I presume if a small
> percentage of nodes redeem without forwarding, then basically nobody
> would re-use.  Not sure if "steal" is the right word, though.

I also tend to use that term for the collect-all-because-you-cheated transaction. Because "rightfully taking what is mine" is too much of a mouthful :)

Cheers, Rusty.

Olaoluwa Osuntokun in reply to Rusty Russell permalink original

On Sun, Aug 21, 2016 at 1:46 PM Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (6 lines)
> > This may not fully solve the problem, since if one presumes that the
> > second-to-last hop is malicious, they can re-create a new onion blob
> > (presuming consistent hashes for each hop, of course).
>
> Great catch.  Oops...
>

During the whole payment negotiation process, the sender and receiver can additionally agree on a shared secret-ish value (possibly the hash of the contract) that should be included in the per-hop payload for the final hop.

If the portion of the per-hop payload doesn't match identically with this value, then the payment should be rejected as a prior node has unsuccessfully attempted re-create the onion packet.

-- Laolu

Christian Decker in reply to Olaoluwa Osuntokun permalink original

I'd like to pick up the conversation about the onion routing protocol again, since we are close to merging our implementation into the lightningd node.

As far as I can see we mostly agree on the spec, with some issues that should be deferred until later/to other specs:

 - Key-rotation policies
 - Backlog of seen shared secrets
 - Payload formatting (what data to include and how it is encoded)

The last pressing issue is the use of the HMAC, specifically what the per-hop verifiable HMAC should include. Having it cover the entirety of the packet, including the payloads, has the advantage that corrupted packets get dropped immediately, which prevents the route length discovery attacks Rusty described and we make more efficient use of our funds, i.e., drop a transfer immediately not allocating HTLCs for a payment that is destined to fail, and quicker retries.

The downside is the rendezvous problem, in which the recipient would provide part of the onion, hence the sender cannot compute the HMACs. We can potentially sidestep this with a partially trusted reflector, have an interactive construction of the packet, or come up with a new scheme ourselves. Anyway, I'm happy to shelve this aspect for a future v2 of the onion routing protocol, and include the payload in the HMAC.

I think for now we should also keep the payload sizes fixed at 20 bytes for per-hop and 1024 byte for end-to-end payload, and we can discuss how to format those payloads in another spec. Since we seem to want to add and remove bits and pieces it might be worth to make it flexible using a generic encoding (JSON, msgpack, ...). This potentially includes the "forward X units of coin Y" and the "expect X units" for the endpoint. We can also address the "last-hop corrupts" problem in the payload with an additional end-to-end secret like you suggested. Having them in the per-hop payload and HMACing the payloads secures them against tampering.

Let me know if there is any major thing that is not/insufficiently addressed. BTW do we have a process in place for upgrading spec drafts or do we keep things informal?

Regards, Christian

On Mon, Aug 22, 2016 at 07:47:56PM +0000, Olaoluwa Osuntokun wrote:

Quoted text (23 lines)
> On Sun, Aug 21, 2016 at 1:46 PM Rusty Russell <rusty at rustcorp.com.au> wrote:
>
> > > This may not fully solve the problem, since if one presumes that the
> > > second-to-last hop is malicious, they can re-create a new onion blob
> > > (presuming consistent hashes for each hop, of course).
> >
> > Great catch.  Oops...
> >
>
> During the whole payment negotiation process, the sender and receiver can
> additionally agree on a shared secret-ish value (possibly the hash of the
> contract) that should be included in the per-hop payload for the final hop.
>
> If the portion of the per-hop payload doesn't match identically with this
> value, then the payment should be rejected as a prior node has
> unsuccessfully attempted re-create the onion packet.
>
>
> -- Laolu

> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
Rusty Russell in reply to Christian Decker permalink original

Christian Decker <decker.christian at gmail.com> writes:

Quoted text (8 lines)
> I'd like to pick up the conversation about the onion routing protocol
> again, since we are close to merging our implementation into the
> lightningd node.
>
> As far as I can see we mostly agree on the spec, with some issues that
> should be deferred until later/to other specs:
>
>  - Key-rotation policies

OK, I've been thinking about the costs of key-rotation.

Assumptions: 1) We simply use a single pubkey for everything about a node, aka its ID. 2) Medium-scale public network, 250,000 nodes and 1M channels. 3) Every node knows the entire public network.

Each node ID is 33 bytes (pubkey) each channel is 6 bytes (blocknum + txnum). You need to associate channels -> ids, say another 8 bytes per channel.

That's 22.25MB each node has to keep.

The proofs are larger: to prove which IDs owns a channel, each one needs a merkle proof (12 x 32 bytes) plus the funding tx (227 bytes, we can skip some though), the two pubkeys (66 bytes), and a signature of the ID using those pubkeys (128 bytes, schnorr would be 64?).

That's an additional 800M each node has to download to completely validate, and of course some nodes will have to keep this so we can download it from somewhere. That's even bigger than Pokemon Go :(

Change Assumptions: 1) We use a "comms" key for each node instead of its ID. 2) Nodes send out a new comms key, signed by ID.

That's another 33 bytes each to keep, or 8.25MB. To rotate a comms key, we need the new key (33 bytes), and a signature from the id (64 bytes), and probably a timestamp, (4 bytes), that's 25.25MB.

That's not too bad if we rotate daily. Probably not if we rotate hourly..

Cheers, Rusty.

Olaoluwa Osuntokun in reply to Christian Decker permalink original

On Fri, Sep 2, 2016 at 5:08 AM Christian Decker <decker.christian at gmail.com> wrote:

Quoted text (8 lines)
> As far as I can see we mostly agree on the spec, with some issues that
> should be deferred until later/to other specs:
>
>  - Key-rotation policies
>  - Backlog of seen shared secrets
>  - Payload formatting (what data to include and how it is encoded)
>
> Sounds good to me. That's a good summarization of the current outstanding

aspects to be deferred based on our past discussions.

Quoted text (3 lines)
> Anyway, I'm happy to shelve this aspect for a future v2 of the onion
> routing protocol, and include the payload in the HMAC.
>

Agreed, the full specification of the rendezvous handshake can deferred to a later v2. We may even learn of some limitations or issues with the current format which may impact the requirements or traits we want from a future rendezvous protocol.

Quoted text (2 lines)
I think for now we should also keep the payload sizes fixed at 20
> bytes for per-hop and 1024 byte for end-to-end payload

Sure, although I have some reservations about the 1024-byte e2e payload due to the potential bandwidth overhead for each HTLC-add in a high frequency setting. However we should gather metrics from live testing environments to see if this is actually a concern in practice.

Quoted text (8 lines)
Since we seem to want to add and remove bits and pieces it might be worth
> to make it flexible using a generic encoding (JSON, msgpack, ...).
> This potentially includes the "forward X units of coin Y" and the "expect X
> units" for the endpoint. We can also address the "last-hop corrupts"
> problem in the payload with an additional end-to-end secret like you
> suggested. Having them in the per-hop payload and HMACing the
> payloads secures them against tampering.
>

It feels like targeting a generic encoding might be at odds with the space constraints imposed by the size of the per-hop payload. However if we can find a format that's both succinct yet generic, then that would be very attractive.

Quoted text (3 lines)
> BTW do we have a process in place for upgrading spec drafts
> or do we keep things informal?
>

Hmm, I'm not sure. As far as I'm aware, none of the current specifications have been elevated to anything above a "draft" state. Perhaps we can hammer out the ins-and-outs of what we'd all like to see in the process in Milan?

Yay! This is exciting :), I'm happy with the way the current specification has turned out. I think your break down of the current outstanding issues to be deferred to later specs are accurate. I also welcome a PR to our "lightning-onion" repo integrating the changes you implemented in your fork of my original code.

-- Laolu

Christian Decker in reply to Rusty Russell permalink original

On Mon, Sep 05, 2016 at 11:55:22AM +0930, Rusty Russell wrote:

Quoted text (12 lines)
> Christian Decker <decker.christian at gmail.com> writes:
> > I'd like to pick up the conversation about the onion routing protocol
> > again, since we are close to merging our implementation into the
> > lightningd node.
> >
> > As far as I can see we mostly agree on the spec, with some issues that
> > should be deferred until later/to other specs:
> >
> >  - Key-rotation policies
>
> OK, I've been thinking about the costs of key-rotation.
>

I forgot that we have two potential key-rotations:

 - Rotating the key used in transactions that hit the Bitcoin network
 - Rotating the public key used for the DH shared secret generation
   for the onion routing protocol

For the moment I was concentrating on the latter.

Quoted text (31 lines)
> Assumptions:
> 1) We simply use a single pubkey for everything about a node, aka its ID.
> 2) Medium-scale public network, 250,000 nodes and 1M channels.
> 3) Every node knows the entire public network.
>
> Each node ID is 33 bytes (pubkey) each channel is 6 bytes (blocknum +
> txnum).  You need to associate channels -> ids, say another 8 bytes per
> channel.
>
> That's 22.25MB each node has to keep.
>
> The proofs are larger: to prove which IDs owns a channel, each one needs
> a merkle proof (12 x 32 bytes) plus the funding tx (227 bytes, we can
> skip some though), the two pubkeys (66 bytes), and a signature of the ID
> using those pubkeys (128 bytes, schnorr would be 64?).
>
> That's an additional 800M each node has to download to completely
> validate, and of course some nodes will have to keep this so we can
> download it from somewhere.  That's even bigger than Pokemon Go :(
>
> Change Assumptions:
> 1) We use a "comms" key for each node instead of its ID.
> 2) Nodes send out a new comms key, signed by ID.
>
> That's another 33 bytes each to keep, or 8.25MB.  To rotate a comms key,
> we need the new key (33 bytes), and a signature from the id (64 bytes),
> and probably a timestamp, (4 bytes), that's 25.25MB.
>
> That's not too bad if we rotate daily.  Probably not if we rotate
> hourly..
>

A node's public key used for DH shared secret generation exists independently of its channels. I think we probably should not bind the rotation of the key we use to talk to that node to one of its channels. However, it does make sense to require that a node also has at least one active channel in order for us to care at all :-)

The comms key approach is in line with what I was thinking as well. We can bind the new communication key with the channel's existence by showing a derivation path from the node's (fixed) public key and the new key. So a node wanting to rotate its communication key just sends the following: "I am <pubkey> (33 byte), please use key <derivation number> (~4 byte) and here is a <signature> (64 bytes) that I signed this rotation off.". The communication overhead is identical to your proposal, but, since you send only the new key, I think in your proposal we'd have to churn through all known node ids to find which one signed the rotation, or where you also using timestamp based derivation?

Another case we could consider is having passive rotations: when an endpoint announces a channel's existence it also sends its rotation interval along. Every <rotation interval> nodes simply derive the new key and use that for the DH shared secret generation should they want to talk to this node. And nodes have a switchover window in which they accept both (would be necessary in the active rotation as well due to delays). The passive rotation incurs no communication overhead and can be bound to the node's channels, so as long as we believe one of its channels to exist, we rotate its keys.

Possibly a mix of active and passive would make sense, with the active rotation enabling emergency rotations in case a key was compromised, but we're in a lot of trouble then anyway :-)

Quoted text (2 lines)
> Cheers,
> Rusty.

Cheers, Christian

Rusty Russell in reply to Christian Decker permalink original

Christian Decker <decker.christian at gmail.com> writes:

Quoted text (17 lines)
> On Mon, Sep 05, 2016 at 11:55:22AM +0930, Rusty Russell wrote:
>> Christian Decker <decker.christian at gmail.com> writes:
>> > I'd like to pick up the conversation about the onion routing protocol
>> > again, since we are close to merging our implementation into the
>> > lightningd node.
>> >
>> > As far as I can see we mostly agree on the spec, with some issues that
>> > should be deferred until later/to other specs:
>> >
>> >  - Key-rotation policies
>>
>> OK, I've been thinking about the costs of key-rotation.
>>
>
> I forgot that we have two potential key-rotations:
>
>  - Rotating the key used in transactions that hit the Bitcoin network

Oh, that's different, yes.

Quoted text (4 lines)
>  - Rotating the public key used for the DH shared secret generation
>    for the onion routing protocol
>
> For the moment I was concentrating on the latter.

Yes. It's the one we need to communicate through the node.

Quoted text (15 lines)
>> Change Assumptions:
>> 1) We use a "comms" key for each node instead of its ID.
>> 2) Nodes send out a new comms key, signed by ID.
>>
>> That's another 33 bytes each to keep, or 8.25MB.  To rotate a comms key,
>> we need the new key (33 bytes), and a signature from the id (64 bytes),
>> and probably a timestamp, (4 bytes), that's 25.25MB.
>>
>> That's not too bad if we rotate daily.  Probably not if we rotate
>> hourly..

> A node's public key used for DH shared secret generation exists
> independently of its channels. I think we probably should not bind the
> rotation of the key we use to talk to that node to one of its
> channels. However, it does make sense to require that a node also has
> at least one active channel in order for us to care at all :-)

This calculation was per-node, not per-channel.

Quoted text (11 lines)
> The comms key approach is in line with what I was thinking as well.
> We can bind the new communication key with the channel's existence by
> showing a derivation path from the node's (fixed) public key and the
> new key. So a node wanting to rotate its communication key just sends
> the following: "I am <pubkey> (33 byte), please use key <derivation
> number> (~4 byte) and here is a <signature> (64 bytes) that I signed
> this rotation off.". The communication overhead is identical to your
> proposal, but, since you send only the new key, I think in your
> proposal we'd have to churn through all known node ids to find which
> one signed the rotation, or where you also using timestamp based
> derivation?

Hmm, do we lose forward secrecy if we use a BIP32 chain? But we may be able to use another derivation method where we derive key N from key N-1. I'm looking at Laolu...

Quoted text (9 lines)
> Another case we could consider is having passive rotations: when an
> endpoint announces a channel's existence it also sends its rotation
> interval along. Every <rotation interval> nodes simply derive the new
> key and use that for the DH shared secret generation should they want
> to talk to this node. And nodes have a switchover window in which they
> accept both (would be necessary in the active rotation as well due to
> delays). The passive rotation incurs no communication overhead and can
> be bound to the node's channels, so as long as we believe one of its
> channels to exist, we rotate its keys.

I like the zero-comms overhead! We could in fact use block number to rotate; key 1 is used for the first N blocks, then key 2, etc, with old keys allowed X blocks late, new keys allowed X blocks early?

I think we should select some N for the moment, rather than making it configurable. If it's too small it might take a long time for clients to derive the current key: 50 usecs each step is almost half a second for a year-old key if we rotate every 6 blocks. Rotation daily makes that much more approachable...

Quoted text (3 lines)
> Possibly a mix of active and passive would make sense, with the active
> rotation enabling emergency rotations in case a key was compromised,
> but we're in a lot of trouble then anyway :-)

In that case, you close the channels and start a new node?

Cheers, Rusty.

Olaoluwa Osuntokun in reply to Rusty Russell permalink original

Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (2 lines)
> Each node ID is 33 bytes (pubkey) each channel is 6 bytes (blocknum +
txnum).

Using blocknum+txnum to identify a channel doesn't account for the possibility of a single transaction which opens multiple channels concurrently. A possible use-case for such a transaction are coin-joined channel openings which obfuscate the relationships being creating with a channel opening. You'd need to tack on an extra byte (maybe two) to also encode the output index of the channel within the transaction. Additionally, identifying channels based solely from blockheight+offsets conjures up some re-org safety concerns. It's also a bit less "verifiable" than referring via the full outpoint.

Quoted text (4 lines)
> The proofs are larger: to prove which IDs owns a channel, each one needs a
> merkle proof (12 x 32 bytes) plus the funding tx (227 bytes, we can skip
> some though), the two pubkeys (66 bytes), and a signature of the ID using
> those pubkeys (128 bytes, schnorr would be 64?).

Are those two pub keys the multi-sig pub keys, or the identity pub keys? In either case, only requiring two pub keys to attest-to/authenticate the state of a channel is insufficient. With only two signatures, then nodes can advertise the same channel several times creating a non-canonical graphs resulting in differing network views. If we'd like to eliminate such a possibility, then we also need to cryptographically bind the two identities to the proof. Using a schnorr multi-signature generated by the four pubkeys would remedy this. Validators can use pubkey recovery to extract the "group pubkey" from the single signature, ensure it's the result of point addition of the four public keys, check the channel isn't closed, then verify the signature over the advertisement as normal.

Christian Decker <decker.christian at gmail.com> wrote:

Quoted text (2 lines)
> I forgot that we have two potential key-rotations:
> - Rotating the key used in transactions that hit the Bitcoin network

If you mean the key included within the 2-of-2 multi-sig, I assume all implementations will be using a fresh key with each channel either way, so we don't need any explicit rotations here?

I've only been thinking of rotations for the onion pubkeys used for the DH shared secret derivation for the onion packets. Identity keys could also possibly either be rotated/revoked, or delegated with some sort of "certificate".

Quoted text (3 lines)
> Another case we could consider is having passive rotations: when an
> endpoint announces a channel's existence it also sends its rotation
> interval along.

IMO a passive rotation scheme is superior due to the bandwidth savings of pushing the onion key rotations to the edges themselves. As you said an active rotation might be used in the emergency case of a forced key rotation due to key compromise.

Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (3 lines)
> Hmm, do we lose forward secrecy if we use a BIP32 chain?  But we may be
> able to use another derivation method where we derive key N from key
> N-1.  I'm looking at Laolu...

Well, sorta. If the master pubkey is published, and nodes use public derivation on the edges to do passive key rotations, then if one of the non-hardened child private keys is leaked, an adversary can derive the master private key thereby gaining the ability to decrypt any saved/intercepted onion packets to the compromised node.

Earlier in this email chain I suggested a scheme to regain forward secrecy in the case of such a private key leak by requiring nodes to do some upfront pre-computation involving an intermediate derivation point. This would still allow passive rotation by the edges. However, in practice those pre-generated would likely be stored in the same location? So that kinda puts us back at the original exploit scenario.

If we were to involve some pairing crypto (IBE style), we would use say block hashes to allow nodes to passively derive keys the "source" node is able to generate the corresponding private key to...

IMO we need to more clearly state our security model/assumptions here to reason about the attack scenarios we'll try to guard against.

-- Laolu

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

(Sorry for delay: travel plus laptop issues...)

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (11 lines)
> Rusty Russell <rusty at rustcorp.com.au> wrote:
>
>> Each node ID is 33 bytes (pubkey) each channel is 6 bytes (blocknum +
> txnum).
>
> Using blocknum+txnum to identify a channel doesn't account for the
> possibility of a single transaction which opens multiple channels
> concurrently. A possible use-case for such a transaction are coin-joined
> channel openings which obfuscate the relationships being creating with a
> channel opening. You'd need to tack on an extra byte (maybe two) to also
> encode the output index of the channel within the transaction.

Great point. We should absolutely support this.

Quoted text (3 lines)
> Additionally, identifying channels based solely from
> blockheight+offsets conjures up some re-org safety concerns. It's also
> a bit less "verifiable" than referring via the full outpoint.

A little, but the compactness is worth it. If you're an SPV node you'll need a proof, and if you're not you'll know if it's not in the main chain.

Quoted text (12 lines)
>> The proofs are larger: to prove which IDs owns a channel, each one needs a
>> merkle proof (12 x 32 bytes) plus the funding tx (227 bytes, we can skip
>> some though), the two pubkeys (66 bytes), and a signature of the ID using
>> those pubkeys (128 bytes, schnorr would be 64?).
>
> Are those two pub keys the multi-sig pub keys, or the identity pub keys? In
> either case, only requiring two pub keys to attest-to/authenticate the state
> of a channel is insufficient. With only two signatures, then nodes can
> advertise the same channel several times creating a non-canonical graphs
> resulting in differing network views. If we'd like to eliminate such a
> possibility, then we also need to cryptographically bind the two identities
> to the proof.

Yeah, it's not sufficient to get the multisig keys to sign the ID.

Quoted text (5 lines)
> Using a schnorr multi-signature generated by the four pubkeys
> would remedy this. Validators can use pubkey recovery to extract the "group
> pubkey" from the single signature, ensure it's the result of point addition
> of the four public keys, check the channel isn't closed, then verify the
> signature over the advertisement as normal.

I think this only works if the on-chain keys are Schnorr, right? Until then, we'd need the ID to sign the pubkeys (or anything which uniquely identified the channel tx).

Quoted text (22 lines)
> Christian Decker <decker.christian at gmail.com> wrote:
>
>> I forgot that we have two potential key-rotations:
>> - Rotating the key used in transactions that hit the Bitcoin network
>
> If you mean the key included within the 2-of-2 multi-sig, I assume all
> implementations will be using a fresh key with each channel either way, so
> we don't need any explicit rotations here?
>
> I've only been thinking of rotations for the onion pubkeys used for the DH
> shared secret derivation for the onion packets. Identity keys could also
> possibly either be rotated/revoked, or delegated with some sort of
> "certificate".
>
>> Another case we could consider is having passive rotations: when an
>> endpoint announces a channel's existence it also sends its rotation
>> interval along.
>
> IMO a passive rotation scheme is superior due to the bandwidth savings of
> pushing the onion key rotations to the edges themselves. As you said an
> active rotation might be used in the emergency case of a forced key rotation
> due to key compromise.

As you state below (and as confirmed by Adam Back and others I asked at Blockstream), there is no passive scheme for forward secrecy though unless we want pairing crypto and magic. So might as well not rotate keys in that case.

Quoted text (13 lines)
> Earlier in this email chain I suggested a scheme to regain forward secrecy
> in the case of such a private key leak by requiring nodes to do some upfront
> pre-computation involving an intermediate derivation point. This would still
> allow passive rotation by the edges. However, in practice those
> pre-generated would likely be stored in the same location? So that kinda
> puts us back at the original exploit scenario.
>
> If we were to involve some pairing crypto (IBE style), we would use say
> block hashes to allow nodes to passively derive keys the "source" node is
> able to generate the corresponding private key to...
>
> IMO we need to more clearly state our security model/assumptions here to
> reason about the attack scenarios we'll try to guard against.

Indeed. Let me try to enumerate the different secrets we need to protect, and you tell me what I missed?

0 - Wallet privkey(s)
  * Must be online for channel creation.
  * Compromise means all not-in-channel funds can be stolen.
1 - Commit signing bitcoin privkey (per peer)
  * Must be online for channel creation, change and close (ie. always).
  * Compromise means we can collaborate with peer to steal funds in that
    channel. (eg. sign a revoked transaction and give all funds to peer,
    or mutually sign a tx spending the funds to anywhere the attacker wants).
2 - Identity privkey
  * Must be online for channel publishing, fee changes.
  * Compromise means we can advertise new rates (or channel
    unavailability), cutting node off lightning network.
3 - Onion privkey
  * Must be online for routing (ie. always)
  * Compromise means we can decode incoming HTLC offers, maybe send fail failure
    messages.
4 - Low-level comms symmetric key (per peer)
  * Must be online always.
  * Compromise means we can decode all messages to peer, and break
    connections with them (we can't create new HTLCs or change bitcoin
    fees without the commit-signing privkey though).
5 - H-preimage (per invoice)
  * Must be online when creating or accepting payment for invoice
    (always, unless we're routing-only).
  * Compromise means we can lose associated incoming amount.

The simplest scheme is that the first four keys are the same. That's horrible for node privacy, since you can see even non-lightning funds. So let's assume the wallet key is separate.

Separating commit keys from identity key allows nodes to post-hoc announce channels (by associating them with the public identity) and also means we can segregate peer privkeys (eg. one process per peer) which is slightly nicer from a security POV.

Separating onion privkey allows rotation; only a win if we get forward secrecy (not a win for this node, as much as for the network as a whole).

The comms symmetric key should be rotated with forward secrecy as well, for similar reasons.

(We *could* derive all the secrets from a single master secret, but that's an implementation issue with its own tradeoffs...).

Thoughts? Rusty.

Olaoluwa Osuntokun in reply to Rusty Russell permalink original
Quoted text (1 line)
> I think this only works if the on-chain keys are Schnorr, right?

We'd use the same curve equation and domain parameters as Bitcoin uses currently, but would swap out EC-DSA for EC-Schnorr. So as a result, pub/priv keys stay the same, meaning the on-chain keys can be used for signing/verifying the multi-sign for channel authentication proofs.

Quoted text (2 lines)
> Indeed.  Let me try to enumerate the different secrets we need to
> protect, and you tell me what I missed?

Excellent, this looks like an accurate breakdown to me. The only thing I'd add is that compromise of the identity public key allows an attacker to open/accept authenticated+confidential p2p connections on the network. In isolation this seems pretty harmless as they're capabilities with one this key is rather limited.

Quoted text (1 line)
>From a compartmentalization standpoint, unless there are significant gains

from coupling keys from distinct categories, all keying material should be as independent as possible.

At the very least (as you detailed), the commit keys should be rolled anew for each channel. This opens up the doors to architectures such as per-channel process signers w/ mlock'd secrets, dedicated hardware, etc.

Quoted text (3 lines)
> Separating onion privkey allows rotation; only a win if we get forward
> secrecy (not a win for this node, as much as for the network as a
> whole).

Agreed, if we're not initially doing passive (or active) key rotation for the onion keys, then coupling the identity and onion keys simplifies the code at that level and nixes a few network layer control messages.

Quoted text (2 lines)
> The comms symmetric key should be rotated with forward secrecy as
> well, for similar reasons.

Indeed, we can throw in a simple ratcheting scheme into the initial p2p spec.

-- Laolu

Christian Decker in reply to Olaoluwa Osuntokun permalink original

On Mon, Oct 03, 2016 at 05:21:35PM +0000, Olaoluwa Osuntokun wrote:

Quoted text (6 lines)
> > I think this only works if the on-chain keys are Schnorr, right?
>
> We'd use the same curve equation and domain parameters as Bitcoin uses
> currently, but would swap out EC-DSA for EC-Schnorr. So as a result,
> pub/priv keys stay the same, meaning the on-chain keys can be used for
> signing/verifying the multi-sign for channel authentication proofs.

So we'd still be using ECDSA for everything that could go to the bitcoin blockchain, and use Schnorr for all other crypto primitives. Sounds good to me, if we can be certain that reuse across different schemes does not open us to new threats.

Quoted text (7 lines)
> > Separating onion privkey allows rotation; only a win if we get forward
> > secrecy (not a win for this node, as much as for the network as a
> > whole).
>
> Agreed, if we're not initially doing passive (or active) key rotation for
> the onion keys, then coupling the identity and onion keys simplifies the
> code at that level and nixes a few network layer control messages.

I'd argue that rotating the onion key is already valuable in order to limit the shared secret backlog, allowing us to forget them after a rotation, even if we don't have forward secrecy. If we can get forward secrecy as well all the better though :-)

Cheers, Christian

Christian Decker in reply to Christian Decker permalink original

Just a quick update on my side: I have updated the spec as discussed during the milan meetup and dropped the end-to-end payload, since we don't have any good usecase for it currently.

I kept the shared secret backlog for now, since committing the routing information to the payment hash is awkward: either we include the payment hash in each per-hop payload, making it possible to stop a replay immediately, or we add it to the last per-hop payload, at which point only the last hop would be able to identify a replay attack, making it possible to replay and observe traffic patterns. In both cases we'd be increasing the per-hop payload size, which is pretty expensive to do.

Both the C-lightning implementation and the lnd implementations have been adapted and can be used.

Cheers, Christian

On Mon, Oct 3, 2016 at 11:34 PM Christian Decker <decker.christian at gmail.com> wrote:

On Mon, Oct 03, 2016 at 05:21:35PM +0000, Olaoluwa Osuntokun wrote:

Quoted text (6 lines)
> > I think this only works if the on-chain keys are Schnorr, right?
>
> We'd use the same curve equation and domain parameters as Bitcoin uses
> currently, but would swap out EC-DSA for EC-Schnorr. So as a result,
> pub/priv keys stay the same, meaning the on-chain keys can be used for
> signing/verifying the multi-sign for channel authentication proofs.

So we'd still be using ECDSA for everything that could go to the bitcoin blockchain, and use Schnorr for all other crypto primitives. Sounds good to me, if we can be certain that reuse across different schemes does not open us to new threats.

Quoted text (7 lines)
> > Separating onion privkey allows rotation; only a win if we get forward
> > secrecy (not a win for this node, as much as for the network as a
> > whole).
>
> Agreed, if we're not initially doing passive (or active) key rotation for
> the onion keys, then coupling the identity and onion keys simplifies the
> code at that level and nixes a few network layer control messages.

I'd argue that rotating the onion key is already valuable in order to limit the shared secret backlog, allowing us to forget them after a rotation, even if we don't have forward secrecy. If we can get forward secrecy as well all the better though :-)

Cheers, Christian

Olaoluwa Osuntokun in reply to Christian Decker permalink original
Quoted text (2 lines)
> I kept the shared secret backlog for now, since committing the routing
> information to the payment hash is awkward

When we agreed to include the payment hash in the MAC check within the header, I assumed that the packet format wouldn't be modified to include the payment hash (either in the header or e2e payload).

Instead, I envisioned that the payment hash would be a parameter to the packet processing/creation function. When creating or processing the packet, the payment hash would be concatenated to the material being authenticated similar to the "associated data" in AEAD cipher modes. With this scheme, there's no additional data added to the packets, but the payment hash is authenticated as part of packet processing at each hop.

So if an adversary attempts a replay, then they're forced to use the same payment hash, otherwise the packet won't propagate. Assuming all nodes remember all payment hashes, then replay attempts always fail and come at a direct monetary cost to the attacker.

-- Laolu

On Thu, Oct 20, 2016 at 6:41 AM Christian Decker <decker.christian at gmail.com> wrote:

Quoted text (56 lines)
> Just a quick update on my side: I have updated the spec as discussed
> during the milan meetup and dropped the end-to-end payload, since we don't
> have any good usecase for it currently.
>
> I kept the shared secret backlog for now, since committing the routing
> information to the payment hash is awkward: either we include the payment
> hash in each per-hop payload, making it possible to stop a replay
> immediately, or we add it to the last per-hop payload, at which point only
> the last hop would be able to identify a replay attack, making it possible
> to replay and observe traffic patterns. In both cases we'd be increasing
> the per-hop payload size, which is pretty expensive to do.
>
> Both the C-lightning implementation and the lnd implementations have been
> adapted and can be used.
>
> Cheers,
> Christian
>
>
> On Mon, Oct 3, 2016 at 11:34 PM Christian Decker <
> decker.christian at gmail.com> wrote:
>
> On Mon, Oct 03, 2016 at 05:21:35PM +0000, Olaoluwa Osuntokun wrote:
> > > I think this only works if the on-chain keys are Schnorr, right?
> >
> > We'd use the same curve equation and domain parameters as Bitcoin uses
> > currently, but would swap out EC-DSA for EC-Schnorr. So as a result,
> > pub/priv keys stay the same, meaning the on-chain keys can be used for
> > signing/verifying the multi-sign for channel authentication proofs.
>
> So we'd still be using ECDSA for everything that could go to the
> bitcoin blockchain, and use Schnorr for all other crypto
> primitives. Sounds good to me, if we can be certain that reuse across
> different schemes does not open us to new threats.
>
> > > Separating onion privkey allows rotation; only a win if we get forward
> > > secrecy (not a win for this node, as much as for the network as a
> > > whole).
> >
> > Agreed, if we're not initially doing passive (or active) key rotation for
> > the onion keys, then coupling the identity and onion keys simplifies the
> > code at that level and nixes a few network layer control messages.
>
> I'd argue that rotating the onion key is already valuable in order to
> limit the shared secret backlog, allowing us to forget them after a
> rotation, even if we don't have forward secrecy. If we can get forward
> secrecy as well all the better though :-)
>
> Cheers,
> Christian
>
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Christian Decker in reply to Olaoluwa Osuntokun permalink original

On Thu, Oct 20, 2016 at 10:26:07PM +0000, Olaoluwa Osuntokun wrote:

Quoted text (15 lines)
> When we agreed to include the payment hash in the MAC check within the
> header, I assumed that the packet format wouldn't be modified to include the
> payment hash (either in the header or e2e payload).
>
> Instead, I envisioned that the payment hash would be a parameter to the
> packet processing/creation function. When creating or processing the packet,
> the payment hash would be concatenated to the material being authenticated
> similar to the "associated data" in AEAD cipher modes. With this scheme,
> there's no additional data added to the packets, but the payment hash is
> authenticated as part of packet processing at each hop.
>
> So if an adversary attempts a replay, then they're forced to use the same
> payment hash, otherwise the packet won't propagate. Assuming all nodes
> remember all payment hashes, then replay attempts always fail and come at a
> direct monetary cost to the attacker.

Damn, I knew I was forgetting something, thank Laolu for the reminder, I'll add that to the spec and the implementations.

Cheers, Christian

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (6 lines)
>> I kept the shared secret backlog for now, since committing the routing
>> information to the payment hash is awkward
>
> When we agreed to include the payment hash in the MAC check within the
> header, I assumed that the packet format wouldn't be modified to include the
> payment hash (either in the header or e2e payload).

Yep, that was my understanding too.

Thanks! Rusty.