The U.S. stock market was now a class system, rooted in speed, of haves and have-nots. The haves paid for nanoseconds; the have-nots had no idea that a nanosecond had value.
— Flash Boys: A Wall Street Revolt by Michael Lewis
This is the money game Michael Lewis depicts in his bestseller Flash Boys: A Wall Street Revolt. High-frequency traders use information edge to trade ahead of pending orders, which is known as front-running. Individual investors can hardly compete with professional traders with faster computer hardware, software, and data lines in a centralized system like Wall Street. So most of the time, they are the prey to be hunted.
The rise of DeFi in 2020 has led to the emergence of an increasing number of decentralized protocols, including DEXs, lending platforms, insurance products, etc., and created a more fair environment for ordinary users. DEXs, especially those based on AMM(Automated Market Maker) like Uniswap with higher capital efficiency and fairer price discovery, seem ideal solutions to the centralization problems.
User transactions are publically accessible and fully transparent. As a result, it effectively prevents trust problems commonly seen in centralized exchanges. However, those advantages are turning public blockchains like Ethereum into a “Dark Forest.”
Ethereum, the Dark Forest
“Dark Forest Theory” is from The Three-Body Problem，a reputed fiction novel by Chinese writer Liu Cixin.
In the novel, Liu compares the universe to a dark forest where civilizations fear one another so much that they don’t dare to reveal themselves. If they do, they will immediately be considered a potential threat and destroyed. With the start of DeFi summer in 2020, Ethereum has become a dark forest where ordinary users become targets of more intelligent “creatures” like bots while frontrunning becomes rampant in DeFi.
The topic of frontrunning in blockchain systems, specifically in decentralized exchanges, was first discussed by Philip Daian in his paper Flash Boys 2.0: Frontrunning, Transaction Reordering, and Consensus Instability in Decentralized Exchanges.
Philip pointed out that like high-frequency traders on Wall Street, arbitrage bots exploit inefficiencies in DEXes, paying high transaction fees and optimizing network latency to frontrun, i.e., anticipate and exploit ordinary users’ DEX trades. While Wall Street’s high-frequency trading mostly takes place in dark pools, DEXs are “lit markets” where every transaction on the blockchain is transparent. It can be replicated, front-run, and even stolen, but you can do nothing about it.
When users submit a transaction on Ethereum, that transaction waits in the mempool before a miner picks it up and adds it to a new block. As a result, miners will prioritize transactions with higher gas fees because they get to keep the fee. When the network gets crowded, you can always raise the gas prices to execute your transactions faster. This part of the profit miners could get, besides regular block rewards, is called Miner Extractable Value, also known as MEV.
At the time of writing, simple transactions like token transfer on Ethereum take 21,000 gas, while more complex smart contract executions like trades on DEXs can cost 100,000 gas or more. Since last summer, the emergence of DeFi activities on Ethereum has led to increasingly complex executions of smart contracts and an explosion of gas fees, which implies also an explosion of MEV.
Huge profits hidden on-chain are driving more players into the dark forest. Most of them are automated bots searching for opportunities to get more MEV. DEXs, a key driver of the booming DeFi market, has become the center of attention.
A Transparent Gas War
The transparency of blockchain, together with the latency in executing orders, makes front-running easy. As a result, anyone can track other users’ pending transactions in the mempool and place their own transactions ahead with higher gas fees. This is called front-running, a major form of MEV attacks.
By creating a transaction with a higher fee, a frontrunner can have their transaction processed and added to a block before the original pending transaction. Besides front-running, other ways to get more MEV also include back-running and sandwich attacks.
We can explain them with a simple example: Bot B finds out that user A is buying 100 ETH. This transaction is enough to push the price higher, so B immediately submits a transaction to buy 50 ETH with a higher gas price. The result is B buys ETH at a lower price while pushing the price up for A. By doing this, B completes a front-running attack.
B then submitted a transaction to sell those 50 ETH at a higher price following user A’s transaction with a slightly lower gas price. This is called back-running.
Together with front-running and back-running, B successfully launched a sandwich attack and made a profit. Those arbitrage bots are everywhere in DeFi. Ironically, the hacker in the DODO’s $3.8million hack in March also ended up being the victim of frontrunning bots.
A lot of the money-making strategies were of the winner-take-all variety. When every player is trying to do the same thing, the player who gets all the money is the one whose computers can take in data and spit out the obvious response to it first.
—Flash Boys: A Wall Street Revolt by Michael Lewis
Though lucrative, frontrunning is not risk-free. More and more bots join the competition, but there is only one winner. In Wall Street’s game, speed is everything. But on Ethereum, miners who can reorder transactions within a block are at the top of the food chain. They can be the front-runner themselves or share the profit with front-runners.
Either way is unfair exploitation of real DEX users. Front-running can cause failed transactions or higher slippage. Websites like sandwiched.wtf allow users to find out how much they were stolen from front-running bots. Front-running also takes up precious block space, which leads to increasingly higher gas fees and a congested network.
MEV attacks put DEXs in a dilemma as the problem gets worse with DEX volume growing, which will keep real users away and slow the growth of DEX. From the other point of view, institutions which value privacy most will not have a strong appetite to participate in decentralized finance as long as those problems exist.
Flashbots launched MEV-Geth, an effort to Democratize Extraction. According to Flashbots, it creates a more efficient communication channel for miners and traders bidding to include their transactions.
The adoption of MEV-Geth should relieve the network and chain congestion caused by bots, but it does not stop front-running.
MantaSwap, A Private AMM DEX
Dedicated to solving those problems caused by a lack of privacy in decentralized finance, Manta Network is ready to launch its first products, including a “private Uniswap” called MantaSwap.
Manta Network is a plug-and-play privacy-preservation protocol built to service the entire DeFi stack. Our products include MantaPay, a multi-asset decentralized privacy payment scheme, and MantaSwap, a private, AMM-based decentralized anonymous exchange.
Powered by zkSNARK, the technology adopted by ZCash， MantaSwap can hide traders’ addresses, which prevents users from being tracked by others.
It also guarantees the privacy of liquidity providers. Additionally, the liquidity token that the liquidity provider gains is also private and tradable. The Manta team chose AMM because the simplicity of its design increases gas efficiency and capital efficiency, so MantaSwap can preserve privacy without sacrificing efficiency.
AMM is one of the most creative DeFi innovations in recent years and is now the most adopted DEX protocol. Unlike regular exchanges, which rely on order books, AMM DEXs use mathematical formulas to calculate the price of assets.
Built with Substrate, Manta takes advantage of the interoperable ecosystem that Polkadot brings and is capable of offering plug-and-play privacy-preservation solutions for other Polkadot projects.
We believe that a privacy DEX will be irreplaceable for DeFi users who need privacy protection, especially institutional users. And with DeFi diving into mass adoption, hopefully, we will see a private Uniswap soon.