LayerZero: The First Omnichain Interoperability Protocol for Cross-Chain Communication

Steve Obasi
Coinmonks
Published in
16 min readJun 30, 2023

--

Introduction

Blockchain technology has revolutionized the way we store, transfer and process data in a decentralized, transparent and immutable way. However, one of the major challenges facing this technology is the lack of interoperability between different blockchain networks.

Each blockchain operates independently, which means users must keep their funds and activities within a specific blockchain. This restriction limits their ability to freely move funds and data between different blockchain systems.

However, there is a solution called LayerZero. It is the first trustless omnichain interoperability protocol that provides a powerful, low-level communication foundation for building various cross-chain applications.

With LayerZero, developers can create applications like cross-chain decentralized exchanges or multi-chain yield aggregators without relying on a trusted middleman or intermediate transactions. In simple terms, LayerZero allows direct transactions across all chains in a secure and trustworthy manner.

Allowing transactions to flow freely between chains provides opportunities for users to consolidate fragmented pockets of liquidity while also making full use of applications on separate chains.

Projects that have attempted to address Blockchain interoperability issue

Several projects have attempted to address the problem of blockchain fragmentation and interoperability, but none of them have achieved the ideal solution of Trustless Valid Delivery.

What is Trustless Valid Delivery? It is a communication primitive (i.e send and receive) that enables cross-chain token transfer by providing the following guarantees:

  • Every message M sent over the network is coupled with a transaction T on the sender-side chain.
  • A message M is delivered to the receiver if and only if the associated transaction T is valid and has been committed on the sender-side chain.

Here are some of the existing solutions and their limitations:

Ethereum — is the most popular platform for decentralized finance applications built via smart contracts. Ethereum 2.0 upgrades have addressed the scalability, security, and sustainability shortcomings in Ethereum 1.0. However, these advancements are largely orthogonal to LayerZero except that they are sure to boost the popularity of Ethereum, creating even more demand for convenient and cheap inter-chain communication.

Polygon — Polygon is a Layer 2 network designed to tackle the scalability and sovereignty issues faced by Ethereum. It offers Ethereum-compatible sidechains that are specific to certain applications. These sidechains bring together the benefits of scalability and autonomy from separate chains, while still leveraging the community and security of the Ethereum network.

However, it’s important to note that when using Polygon, the user’s token needs to be converted into a protocol-specific token. This conversion enables transaction consensus through an intermediate consensus layer. Although this layer is typically implemented securely, it does introduce a need for users to place trust in the sidechain facilitating the token transfer.

Polkadot — Polkadot is an early example of an open cross-chain ecosystem that showcases the potential of such systems. It operates using a relay chain that connects multiple domain-specific parallel chains, also known as “parachains.” These parachains enable the seamless flow of tokens and data between them. However, it’s worth noting that inter-chain communication in Polkadot always requires crossing the relay chain, which incurs additional costs.

LayerZero, on the other hand, offers a similar low-level communication platform as Polkadot but eliminates the need for extra transactions caused by an on-chain intermediary. It provides a direct and efficient communication primitive that allows for cross-chain interactions without the overhead of involving an on-chain middleman.

THORChain –is a DEX that utilizes pairwise liquidity pools to facilitate token transfers across various third-party chains. Each liquidity pool pairs a specific third-party currency with a native token called RUNE, which serves as a common medium for exchanging tokens. However, it’s important to note that while RUNE helps address scalability concerns, it introduces an additional complexity to the transaction process, which can make simple operations more cumbersome.

AnySwap — AnySwap is a DEX that aims to simplify token exchanges in a manner similar to THORChain. It utilizes an intermediate token called ANY, which is based on Fusion distributed control rights management. However, it’s important to note that like THORChain, the use of the ANY intermediate token introduces certain drawbacks such as overhead, delays, and additional transfer fees. These factors can potentially impact the efficiency and cost-effectiveness of transactions on the platform.

Cosmos — Cosmos is a blockchain network technology that enables the transfer of arbitrary messages between supported chains. It incorporates an Inter-Blockchain Communication (IBC) protocol, which facilitates direct cross-chain communication without the need for intermediaries or validators. However, it’s important to note that implementing IBC requires both the source and destination chains to adhere to certain specifications regarding consensus algorithms, data structures, and complex state machine replication logic. This ensures the proper functioning of the communication protocol and enables seamless interoperability between chains within the Cosmos ecosystem.

Chainlink — The Chainlink Decentralized Oracle Network (DON) framework is designed for building and connecting to decentralized oracle networks. Smart contracts, while being immutable, lack direct access to off-chain data sources that are crucial for their execution. Examples of such data include stock prices, measurements from IoT devices, and outputs from secure off-chain computations.

A DON extends the immutability property of smart contracts to the data sources and external resources they rely on, without relying on a central authority. By utilizing the Chainlink DON framework, the LayerZero protocol gains the capability to achieve trustless message delivery between different chains. This allows LayerZero to securely and reliably transmit information across disparate blockchain networks without the need for intermediaries or centralized entities.

What is the LayerZero Protocol

LayerZero is a communication protocol that enables direct, cross-chain transactions between blockchain networks. It provides a new way of interacting across chains without requiring a third party to intermediate. Therefore, this protocol preserves the core reason blockchains were invented in the first place: trustlessness.

The LayerZero protocol simplifies cross-chain transactions by providing a lightweight on-chain client called the LayerZero Endpoint. This client is supported by every chain in the network, creating a fully connected network where each node has a direct connection to every other node. This direct connection enables seamless cross-chain transactions with any blockchain on the network.

This capability opens up a range of possibilities for large-scale applications. Users can engage in cross-chain decentralized exchanges, multi-chain yield aggregation, and cross-chain lending. They can freely move liquidity between blockchains without relying on third-party systems. This means that a single pool of liquidity can be utilized across multiple decentralized finance (DeFi) applications on different chains.

In simpler terms, LayerZero acts as a universal translator for different blockchains, facilitating the exchange of assets and the utilization of various applications across multiple chains.

LayerZero currently connects more than 30 mainnet blockchains. It is already integrated with popular decentralized exchanges like PancakeSwap, SushiSwap, Trader Joe, and Uniswap. These integrations have resulted in a substantial transactional volume exceeding $6 billion and securing over $7 billion in total value locked.

The diagram below provides an overview of the LayerZero protocol, showcasing its functionality and connectivity within the cross-chain ecosystem. We will use the diagram to illustrate how LayerZero protocol works.

LayerZero Protocol

The steps involved in the LayerZero protocol are as follows:

1. In the context of the user application on chain A (App A), let’s consider a transaction T that involves a series of actions. We can uniquely identify transaction T using a transaction identifier, denoted as “t” (the specific format may depend on the type of chain A).

As part of transaction T, there is a step that involves sending a message over LayerZero, with the condition that the message must be delivered validly based on transaction T. In order to accomplish this, App A sends a request to the LayerZero Communicator, providing the following information:

  • t: The unique identifier for transaction T.
  • dst: A global identifier that points to a smart contract on chain B. This identifies the destination of the message within the LayerZero network.
  • payload: Any data that App A wishes to send to App B. This could be any relevant information or instructions.
  • relayerargs: These are additional arguments that describe payment information, which would be relevant if App A intends to use the reference Relayer service.

By providing this information to the LayerZero Communicator, App A can initiate the transmission of the message, ensuring its valid delivery based on the conditions associated with transaction T.

2. Once App A provides the necessary information to the LayerZero Communicator, the Communicator proceeds to construct a LayerZero packet. This packet, referred to as Packet(dst, payload), contains the destination (dst) and the payload data that App A wishes to transmit.

Along with the constructed packet, the LayerZero Communicator also includes the transaction identifier (t) and the relayerargs (payment information) provided by App A. The Communicator then sends this packet, along with t and relayerargs, to the Validator.

3. After receiving the packet, the Validator proceeds to send the transaction identifier (t) and the destination (dst) information to the Network. This step serves as a notification to the Network that the block header for the current block on chain A needs to be sent to chain B.

By sending this information to the Network, the necessary actions are initiated to transmit the block header from chain A to chain B, ensuring that the relevant data is shared between the two chains in a timely and secure manner.

4. The Validator forwards the LayerZero packet (Packet(dst, payload)), transaction identifier (t), and relayerargs to the Relayer. This action serves as a notification to the Relayer that the transaction proof for T needs to be prefetched and eventually sent to chain B.

It’s important to note that this step occurs concurrently with Step 3, meaning that while the Validator is sending t and dst to the Network to initiate the block header transfer, it also informs the Relayer about the transaction proof that will be required for the successful execution of the transaction on chain B.

5. The Network sends the destination (dst) and the block ID of the current transaction (curblkid) to the Oracle. This action informs the Oracle that it needs to fetch the block header for the current block on chain A and transmit it to chain B.

If multiple Layer Zero transactions occurred within the same block, Step 5 is executed only once. This ensures that the Oracle fetches and sends the block header efficiently, regardless of the number of Layer Zero transactions present in the block.

6. Oracle reads the block header (blkhdr) from chain A.

7. The Relayer retrieves the transaction proof associated with transaction T (proof(t)) from chain A. It reads this proof from the blockchain and stores it off-chain for future use.

It’s important to note that Steps 6 and 7 occur asynchronously to each other. This means that the Relayer can perform these steps independently and concurrently. Step 6 involves reading the transaction proof from chain A, while Step 7 involves storing the proof off-chain. This asynchronous nature allows for efficient handling of the LayerZero protocol, enabling parallel execution of these steps without one being dependent on the completion of the other.

8. Once the Oracle has obtained the block header (blkhdr) from chain A, it proceeds to verify that the corresponding block is stably committed on chain A. This verification ensures the reliability and integrity of the block before further processing.

Once the stability of the block on chain A is confirmed, the Oracle sends the block header (blkhdr) to the Network on chain B. The specific mechanism for determining when this transfer occurs may vary depending on the chain being used. However, it typically involves waiting for a certain number of block confirmations to ensure the stability and finality of the block on chain A.

9. Network sends the block hash.

10. The Validator forwards blkhdrhash to the Relayer.

11. Upon receiving blkhdrhash (the hash of the block header), the Relayer proceeds to send a list of tuples containing Packet(dst, payload), t, and proof(t) that correspond to the current block. These tuples represent the LayerZero packets, transaction identifiers, and transaction proofs that match the block identified by blkhdrhash.

In cases where multiple users simultaneously send messages between the same endpoints, there may be multiple packets and associated transaction proofs within the same block. The Relayer ensures that all relevant packets and transaction proofs are included in the list, capturing the messages sent by different users in a comprehensive manner. This allows for the proper synchronization and processing of LayerZero transactions within the same block, despite multiple concurrent activities occurring between the same endpoints.

12. The Validator, utilizing the transaction proofs received and the block headers stored by the Network, engages in a validation process to determine the validity and commitment of the associated transaction T. It examines the relationship between the transaction proof and the block header to establish their coherence.

If the block header and transaction proof do not match, indicating a discrepancy or inconsistency, the Validator discards the message. This ensures that only valid and accurately verified transactions are processed within the LayerZero protocol.

However, if the block header and transaction proof match, signifying their compatibility and consistency, the Validator proceeds to send the LayerZero packet, Packet(dst, payload), to the Communicator.

13. The Communicator proceeds to emit the Packet(dst, payload) to App B.

Achieving Trustless Valid Delivery

In the design of LayerZero, trustlessness is a fundamental principle. Rather than relying on trust, LayerZero emphasizes the concept of independence between its components. This means that the user doesn’t need to trust the individual elements of LayerZero, but rather the independence between the Oracle and Relayer. This approach ensures efficiency and keeps the protocol lightweight.

Valid delivery is a crucial aspect of LayerZero. According to the protocol, a message M is considered delivered to the user application only if the transaction proof (associated with M) can be successfully validated in Step 12. The validation process relies on matching the block header with the transaction proof. There are two scenarios in which this matching occurs:

  1. Both the block header provided by the Oracle and the transaction proof provided by the Relayer are valid.
  2. Both the block header and the transaction proof provided by the Oracle and the Relayer, respectively, are invalid, but still match.

Scenario 2 can only happen if the Oracle and the Relayer collude. However, the design of LayerZero eliminates the possibility of collusion.

Therefore, if a message is delivered to the user application on the receiver side, it is guaranteed to meet the criteria of valid delivery.

Having a communication protocol that ensures trustless valid delivery, without relying on intermediary entities or tokens, is the ideal solution for enabling cross-chain transactions. LayerZero is the first system that has proven this property. This characteristic will drive user adoption of LayerZero as the preferred method for cross-chain messaging.

LayerZero Endpoint

The LayerZero Endpoint is implemented as a set of smart contracts on each chain within the LayerZero network. Its core functionality is divided into three modules: Communication, Validation, and Network. These modules operate in a similar manner to a network stack, with messages flowing down the stack from the Communicator to the Validator and then to the Network on the sender side. On the recipient side, messages travel up the stack in reverse order.

Apart from the core modules, the LayerZero Endpoint can be expanded through Libraries, which are additional smart contracts that define how communication should be handled for a specific chain. Each chain in the LayerZero network has its own associated Library, and every Endpoint includes copies of all the Libraries.

This modular design allows for the seamless integration of new chains into the LayerZero network whenever needed. Moreover, when two chains need to communicate, it only requires that their respective libraries be present on both ends. This feature enables LayerZero to function as a fully-connected network, facilitating transactions between any pair of nodes within the network.

LayerZero Endpoint Cost Scalability

One of the challenges in running smart contracts on Layer 1 chains is the cost associated with storing data, especially as the amount of data increases. To ensure that the LayerZero Endpoint remains practical, it has been designed to be as lightweight as possible.

A key observation is the fact that there is no need to replicate and store block headers within the client itself. Instead, it relies on off-chain entities, namely the Oracle and Relayer, to fetch the required cross-chain headers and transaction proofs. By delegating this task to these off-chain entities, it has significantly reduced the weight and resource requirements of LayerZero Endpoints.

This lightweight design approach makes LayerZero Endpoints cost-effective, even on chains known for their high costs, such as Ethereum. It allows users to benefit from the functionalities of LayerZero without incurring excessive expenses associated with data storage on Layer 1 chains.

Case Study: LayerZero on EVM

Here is a brief overview of how LayerZero support for Ethereum Virtual Machines (EVMs) is implemented. While the implementation details may vary across different chains, let’s focus on the specific requirements of the Ethereum chain.

LayerZero Packet: The format of the Layer Zero packet varies depending on the source and destination chains. The table below illustrates the precise layout of the Layer Zero packet for EVM endpoints:

LayerZero packet for EVM endpoints

Sender-side chain transaction stability: To maintain the stability of the message transaction on the source chain, LayerZero leverages the reliable nature of decentralized oracle networks. This is achieved by allowing the Oracle to notify the destination chain about a specific block header only after it has received a certain number of block confirmations. In the context of Ethereum, this number is typically set at 15.

In practical terms, Step 8 of the LayerZero protocol is executed by the Oracle once it has successfully obtained and confirmed 15 block confirmations on chain A. By waiting for these confirmations, LayerZero ensures that the transaction on the source chain is considered stable and less susceptible to potential network inconsistencies or reorganizations.

LayerZero Endpoint: The LayerZero Endpoint is built using a series of smart contracts, which consist of four main modules: the Communicator, Validator, Network, and Library. While the Communicator, Validator, and Network modules are implemented as separate smart contracts for most existing blockchains, including Ethereum, the design allows for flexibility in accommodating chains with different requirements in the future.

In the case of the Ethereum blockchain, the Library component plays a crucial role in supporting LayerZero Endpoint. It handles the construction of the LayerZero packet specific to the EVM, as illustrated in Figure 6. Additionally, the Library takes care of encoding and decoding EVM smart contract addresses, enabling seamless communication between different chains.

Moreover, the Library is responsible for performing the actual computation required to validate the transaction proof. In the case of the EVM, our implementation utilizes Merkle-Patricia Tree validation for transactions within an EVM block. We have built upon the open-source implementation provided by GoldenGate, ensuring the integrity and reliability of the validation process.

By leveraging the capabilities of the Library, LayerZero is able to support the Ethereum blockchain and efficiently handle the unique aspects of EVM-based transactions. This modular design allows for extensibility and enables the inclusion of new chains with specific requirements, further expanding the capabilities of LayerZero.

Applications on LayerZero

LayerZero’s capabilities enable the development of various large-scale applications, three of which are cross-chain decentralized exchanges, multi-chain yield aggregators, and multi-chain lending. These examples showcase the potential of LayerZero to revolutionize the decentralized finance landscape by providing trustless cross-chain transactions.

1. Cross-chain decentralized exchange: LayerZero facilitates the creation of a cross-chain DEX, also known as a cross-chain bridge, that operates exclusively with native assets. Unlike existing DEX designs that rely on wrapped tokens or intermediary sidechains, a DEX built using LayerZero allows liquidity pools to exist on multiple chains. Users can deposit their native assets into one pool and withdraw native assets from another, enabling seamless asset transfers between chains. LayerZero’s messaging primitive supports direct bridges with 1:1 pricing, automated market making with ab=k pricing, and other pricing derivations like CurveDAO. The guarantee of valid delivery provided by LayerZero ensures secure and efficient cross-chain decentralized exchange operations.

2. Multi-chain yield aggregator: Traditional yield aggregators operate within a single chain ecosystem, limiting their ability to tap into yield opportunities across different ecosystems. By utilizing LayerZero for cross-chain transactions, a multi-chain yield aggregator can leverage the best yield opportunities from various ecosystems. This expands access to high-yield opportunities and enables users to benefit from market inefficiencies across multiple chains. With LayerZero, the strategy of a multi-chain yield aggregator can adapt to different scenarios, ranging from taking advantage of opportunities on a single chain to exploring exponentially more opportunities across chains.

3. Multi-chain lending: Currently, users face challenges when trying to seize opportunities on chains where they do not hold assets. For instance, if a user primarily holds ETH but wants to take advantage of an opportunity on Polygon, they would typically need to move their entire asset base to Polygon or engage in a complex process of borrowing and bridging assets. LayerZero simplifies this process by enabling a lending protocol that allows users to keep their assets on Ethereum while lending them out and borrowing directly in the desired asset on Polygon. This eliminates the need for costly intermediaries such as bridges and swap fees, making multi-chain lending more efficient and accessible.

While these examples only scratch the surface of the possibilities enabled by LayerZero. Developers can leverage LayerZero’s capabilities to build applications without worrying about the differences in semantics between inter-chain and intra-chain transactions. Users gain the freedom to move liquidity across chains seamlessly. The community can now explore and create innovative applications empowered by the trustless cross-chain transactions facilitated by LayerZero.

Conclusion

The article presents LayerZero as a groundbreaking protocol for trustless and efficient cross-chain communication. It emphasizes the elimination of intermediaries and the direct transfer of tokens across different blockchain networks. LayerZero’s design and implementation address the longstanding challenge of interoperability in the blockchain industry. Unlike existing solutions that involve conversions or additional transactions, LayerZero enables secure and seamless token transfers between chains.

The protocol’s key features, including trustlessness, modularity, and user experience, are highlighted as driving forces in shaping the future of blockchain interoperability.

With its innovative approach and powerful communication foundation, LayerZero opens up a multitude of possibilities for building cross-chain applications that leverage the strengths of different blockchain systems.

Credit

All images are from LayerZero whitepaper

--

--

Steve Obasi
Coinmonks

Crypto Research Writer. Follow me to gain insights on happenings in Finance and Web3