ArtexSwap is a decentralized exchange that uses Artela EVM++ and Aspect technology to solve MEV risks and Rug Pull problems, improve transaction security and efficiency, and is suitable for decentralized trading scenarios that require high security and flexibility.

Since the birth of Ethereum, it has been the technology home of digital currency, global payment and applications. DEX is the cornerstone of decentralized finance (DeFi). After all, without DEX, DeFi can be said to be just empty talk. As a platform running on the blockchain, it runs direct transactions between users and is not regulated by any third-party institutions, which allows it to create more advanced financial products.

1. Dex mainstream architecture

At present, DEX is flourishing in the Ethereum ecosystem. There are many different design patterns for DEX, and each pattern has its own advantages and disadvantages in terms of functionality, scalability, and decentralization.

Depending on the transaction mechanism, DEX can be divided into two categories (as shown below).

1.1. Order book based DEX

The order book is essentially a matching algorithm that automatically searches for buy and sell orders that have not yet been signed in various markets. The trading platform system will automatically match these buy and sell orders. It is suitable for scenarios that require efficient price matching and flexible trading strategies. In short, the liquidity of the order book comes from two sources: traders and market makers.

Further reading: "Brief Analysis: Order Book Model and Automated Market Making AMM" (see Appendix)

1.2. Automated Market Maker (AMM)

Automated Market Maker (AMM) is a pricing and liquidity determination mechanism in DEX. Simply put, the market maker provides liquidity assets (two assets) for the liquidity pool. The product of the reserves in the liquidity pool is maintained at a value of k. When a user takes a coin, he needs to provide another coin to the liquidity pool to maintain this k value.

For a detailed understanding of AMM, please read: "UniswapX Research Report (Part 1): Summarizing the Development Links of V1-3 and Interpreting the Principle Innovation and Challenges of the Next Generation DEX"

1.3 What value does DEX have?

[Data source: THE BLOCK]

According to CoinGecKo's statistics, as of July 9, 2024, there are approximately 835 known DEX exchanges, with a total 24-hour trading volume of US$8.35 billion and 320 million monthly visits.

The 3 largest decentralized exchanges by trading volume are BabyDogeSwap, Uniswap V3 (Ethereum), and Orca.

We calculated the 24-hour trading volume of the top three DEX and CEX exchanges. DEX accounts for 16% of the daily trading liquidity, and the 24-hour trading volume of DEX has increased by 315% year-on-year compared to this time in 2023 (2 billion in 2023), and the trading volume has increased by 166% year-on-year (120 million in 2023). It is obvious that the market demand for decentralized trading platforms is huge.

Since decentralized exchanges (DEX) use deterministic smart contracts to conduct transactions without the intervention of a centralized third party, this transparent operation is in stark contrast to traditional financial markets.

For example, in 2022, FTX, one of the largest cryptocurrency trading platforms at the time, went bankrupt during a series of declines due to the misappropriation of user funds, triggering widespread market shocks.

Additionally, DEXs improve financial inclusion through decentralization, and some CEXs may restrict user access based on geographic location or other factors.

But in general, users only need to access the Internet and connect to a compatible self-built wallet to use DEX services. This model, which does not require cumbersome registration and review, enables new users to join the platform quickly and conveniently, improving the user experience.

2. Main risks of DEX

Decentralized exchanges (DEX) ensure transaction execution, increase transparency, and are accessible without permission. These features significantly lower the barriers to trading and providing liquidity. However, DEX is also accompanied by some risks, which include but are not limited to the following aspects:

  1. Smart contract risks: Although blockchain technology can safely execute financial transactions, the security of smart contracts depends on the technical level and experience of the development team.

  2. Front-running risk: Due to the public and transparent nature of on-chain transactions, arbitrageurs or MEV robots may front-run transactions and extract value from ordinary users. These robots are similar to high-frequency traders in traditional financial markets, profiting from ordinary users' transactions by paying higher transaction fees and taking advantage of network delays.

  3. Network risk: Since transactions are conducted on-chain, DEX transaction costs can be high, and they are even higher when the network is congested or down. Therefore, users are vulnerable to market fluctuations.

  4. Rug Pull risk: A common and serious problem in the field of decentralized finance (DeFi). There are many projects that suddenly withdraw liquidity and run away with the funds after attracting a large amount of investor funds. Currently, the risks of Rug Pull can be roughly divided into three categories:

  • Liquidity Withdrawal

  • Developers hold a large number of tokens and/or issue additional tokens

  • Fake Projects

This scam caused heavy losses to investors and the project value instantly dropped to zero, which had a significant impact on the trust of the entire DeFi market.

For example, the SushiSwap incident in 2021 is a typical example. After the project raised a lot of funds, Chef Nomi, the anonymous founder of SushiSwap, suddenly sold $13 million worth of SUSHI tokens in the developer fund, causing market panic and causing the token price to plummet.

Although Chef Nomi later returned the funds and the community took over the project management, this incident caused huge losses and psychological shock to investors.

3. Issues extending from Bancor to DEX

If we talk about who was the first project to try out AMM, we have to mention Bancor. It’s a bit pitiful to say that it did not receive widespread attention before the DeFi boom, so many people mistakenly believed that AMM was invented by Uniswap.

Today, with the launch of Bancor V2, although V2 introduces innovative designs such as oracles providing the latest prices and updating the token pool ratio based on oracle prices, it still has some shortcomings.

  • Although the introduction of oracles can provide more accurate price information, it also brings challenges in implementation. For example, if there is no corresponding trading pair price on the centralized trading platform, this creates a chicken-and-egg problem. In addition, the reliability and security of oracles are also worthy of attention. Oracles may become targets of attacks, leading to price manipulation and other security issues.

  • Although the dynamic pool model can update the proportion of the token pool according to the price of the oracle, liquidity providers (LPs) may face greater risk of loss in the case of high market volatility. The greater the market volatility, the more serious the LP's impermanent loss may be, which may cause liquidity providers to withdraw funds, thereby affecting the stability and trading efficiency of the liquidity pool.

  • Bancor’s design may also face counterparty risk. Although the oracle mechanism has been introduced, if the market price fluctuates violently and the oracle cannot update the price in time, the liquidity provider may still face greater risks. If the oracle price is not updated in time or is inaccurate, it may cause LP to lose money in price fluctuations.

Although Bancor V2 introduces many innovative designs, its complexity also increases the learning and usage threshold for users. Compared with other relatively simple and easy-to-use AMM models, Bancor may require users to have more professional knowledge and technical background to fully understand and utilize its new features. This may limit its user growth and market acceptance.

4. DEX implementation of ArtexSwap

The ArtexSwap platform operates similarly to Uniswap, but with enhanced security through the use of the native capabilities of Artela EVM++.

4.1Artela’s Scalability Mechanism

First of all, in order to better understand the underlying environment of ArtexSwap, let us briefly talk about the underlying operating mechanism of Artela. The scalability here actually contains two meanings, namely the scalability and performance of EVM.

For scalability, Artela introduced Aspect technology to implement it. This technology supports developers to create on-chain custom programs in the WebAssembly (WASM) environment. These programs can collaborate with EVM to provide high-performance customized application-specific extensions for dApp.

For more information, please visit: Vitalik Buterin’s full text: The next step for Web3.0 infrastructure: “Encapsulation or extension”? (see Appendix)

From a performance perspective, it is to improve the execution efficiency of EVM. We all know that EVM is a serial virtual machine environment. Compared with today's hardware, the utilization rate of this method is very low, so parallel processing is particularly important.

To achieve parallel execution, how to solve the following problems:

1. How to resolve conflicts between things executed at the same time?

A parallel execution strategy using predictive optimistic execution is adopted, assuming that there is no conflict between transactions in the initial state, and each transaction records the modification but is not finalized immediately.

After the transaction is executed, it is verified to check whether there is any conflict. If so, it is re-executed.

Predictiveness is achieved by analyzing historical transaction data through AI models, predicting transaction dependencies, optimizing execution order, and reducing conflicts and duplicate executions.

In contrast, Sei and Monad rely on predefined transaction dependency files and lack the adaptive capabilities of Artela’s AI-based dynamic prediction model, which is Artela’s advantage in reducing execution conflicts.

2. How to increase the speed of IO and reduce the waiting time for transaction execution?

Asynchronous preloading technology is used to solve the input and output (I/O) bottleneck caused by state access.

Before a transaction is executed, Artela uses a predictive model to preload the required state data from slow storage (such as hard disk) to fast storage (such as memory). This advance loading and caching data technology enables multiple processors or execution threads to access it simultaneously, improving the parallelism and efficiency of execution.

3. How to solve the problem of data expansion during writing and increased pressure on database processing?

Artela has developed a parallel storage system by combining a variety of traditional data processing technologies to improve the efficiency of parallel processing. The parallel storage system mainly solves two problems: one is to realize the parallel processing of storage, and the other is to improve the ability to efficiently record data status to the database. In the process of data storage, common problems include data expansion when writing and increased database processing pressure. To this end, Artela adopts a strategy of separating state commitment (SC) from state storage (SS). This strategy divides the storage task into two parts: one part is responsible for fast processing operations and does not retain complex data structures to save space and reduce data duplication; the other part records all detailed data information. In addition, Artela reduces the complexity of data preservation by merging small blocks of data into large blocks, so as not to affect performance when processing large amounts of data.

In addition, the validator nodes support horizontal expansion, and the network can automatically adjust the size of computing nodes according to the current load or demand. This expansion process is coordinated by the elasticity protocol to ensure sufficient computing resources in the consensus network.

Through elastic computing, the computing power of network nodes can be expanded, and elastic block space is realized, allowing independent block space to be applied for according to demand, which not only meets the expansion needs of public block space, but also ensures performance and stability.

This allows the DEX network to respond calmly to peak transactions like the elastic expansion of Web2.

It is worth mentioning that elastic block space, as a solution for horizontally expanding blockchain performance, is based on the premise that "transactions can be parallelized". Only after the degree of transaction parallelism is increased, it is necessary to horizontally expand the node's machine resources to improve transaction throughput.

4.2 ArtexSwap’s DEX Security Exploration

ArtexSwap has been updated to version 2.0. From the perspective of ArtexSwap’s architecture, it mainly focuses on three security aspects, namely:

  • How can DEX identify and prevent malicious behavior?

  • How to prevent users from being harmed by Rug Pull during transactions?

  • How to prevent high slippage?

Blacklist Mechanism

The blacklist mechanism is a strategy that puts the focus on security first, because from a behavioral perspective, addresses and users that have participated in "bad things" are very likely to commit crimes again. By marking accounts, addresses and contracts with dangerous labels, the ArtexSwap platform can conduct a priori analysis of both parties and the environment of the transaction before the transaction. The Blacklist mechanism will continuously monitor transaction activities and eliminate the "dangerous elements" on the blacklist one by one. When operation requests from blacklisted accounts are detected, these requests will be automatically blocked to prevent malicious behavior.

For example, if an account is blacklisted for having participated in Rug Pull or other fraudulent activities, that account will not be able to trade or add liquidity on the DEX, thereby protecting other users from potential losses.

In essence, ArtexSwap provides a C-end passive defense system with a rear-end focus.

Anti-Rug Mechanism

Rug Pull refers to the situation where developers or large holders suddenly increase the token supply or withdraw most of the funds in the liquidity pool, causing the token price to plummet and investors to suffer huge losses.

This type of situation is usually accompanied by a backdoor in the contract. If the contract reaches this step, it is usually a fish that slips through the blacklist mechanism. Because the blacklist information has a certain lag, there are generally two situations:

1. This contract vulnerability has not been discovered,

2. Did you find the blacklist?

Let’s talk about the first one first. When there is no direct evidence that the token contract is problematic, ArtexSwap generally adopts an optimistic mechanism to deal with it, that is, it assumes that it is safe, but the ArtexSwap platform will always monitor any attempts to significantly increase the token supply. Once such a situation is discovered, it will be blocked, and at the same time, other users will be prevented from trading related tokens to avoid losses.

The second method relies on off-chain message communication. When off-chain message communication is enabled, Aspect allows interaction and data exchange outside the blockchain. This allows ArtexSwap to obtain the addresses of relevant malicious contracts from third-party information sources in real time, and then perform security checks on the token contracts on the entire DEX. Once a malicious contract is found, all related operations will be directly blocked.

Slippage Mechanism

What needs to be made clear is that under the liquidity mechanism of AMM, high slippage leading to losses is a high probability event. To put it simply, slippage refers to the difference between the transaction execution price and the expected price. When the market is volatile or liquidity is insufficient, slippage will become significant. This is a mechanism problem.

Obviously, the prevention of Slippage is a "predictive" problem. It is not difficult to solve the problem of insufficient liquidity. The contract of the ArtexSwap platform only needs to monitor the liquidity pool in real time to achieve this goal. The difficulty lies in the volatility of the market. Because the market is an external event information, the first thing that comes to mind is to access the oracle to obtain the market status. In order to achieve this, ArtexSwap needs to use its basic operating environment. Artela supports Aspect technology. ArtexSwap uses this to create a dApp on the chain. The dApp can interact with third-party oracles to obtain market fluctuations. Artela supports AI agents, which predict the high slippage of transactions at a certain moment through market status data and AI, and combine the liquidity monitoring mentioned above to obtain an estimated value. When the estimate exceeds a threshold (30%), the transaction is blocked, thereby protecting traders from losses caused by drastic price fluctuations.

5. Summary

Although we are unsure whether the current DEX model can support long-term growth and institutional adoption, it is foreseeable that DEX will continue to be an indispensable infrastructure in the cryptocurrency ecosystem.

Again, behind every successful scam, there may be a user who stops using Web3, and the DEX ecosystem will have nowhere to go without any new users, so for DEX, losing security means losing everything.

However, under the current hot background of DEX track, the narrative of derivatives seems to be able to flourish. But in the long run, DEX is the most certain demand of users, so no amount of attention is too much.

appendix

《Brief Analysis: Order Book Model and Automated Market Making AMM》

https://mirror.xyz/coincapital.eth/jkCgaKOOtXUn2Iv47y_1npwsyC5Cm0qL3GoVhTUA-IE

《V God's full text interpretation: Is the next step for Web3.0 infrastructure "encapsulation or extension"? 》https://www.blocktempo.com/is-the-next-step-for-web3-infrastructure-encapsulation-or-extension/