How to DeFi on Polkadot Series: Part 3 Parachains

TL;DR

  • A Parachain is an independent network connected to Polkadot.
  • Lateral communication between networks is only possible if both networks are Parachains at the moment of the communication.
  • As of now the second round of parachain auctions is happening on Kusama, currently, 9 slots have been lent.
  • On Kusama, a Parachain slot can be rented for up to 48 weeks while for Polkadot a Parachain slot can be rented for up to two years.

Trosset #24 AB Curated

History

The history of Polkadot started in 2016 when Dr. Gavin Wood quit the Ethereum foundation and a few months later presented what would be the first draft of the Polkadot white paper. Initially, Wood was not thinking about creating a new network, he was working on a re-design of Ethereum into a sharded version.

Wood was looking for a solution to some of the major issues Ethereum started to face back then which was scalability and consensus as well as problems with Solidity which ended in several exploits happening every year due to badly written smart contracts.

Polkadot was designed as a next-generation blockchain that is focused on fixing some common issues that legacy blockchains had, like communication with external networks.

From the beginning, Wood made it clear that Polkadot would use a Nominated Proof of Stake (NPOS) scheme as it was considered as a good alternative to the commonly used Proof of Work (POW) consensus.

Polkadot offers a multichain architecture that allows the interconnection of networks built with Substrate and interconnection with external networks. In case you missed our previous articles, Substrate is a modular framework that allows us to build complex blockchains attaching customizable components. This allows a blockchain ‘A’ to adopt features of a blockchain ‘B’ easily if both of them were built on top of Substrate and hence share the same base.

The reason behind the concept of “Parachain” comes from the ability of Substrate networks to run in parallel to the relay chain and because they are capable of running parallel transactions.

To do this, Polkadot was designed as a sharded multichain network represented as a ring with different types of nodes surrounding it.

A shard is a partition of a system, sharding in design is commonly used on databases and search engines as they help to spread the load a system is receiving, splitting it into the shards. Every shard on Polkadot is called a Parachain and any Parachain joining the ring helps the relay chain to increase the number of transactions it can process as a whole.

In the Polkadot ecosystem, every chain is autonomous and self-governed by default, this is because Polkadot as a relay chain, considered a Layer 0, has few functionalities, its main task is to keep the network secure.

In simple terms, we could see Polkadot as an empty mega warehouse with guards called “Validators” surrounding the building, with a good surveillance system. This space inside the warehouse is divided into a certain amount of equally sized squares that are available to rent for any company aiming to enjoy the security the warehouse offers.

To avoid chaos inside the warehouse the free slots are offered to the public through a public auction once a time every X weeks. Polkadot aims to give everyone the same opportunity to get one of the squares and so it does not give a specific date to decide a winner, rather the participants of such auctions, dutch auction specifically, are given a range of days to get as many funds as possible and win the current auction. While getting funds could be easier for a big company, let’s ask ourselves, what is the possibility of a small company winning one of the available spaces?

Small companies have two options here, wait for the bigger companies to get a slot first and wait for the bids to decrease in price or get a space in one of the squares offered in the Kusama warehouse. The Kusama warehouse offers the same perks as Polkadot but with a lighter and faster governance system, promoting itself as a place where innovators converge.

If at some point a company decides to bid for a slot in the Kusama warehouse instead of the Polkadot warehouse it must remember that spaces inside the Kusama warehouse are rented for a maximum of 48 weeks as they try to allow others to come and enjoy the perks their installations offer while Polkadot warehouse offers spaces for up to two years and so it is more suitable for companies that have a clear roadmap focusing on long term production.

Once a company is installed inside one of the warehouses it is named “Parachain” and it can continue working as usual but also will be able to communicate with other companies that have a space too. For this, one or more third parties called “Collators” are assigned to each company with the sole purpose of taking notes about every movement a company is doing so the warehouse management can keep track of all the actions made by every company inside and keep the place safe. Collators are not only in charge of delivering notes to the directive of the warehouse, they are also in charge of delivering messages between companies aiming to communicate between them.

As we know from real-world scenarios some companies might not be on good terms either with the directive of the warehouse or with other companies inside and so they might try to sabotage the common space delivering messages with incorrect data that can harm the harmony inside the warehouse, for this, guards (validators) of the relay chain are in charge of checking every message Collators are transporting and be sure the information on it is legit before it reaches its final destination.

What is a Parachain?

A Parachain is a blockchain that wins a slot to connect with any of the relay chains (Polkadot/Kusama). It is called Parachain because this kind of chain will run parallel to Polkadot. Once a blockchain is connected with the relay chain, it will share the entire network’s security, and it will be able to communicate with other Parachains through XCMP.

Fractal Lotus 2 by Obxium

How can an isolated Substrate network become a Parachain?

Cumulus is a group of tools that allows any substrate-based chain to connect to the relay chain as a Parachain.

Cumulus is composed of three components:

  1. Cumulus Runtime
  2. Cumulus Consensus
  3. Cumulus Collator

How are transactions synchronized in Polkadot?

Once a chain becomes a Parachain, their transactions are not directly processed by the relay chain, they are collected by an authoritarian kind of node named “Collator” that is in charge of collecting the Parachains’ transactions and proposing blocks to the relay chain.

By default, a Collator cannot continue proposing blocks to the relay chain Validators if their last candidate block has not been accepted yet.

Collators are so important in the Polkadot ecosystem because they maintain a full node for both the relay chain and the Parachain they are collecting transactions for. Thanks to this feature, Collators are a key element for messaging between Parachains, since they are all connected to the relay chain and so between them, they can easily take a message from the Parachain ‘A’ and share it with its peers so it gets delivered to the Parachain ‘B’.

Contrary to what you might think, having multiples Collators does not improve the security of the network as Collators does not reject invalid blocks, unlike relay chain Validators, few Collators are needed to keep a Parachain connected with the rest of the networks and an excess of Collator may slow the network.

Collators have the power to censor transactions so it is important that chains select Collators they can trust. The most common ways to select reliable Collators are through stake voting or using on-chain governance but every chain is free to implement its own logic.

What is a Parathread?

Parathread is a concept created for chains that want to benefit from Polkadot shared security but that can’t afford to lease an entire slot for themselves can opt to pay the relay chain per block. The idea behind this concept is that since these kinds of chains don’t need to produce blocks constantly, multiple chains can share a single Parachain slot.

What is the difference between a Parachain a and a Parathread?

The main difference between a Parachain and a Parathread is that a Parachain leases a dedicated slot to be connected to the relay chain (and hence being able to communicate with other Parachains) during a specific period.

In terms of development, a Parachain and a Parathread are similar and they don’t require big changes to switch from one to another.

Even though a Parathread can connect to the relay chain block by block, they can send messages to other Parachains through XCMP just as any other Parachain would do.

Parathreads are constantly participating in a block-to-block auction with other Parathreads where only those that win will get their proposed block included in the next block of the relay chain.

How do Parachains communicate between them?

Every time two Parachains need to communicate, they do it using XCMP. XCMP is a queuing mechanism based on a Merkle tree. A Merkle tree is a hash tree in which the leaves are the hashes of a data block. Merkle trees in blockchain are used to verify other peers don’t send fake blocks.

Collator nodes are in charge of moving transactions from the output queue of Parachain ‘A’ and insert it in the input queue of the Parachain ‘B.’ The metadata generated by such a movement is hashed and inserted in the relay chain.

Before two Parachains can communicate, they need to open a direct communication channel between them. Opening a channel will require a deposit of assets issued by the relay chain (DOT in the case of Polkadot). If the communication traffic between Parachains is expected to be high; In that case, they can open a second channel, so one of them is used for sending messages and the second one to receive messages. There is no possibility of opening a third channel, but XCMP is still under development, and it does not have a final design yet. If at some point, a channel is not required anymore, the original deposit will be returned, and the channel will be closed.

While XCMP is in development, a lite version of XCMP named HRMP (Horizontal Relay-routed Message Passing) is being used. HRMP has the same functionality as XCMP, but it stores all the messages in the relay chain, which complicates the scalability of the network as the number of messages sent between Parachains grows. According to the current plan, once XCMP is implemented in the relay chain runtime, HRMP will be deprecated automatically.

Security between Parachains

Polkadot, as a relay chain, takes care that all the Parachains execute their code correctly. Once a blockchain has joined Polkadot as a Parachain, other Parachains will trust its code since they trust Polkadot’s security system.

SPREE modules

SPREE (Shared Protected Runtime Execution Enclaves) are fragments of code that are already available out of the box in the relay chain and that can be used by Parachains. Even though they are part of the relay chain, this kind of fragment has its own storage, and such storage cannot be altered by any Parachain. In layman terms, a SPREE module is a small piece of WebAssembly code isolated from the relay chain modules.

SPREE modules are important for Parachains because they help to guarantee code is executed in the destination Parachain when a message is sent.

One scenario where a SPREE module could be of help is when a Parachain with a Decentralized exchange offers its functionality to other Parachains but it does not have any way to secure that once the assets from the Parachain ‘A’ are sent, the Parachain ‘B’ will allow the same. Having a SPREE module in that scenario would make sure that both endpoints execute their part of the transaction.

Block production

  • BABE
  • Sassafras

Testnets

A testnet on a blockchain is an alternative blockchain used for testing purposes only. Testnets are usually ahead of the mainnet since they are mostly used to test new deployments. As with any mainnet, we can also find tokens in a testnet, the major difference is that tokens on testnets have no real value and they can’t be sent to a mainnet.

Just as any other blockchain, Polkadot has a testnet as well. Below we’ll try to explain the use given to each one of them.

Westend

Westend is the latest testnet for Polkadot, to give the developers the capacity to interact with a network that would behave as Polkadot or Kusama but without the need to spend DOT or Kusama.

One of the first uses it had when it was launched was helping the Validators to test their deployments as well as facilitating the testing of new wallets being developed for Polkadot/Kusama and the connection of Exchanges that were aiming to support any of the tokens of the relay chains.

Westend token

As we mentioned before you don’t need to hold tokens from the mainnet to interact with a testnet and so you don’t need DOT to interact with Westend, instead you will need ‘Westies’ (WND), if you need to test something on Polkadot and don’t want to spend your DOT you can get some using the Westend faucet in the Matrix chatroom or you can also set up your own Westend validator and get some WND as a reward.

Rococo

Rococo is a testnet launched to facilitate testing for projects aiming to join any of the relay chains as Parachain. One of the major changes between Westend and Rococo was that Rococo included the integration with Cumulus and HRMP.

Rococo native tokens called ROC are directly given to teams working with cross-chain messaging features. As users, we can get some ROC in the Rococo faucet of the matrix chatroom.

Substrate compatibility with EVM

Since the initial design of the network Polkadot had a vision of a multichain ecosystem, as part of this plan, compatibility with Ethereum as part of the roadmap since the early stages of the network.

Thanks to the modular library system of Substrate, it was decided to build an EVM module.

Frontier is a suite of tools that provides an Ethereum compatibility layer and it should not be considered a bridge. Frontier is composed of two pallets:

EVM pallet (Stable)

The EVM pallet uses Sputnik VM as the engine. Sputnik is a rust implementation of the Ethereum Virtual Machine and the accounts created with Sputnik are not compatible by default with Substrate, this is where the EVM pallet goes comes into action mapping the Substrate accounts with the sputnik accounts so if a balance changes in a substrate account the underlying Sputnik account will be updated as well.

In terms of compatibility with the Ethereum network, the EVM pallet offers almost the same results the original EVM would do, including gas cost.

Ethereum pallet

The Ethereum pallet brings Ethereum block emulation, allows already existing dApps to be deployed on Substrate with little modifications, and validates Ethereum encoded transactions.

Even though the Ethereum pallet is already available, it is considered a work in progress by the development team since some parts of it could be changed in the future.

Parachain leasing offering

Projects built with Substrate are L1 networks capable of running isolated with the possibility to connect to the relay chain (Polkadot/Kusama) as Parachains if they win a slot.

How are Parachain slots earned?

The mechanism to get a slot for your project is through the participation of the auction. Such auctions are permissionless and are won with the support of the community for your project. The winner of an auction will bond a specific amount of DOT/KSM (depending on which network you’re participating in) to the relay chain for the rent of a slot for the leasing period.

The first network to celebrate a Parachain leasing offering event was Rococo back in X (check the month), after a successful event in the Parachains testnet the same event was celebrated in Kusama with a cap of 5 slots.

Parachains slots are leased for 6 months, allowing a winner of a slot to lease it for a maximum of 4 periods (2 years). Once the leasing period ends a project needs to participate again in a new round of auctions and win if they want to continue being connected as Parachain.

Beware that under certain circumstances the council of the relay chain might vote to remove your chain as Parachain if it is causing issues or if it is bringing harm to the network.

Winners of the first round of Parachains on Kusama

Karura

Karura is a decentralized cross-chain DeFi hub for Kusama.

Moonriver

Moonriver is a canary network of Moonbeam, an Ethereum-compatible smart contract platform.

Shiden

Shiden is a smart contract platform supporting both EVM and substrate contracts.

Khala

Khala is a blockchain-focused on privacy in Polkadot that implements confidential contracts.

Bifrost

Bifrost is a staking liquidity DeFi project on Polkadot.

KILT

Kilt is a blockchain identity protocol for anonymous and verified credentials.

Calamari

Calamari is a blockchain offering on-chain privacy for swaps and transactions through ZKP.

Basilisk

Liquidity Omnipool protocol. Stake single-sided assets.

Parallel Heiko

Parallel Heiko is a DeFi hub focused on lending and liquid staking.

Sources

Cumulus- https://wiki.Polkadot.network/docs/build-cumulus

XCMP- https://research.web3.foundation/en/latest/Polkadot/XCMP/index.html

SPREE — https://wiki.Polkadot.network/docs/learn-spree

Westend — https://Polkadot.network/westend-introducing-a-new-testnet-for-Polkadot-and-Kusama/

--

--