As we discussed in the first part of this series, scalability is a big issue for mainstream blockchain adoption. The solutions for scalability are mainly classified into 2 categories: layer 1 and layer 2 solutions. In this article, We will discuss the layer 2 solutions, which are state channels and plasma.
As we discussed in the previous part of the S-trilogy, layer 2 solutions try to squeeze in the maximum number of possible operations with currently available throughput. A second layer is built in layer 2 solutions, which hinges around the first layer.
State Channels – A Layer 2 Solution
State channels follow the same principle, and are a layer 2 solution. Firstly, a channel is created on-chain. Secondly, transactions are made off-chain, and
Transactional capacity is increased dramatically as channels are net-settled on the blockchain.
Bitcoin is implementing this concept of state channels to make payments scalable and with a project called the Lightning Network. Raiden is Ethereum’s version of Bitcoin’s Lightning Network. Both of these projects are in the development phase. These projects are quite similar and discussing any one of these will be sufficient enough to understand the concept of state channels. We will be discussing Raiden in this blog.
For understanding this section, you should have a basic understanding of what ERC20 tokens are and how they work. Also, you should have a basic understanding of what smart contracts are and how they work.
Raiden is a scaling solution for transfer of ERC20 tokens on ethereum blockchain.
As we discussed before, it is built on the concept of payment channels. Instead of making thousands of on-chain transfer of these tokens, we can send these transactions off-chain with ultimate settlement on-chain leading to minimum fees and maximum throughput. It is actually a system of smart contracts built on Ethereum blockchain which allows these fast and cheap token transfers between two parties.
How does it work?
Suppose A and B want to make cheap and fast ERC20 token transactions using payment channels. They need to take the following steps:
- A channel with a channel Id will be created on-chain where atleast one of them will escrow some amount of ERC20 tokens. Assume both of them deposit 10 tokens each, which means the initial state of channel is [10,10].
- A transfers 4 tokens to B. They both sign a message which stores the current state of channel as [6,14] with the timestamp. This means that both of them agree to the current state of channel and they cannot refute their signature. These signed messages are just like checks – which once signed cannot bounce back. Signed message is not updated on blockchain instead both parties keep a copy of it. Let’s name this copy of message as SM1.
- B transfers 8 tokens to A. Current state of channel becomes [14,6]. They both sign a message with current state and the timestamp and keep a copy of it with them. Let’s name this copy of message as SM2.
- Any one of them can settle the channel by providing the channel Id and latest signed message to the Raiden smart contract. 14 tokens will be transferred to address of A and 6 tokens to address of B.
Now, what if B submits the signed message, SM1? Raiden contract doesn’t know that there is another signed message SM2. So, B can cheat this way and get himself 14 tokens. This is why there is a challenge period where A can submit the copy of signed message SM2. As its time stamp is higher than that of SM1, Raiden contract will settle the channel in
You don’t need to open a new channel with every new party you want to transact with. Raiden is constructed as a network. This means, although Alice in the figure above might not yet have an open payment channel with Dave, she is indirectly connected to Dave via Bob, or even using multiple steps in between. With the Raiden Network, users are able to transact with anyone who is connected to their network of payment channels through multiple hops. Bob cannot steal Alice’s funds, as he will only receive the sender’s incoming payment if he has already sent the outgoing payment to the recipient.
Let us understand this with another example. Suppose you have to receive a check from a person with whom you have no contact. It is entirely sufficient if you know someone who knows someone – who eventually knows someone – that knows this other person. They all pass checks on to each other until one finally reaches you. But all of them are only valid if you confirm to everyone that you have received yours in the end. None of the middle man can take away your check and this is achieved using cryptography tricks. These middle man can be incentivized with a fees for a healthy network.
Benefits of Raiden Network
Most of the transactions are made off-chain, bigger the network the lesser number of on-chain transactions. This will make the system highly scalable.
It takes about 15–30 seconds to mine a new block in Ethereum. For the finality of transaction, we need to wait for some number of confirmations. Many exchanges wait for 32 confirmations before finalizing a transaction. In Raiden Network, once you have the signed message you can be certain that you hold the amount included in the message. There is no need to wait for any confirmations.
Transaction fees is much lower, as only a very small fraction of transactions is made on-chain. Combined fees on all transactions is greatly reduced in comparison to a case where all transactions are made on-chain.
Privacy is improved as only net settled transaction is stored on public blockchain. All transactions are not visible to the entire world.
Plasma is a scaling solution proposed by Joseph Poon and Vitalik Buterin. They have published a whitepaper on Plasma. Joseph Poon is also coauthor of Lightning Network whitepaper.
Plasma is blockchain within blockchains. Root blockchain, the main Ethereum blockchain, has many child plasma blockchains and each of those blockchains can have their own child blockchains. It is a series of smart contracts which runs on top of a root blockchain, this allows for many blockchains within root blockchain. Root blockchain contract processes only a tiny amount of commitments from child blockchains hence providing high scalability.
Separate plasma contracts can be deployed on root chain each working for different purposes such as private blockchain, decentralised exchange, social network, micropayments.
Private blockchains are a beneficial choice for institutions. Vitalik Buterin discusses in this blog about the comparison between private blockchain and public blockchain. He says that although private blockchain seems more feasible for institutions, public blockchain has its own advantages.
Plasma makes it possible to run a private blockchain over public blockchain hence providing benefits of both, making it perfect for private institutions.
Now, that you have a understanding of state channels and plasma – a solution for the issue of scalability in blockchain, we will move forward to DAG in the next part of this series. Please click here to navigate to the next article in this trilogy.
To learn more about how Deqode is working towards solving the scalability issues of blockchain, drop your email here.
Hey, check out æternity – it has state channels implemented directly on the protocol level (Layer 1), not via smart contracts. The æternity’s state channels have been developed together with the Mainnet, resulting in more “native” interaction between off-chain and on-chain states – learn more here: https://forum.aeternity.com/t/state-of-state-channel-aepps-we-need-more/2820.