#WhatTheFork Is LayerZero

Written by itsarjn | Published 2023/04/18
Tech Story Tags: web3 | blockchain | blockchain-technology | software-development | blockchain-interoprability | layerzero | whatthefork | blockchain-trilemma

TLDRI have gone into the depths of LayerZero to understand its inner workings, going through the whitepaper so you don't have to.via the TL;DR App

Interoperability in blockchain technology refers to the ability of different blockchain networks to seamlessly communicate, collaborate, and exchange information or value with one another.

The blockchain faces a trilemma problem which is to ensure that Security, Decentralization and Scalability are achieved simultaneously. But this is easier said than done. While many newer chains claim that they have solved the trilemma problem, it still remains to be proven. Only 2 out of the above-mentioned 3 aspects have been achieved by all the chains.

That is the reason there are lots of new Blockchains coming up every now and then solving a niche problem faced by previous existing chains. Hence, many different types of dApps are built on different chains leading to the fragmentation of resources and assets across chains. Also, transactions have always been a single-chain concept.

This makes it more than ever, the need to have an interoperability infrastructure that makes it possible to transfer assets cross-chain. And these infrastructure/protocol needs to work in a trustless manner to ensure they uphold the very foundation that the web3 technology is built.

In this article, we will be looking at one such project working on interoperability called LayerZero.


#WhatTheFork is LayerZero?

LayerZero started out as a stealth startup and describes itself as an omni-chain interoperability protocol that uses a low-level messaging system to enable cross-chain transactions.

LayerZero sets itself apart from other bridges by mentioning that it relies on simple messaging, unlike other bridges which use lock and withdrawal mechanisms (which will be explained in the later part of this article).

At the time of writing this article, LayerZero has raised about $120M in its series B round, hitting a valuation of $3B. Their investors include giants like Multicoin Capital, Binance Labs, A16z, FTX (lol), Sequoia, Coinbase, Gemini, PayPal, Uniswap and many others.

LayerZero announced their beta launch at around mid-March 2022 with 7 EVM chain integrations — Ethereum, Avalanche, Polygon, BNB Chain, Fantom, Arbitrum and Optimism.

By Sept 2022, LayerZero supported 11 chains including Swimmer, DFK, Harmony, and Moonbeam.

Since we have set the context for What is and the Importance of Interoperability, let’s look at how LayerZero achieves this differently from other bridges.


How do exchange bridges function?

  1. Creation of a representation of the asset: When a user wants to move an asset from one chain to another, the bridge creates a representation of the original asset on the target blockchain. This representation is often referred to as a “wrapped” or “pegged” token.

  2. Locking of the original asset: To ensure the total supply of the asset remains unchanged, the original asset is locked or put into a smart contract on the source blockchain. This ensures that the asset cannot be accessed or spent while it is being used on the target blockchain.

  3. Verification and confirmation: The bridge uses a combination of validators or nodes to come to a consensus, so as to verify and confirm transactions between the two blockchains. These validators are responsible for ensuring that the transactions are valid and secure.

  4. Minting of the wrapped asset: Once the original asset is locked and the transaction is confirmed, the bridge mints the wrapped or pegged token on the target blockchain. This token represents the original asset and can be used within the target blockchain ecosystem.

  5. Redeeming the original asset: When a user wants to move the asset back to the source blockchain, the wrapped or pegged token is burned or destroyed on the target blockchain. The bridge then unlocks the original asset on the source blockchain, making it available for the user to access or spend once again.

The intermediate consensus layer as described in step 3, though usually implemented in a secure manner, does require the user to trust a side chain to facilitate the token transfer.

Also, there are unnecessary overheads in the form of wrapped tokens which then have to be swapped for the actual tokens the user wants to use.

This solution is cost heavy and if the consensus layer breaks for some reason, that can become the reason for a huge disaster.


How does LayerZero work?

Before diving into the depths, let’s take a look at the various components involved in making this whole thing work and then, a step by step guide on the entire transaction lifecycle.

Components of LayerZero

  1. Endpoints
  2. Oracles
  3. Relayers

Endpoints

  1. Endpoints are a collection of smart contracts

  2. Every chain has one endpoint implemented as a series of on-chain smart contracts

  3. An Endpoint’s purpose is to allow the user to send a message using the LayerZero protocol backend, guaranteeing valid delivery

  4. Endpoints are split into 4 modules:

Communicator, Validator & Network

  • These 3 modules make up the core functionality of LayerZero Endpoint.

  • These modules act in a manner similar to a network stack, with messages sent down the stack on the sender side — Communicator to Validator to Network and then up the stack on the recipient side.

Libraries

  • LayerZero Endpoint can be extended via Libraries, which are auxiliary smart contracts that define how communication for a specific chain should be handled.
  • Each chain in the LayerZero network has an associated Library, and each Endpoint includes a copy of every Library.

Oracles

An Oracle is a third-party service that can make off-chain data available on-chain.

Here, Oracle provides a mechanism to read a block header from one chain and send it to another chain.

Relayers

The Relayer is an off-chain service that is similar in function to an Oracle, but instead of fetching block headers, it fetches the proof for a specified transaction.

To ensure valid delivery of messages, the Oracle and Relayer must be independent of each other. The users can implement their own Relayer service and the Oracle is handled by Chainlink which is currently the industry leader.


Architecture

Let’s break the above architecture into multiple steps

  1. A User Application (UA) uses LayerZero’s reference Relayer and executes a transaction. The UA sends a request to LayerZero’s Communicator with information about the transaction, such as a transaction identifier, data to be transferred from A to B (payload), identifier pointing to the UA smart contract on Chain B (dst), etc.

  2. The Communicator sends this data in the form of a LayerZero Packet to the Validator.

  3. The Validator sends the transaction identifier and the identifier for the smart contract on Chain B to the Network. As a result, the Network gets notified that the block header from Chain A needs to be sent to Chain B.

Summary of steps 1–3: A UA packages and transmits the data on Chain A to LayerZero’s endpoint on Chain A.

4. The Validator forwards this information to the Relayer. As a result, the Relayer is notified to prefetch the transaction proof and send it to Chain B.

5. The Network sends the identifier for the smart contract on Chain B along with the block ID of the transaction to the Oracle. As a result, the Oracle is notified to fetch the block header for the current block on Chain A and send it to Chain B.

Summary of steps 4 & 5: LayerZero’s Endpoints on Chain A send the transaction’s information to LayerZero’s reference Relayer and block ID of the transaction to the Oracle.

6. The Oracle then obtains the block header from Chain A.

7. The Relayer receives the transaction proof from Chain A and stores it off-chain.

Summary of steps 6 & 7: The Relayer and the Oracle receive the transaction proof and block header, respectively, from Chain A.

8. The Oracle waits for a certain number of block confirmations before confirming that the block has been successfully committed on Chain A. Post confirmation, the Oracle sends the block header to the Network on Chain B.

9. The Network sends the block hash to the Validator.

10. The Validator forwards the block hash to the Relayer.

11. The Relayer sends transactions that match the current block.

12. The Validator ensures that the transaction is valid and committed by going through the transaction proof and the block headers stored by the Network. If the block header and transaction proof match, the transaction information is sent to the communicator in the form of a Packet.

13. The Communicator emits the information (Packet) to the User Application on Chain B.

Summary of steps 8–13: LayerZero’s Endpoint on Chain B obtains the information initiated by the UA on Chain A using the block header and emits it to the UA on Chain B.


What’s in it for the users

  • No more hassle of switching between multiple networks. Less the clicks, the better the UX.

  • No need of executing multiple transactions and switching between tokens and their wrapped counterparts. Less money spent on transaction fees means more money to spend on other things.

  • No need to trust any centralized systems or intermediary chains.

  • Ease of transacting between chains and access to a very wide range of liquidity pools.


What’s in it for the developers

  • Ease of Integration — User applications building with LayerZero simply needs to implement two functions — send and receive. Any of the supported chains can be integrated with constraints. Basically, the team over at LayerZero has taken the developer-first approach.

  • Potential — LayerZero, as its name suggests, is a ground-level piece of infrastructure that can be utilized by liquidity networks, multi-chain yield aggregators, multi-chain lending protocols, and many other dApps to build out super interesting and uniquely multi-chain crypto use cases.

  • LayerZero Scan — LayerZero has built out its own explorer — LayerZero Scan, where cross-chain transactions are now tied together in a single database which allows users and developers to easily pull the state, status, and timing of transactions.


To summarize

The current experience of using bridges is not a pleasant one.

LayerZero looks quite promising and if the developer and user experience turns out to be how they claimed, then it can be a game changer in bringing about mass adoption.


That’s all for now folks..

Will be back with more articles in the #WhatTheFork series.

Also being a web3 engineer by profession, I am planning to write developer guides on such topics, explaining in detail such protocols/products from an integration perspective. More of degen less of normies stuff.

Find me on the web here.

Also published here.


Written by itsarjn | Your friendly neighborhood web3 guy..
Published by HackerNoon on 2023/04/18