An Introduction to Cross Layer Transfer

Praveen Surendran
Tokamak Network
Published in
10 min readAug 3, 2021

Note: We have written several articles related to cross-layer transfer, and the below list will help the readers to navigate through them quickly.

An Introduction to Cross Layer Transfer

Fast Withdrawals In Optimistic Rollups — Part 1

Fast Withdrawals In Optimistic Rollups — Part 2

Standardising Cross-Domain Asset Transfer

The Ethereum Layer-2 ecosystem is proliferating quickly, making it difficult for the general audience to get up to date with the latest information. It isn’t easy to keep attention to every detail in this space; but still, we believe that a blockchain enthusiast should have an aerial view of the various solutions present in the Layer-2 ecosystem. They should know the key features that distinguish each of them,associated challenges posed by them and the future trends.

Keeping that in mind, we thought of writing a prequel for our article series — Fast Withdrawal in Optimistic Rollup (Part 1, Part 2). The main goal is to help the reader familiarize with different Layer-2 projects, and make your journey smooth while reading in-depth technical articles related to cross-layer transfer mechanisms.

Layer-1 can’t handle everything!!!

A Layer-1 network refers to a blockchain in the decentralised ecosystem, while a Layer-2 protocol is a third-party integration that can be used in conjunction with a Layer-1 blockchain. Bitcoin, Litecoin, and Ethereum, for example, are Layer-1 blockchains.

Ethereum opened up a gateway of opportunities for new business models to emerge. Users can now leverage the advantages of Decentralized Applications (DApps) in this new era, retaining control and ownership of their data and assets. With a lot of potential, these new applications attracted a boatload of users to the Ethereum ecosystem. Gaining user adoption is excellent, but the fundamental question is whether the technology can process an enormous volume of transactions without affecting user experience.

The community tasted the first bitter truth with the Ethereum platform during the CryptoKitties craze around 2017. CryptoKitties lets players buy and breed “crypto-pets” on Ethereum’s underlying Blockchain network. Etherscan has reported a six-fold increase in pending transactions on Ethereum since the game’s release. The game’s popularity has underscored one of the technology’s most significant downsides: its lack of scalability. The below chart gives you a fair idea about the pending transactions in the queue during CryptoKitties craze.

Pending Transactions in Ethereum

Another most recent example is the 2020’s DeFi (Decentralized finance) craze, which attracted many users to the platform. The diverse ecosystem of DeFI solutions built on this Platform is one of the main drivers of Ethereum’s success. But, the consequence of widespread adoption was that the number of transactions on Ethereum skyrocketed, slowing the network and increasing transaction fees. Take a look at how the Gas price spiked in the below chart during DeFI craze.

Over the years, the community has widely researched and tested different scaling solutions for Ethereum.

Layer-1 scaling solutions aim to improve scalability by making changes in the protocol of the base layer. The naive way is to increase the block size, which helps to increase the number of transactions verified per block. But, this could make mining expensive which leads to centralization. The Ethereum community doesn’t want to make this Layer-1 change because it would sacrifice decentralization and thus network security.

There are also opportunities to improve layer-1 scalability by making other foundational updates. Eth2 is one such major update that aspires to make the Ethereum blockchain more scalable, secure and sustainable.

The notable changes in Eth2 are:

  1. Consensus protocol improvements (Ethereum adopting Proof of Stake as its consensus protocol)
  2. Sharding (Breaking the state of the entire blockchain network into distinct datasets called shards).

The community believes that Eth2 will indeed scale Ethereum to the tune of thousands of transactions per second.

Layer-2 is Flourishing

Layer-2s are considered a saviour of Ethereum to solve its high gas price issues. Layer-2 refers to a network or technology that operates on top of an underlying blockchain protocol to improve its scalability and efficiency. These scaling solutions shift a portion of a blockchain protocol’s transactional burden to an adjacent system architecture, which then handles the brunt of the network’s processing and only subsequently reports back to the main blockchain to finalize its results.

I will list down the significant layer- 2 solutions below and the corresponding links to read about it further.

  1. Rollups
  2. Plasma
  3. Validium
  4. State Channels
  5. Sidechains (To consider sidechain as a layer-2 solution is still a controversial topic. The community has dual opinions, supporting both sides. Since it is included as a layer-2 in the Ethereum official docs, I listed sidechain here).

Rollups are of our main interest and we have two types of Rollups:

  • Optimistic Rollups — It assumes that the transactions are valid by default and only runs computation, via fraud proof, in the event of a challenge.
  • ZK Rollup — runs a computation off-chain and submits the validity proof (zk- SNARK) to the chain. Anyone can verify the proof, which is not at all a resource-intensive task.

The below picture will help you understand the significant layer-2 projects (Source).

Layer-2 Projects

Also, L2beat is another source that gives you an idea about the Total value locked (TVL) in these layer-2 solutions. The TVL figures themselves are enough for you to understand the significance of the layer-2 ecosystem. The below picture shows the TVL in some of the major layer-2 proponents.

Total value locked in Layer-2

Now, you might have understood the depth of the layer-2 ecosystem and the pace at which it is flourishing. At this point, you should realise the associated problems with such a diverse ecosystem.

Seoul is Expensive, So is Ethereum (Analogy)

Layer 2s are still a step in the right direction, and they are needed even with the eventual merge of ETH2 later this year. The throughput and speed that they offer cannot be done purely on Ethereum 2.0’s Layer 1 network. At least for now, we can assume that the growing demands of applications, especially DeFi and the gaming industry, can be met by these layer-2 solutions.

But is there a single layer-2 solution that solves all the problems? Do the users and apps concentrate only on a single layer-2 solution? Can the apps running on different layer-2 platforms communicate with each other without going to the base layer? Will the liquidity of DeFI get fragmented to different layer-2 solutions?

Let’s try to understand more about it with an analogy.

Seoul is the capital of South Korea, one of the busiest and densely populated cities in the world. It is not easy for everyone to fit into a single “city” like Seoul, where property prices skyrocket. It is reasonable to assume that people would go to other cities such as Busan, Daego, Incheon etc., where it is cheaper to live (compared to Seoul) and have better opportunities.

Think of the Ethereum platform as the city Seoul, where a boatload of DApps and their users are currently thriving. More and more transactions on layer-1 slow down the network and shoot up the Gas price. It is reasonable for the users and DApps to look for other options (like people moving from Seoul to Busan, Daego, Incheon) for cheaper fees and high throughput. These options are different Layer-2 solutions such as rollups, state channels, validium, plasma or other EVM compliant sidechains. Apps may cluster into rollup, chains or sidechains based on their need to maintain close communication ties — the same way populations tend to cluster in regions and cities

The layer-2 ecosystem is thriving at such a fast pace, and it isn’t easy to pick one out of them as the sure-shot solution. Each layer-2 solution aims to gain more adoption and attract newer projects to their platform. These competitions are exciting and produce fruitful results, which is valuable for the greater adoption of Ethereum. But, have you thought about how users and Dapps living in different L2 solutions interact with each other? Is there a standard defined for cross-layer communications?

A proper communication channel is present between Seoul and other cities, without which the economy couldn’t flourish. Likewise, for greater adoption of Ethereum, the transfer of funds and assets between the layer-2 solutions should be seamless unless it affects the user experience. It is challenging as we know that different layer-2 solutions follow a different set of rules and protocols. This is an evolving environment where it is not only the ecosystems that change, but also the bridges and technical implementations that determine the rules within which they operate.

At, Tokamak network, we are currently working on protocols that enables users to perform

  1. fast withdrawal from L2 to L1 in our optimistic rollup solution
  2. fast cross-layer transfer between layer-2 solutions (L2-L2)

L1<->L2 Communication Basics

Understanding L1<->L2 communication is as simple as understanding the cross-contract communication within Ethereum. You should also be aware of some caveats, and we will discuss them at the end.

Interaction Between Smart Contracts

Let’s see a code example of how two contracts living within Ethereum can interact with each other.

contract MyContract {doSomething() public {// ... some sort of code goes here}}contract MyOtherContract {function doTheThing(address myContractAddress, uint256 myFunctionParam) public {myContractAddress.call(abi.encodeWithSignature("doSomething(uint256)",myFunctionParam));}}

Here, MyOtherContract.doTheThing triggers a “call” to MyContract.doSomething. A “call” is defined by a few key input parameters, mainly a target address and some calldata. In this specific example, the target address is going to be the address of our instance of MyContract. The calldata, on the other hand, depends on the function we’re trying to call.

L1<->L2 Contract Call

Now let’s see how communication happens between L2 Rollups and Ethereum. There are special smart contracts known as “Messenger Contracts”, which enable the L1<->L2 communication. Both L1 and L2 have their messenger contracts which abstract the low-level communication details. Token Bridges make use of these messenger contracts for transferring tokens across layers.

In optimism, we have OVM_L1CrossDomainMessenger and OVM_L2CrossDomainMessenger contracts come pre-deployed to the network.

The sendMessage function in the messenger contract is used to call a contract on an entirely different network.

function sendMessage(address _target,bytes memory _message,uint32 _gasLimit) public;

Now, let’s see a code sample where a contract on L1 interacts with a contract on L2 using the sendMessage function.

// Pretend this is on L2contract MyOptimisticContract {doSomething() public {// ... some sort of code goes here}}// And pretend this is on L1contract MyOtherContract {function doTheThing(address myOptimisticContractAddress, uint256 myFunctionParam) public {ovmL1CrossDomainMessenger.sendMessage(myOptimisticContractAddress,abi.encodeWithSignature("doSomething(uint256)",myFunctionParam),1000000 // use whatever gas limit you want)}}

The cross-layer contract calls are asynchronous. If you want to know about the call result, you’ll have to wait for the other contract to send a message back to you. Also, in optimistic rollups, there is a challenge period, wherein messages sent from Layer 2 to Layer 1 cannot be relayed for at least one week. This feature is essential to keep the integrity of the optimistic rollups. This is the reason for the long withdrawal time in Optimistic Rollups.

Token Bridges

A bridge is responsible for holding the assets on a layer-1 blockchain while the same assets are released on another (and external) service. It defines who has custody of the funds and the conditions that must be satisfied before the assets can be unlocked.

Bridge

In Optimism, we have L1_Standard Bridge and L2_Standard bridge that enables a user to deposit (L1-> L2) and withdraw(L2-> L1) ERC20 tokens.

These token bridges make use of the messenger contract for L1<->L2 communication. There are also other projects which developed their own custom bridges on Optimism (optimism-dai-bridge).

Also, the layer-2 community is now trying to bring a standard interface for cross-domain ERC20 transfers. We will discuss more on standardization in a different post.

Hop protocol is another initiative related to the cross-layer transfer.Hop allows users to quickly and easily transfer tokens directly between layer-2s, sidechains, and layer-1 Ethereum.

By now, you might have understood the role played by Layer-2 solutions in bringing Ethereum to greater heights. Tokamak network is soon going to release an optimistic rollup solution as its layer-2 technology. The considerable criticism of Optimistic rollups is the withdrawal delays. You may now read our Fast withdrawal article series (Part 1, Part 2) to learn more about how we plan to tackle the withdrawal delays in our Optimistic Rollup solution.

References

  1. https://www.gemini.com/cryptopedia/blockchain-layer-2-network-layer-1-network#section-layer-2-scaling-solutions
  2. https://community.optimism.io/docs/developers/bridge/messaging.html
  3. http://www.cryptonyc.org/Living-On-Maker-Island/
  4. https://forum.makerdao.com/t/a-multichain-strategy-and-roadmap-for-maker/8380
  5. Layer 2 Won’t Save Ethereum. What no one’s talking about: the… | by Jimmy Chang | Coinmonks | Apr, 2021 | Medium
  6. https://www.reddit.com/r/ethereum/comments/lzqhm9/how_does_crossproject_composability_work_for_the/

--

--