Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

An Alternative Onion-Routing Proposal

10 messages, Dec 14 to 20, 2015. Started by Olaoluwa Osuntokun.

Olaoluwa Osuntokun (4), Rusty Russell (3), Zooko Wilcox-OHearn (2), Douglas Roark

Permalink First message in the Wayback Machine

Olaoluwa Osuntokun permalink original

Hi y'all!!

So I've been drafting up some schemes for the design of onion routing within the Lightning Network myself. Rather than create my own mixing format, and onion routing protocol, I've instead turned to some of the existing academic literature concerning the subject. I found two schemes, the first building upon the other, which seem to fit elegantly into our problem domain, directly solving many problems we've encountered along the way.

The two schemes of interest are first Sphinx[1]: a compact mixing format, and HORNET[2][3], which leverages Sphinx to build a low-latency, high-bandwidth onion routing protocol.

Alright, let's jump into and overview of both schemes!

(heads up, this post is a bit long as it includes a brain dump of ideas I've been been floating around in my head for the past two months or so)

First, I'll give a brief overview of Sphinx. I won't delve into the exact details of the protocol, instead I'll highlight the key insight that allows for *extremely* small mix-headers. If we assume a maximum diameter of 20 hops, and a 16-byte MAC, then a full onion blob weighs in at only 705 bytes! This is considerably smaller (a 4X size reduction) than the 3840 bytes per onion-blob in current proposal. I recommend consulting the paper for the proper specifics. Additionally the paper includes a formal proof of security in the Universal Composability model[4], achieving each of the 4 properties outlined for a secure onion routing protocol in [5].

(btw, don't dismiss figures 1 and 2 in the Sphinx paper. They may look strange, but finally grokking them resulted in a break through allowing me to finish my implementation)

So, at this point, y'all may be wondering how Sphinx achieves such compact mix-headers. Well, Rather, than including a group element to perform DH with for *each* hop in the route, mix-headers in Sphinx only contain a single group element. This single group element is then deterministically re-randomized by each hop in the route, preparing the group element for the hop directly following it.

Here's a brief sketch of the mechanism (covering only the DH aspects):

Say Alice wants to route a payment to Bob (Y_b) over Lightning. Alice
consults her
routing/service table, and finds a route via Carol and Dave. Next, to
create the
mix-header, Alice grabs key-pairs for Carol (Y_c) and Dave (Y_d). She then
generates
an ephemeral DH key-pair (a_0 = g^x) then proceeds to derive a shared
secret
for each hop in the route. Using multiplicative notation, the DH derivation
looks something like this (s = shared key, b = blinding factor):
  * a_0 = g^x,       s_0 = (Y_c)^x,         b_0 = hash(a_0, s_0)
  * a_1 = (a_0)^b_0, s_1 = (Y_d)^x*b_0,     b_1 = hash(a_1, s_1)
  * a_2 = (a_1)^b_1, s_2 = (Y_b)^x*b_0*b_1, b_2 = hash(a_2, s_2)
  ......... continued if more hops were in the route ..........

Alice computes all the blinding factors and shared secrets up front, allowing her to create the mix-header for each hop using the derived hop shared secret to derive subsequent decryption and MAC keys. Each node receives a_{i}, and prepares a_{i+1} for the next hop by re-randomizing the group element using the blinding factor.

The formula for computing the size of a mix-header for a given hop count,
and
security parameter is (ignoring the final message size):
  * p + (2r + 2)s
    * p = pub key size (in bytes, for DH each hop)
    * r = max number of hops
    * s = symmetric key size (in bytes)
So, for 20 hops the size is computed as (with a symmetric key size of 16
bytes):
  * 33 + (2*20 + 2) * 16 = 705 bytes!

445% smaller than the 3840 bytes of the current proposal.

The original version of Sphinx was designed with anonymous mailing in mind.
So the final mix-header to the destination node includes a final
destination
email-address (k-bits), and an Identifier (k-bits) used to generate reply
messages back to the sender. If we remove these from the mix-net, we save
2k-bits arriving at a new formula to compute the mix-header size:
  * p + (2*r*s)
So with 20 hops the size is reduced to:
  * 33 + (2*20*16) = 673 bytes
With this size reduction the, the base64 encoding of a mix-header for two
hops
can fit entirely into a tweet!
  * 33 + (2*2*16) = 97 bytes

However, it occurred to me that the final destination address may be useful in the context of a more hub-and-spoke-y network. In this scheme the payment would be routed to a "shared node", who would then use the destination address to demultiplexing the payment to one of its connected links in a "host:port" fashion.

Finally, Sphinx has built-in protection for replay attacks. Meaning an adversary is unable to force a node to process a previously processed mix-header. It achieves this protection by having all nodes remember every derived shard secret it has ever come across. However, within the paper, the extent of the past with which a node is to recall is unspecified, leading to potentially large storage overhead. However, it's worth noting that the paper recommends frequent key rotation, during which this table may be safely cleared. Additionally, nodes may also employ a decaying bloom-filter/hash-set [6] for use in-between key rotations to create an upper bound on the storage overhead.

With that said, Sphinx is much more compact than the current proposal, carries a formal proof of security, and specifies replay protection.

It was recently brought up in [7], that allowing nodes to use onion routing with Lightning as an end-to-end messaging interface. This is where HORNET comes in. One could use Sphinx's Single-Use-Reply-Blocks to allow the recipient to communicate with the sender after a dummy onion circuit has been set up. However, this introduces some performance considerations, due to Sphinx requiring each hop to perform 2 asymmetric crypto operations (shared secret derivation + group element blinding) before forwarding. HORNET gets around this performance issue by first using Sphinx to set up a duplex onion circuit between sender and receiver, which after set up, only requires nodes to compute purely symmetric crypto operations before forwarding.

Continuing, both Sphinx and the current proposal only provide sender anonymity. Meaning that only the source maintains unlinkability, therefore it learns the destination's location. The addition of HORNET allows both side to retain full unlinkability. HORNET has a built-in, an optional rendezvous protocol, which is a bit similar to the way Hidden Services in TOR work.

With that said, what follows is a brief high-level overview of the HORNET onion-routing protocol (focusing on the initial set up, instead of data transmission).

Unlike Sphinx, which is essentially a "fire-and-forget" onion routing protocol from the view of the sender, HORNET requires a cumulative circuit round-trip as a set up phase before messaging can begin. Once completed, this set up phase creates a duplex onion circuit between the sender and destination, allowing a level of throughput approaching 93 Gb/s as reported experimentation section within the paper.

The primary addition to Sphinx's mix-header format is something they've
dubbed the
Anonymous Header (AHDR). Instead of requiring each node in the mix-net to
store
per-session state (which would prohibit scale in large networks), all
session-state
is instead stored within the onion-packet itself. Therefore, each node only
needs to
maintain a local secret. A full AHDR contains contains a series of
Forwarding
Segments (FSes) for each hop, allowing them to decrypt the per-hop onion,
revealing the next hop in the path. Each FS contains: the next hop in the
route,
a TTL value, and a derived shared secret. A full AHDR has the following
format:
  * (FS, MAC, Onion wrapped FSes)
First, let's go over how a duplex onion circuit is achieved, maintaining
sender
unlinkability (once again, using multiplicative notation):
  * Sender Set Up:
    * The sender obtains the current keys for each hop in the path,
constructing
      a forward, and backwards path (the reverse of the forward path).
    * The sender then generates a per-session ephemeral DH key-pair: (x,
g^x)
    * Using the Sphinx protocol described above, then sender then generates
two
      Sphinx mix-headers: one for the forwards path, and another for the
backwards
      path. At this point, the source has derived shared secrets for each
node along
      both paths.
    * The message payload (SP) of the forward Sphinx mix-header (encrypted
to the
      destination), is the backwards Sphinx mix-header which allows the
destination
      to reply to the sender.
    * The Sphinx mix-header (SHDR) is then extended with two additions:
      * A empty list of FSes (P_fs), which each intermediate node can
populate
        without learning the total path length, nor their position within
the
        route.
      * The Sphinx per-hop MAC is also extended over the HORNET Common
Header
        (CHDR): (packet type, hops, TTL)
    * The sender then sends this set up packet to the first node in the
route:
      (CHDR, SHDR, SP, P_fsf)
  * Intermediate Node Set Up:
    * Upon receipt of the Sphinx packet, each node processes it as normal
      (according to Sphinx): deriving the shared secret, recovering the
next hop's
      ID, and re-blinding the group element.
    * Next, the node verifies the next-hop is correct, and that the packet
      hasn't yet expired according to its TTL.
    * In order to provide forward secrecy for the messaging phase,
      the node then derives a new DH key-pair (y, g^y), and then derives a
new
      shared secret to be included within the FS: (a_i)^y
    * Using it's local shared secret (SV_i), the node creates a FS that
only it
      can decrypt, adding this to the FS payload. This payload entry
additionally
      includes the new ephemeral DH-key pair (y, g^y), allowing the source
to derive
      the shared secret which will be used for the FS's MAC (and also when
transmitting data).
    * Finally the node re-assembles the packet (CHDR', SHDR', SP, P_fsf'),
and
      forwards it to the next hop.
  * Destination Set Up:
    * The destination initially processes the packet identically to the
intermediate
      nodes described above.
    * It then decrypts the Sphinx payload, uncovering the backwards SHDR.
The node
      then creates a new payload each of the completed FSes in the payload.
      destined to the source.
    * At this point, the destination has no knowledge of any of the derived
shared
      secrets, other than the one it has derived with the source.
    * Next, it creates a new FS list P_fsb, to collect FSes along the
backwards path.
    * Finally, it creates the backwards set up packet (CHDR, SHDR, SP_b,
P_fsb), and
      sends it to the first node on the backwards path.
    * Each intermediate node then processes the backwards packet just as
before.
  * Data Transfer (brief overview, consult the paper for proper details)
    * The source node then recovers the Sphinx payload SP_b, recovering the
      forwarding segments for the forward (P_fsf) and backwards path (P_fsb)
    * At this point, set up has been completed!
    * The source node then constructs two initial AHDR's, one so it can
send
      messages to the destination via the circuit, and the other which will
      allow the destination to reply to the source.
    * After the first message from S -> D, D obtains the backwards AHDR,
      allowing it to reply without knowing the actual route.

The, the following modifications are necessary to achieve sender-receiver unlinkability as described earlier. The modification to allow send-receiver unlinkability is relatively straight forward. It involves nested AHDRs. Lets say Alice wants to send a message (or a payment in our case) to Bob while maintaining full unlinkability. Bob will first need to select a rendezvous point (RP), let's call him Rodriguez. Bob then executes the set up protocol detailed above between himself and Rodriguez. As a result, Bob obtains a AHDR allowing Rodriguez to route messages (via some specified path) to Bob (R -> B). Bob then publishes this AHDR_rb to some "public bulletin board", or in the case that Alice has a hidden service set up, directly to Alice. Alice then obtains the AHDR_rb, routing as normal to Rodriguez, but then includes AHDR_rb, nested within the regular AHDR_ar (Alice -> Bob). Once this mix-header reaches Bob, he recovers the nested AHDR, allowing him to complete the route to Bob. Additionally, its possible for Bob to specify several rendezvous points, allowing Alice to select the closest/cheapest route to her. As a side effect, the usage of this nested AHDR doubles the bandwidth required for each node to forward along the path.

With this duplex onion route set up (with or without the RP), Alice can send a message to Bob, asking for R (along with other payment details), then propagate HTLCs along the full path in order to pay Bob. In order to mitigate the potential DoS attacks introduced by adding a message layer for control signals, we can either introduce a payment system (as suggested in [8]), or a required Hashcash challenge (avoiding SHA-256, using either SHA-3 or BLAKE2). However, seeing as we'd like to maintain the responsiveness of the network, I'm personally leaning towards payments (if we do in fact deem in network messaging attractive).

Okay, so that concludes my first post on the mailing list! So at this point y'all may be wondering where the implementation I mentioned above is? Well, so far I have a working implementation of Sphinx by itself, not yet integrating the aspects of HORNET, but, it's not yet publicly released.

We (me+Tadge+Joseph) are planning on publicly releasing our in progress implementation of Lightning, sometime near the end of this month (December) :).

1. http://www.cypherpunks.ca/~iang/pubs/Sphinx_Oakland09.pdf 2. http://arxiv.org/pdf/1507.05724v1.pdf (HORNET w/ forward secrecy) 3. http://www.scion-architecture.net/pdf/2015-HORNET.pdf 4. https://eprint.iacr.org/2000/067.pdf 5. http://cs.brown.edu/~anna/papers/cl05-full.pdf 6. https://moderncrypto.org/mail-archive/messaging/2015/001906.html 7. https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/onion-routing-for-messages#m-00ee959b 8. https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/onion-routing-for-messages#m-e0586024

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (1 line)
> Hi y'all!!

Hi Olaoluwa, welcome to the list!

        I've yet to read the papers, so forgive if I've made an error
below.
Quoted text (9 lines)
> First, I'll give a brief overview of Sphinx. I won't delve into the exact
> details of the protocol, instead I'll highlight the key insight that allows
> for
> *extremely* small mix-headers. If we assume a maximum diameter of 20 hops,
> and a
> 16-byte MAC, then a full onion blob weighs in at only 705 bytes! This is
> considerably smaller (a 4X size reduction) than the 3840 bytes per
> onion-blob in
> current proposal.

Not sure where these numbers come from? The current header overhead is sha256 (32 bytes) + pubkey (33 bytes), or 1300 bytes. (Don't be confused by the current test implemenation which doesn't serialize the pubkey).

If we were to cut to a 16 byte MAC (which seems unwise), that would be 980 bytes.

Quoted text (22 lines)
> Alice computes all the blinding factors and shared secrets up front,
> allowing
> her to create the mix-header for each hop using the derived hop shared
> secret
> to derive subsequent decryption and MAC keys. Each node receives a_{i}, and
> prepares a_{i+1} for the next hop by re-randomizing the group element using
> the
> blinding factor.
>
> The formula for computing the size of a mix-header for a given hop count,
> and
> security parameter is (ignoring the final message size):
>   * p + (2r + 2)s
>     * p = pub key size (in bytes, for DH each hop)
>     * r = max number of hops
>     * s = symmetric key size (in bytes)
>
> So, for 20 hops the size is computed as (with a symmetric key size of 16
> bytes):
>   * 33 + (2*20 + 2) * 16 = 705 bytes!
>
> 445% smaller than the 3840 bytes of the current proposal.

Or, if we're standarizing on ChaCha20, with a 32-byte key:

   33 + (2 * 20 + 2) * 32 = 1377 bytes.
Quoted text (10 lines)
> The original version of Sphinx was designed with anonymous mailing in mind.
> So the final mix-header to the destination node includes a final
> destination
> email-address (k-bits), and an Identifier (k-bits) used to generate reply
> messages back to the sender. If we remove these from the mix-net, we save
> 2k-bits arriving at a new formula to compute the mix-header size:
>   * p + (2*r*s)
>
> So with 20 hops the size is reduced to:
>   * 33 + (2*20*16) = 673 bytes

Or 33 + 2 * 20 * 32 = 1313 bytes for ChaCha20.

Quoted text (4 lines)
> With this size reduction the, the base64 encoding of a mix-header for two
> hops
> can fit entirely into a tweet!
>   * 33 + (2*2*16) = 97 bytes

Now, *that* is an important metric :)

More important than the size is the idea of reusing a proven design over an ad-hoc one, so we should use this anyway.

HORNET seems a bit over-the-horizon for now, so I'll leave that reply for a future message :)

Quoted text (3 lines)
> We (me+Tadge+Joseph) are planning on publicly releasing our in progress
> implementation of Lightning, sometime near the end of this month (December)
> :).

Great! Let's argue about protobufs and ChaCha20 vs AES before then :)

Thanks! Rusty.

Olaoluwa Osuntokun in reply to Rusty Russell permalink original
Quoted text (6 lines)
>
> Not sure where these numbers come from?  The current header overhead is
> sha256 (32 bytes) + pubkey (33 bytes), or 1300 bytes.  (Don't be
> confused by the current test implementation which doesn't serialize the
> pubkey).
>

Hmm, I pulled those numbers from here: https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/onion-routing-strawman-proposal#m-c3d351f5: "That's a fixed 3840 bytes; each node decrypts and removed the tail entry, then prepends padding." Perhaps there's been a newer iteration I've missed, or the 3.8K bytes isn't the true serialized size.

Quoted text (1 line)
> If we were to cut to a 16 byte MAC (which seems unwise)

With Poly1035 (which takes 32-byte key and produces a 16-byte tag), forged messages are rejected with a probability of 1-(n/(2^102)) for a 16n-byte message[1]. Since the MAC is computed over the 656 byte (20 hops, s=16) routing-info portion (the onion-wrapped part of the mix header), forged tags will be rejected with a probability of 1-(656/(2^102)), which seems okay to me.

Quoted text (4 lines)
> Or, if we're standarizing on ChaCha20, with a 32-byte key:
>
>    33 + (2 * 20 + 2) * 32 = 1377 bytes.
>

Apologies for the ambiguity, but, the "(..)*16" (s) more accurately refers to the size of the HMAC and node ID's. So if using ChaCha for a stream cipher, and Poly1035 for MACs rather than AES-CTR + a truncated SHA-256-HMAC, the size remains the same. Either AES-CTR or ChaCha20 are valid candidates for the required stream-cipher in the Sphinx construction.

As an side, my current implementation uses AES-CTR as a stream cipher, and a truncated SHA-256-HMAC for the MAC (s=20). It was written before we cozied up to ChaCha20-Poly1035. I'll be porting it over to ChaCha-Poly3015 once I tick off some more high-priority items from my TODO list (assuming we're comfortable with 16-byte node ID's, node ID's are used to map to a node's current DH-key (id -> key)).

HORNET seems a bit over-the-horizon for now

Quoted text (1 line)
>

Agreed! Sphinx should be sufficient for now.

Great! Let's argue about protobufs and ChaCha20 vs AES before then :)

Quoted text (1 line)
>

Perhaps in a new thread :)

Oh, and also, we've come up with a slight variation on the current proposed p2p crypto handshake. It builds off of the current method (ephemerals first, etc.). I should get around to posting it to the ML sometime tomorrow+1 (I'd like to make sure it's sound).

1. https://tools.ietf.org/html/rfc7539 (Section 4)
Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (12 lines)
>>
>> Not sure where these numbers come from?  The current header overhead is
>> sha256 (32 bytes) + pubkey (33 bytes), or 1300 bytes.  (Don't be
>> confused by the current test implementation which doesn't serialize the
>> pubkey).
>>
>
> Hmm, I pulled those numbers from here:
> https://www.learnbitcoin.com/archive/lists/lightning-dev/t/2015/onion-routing-strawman-proposal#m-c3d351f5:
> "That's a fixed 3840 bytes; each node decrypts and removed the tail entry,
> then prepends padding." Perhaps there's been a newer iteration I've missed,
> or the 3.8K bytes isn't the true serialized size.

Hi Roasbeef!

Ah, that includes payloads for each node, though, not just the headers. There's stuff in there for Future Use.

Quoted text (8 lines)
>> If we were to cut to a 16 byte MAC (which seems unwise)
>
> With Poly1035 (which takes 32-byte key and produces a 16-byte tag), forged
> messages are rejected with a probability of 1-(n/(2^102)) for a 16n-byte
> message[1].  Since the MAC is computed over the 656 byte (20 hops, s=16)
> routing-info portion (the onion-wrapped part of the mix header), forged
> tags will be rejected with a probability of 1-(656/(2^102)), which seems
> okay to me.

Ah, I hadn't appreciated that poly1035 was 128 bit tags already! Let's argue it in the crypto thread which we'll start. I'm happy to the crypto experts debate AES-CTR + HMAC-SHA-256 (which I used) vs ChaCha20+poly1035.

It's a simple change, code-wise.

Quoted text (17 lines)
>> Or, if we're standarizing on ChaCha20, with a 32-byte key:
>>
>>    33 + (2 * 20 + 2) * 32 = 1377 bytes.
>>
>
> Apologies for the ambiguity, but, the "(..)*16" (s) more accurately refers
> to the size of the HMAC and node ID's. So if using ChaCha for a stream
> cipher, and Poly1035 for MACs rather than AES-CTR + a truncated
> SHA-256-HMAC, the size remains the same. Either AES-CTR or ChaCha20 are
> valid candidates for the required stream-cipher in the Sphinx construction.
>
> As an side, my current implementation uses AES-CTR as a stream cipher, and
> a truncated SHA-256-HMAC for the MAC (s=20). It was written before we
> cozied up to ChaCha20-Poly1035. I'll be porting it over to ChaCha-Poly3015
> once I tick off some more high-priority items from my TODO list (assuming
> we're comfortable with 16-byte node ID's, node ID's are used to map to a
> node's current DH-key (id -> key)).

128 bits definitely seems a bit tight for node ids: I assumed a full bitcoin EC pubkey in my current implementation.

Quoted text (4 lines)
> HORNET seems a bit over-the-horizon for now
>>
>
> Agreed! Sphinx should be sufficient for now.

Matts was really interested in sending messages over LN, though, so no doubt he'll be salivating at the idea of extending in this direction :)

Quoted text (9 lines)
> Great!  Let's argue about protobufs and ChaCha20 vs AES before then :)
>>
>
> Perhaps in a new thread :)
>
> Oh, and also, we've come up with a slight variation on the current proposed
> p2p crypto handshake. It builds off of the current method (ephemerals
> first, etc.). I should get around to posting it to the ML sometime
> tomorrow+1 (I'd like to make sure it's sound).

Sure, let's discuss that. I want to modify the handshake anyway to include a <len> prefix (like every other message). This lets us upgrade the crypto later, by appending a key for a different system.

Quoted text (1 line)
> 1. https://tools.ietf.org/html/rfc7539 (Section 4)

That's a definite MUST READ for any implementer...

Thanks! Rusty. PS. Are we having fun yet?

Zooko Wilcox-OHearn in reply to Rusty Russell permalink original

I'm so happy to see this direction of re-using prior work — SPHINX — instead of inventing a new wheel. Thank you, roasbeef!

On Tue, Dec 15, 2015 at 11:38 PM, Rusty Russell <rusty at rustcorp.com.au> wrote:

Quoted text (2 lines)
>
> I'm happy to the crypto experts debate AES-CTR + HMAC-SHA-256 (which I used) vs ChaCha20+poly1035.

I'd prefer ChaCha20+poly1305.

Quoted text (2 lines)
> 128 bits definitely seems a bit tight for node ids: I assumed a full
> bitcoin EC pubkey in my current implementation.

I have a pretty good sense of how risky short node ids are, but I don't have a good idea of how costly long node ids are in this context. I also don't know how many node ids are likely to exist in the long-run, successful scenario. 10⁹? 10¹²? Not more than 10¹⁵!

I'd suggest 192-bit nodeids, based on such musings as:

* http://ecrypt-eu.blogspot.de/2015/11/break-dozen-secret-keys-get-million.html
* http://www.keylength.com/en/compare/

I feel confident that 192-bit nodeids are safe enough. Whether they are, practically speaking, more efficient than 256-bit nodeids I'll leave up to you to answer.

Quoted text (2 lines)
> Matts was really interested in sending messages over LN, though, so no
> doubt he'll be salivating at the idea of extending in this direction :)

☺

Quoted text (7 lines)
> Sure, let's discuss that.  I want to modify the handshake anyway to
> include a <len> prefix (like every other message).  This lets us upgrade
> the crypto later, by appending a key for a different system.
>
>> 1. https://tools.ietf.org/html/rfc7539 (Section 4)
>
> That's a definite MUST READ for any implementer...

+1! Please don't assume that your endpoint can reliably update persistent state, and if at all possible don't assume that your platform's CSPRNG is good. This is the weakest point in the system IMHO, based on empirical evidence.

A good way to strengthen this weak point is to mix persistent state, *and* platform CSPRNG, *and* mix in unique and/or private information from the current protocol state, so that if any of those one is good then your nonce is unique and your key unguessable.

Quoted text (1 line)
> PS.  Are we having fun yet?

YES!

Regards,

Zooko

Olaoluwa Osuntokun in reply to Zooko Wilcox-OHearn permalink original
Quoted text (8 lines)
>
>
> >
> > I'm happy to the crypto experts debate AES-CTR + HMAC-SHA-256 (which I
> used) vs ChaCha20+poly1035.
>
> I'd prefer ChaCha20+poly1305.
>

Welcome aboard the Cha Cha Train! [1]

Quoted text (21 lines)
>
> > 128 bits definitely seems a bit tight for node ids: I assumed a full
> > bitcoin EC pubkey in my current implementation.
>
> I have a pretty good sense of how risky short node ids are, but I
> don't have a good idea of how costly long node ids are in this
> context. I also don't know how many node ids are likely to exist in
> the long-run, successful scenario. 10⁹? 10¹²? Not more than 10¹⁵!
>
> I'd suggest 192-bit nodeids, based on such musings as:
>
> *
> http://ecrypt-eu.blogspot.de/2015/11/break-dozen-secret-keys-get-million.html
>
> * http://www.keylength.com/en/compare/
>
> I feel confident that 192-bit nodeids are safe enough. Whether they
> are, practically speaking, more efficient than 256-bit nodeids I'll
> leave up to you to answer.
>
>

Currently, in our code, node ID's take two forms: either the hash160 (Bitcoin style) of a node's current pub-key or the raw serialized pub-key itself. This is done such that "nodeID at host" locators explicitly provide a level of backwards (p2pkh) compatibility for end wallets that are unable to establish a connection in a timely manner.

Within the Sphinx mix-header, I think we should be safely able to truncate this (the hash160) to 16-bytes. In the case of a collision, the onion-route propagation across the incorrect node will simply fail, as it won't be able to properly derive the shared secret.

Otherwise, we'd be forced to ditch chacha20+poly3015 for AES-CTR+SHA-256-HMAC within Sphinx if serialized pub-keys are used for node ID's in the routing info.

Quoted text (4 lines)
> > Matts was really interested in sending messages over LN, though, so no
> > doubt he'll be salivating at the idea of extending in this direction :)
>
>

I can't blame him! Utilizing HORNET's rendezvous protocol will allow for a high level of privacy for both sender *and* receiver.

Quoted text (7 lines)
>
> > Sure, let's discuss that.  I want to modify the handshake anyway to
> > include a <len> prefix (like every other message).  This lets us upgrade
> > the crypto later, by appending a key for a different system.
> >
>
>

Sure. If we end up going with cha cha, I'd like us to adopt the practice of encrypting the packet lengths with a separate key (and a new instance of chacha20) similar to openssh's chacha20-poly3015 specification[2]. With this construction, packet-length+packet-payload remain confidential.

Quoted text (3 lines)
> > PS.  Are we having fun yet?
>
>

Definitely! On my Winter Break atm, so getting a chance to catch up on all the fun I missed out on during this past quarter :)

1. https://www.youtube.com/watch?v=xGQ5OOyuaxs 2. https://tools.ietf.org/html/draft-josefsson-ssh-chacha20-poly1305-openssh-00

-- Laolu

Zooko Wilcox-OHearn in reply to Olaoluwa Osuntokun permalink original

On Thu, Dec 17, 2015 at 6:08 PM, Olaoluwa Osuntokun <laolu32 at gmail.com> wrote:

Quoted text (6 lines)
>
> Currently, in our code, node ID's take two forms: either the hash160
> (Bitcoin style) of a node's current pub-key or the raw serialized pub-key
> itself. This is done such that "nodeID at host" locators explicitly provide a
> level of backwards (p2pkh) compatibility for end wallets that are unable to
> establish a connection in a timely manner.

I'm afraid I don't understand how this backwards-compatibility works, so if it is important that I understand it please point me to docs or explain it more.

Quoted text (4 lines)
> Within the Sphinx mix-header, I think we should be safely able to truncate
> this (the hash160) to 16-bytes. In the case of a collision, the onion-route
> propagation across the incorrect node will simply fail, as it won't be able
> to properly derive the shared secret.

Do you mind explaining why you think this is safe? I don't understand how it could be safe, in the case that the attacker knows a private key that maps to the same 128-bit nodeid as a user's private key does.

Quoted text (3 lines)
> Otherwise, we'd be forced to ditch chacha20+poly3015 for
> AES-CTR+SHA-256-HMAC within Sphinx if serialized pub-keys are used for node
> ID's in the routing info.

I don't understand why the use of entire public keys instead of possibly-truncated hashes of public keys would force a decision about which cipher and MAC to use.

Sincerely,

Zooko

Douglas Roark in reply to Zooko Wilcox-OHearn permalink original

Hello. I wanted to throw an idea out into the open and see if anybody had any thoughts.

Earlier this year, I worked on an effort to attach payment data to DNSSEC via DANE[1]. This included working on an RFC draft[2] that explained the concept. The idea was to use the DNSSEC system as a database of sorts that could get trusted payment info out to users. If you wanted to pay Top Quality Widgets for their goods, you could look them up on the DNS system and be reasonably certain that you were actually paying them. The setup was designed to allow for all manner of payment methods, with ACH and Bitcoin being the first two to be supported.

(Note that the effort eventually fell by the wayside before a much-improved second RFC draft could get out the door; the first draft barely touches Bitcoin at all. If anybody's interested, I can provide a basic outline of what was going to be in it, at least on the Bitcoin side.)

I'm wondering what others think of this idea, and how it could apply to Lightning. The main hangup out the gate would be that the payment info has to be attached to a domain (e.g., topqualitywidgets.com) that supports the scheme. This would, in all likelihood, mean custom domains would be needed where support for the scheme was explicitly included. This could be tricky.

Despite that hangup, I think this is an interesting scheme that may be worth exploring, perhaps in a modified form. We had the scheme set up where, on the Bitcoin side, the keys were really flexible and could support things like per-user payment addresses (i.e., static addresses weren't mandatory). I thought it was pretty slick, but hey, I'm biased. :)

One related-but-separate thing to keep in mind is that, if there is any sort of ID at host scheme deployed in Lightning, it really ought to support internationalization. [3] suggests taking the ID and hashing it with SHA-256.

Any thoughts? I really like the idea of having some sort of quasi-permanent method for storing data without having to rely on a complicated scheme to find other nodes in the network. It should be optional, of course, and should work alongside any mandatory schemes to find other users on the network.

Thanks.

[1] https://en.wikipedia.org/wiki/DNS-based_Authentication_of_Named_Entities [2] https://tools.ietf.org/html/draft-wiley-paymentassoc-00 [3] https://tools.ietf.org/html/draft-ietf-dane-smime-09

- -- - --- Douglas Roark Cryptocurrency, network security, travel, and art. https://onename.com/droark joroark at vt.edu PGP key ID: 26623924

Olaoluwa Osuntokun in reply to Zooko Wilcox-OHearn permalink original
Quoted text (6 lines)
>
>
> I'm afraid I don't understand how this backwards-compatibility works,
> so if it is important that I understand it please point me to docs or
> explain it more.
>

So we don't have any docs out (yet). But the general ideas arises from considering the following scenario: an edge wallet wishes to send funds over lightning to 49hwYWYV26Qgym2n1GnpgxBffhKf at roasbeef.computer. Assuming we're not use HORNET for payment related messages, the wallet attempts to connect directly to roasbeef.computer but is unable to. As a fallback, the wallet simply decodes the ID from base58, appends the checksum, adds a version byte, and then sends the coins to the resulting address.

Essentially, the idea is to have an easy mechanism for a graceful fallback to regular on-chain Bitcoin transactions. But, it's really just a half-baked idea at this point.

Quoted text (4 lines)
Do you mind explaining why you think this is safe? I don't understand
> how it could be safe, in the case that the attacker knows a private
> key that maps to the same 128-bit nodeid as a user's private key does.
>

Sure. Also, I'm referring to colliding public-key hashes. So for a moment let's view the network as essentially having two namespaces: global vs local. It's not a requirement that the local namespace be of lower cardinality than the global namespace. However, in the case of 16-byte local (mix-net) ID, and 32-byte global ID (LN) it is, therefore collisions are more frequent. In practice, I think this is safe because in the case a global node ID conflicts with the local mix-net ID, it doesn't undermine the propagation of an HTLC, since only one node will be able to successfully check the MAC, and unwrap the mix-header for the next hop.

Here's an illustration:

Say Alice wishes to send funds to Dave, and her channel sub-graph looks
like this:
                 Estelle
               /
Alice -- Bob
                \
                Carol  - Dave

Alice collects the necessary public keys for the route: Bob -> Carol -> Dave. She then generates the Sphinx mix-header for the route. As a step in the process she generates 16-byte local node ID's for the "next-hop" part of each node's mix-header. She then sends the mix-header to Bob, the first hop. However, unbeknownst to Alice, the 16-byte ID of Estelle's public-key collides with Carol's ID. Bob get's the mix-header, and processes it as normal: checks the MAC, re-blinds group element, and finally peels off layer from nested mix-header. Bob then realizes there's a collision in the local namespace. So he first tries to send the mix-header to Estelle first. Estelle rejects the mix-header because she's unable to check the MAC since her derived shared secret isn't the one Alice computed for this hop. Bob gets this error message, so he instead forwards it to Carol, who accepts, resulting in everything continuing as normal.

To Estelle it just looks like Bob computed the mix-header incorrectly, or simply forwarded to the wrong node.

I think that's okay (there may be something I'm overlooking)?

Quoted text (9 lines)
> > Otherwise, we'd be forced to ditch chacha20+poly3015 for
> > AES-CTR+SHA-256-HMAC within Sphinx if serialized pub-keys are used for
> node
> > ID's in the routing info.
>
> I don't understand why the use of entire public keys instead of
> possibly-truncated hashes of public keys would force a decision about
> which cipher and MAC to use.
>

Sphinx requires that the mix-net node ID's be the same size as the MAC within the mix-header. So if node ID's in the mix-net were 32-bytes, then we couldn't use poly3015 to generate tags since its tag size is 16-bytes.

-- Laolu

Rusty Russell in reply to Olaoluwa Osuntokun permalink original

Olaoluwa Osuntokun <laolu32 at gmail.com> writes:

Quoted text (4 lines)
> Sure. If we end up going with cha cha, I'd like us to adopt the practice of
> encrypting the packet lengths with a separate key (and a new instance of
> chacha20)  similar to openssh's chacha20-poly3015 specification[2]. With
> this construction, packet-length+packet-payload remain confidential.

Nice! While timing and packet boundary measurement will probably be quite effective at determining sizes anyway, let's not make it easy.

Note that we have to handle some limited re-transmission, due to nodes going down. The protocol assumes nodes store things persistently, but of course there can be packet loss / connection issues.

Since our protocol is basically command/response, a node should respond to retransmission by retransmitting the response. (There are a few corner cases where we need to re-xmit more than one, but you get the idea).

Cheers, Rusty.