SLIPPAGE WHEN WET: An intro into the world of MEV.
Magnus Woodgate | Principal Researcher @ Romulus Technologies
So a bit of backstory, I first gave this talk at the University of Zürich in collaboration with the Smart Contracts Lab & DeFiAM/ProxyFi and I had a great reaction, so decided to make a longer format blog post.
To go back to where it all begins; what is slippage?
Slippage occurs when there is a disparity between the intended execution price of a trade and the price at which the trade is actually executed. This can happen for several reasons, including:
Market Volatility: High volatility can cause prices to move rapidly, leading to a difference between the expected price and the actual execution price.
Low Liquidity: In markets with low liquidity, there may not be enough buyers or sellers at the desired price, causing the trade to be executed at a less favorable price.
Order Size: Large orders can significantly impact the market price, especially in low-liquidity environments, leading to slippage.
The invariant curves here demonstrate different type of pricing a swapper will receive when they come to the pool, i.e. the larger the swap size, the more slippage, but not all invariant curves are the same.
Slippage is particularly important, because is often spoken about in combination with MEV as some forms of negative MEV can impact a user’s slippage (e.g. trade execution) giving the user a worse resulting price.
SO WHAT IS MEV?
MEV quite literally is “Maximal Extractable Value”. It’s basically the ordering of transactions (TXs).
Let’s go over the most well known types of MEV transaction ordering:
Front-running: This occurs when a miner sees a profitable transaction pending in the mempool (the pool of unconfirmed transactions) and inserts their transaction just before it. For example, if a transaction is about to purchase a significant amount of a token, the miner can buy the token first, causing the price to rise, and then sell it at the higher price after the original transaction is executed.
Back-running: In this strategy, the miner inserts their transaction immediately after a known profitable transaction. For example, if a large buy order is expected to drive up the price of a token, the miner could place a buy order just after this to benefit from the price increase.
Sandwich Attacks: This is a combination of front-running and back-running. A miner places a transaction before and after a target transaction. For instance, the miner can first buy a token before a large buy order to drive the price up and then sell the token right after the large buy order is executed, profiting from the price difference.
And everything else… anything from one off token unlocks to DAO voting systems and all new kinds of token formats that aren’t even developed yet!
What’s a mempool?
Another key concept to be understood when it comes to MEV and a lot of the systems surrounding modern MEV design is the mempool i.e. the memory pool of transactions.
A common feature of many chains, although not all blockchains support the ability to monitor the mempool like Ethereum does.
This in part is due to the activities of MEV and some blockchain’s intentional design decisions to reduce some of the more negative MEV, however most chains still have an internal mempool that is visible whoever is in control of the RPC endpoint.
Let’s take a look at what is happening with the mempool on Ethereum:
So as you can see users submit their transaction (TX) to the mempool, where searchers monitor and then submit directly to “builders” who are able to combine multiple TXs from a wide arrange of searchers into a full block.
Flashbots.
So what is Flashbots? An iconic name (to those who know Flashboys), inspired the brilliant piece of research published in Flash Boys 2.0, outlining the issues with public PGAs (priority gas auctions) and how MEV searchers were driving up gas prices, and sending a lot of unnecessary TXs to the blockchains they were taking place on.
The result: a Geth extension, enabling direct MEV Auctions for Ethereum, while generating additional yield for those who run it.
If you’re interested in learning more about flashbots, checkout their docs.
So why should I care?
According to Coin Telegraph, MEV can also be called:
“…Ethereum’s Invisible Tax”
And furthermore, CowSwap also states:
“…MEV has cost traders over $1.5 billion in losses.”
And these activities don’t just apply to Ethereum but a large majority of today’s blockchain systems.
It impacts user’s performance.
Users / traders can receive worse execution if not taking MEV into account (very similar to the original days of HFT in TradFi with rapidly changing order book liquidity).
Users / traders are missing out on generating additional revenue from their order flow.
MEV systems are constantly evolving and remaining unaware may only negatively impact your on-chain experience in new and unforeseen ways.
BUT IT IS NOT ALL BAD!
Arbitrage (and back running MEV) keeps the DeFi markets efficient, so you don’t have to worry about negative price discrepencies between pools / other on-chain venues.
Some systems want MEV searchers, they actually need them to function! E.g. liquidation systems such as Aave to keep the protocol safe for depositors.
The existence of MEV has created brilliant concepts like the monetization of order flow, bringing extra rewards to the users of DeFi.
In any case, let’s dig into some examples and shine some light on this dark forest.
3.2 Million USD Profit in a Single TX.
This specific case is an arbitrage TX between two WBTC / WETH Uniswap pools.
The searcher made a profit of $3.2 million out of this singular arbitrage TX.
The searcher paid 1.2582 ETH to the miner as a “bribe” (to ensure their TX was prioritized before any competition).
This swap borrowed about 297 WBTC directly from Uniswap, using the flash swap mechanism possible with atomic TXs and modern AMM.
Synthetix Protocol Contract Deprecation
NOTE: This section I felt the need to add due to the great article by Robert Miller, check out their original blog post here.
In May of 2021, an “alpha leaker” KALEB posted the following message in the the Flashbots public searchers discord:
In the end the plan was for the searcher (Robert Miller) to submit the bundle via Flashbots, but there happened to be a string of non-Flashbots blocks, meaning the TX did not go through in time!
The winner ended up submitting a TX through the public mempool (with all of its risks) and won.
JIT Liquidity Provisioning
JIT (Just in Time) LPing is the process of sandwiching a TX, where the frontrun TX adds liquidity, and then the backrun TX removes the liquidity.
This concept applies specifically to concentrated liquidity protocols (such as Uniswap V3).
This would allow a searcher to potentially take 100% of the fees the pool would have given to other liquidity providers within the tick range.
i.e. as an LP you miss out on yield.
This problem seemed to generate enough attention that the Uniswap foundation researched into their on-chain swap data to analyze how often this happens.
IN SUMMARY
It’s a dark forest out there.
Not all MEV is bad.
MEV is helping to grow the DeFi ecosystem.
Don’t get MEVd.
Looking for ASSISTANCE?
Romulus Technologies is a Swiss based DeFi research firm specializing in security and low-level on-chain topics. If you are looking to get your project’s smart contracts audited, optimize for gas usage or get an expert review of your system architecture don’t hestiate to reach out to us info@romulus-technologies.xyz.
Disclaimer
The information provided on this blog is for general informational and educational purposes only. It is not intended as, and should not be construed as, financial advice. The content represents the personal opinions and views of the author, which are subject to change. We do not warrant or guarantee the accuracy, completeness, or adequacy of the information presented. The information contained on this blog is for general informational purposes only and does not constitute financial or investment advice. DeFi (Decentralized Finance) is a rapidly evolving and complex field with inherent risks. The content on this blog is not intended to be a substitute for professional financial advice.