LayerZero was born to solve the problem of bridge security. That problem is creating a big threat to DeFi when cross-chain linking is an inevitable trend. Although it does not solve everything, LayerZero creates a spark to develop decentralized finance.
I wrote an introductory article “What is LayerZero? Overview of LayerZero cryptocurrency” on Weakhand Website. But in this article, I will focus on analyzing the structure and operating mechanism as well as how LayerZero operates.
To understand more about how LayerZero operates, you can read the following article:
- Bridges: Design, Trade-offs, and Opportunities
- What is LayerZero? LayerZero Cryptocurrency Overview
LayerZero Overview
LayerZero is the infrastructure for developing Omnichain applications. dApps built on LayerZero will inherit the platform’s multi-chain communication technology. Helps come up with new solutions that bring many benefits to users.
LayerZero is also a bridge that relays messages between different networks. Thanks to LayerZero’s structure and intelligent operation, that activity takes place safely. The specific structure and operation of LayerZero will be presented in great detail in the next section, please read it carefully!
LayerZero’s Working Mechanism
Structure
In general, LayerZero is the bottom layer of Layer 1. It connects Layer 1, Layer 2 or even Layer3. Connecting to LayerZero is very simple and easy thanks to the toolkit and its internal structure. We continue to study in depth the detailed structure of LayerZero right below.
Basically LayerZero is divided into 3 main parts: Endpoint, Relayer, Oracle:
- Endpoints: Is a user-facing interface. Can also view points placed on other networks and link with Relayer, Oracle. Its main task is to receive and send information and messages between networks. It can be viewed as a client placed on blockchains. Especially without storing data, the Node is super light, so it helps LayerZero transition at a very cheap fee. Additionally, user applications will be built on the Endpoint.
- Oracle: Is a third-party service that provides a mechanism, operating independently of LayerZero components. It reads the block header from one thread and sends it to another thread. In theory, this Oracle could be any third-party service that provides this mechanism, but currently LayerZero is using Chainlink, which provides the market leading Oracle service.
- Relayer: Is a service that operates Off-chain and has similar functions to Oracle. But instead of fetching block headers, it fetches proof for a specific transaction. Users can create their own Relayer service. At Relayer data will be stored Off-chain.
Continuing to delve into the structure of the Endpoint, it is divided into 4 parts: Communication, Validation, Network, Thư viện. About Communication, Validation, Network is the core function of Endpoint. Still Thư viện is a library that stores the core modules of each network. When new networks want to integrate into LayerZero, simply add the module to the library without modifying anything else. This feature makes LayerZero integration easy and users can pass messages to any network that has a module in the library.
Mechanism of action
Details of LayerZero’s operation when transferring a message across the chain will be specified in 13 steps as shown in the picture:
Step 1: When a user commits a transaction T. The user application on chain A sends a transaction T, the transaction T will be identified by an identifier (the format of this code is determined by each different chain ). This message will be sent to LayerZero Communicator contains the following information:
- t: Unique transaction identifier for T
- dst: Universal identifier pointing to the smart contract on chain B.
- payload: Any data that the application on chain A wants to send to the application on chain B.
- relayer_args: The payment description argument is formed in case application A wants to use it Relayer reference.
Step 2:
Communicator close a containing LayerZero package dst and payload. payloadcalled Packet(dst, payload). And send it along t, relayer_args next Validator.
Step 3: Validator send t and dst next Network. This step informs Network that the block header for the current block on chain A needs to be sent to chain B.
Step 4: Validator send Packet(dst, payload), t and relay_args arrive Relayer, inform
Relayer that it is necessary to fetch transaction proof for T first and then sent to chain B. This step happens concurrently with step 3.
Step 5: Network send dst and blockID of the current transaction (cur_blk_id) to Oracle. This forces Oracle must fetch the block header for the currently incoming block on chain A and send it to chain B. In case there are multiple LayerZero transactions occurring in the same block, this step must be performed only once.
Step 6: Oracle Read block header (blk_hdr) from string A.
Step 7: Relayer Read the transaction proof associated with transaction T(proof
Stargate is LayerZero’s debut product
After reading the entire operating mechanism, you will certainly wonder, LayerZero transfers messages, so how will assets be transferred? In this section we go into the workings of Stargate to learn how it relies on message passing technology to support cross-chain transactions.
If you don’t know about Stargate, Stargate is a Dex Crosschain built on LayerZero technology. The project is developed by the LayerZero Labs team. And is the first project developed on LayerZero.
Stargate works by creating a liquidity pool for Stablecoins on networks through LayerZero Endpoints. When a user wants to transfer funds from the start chain to the destination chain. Then the user must deposit money into the Pool of the first chain. Next, the Endpoint in the first thread will send a message to the Endpoint of the target thread according to the process presented in the working mechanism of LayerZero. After the Endpoint in the destination chain receives news that the user needs to transfer money to the wallet address in the destination chain and it has been confirmed that there is enough money in the first chain liquidity pool, the Endpoint will transfer the news to the Pool in the destination chain for the correct transfer. assets are recorded in the message to the destination chain wallet address.
In general, Stargate works like cross-chain money transfer through Stablecoin. But Stargate supports always transferring any asset other than Stablecoin. Thanks to the connection to other Dexes on the networks to convert assets to Stablecoins. Then just transfer the correct amount of Stablecoin to another chain and then exchange it for the asset the user wants to receive on the destination chain.
Stargate supports transferring any type of asset or to all networks, as long as the network is connected to LayerZero and has liquidity locked in the Pool to transfer funds.
Summary
With LayerZero, it is not only possible to transfer simple asset messages, but with that operating mechanism it can also transfer message data files with algorithms to apply to Pool AMM or other algorithms. .
So I have presented in the most detail how LayerZero works and applications. Hope this article brings you a lot of useful knowledge.