HomeEconomicHow to build a safe and efficient DEX on Layer3?

How to build a safe and efficient DEX on Layer3?

Tips from FT Chinese Website: If you are interested in more content of FT Chinese Website, please search for “FT Chinese Website” in the Apple App Store or Google Play, and download the official application of FT Chinese Website.

The concept of Layer 3 is currently attracting attention in the blockchain community, and is regarded by many as a revolutionary advancement, because developers can create a variety of smart contracts and decentralized applications (dApps) on top of the blockchain platform. Layer 3 is a great engineering innovation for the Ethereum scaling ecosystem. If the emergence of Layer 2 solves the problem of general-purpose expansion, then the emergence of Layer 3 solves the problem of higher speed, lower cost, and customized expansion.

There are already many decentralized exchanges DEX built on Layer 2, so why do we need to build DEX on Layer 3? Most DEXs built on Layer 2 use the AMM model, and a few Layer 2 DEXs that use the order book model, such as ZigZag, have transaction costs that are a bit higher than CEX. Regardless of the AMM model or the order book model, the transaction speed and cost of DEX on Layer 3 will have a better user experience.

The reasons why Layer3 can build a safe and efficient DEX are as follows:

Layer3’s DEX can use a language that is more powerful than Layer1 Solidity to write a matching engine such as Rust;

Layer3 can be highly customized, simplifying the user’s transaction steps, and does not need to call the wallet authorization every time an order is placed;

The TPS of Layer3 is 100 times higher than that of Layer2. The cost is reduced by 1/100 order of magnitude again;

Layer3 is the same as Layer2, the consensus layer of both is assumed by Layer1, and the security level is high enough;

Layer3 has an independent data availability layer, and the visibility of off-chain transactions and asset status can be easily known and obtained;

Users can use EOA wallet or smart contract wallet to realize asset self-custody to better protect asset security.

Figure 1: DEX performance changes from Layer 1 to Layer 3

Layered Structure of Blockchain Infrastructure

At present, the blockchain infrastructure is mainly divided into four layers: Layer0, Layer1, Layer2, and Layer3. What exactly do these “Layers” refer to? Layer 1, which we are most familiar with, usually refers to the main network of the blockchain, which can be connected and traded through each node P2P without going through a centralized client server, among which Ethereum is the most typical. Every transaction is registered as a block and stored in a distributed database. Layer1 is the first to appear among the four layers. In order to achieve cross-chain assets, the Omnichain interoperability protocol, Layer0, has emerged, and its main application is various cross-chain bridges.

The classic blockchain Trilemma “trilemma” refers to different solutions in the same layer, and it is difficult to satisfy the three aspects of decentralization, scalability, and security at the same time. A typical case is that ETH has chosen decentralization and security at the expense of scalability, while many later public chains rely on a framework with a lower degree of decentralization to achieve higher TPS. Because of the existence of the “trilemma”, with the increase in the number of transactions, transaction delays and fee surges inevitably occurred. In order to solve network congestion, developers have proposed a Layer 2 expansion solution based on OP or ZK.

In this multi-layer structure design, Layer1 provides consensus for Layer2 and guarantees transaction security, while Layer2 separates calculations from the main blockchain as a relatively independent execution layer, minimizing delays and reducing transaction costs. Layer3 provides an abstraction layer between users and the underlying blockchain technology, making it easier for users to interact with dApps and smart contracts while keeping them secure through the underlying blockchain. Layer3 can further perform data compression on the basis of Layer2, and then pack the proof back to Layer1 through Layer2 for on-chain verification, thereby achieving faster and lower-cost transactions than Layer2.

After Layer2 completes the purpose of general-purpose expansion, developers and users will transfer to Layer3 to obtain more customized functions and higher performance, so it is expected that Layer3 will have a variety of large-scale applications. At present, a large number of dApps are using decentralized technology to move various business models of Web2 to Layer2. Layer3 will bring more possibilities and greater imagination to these applications.

How to use zero-knowledge proof to connect DEX to Layer3

DEX is a very important type of Layer3 application. If you want to build a DEX called OX Exchange on Layer3 developed by Fox Tech, what is the most critical technology to achieve this purpose? To deploy such a decentralized exchange at Layer 3, the use of zero-knowledge proof is the most critical.

From the perspective of interaction logic, the user’s operation in OX Exchange will be implemented in the form of calling a smart contract, that is to say, every buy and sell order will be converted into a call transaction (transaction) to the contract function, and such Every transaction will be submitted to the Layer2 node and executed through zkEVM.

In terms of specific implementation, smart contracts specifically deployed on Layer 2 will interact with Layer 3 applications. After receiving the batch transactions from Layer3, the Fox node of Layer2 will generate zkrollup proofs, including splitting opcodes and generating circuits, and then prove the correctness of execution based on the zero-knowledge proof algorithm. Finally, submit the generated execution correctness proof to the Layer1 chain, pass the verification of the contract on the chain, and accept the status update.

The service provided by Layer2’s zkrollup can obtain lower latency and better user experience. Specifically, OX needs to interact with Fox zkRollup located in Layer2, so as to use Fox’s “packaging” to obtain greater throughput. OX can provide a rich front-end operation interface, and the underlying complex interaction logic is completely transparent to users. Users can connect to Web3 wallets and directly use various services of DEX as in all DEXs.

It can be seen from this process that the zkRollup layer of Layer 2 is still responsible for performing calculations off-chain and submitting certificates to update the status on the chain, while Layer 3 is mainly responsible for performing more specific order engine functions that directly interact with users. By performing complex calculations from the chain in layers, the efficiency can be effectively improved, the transaction cost and throughput will undergo qualitative changes, and the user experience will be significantly improved.

Figure 2: Layer3 DEX architecture diagram

How to ensure the security of user assets through data availability DA

In all Web 3.0 projects, Data Available plays a vital role. All traditional applications, including the centralized exchange CEX, usually do not use DA, so the transparency of user data is extremely low, and the asset security level of CEX users depends entirely on whether the exchange is doing evil or not. Layer3 DEX uses proprietary data availability (DA), so while greatly reducing user fees, it also guarantees user transaction data and asset security.

Layer3 DEX has high throughput, which means that there is a huge amount of data to be processed. These data adopt the hybrid storage mode of “DA layer + L2” to take into account the efficiency and security. Contracts deployed on L2 only need to record a few key data and a Merkel root, while all other data in the process will be recorded on the DA layer. When the user interacts with the L3 application, the original data during the interaction process will be stored in the DA layer, and the DA layer will calculate a new Merkel root for the updated data; at the same time, the L3 application will also send a Proof, the contract will thus check the correctness of the Merkel root update. Such a mechanism can ensure the consistency between the state of the L2 contract and the DA layer, that is, to ensure that the recorded state is always correct.

The data of the centralized application is like a black box, and the L3 application with the DA layer is like a transparent and safe safe. Users of L3 applications don’t have to worry about the project party running away or going bankrupt, because the security of their assets no longer depends on the project party but on the three-layer Ethereum. In the case of zk-Rollup like Fox, the Ethereum consensus layer provides the best security for Layer 3 applications.

Figure 3: Data Availability DA of Layer 3 DEX

(Introduction to the author: Kang Shuiyue is the CEO of Fox Tech; Lin Yanxi is the CTO of Fox Tech. This article only represents the author’s point of view. Responsible editor email: Tao.feng@ftchinese.com)

Related Articles


Please enter your comment!
Please enter your name here
Captcha verification failed!
CAPTCHA user score failed. Please contact us!

Popular Articles