Raiden Protocol Explained

Raiden Network
Feb 15, 2019 · 9 min read

A few weeks ago, we published a video explaining the underlying logic behind Raiden. This article breaks down the video’s content into reading content and infographics.

We will guide you through the basics of a payment channel network, as well as the mechanics of mediated transfers, routing and handling of multiple pending transfers.

Payment Channel Network Basics

Payment channels enable tokens to be exchanged between counterparties off-chain. A payment channel in Raiden is always backed by an on-chain deposit of tokens.

When making a payment, the sender signs a balance proof to the respective receiver. As an analogy, balance proofs can be imagined as a form of digital checks. They cannot exceed the amount of tokens held on-chain by both parties respectively and are therefore guaranteed to be redeemable for tokens.

Payments executed via a payment channel have the potential to be orders of magnitude faster and cheaper than on the blockchain. However, opening payment channels with counterparties costs gas and requires an on-chain deposit preventing the tokens from being used while held as deposit. Luckily, this downside can be mitigated, since in a payment channel network, users do not need to open channels with everyone they want to pay.

A payment channel network lets users pay anyone in the network by using a path of connected payment channels to mediate the payment. Within a token network, many payments can happen concurrently and independently of each other.

In order to ensure that all users behave in a fair way, a set of rules to govern the network is required. The Raiden Network protocol ensures that all nodes follow the exact same rules when sending and receiving payments.

Mediated Transfers

Mediated transfers use several payment channels to finalize a payment, allowing users to make payments with other users they don’t necessarily have a payment channel with.

In the example below, Alice sends a payment to Dave using the channels between herself, Bob, Charlie and Dave. This payment is locked as a pending transfer which means that it requires a secret before it can be claimed for tokens.

Upon receiving the transfer, Dave requests the secret from Alice. Alice sends Dave the secret, which he uses to unlock his pending transfer. Dave sends the secret to Charlie who signs a balance proof reflecting the added value of the unlocked pending transfer and sends it to Dave. The protocol is then followed backwards until the secret is revealed to everyone in the mediated transfer route.

If one of the mediating nodes stops responding (e.g. because it is offline) after the secret has been requested, it will not be possible to unlock all pending transfers before the locks expire.

In such an instance, Dave can instead submit the secret to a smart contract called the secret registry. Upon registering the secret on-chain, the mediating nodes can see the secret, unlock their transfers, and send a signed updated balance proof to their counterparty.

Routing

In order to successfully conduct a mediated transfer, a path of payment channels with sufficient capacity between sender and receiver is needed.

Capacity means that the payment channels used for the payment have sufficient tokens to create pending transfers in all required channels.

In our example, Alice wants to pay Dave 3 tokens, so she needs to find a route of connected channels with a capacity of 3 in the mediating payment channels.

The Raiden Network protocol has a full picture of the network and all initial channel balances. Suppose all users have deposited 5 tokens per channel and have already made some transfers. The protocol then tries different paths until one with enough capacity is found:

  1. Since Alice has 5 tokens and Bob has 5, there is sufficient capacity.
  2. Bob has 4 tokens allowing the payment to continue.
  3. Since Charlie only has 2 whereas Dave has 8, this route is not possible.
  4. Charlie initiates a refund transfer that Bob will claim.

The Raiden Network protocol now tries a path via Earl, Frank and Gary which works because there is sufficient capacity in all channels.

Since Dave has received the payment, he now requests the secret from Alice, allowing all participants to unlock their transfers and sign new balance proofs to their counterparty.

In the future, auxiliary services like pathfinding will make it easier to find a route with sufficient capacity to mediate transfers. Pathfinding services will be included in the upcoming Ithaca release.

Handling of Multiple Pending Transfers

In order to manage several pending transfers, nodes keep a local state in the structure of a Merkle tree.

A Merkle tree is a data structure, in which the root of the tree is the hashed value of the data contained in the tree. Merkle trees allow for a concise cryptographic representation of a large number of pending transfers with a single value; the Merkle root. If one data point is removed from the Merkle tree, the root will change.

In the Raiden Network, every node has one Merkle tree per channel per direction.

During a mediated transfer, every mediating node adds the mediated transfer to their Merkle tree. As new pending transfers are created, the mediating node checks if the root of the tree matches their local state.

This design allows the protocol to deal with 160 pending transfers per channel. The limit to 160 is a rounded value that ensures the gas cost of unlocking will be less than 40% of Ethereum’s traditional pi-million (3141592) block gas limit; also see the Raiden docs for more info.

In our example, Bob will mediate several transfers for Alice. To make sure that Alice isn’t cheating, the protocol will construct a Merkle tree of all the pending transfers that Bob expects to claim from Alice:

Off-chain Unlock of Multiple Pending Transfers

We already learned that nodes can become unresponsive during a pending transfer, which results in the secret being registered on-chain in the secret registry.

Next, we will show how the Raiden Network protocol manages unlocks if there are multiple pending transfers.

In the example, Bob still needs to unlock his pending transfers to Charlie, Erik and Frank, the only problem being that Alice has closed the channel.

Summarizing the example, the settlement process of pending locks ensures that pre-allocated funds, which had been secured by locks, get unlocked either to the receiver or to the sender of the payment. The direction is determined by whether or not the secret is known. If the secret is revealed off-chain then no on-chain interaction is required. If the counterparty is unresponsive, the blockchain can always be used to guarantee safe transfers.

We hope you enjoyed this little deep dive into the basic principles of the Raiden protocol.

If you’re curious to learn more about the Raiden Network, please feel free to try the software yourself or check out our documentation. For any technical question, shoot us a message in our Gitter chat.

Last but not least, we’re still hosting a bug bounty for the Raiden Red Eyes code. If you are a bounty hunter, you can check the bounty rewards and submission rules here.

The Raiden Team

Make sure to stay up to date by following us on Twitter and Medium and joining the conversations on Reddit and Gitter!

The Raiden project is led by brainbot labs Est.

Disclaimer: The provided content may contain views and opinions, errors and omissions by which the content creator(s) and any represented organizations cannot be held liable. The wording and concepts regarding financial terminology (e.g. “payments”, “checks”, “currency”, “transfer” [of value]) are exclusively used in an exemplary way to describe technological principles and do not necessarily conform to the real world or legal equivalents of these terms and concepts.

Raiden Network Blog

Fast, cheap, scalable token transfers for Ethereum.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store