History of Atomic Routing

History of Atomic Routing

Gabriel Comte

Non-chronological order

Ordered by topics rather than time

Simplified contracts

Some details are sacrificed to remove complexity

The goal is to understand the core concepts

Inflexible channel ownership

  • To this day, payment channels are built between 2 parties
  • Transactions are possible between Alice and Bob, Charlie is left out
  • This cannot be changed, or it requires on-chain action

Channel overdose

Do we need to open a payment channel with everyone we want to transact with?

That's very inefficient!

Centralized hubs

"Hub and Spoke" network model

Visualization

Multi-Hub

Security model

The payment processors are businesses and have incentives to behave ethically

Drawbacks

  • Insecure (based on trust)
  • High barrier to entry
  • Payment processor can invade privacy and censor payments
  • Potentially unreliable (payment processor is down)

Ryan Fugger: Ripple

  • Paper released in 2004 (more papers)
  • Not the cryptocurrency
  • System based on debt (and trust)

Ripple idea

  • Use already existing trust-relationships to transfer debt
  • You would lend your mother up to $2.000 and trust she could pay it back some day
  • She would lend you up to $10.000 and trust you could pay it back
  • You'd lend your boss $500
  • ...

Ripple idea

This results in a network of trust relations

Scenario

Your boss wants to buy something from John for $50 (on credit)

  • He owes you $50
  • You owe your mother $50
  • Your mother owes $50 to John

Trust situation after 'payment'

New situation

John could now send $200 into the opposite direction

  • He trusts your mother a debt of $150
  • Plus he owes her $50

System was used ...

... on a centralized platform. (Ripplepay website)

  • Platform could become malicious
  • The whole point was to not have to trust unknown entities

Building it in a decentralized way ...

  • Routing turns out to be a major problem
  • No known solution to make transaction atomic
  • How do you even know whether a payment went through?

Someone does not pay

  • Someone does not pay willingly
  • Someone is just offline or has technical problems ...

Someone does not pay

  • Is the payment just stuck or will it not go through?
  • Where exactly is the routing failing?
  • Sender says he paid, receiver says he didn't receive. Who is lying?

Proof that payment went through

Return a secret when payment arrived;

I will pay you as long as you know p such that sha256(p) == h

Payment proof

  • Atomicity is still a problem
  • How can disputes be resolved?

Project Ripple

Lessons learned

  • We need some form of a court to resolve disputes
  • It needs to define:
    • Time frame available for forwarding
    • Was payment forwarded or not
    • How to resolve disputes?

Spoiler Alert!

  • The Bitcoin consensus itself could be that court!
  • It defines time through its block time
  • We can use scripts to ensure a transaction is routed through atomically

Conclusion

  • Concept of routing through the network looks promising
  • But the Bitcoin way please
    • Not based on credit but fully backed
    • Trustless

HTLC

  • Hashed TimeLock Contract
  • Proposed by Poon and Dryja in the Lightning Network paper
  • Uses time locks
  • Uses hash locks

Time lock

Funds can only be spent after a given time or block number

Hash lock

Funds can only be spent if you know the secret s, such that:

hash(s) == x

x is written to the unlocking script, s needs to be provided by the spender such that x can be reproduced

Combine restrictions

signature + hash lock + time lock


Funds can be spent by you, at block 800,000 (or later), if you know a secret

simplified HTLC

signature, hash lock, time lock


Funds can be spent by Alice at block 800,000 (or later)

OR

by Bob if he knows a secret

Scenario

Alice wants to send Eric 1 BTC

HTLCs in action

HTLCs in action

1) Eric creates a secret R and communicates its hash to Alice

HTLCs in action

2) Alice creates a commitment TX: I will pay Bob 1.003 BTC if he presents the secret (R) that leads to hash H, during the next 10 blocks

HTLCs in action

Bob now also knows H, so he can craft a similar TX

HTLCs in action

3) Bob creates a commitment TX: I will pay Carol 1.002 BTC if she presents the secret (R) that leads to hash H, during the next 9 blocks

HTLCs in action

Remember, the commitment TX spends the 2-of-2 multiSig (funding TX) and is not being published to the Bitcoin network!

HTLCs in action

4) Carol now also knows H, she crafts a similar TX for Diana

5) Same story for Diana

Notice

Diminishing BTC amount --> a fee for the routing is being paid

Notice

Diminishing time lock --> Security measure to ensure atomicity of the transaction

Notice

Eric is the only one who knows actually knows R! Diana constructed an HTLC in which she promised 1 BTC to Eric if he reveals R!

Notice

Eric is happy! But what about Diana? Will she ever receive her "refund" from Carol?

Eric claims his funds!

Eric publishes the HTLC on-chain (closes the channel)

Eric claims his funds!

Now he has 7 blocks to spend the commitment TX, or else Diana can take the money back.

Eric claims his funds!

He spends that commitment TX and sends it to himself to ensure the money belongs to him forever. This means, he needs to reveal R on-chain!

Eric claims his funds!

Bob, Carol and Diana are watching the blockchain and learn R from there! They can now also claim their funds.

Eric claims his funds!

Happy end!

Eric claims his funds!

Well, not really.

Eric claims his funds!

Even though the payment went through, channels have also been closed, which is unfortunate.

HTLC consolidation

So let's go back to the moment Diana sent Eric her HTLC

HTLC consolidation

As we have just witnessed, Eric could claim his funds now, and Diana knows that as well.

HTLC consolidation

So Eric asks Diana to move to a new channel state, where Eric owns +1 BTC, and Diana -1 BTC

HTLC consolidation

Diana tells Eric that she is only willing to do that if he tells her R

HTLCs in action

HTLC consolidation

HTLC consolidation

They collaboratively move to a new channel state and remove the HTLC

HTLCs in action

Diana has given 1 BTC to Bob. She is now in the same situation as Bob before.

HTLCs in action

The scheme repeats through 7, 8, 9 until the transaction went through.

HTLCs in action

What if step 1 does not happen?

Payment cannot be constructed.

HTLCs in action

What if step 2 does not happen?

Alice searches for a new payment route

HTLCs in action

What if one of steps 2, 3, 4, 5, 6 does not happen?

Funds are locked in HTLC until time lock runs out

HTLCs in action

What if one of steps 7, 8, 9 does not happen?

Bob, Carol or Diana may lose 1 BTC

HTLCs in action

They are protected by the time-lock to have enough time to react. But if they leave the system, they can only harm themselves, not anyone else.

Conclusion

The transaction is atomic! (as long as you run your system responsibly)

Bitcoin fixed the ripple-problem :-)

Questions?

Any questions so far?

Practical consequences

The more hops involved, the more ...

  • ... latency
  • ... fees
  • ... unreliabiltiy

Hash lock script

Extract from HTLC output script in (Bolt 3)


# To remote node with preimage.
OP_HASH160 <RIPEMD160(payment_hash)> OP_EQUALVERIFY
OP_CHECKSIG
						

Time lock script

Extract from HTLC output script in (Bolt 3)


# To remote node after timeout.
OP_DROP <cltv_expiry> OP_CHECKLOCKTIMEVERIFY OP_DROP
OP_CHECKSIG
						

Questions?

Any questions regarding HTLCs?

Network topography

Open many channels

The better you're connected, the fewer hops you're gonna have

Announced channels

  • You can choose whether you want to announce your channel to the channel graph
  • If you do, your node may also forward payments

Liquidity constraints

  • Liquidity is required on the entire payment path (remember Ripple)
  • Actual distribution of channel funds is not public
  • Polar

Multi-path payments

Source-routing

Source-routing

  • Source routing means freedom & responsiblity
  • Pathfinding can be tricky

Onion routing

Onion routing

  • Each node only knows the previous and the next hop
  • Nothing more
  • Source & Destination unknown

Resources

History

Current implementation