Onion Routing

Privacy and routing in Lightning

Intermediate

"Privacy is not secrecy. A private matter is something one doesn't want the whole world to know, but a secret matter is something one doesn't want anybody to know."

Eric Hughes, Cypherpunk Manifesto1993

A Note from Satoshi

"When designing Bitcoin, one of my core principles was pseudonymity. I wanted to create a system where financial transactions wouldn't expose users' real-world identities, but would still maintain a transparent ledger. However, I recognized that a fully transparent blockchain means transaction patterns can potentially identify users over time.

Onion routing, a technology pioneered by the cypherpunks and deployed in the Tor network, represented an elegant solution to this challenge when applied to payment routing. By encrypting payment information in multiple layers that can only be peeled away one at a time, Lightning's implementation of onion routing ensures that no single node in a payment path can determine both the sender and recipient.

This approach brilliantly balances the need for routing information with the preservation of user privacy. It's a testament to the cypherpunk ethos that has always been at the heart of Bitcoin: using cryptography to protect individual liberty in the digital age."

The Privacy Challenge in Payment Networks

While Bitcoin offers pseudonymity, its public ledger means all transactions are visible to everyone. The Lightning Network faces a different privacy challenge: how to route payments across multiple nodes without revealing sensitive information about who is paying whom.

Privacy Concerns in Payment Routing

In Traditional Payment Networks
  • Intermediaries Know All: Every entity in the payment path knows the sender, recipient, and amount
  • Data Collection: Payment processors aggregate and sell transaction data
  • Surveillance: Financial institutions monitor and report transaction patterns
  • Censorship: Centralized hubs can block payments to specific recipients
In Distributed Networks
  • Path Information: Route information must be shared, but can expose user behavior
  • Network Analysis: Flow analysis can identify payment patterns even without direct identification
  • Selective Privacy: Need to reveal some information to intermediate nodes for routing
  • Balance Between Privacy and Functionality: Complete privacy can harm routing efficiency
Historical Context

"The development of onion routing dates back to the mid-1990s, when U.S. Naval Research Laboratory researchers created the concept to protect intelligence communications. The technology was later refined and became the foundation of the Tor network in the early 2000s. Lightning Network's adoption of onion routing demonstrates how cryptographic innovations continue to cross-pollinate across different privacy-preserving systems."

Onion Routing: A Technical Deep Dive

Onion routing in the Lightning Network is implemented via the Sphinx packet format, a specialized cryptographic construction designed to ensure privacy while facilitating payment routing across multiple hops.

The Sphinx Packet Format

Sphinx is a cryptographic packet format with several key privacy-preserving properties:

Fixed Size

All Sphinx packets are the same size (1300 bytes) regardless of route length, preventing size-based correlation analysis. Even as layers are peeled away, the packet maintains the same size.

Ephemeral Keys

Each packet uses ephemeral session keys for encryption, ensuring that even repeated payments between the same parties look completely different at the packet level.

Per-Hop Payloads

Each node can only decrypt the information meant for it, which includes routing instructions to the next node and any specific handling requirements.

Replay Protection

Sphinx includes mechanisms to prevent replay attacks, where an attacker might try to send the same packet multiple times to analyze responses or drain funds.

Sphinx Packet Structure
Version (1 byte)
Public Key (33 bytes)
HMAC (32 bytes)
Routing Info (1234 bytes)

The Routing Info field contains encrypted data for each hop, with a unique structure that prevents intermediary nodes from determining how many hops remain or where they are in the route.

The Onion Routing Process

1

Route Construction and Encryption

  1. Select Route: The sender identifies a viable path through the network based on capacity, fees, and reliability.
  2. Create Session Key: The sender generates a random session key for this payment.
  3. Layered Encryption: Starting with the final recipient, the sender constructs the packet by:
    • Creating a shared secret with each node using ECDH (Elliptic Curve Diffie-Hellman)
    • Encrypting each hop's payload with its corresponding shared secret
    • Encrypting all subsequent hops' data
    • Working backwards through the route
2

Processing at Each Hop

  1. Receive Packet: Node receives the Sphinx packet and extracts the ephemeral public key.
  2. Derive Shared Secret: Node uses its private key and the packet's public key to compute the shared secret.
  3. Decrypt Own Layer: Using the shared secret to derive decryption keys, the node:
    • Verifies the HMAC to ensure packet integrity
    • Decrypts its routing information
    • Learns the next-hop node identifier
    • Discovers amount to forward and any fees to collect
  4. Blind the Packet: Performs cryptographic operations that effectively "peel" its layer while maintaining packet size.
3

Final Recipient Processing

  1. Decrypt Final Layer: The recipient node decrypts its layer of the onion.
  2. Identify Payment: The inner payload contains a payment hash that corresponds to an invoice the recipient previously created.
  3. Claim Payment: By releasing the preimage (the secret that hashes to the payment hash), the recipient can claim the payment.
  4. Backwards Settlement: The preimage travels back through the route, allowing each node to claim its incoming HTLC.

Visualizing Onion Routing

Sender
Node A
Node B
Recipient
Complete Onion Packet

All routing data encrypted in multiple layers

First Layer Decrypted

Node A peels its layer and forwards

Second Layer Decrypted

Node B peels its layer and forwards

Final Payload Reached

Recipient accesses payment information

Information Visible to Each Party

NodeKnows SenderKnows RecipientKnows Full RouteKnows Payment Amount
SenderYes (self)YesYesYes
Node ASees previous hopNoNoSees forward amount
Node BNoSees next hopNoSees forward amount
RecipientNoYes (self)NoYes

Each node in the route only has partial information, preserving the privacy of the overall payment.

Advanced Privacy Techniques

Beyond basic onion routing, the Lightning Network incorporates additional privacy-enhancing techniques:

Amount Blinding

To prevent amount correlation attacks, the Lightning Network supports techniques to obscure the exact payment amount:

  • Basic Fee Obfuscation: Each hop charges a fee, so the amount decreases slightly at each step, making perfect correlation harder
  • Variable-size HTLCs: Adding random amounts to payments to obscure the true value
  • Multi-part Payments (MPP): Breaking a payment into multiple smaller payments that take different routes

"Splitting payments into random-sized chunks across multiple routes creates a form of financial chaff that significantly increases the difficulty of transaction analysis."

Timing Obfuscation

Timing analysis can potentially link payments as they move through the network. Several techniques mitigate this risk:

  • Hold Time Randomization: Nodes can add random delays before forwarding payments to break timing correlations
  • Parallel Path Selection: Using multiple paths simultaneously creates timing ambiguity
  • Payload Padding: Adding random data to ensure all Sphinx packets look identical regardless of position in route

"Advanced timing obfuscation techniques draw inspiration from mix networks used in high-security communication systems, applying these concepts to financial transactions."

Route Randomization

Selecting unpredictable routes further enhances privacy by preventing pattern analysis:

  • Random Route Selection: Choosing different paths for payments even to the same recipient
  • Extra Hop Insertion: Adding additional hops beyond the shortest path to increase privacy
  • Trampoline Routing: Delegating partial route selection to trusted intermediate nodes

"By introducing randomness and unpredictability into routing decisions, the network creates plausible deniability for all participants, making traffic analysis substantially more complex."

Rendezvous Routing

A proposed advanced technique for sender-recipient privacy:

  • Blind Meeting Points: Sender and recipient each choose part of the route, meeting at an intermediate rendezvous point
  • Two-sided Anonymity: Neither sender nor recipient needs to know the other's network location
  • Invoice Privacy: Enhanced with blinded paths that hide recipient node information

"Rendezvous routing represents the cutting edge of Lightning Network privacy research, potentially offering privacy guarantees comparable to those of advanced anonymity networks."

Privacy Challenges and Limitations

While onion routing provides strong privacy guarantees, several challenges and attack vectors remain:

Known Limitations

Timing Analysis

An observer controlling multiple nodes in the network might correlate timing of incoming and outgoing payments, especially in a low-traffic network. This is most effective if the attacker controls nodes at both ends of a route segment.

Balance Probing

An attacker can send probe payments to determine channel balances, revealing information about payment flows. This works by attempting payments of different sizes and observing which ones succeed or fail.

Channel Graph Analysis

The Lightning Network's public channel graph reveals connectivity patterns. While individual payments are private, the network structure itself is public, which can be used for probabilistic route analysis.

Invoice Correlation

Standard Lightning invoices contain routing hints that might reveal the recipient's node or channel information. While this helps with routing, it can reduce privacy if invoices are leaked or shared publicly.

Technical Insight

"The most effective attacks against onion routing come from adversaries who can observe multiple points in the network. This is the same challenge faced by Tor and other privacy networks. Increasing network density and transaction volume helps mitigate these risks by creating more 'noise' that makes correlation harder."

Future Privacy Enhancements

The Lightning Network community continues to research and implement enhanced privacy features:

Blinded Paths

Allows recipients to include encrypted routing information in invoices without revealing their node identity or network location.

TOR Integration

Running Lightning nodes over TOR adds an additional layer of network-level privacy, hiding IP addresses and physical locations.

Trampoline Payments

Allows lightweight clients to delegate route finding to trusted nodes while still maintaining payment privacy.

Private Channels

Channels that aren't announced to the public network, providing additional privacy for direct connections between trusted parties.

Each new privacy enhancement represents a trade-off between privacy, efficiency, and usability. The Lightning Network's flexible architecture allows for ongoing innovation in this area.

Satoshi's Perspective

"The privacy innovations in Lightning's onion routing reflect the core ethos of Bitcoin: using cryptography creatively to solve problems that once required trusted third parties. In Bitcoin's blockchain, pseudonymity was the best we could achieve while maintaining a public ledger. With Lightning, we approach true transactional privacy.

I find it fascinating how the Lightning Network combines concepts from different cryptographic domains—payment channels from Bitcoin, onion routing from privacy networks like Tor, and threshold cryptography from secure multi-party computation. This cross-pollination of ideas is exactly how technological evolution should work.

The beauty of onion routing isn't just in its privacy properties, but in how it enables a distributed network to route payments without any central coordinator. Each node only needs to know its immediate connections, yet together they form a network capable of finding optimal routes across the globe. This embodies the Bitcoin principle of emergent order from simple rules."