← Back to list

Carbon — the MEV sandwich is toast

When discussing Carbon you will often hear the claim that “there is no MEV on Carbon” or that “Carbon is MEV resistant, specifically to…

Stefan Loesch in CarbonDeFi · 2023-07-31 07:47 · 103 claps · 8.3 min read
#carbon #defi #amm #mev #english
Open on Medium ↗
Wiki topics: CRY · Crypto & Web3 🌱 · Environment & Climate

Carbon — the MEV sandwich is toast

Note: my colleague Mark has taken this topic much further and doing the hard work. In his first post he calculates the actual formulas underlying the assertion that large enough fees prevent sandwich attacks that is made in this article here, and in his second post he looks much closer into what those formulas actually mean.

When discussing Carbon you will often hear the claim that “there is no MEV on Carbon” or that “Carbon is MEV resistant, specifically to sandwich attacks”. As usual, this is more complex than those simple statements allow for, which is why I want to discuss this topic here in more detail. The TLDR is — a typical Carbon strategy is indeed resistant to sandwich attacks, which is the most common form of MEV. However — not all strategies are. This is of course not surprising as Carbon strategies are a strict superset of Uniswap v3 positions, and Uniswap v3 positions are vulnerable.

How Carbon works

In order to make this note self consistent, here is a brief description of how Carbon works (please feel free to skip this section if you are already familiar with it).

Every Carbon strategy consists of two orders, one buy order (eg buy ETH for USDC) and one sell order (eg sell ETH for USDC) and of course buying should happen at a lower price (for the strategy owner) than selling, otherwise the strategy will be emptied quickly by the market. Which is why a Carbon strategy is often referred to as a buy-low-sell-high strategy.

A Carbon “Strategy”: Buy Low, Sell High

A Carbon “Strategy”: Buy Low, Sell High

Orders can be single-price orders aka limit orders (buy ETH for USDC at 2000 USDC per ETH) or range orders (ditto between 2000 and 1800 USDC per ETH, starting at 2000). The volume of an order is always determined by the token being sold, and for not too wide ranges one can approximate range orders with easier-to-reason-about sets of equally-sized single-price orders (buy 10 USDC worth of ETH at 2000, 10 at 1999, 10 at 1998, …, 10 at 1900). A strategy can either be any combination of two opposing limit or range orders, ie a recurring strategy, or it can execute only once either buying or selling, again in range or limit format, and then stop, ie be a disposable strategy.

Range Sell Order: Sell (approximately) the same amount at every tick between 100–105

Range Sell Order: Sell (approximately) the same amount at every tick between 100–105

MEV, arbitrages and sandwich attacks

MEV used to stand for “Miner Extractable Value”, but this was changed somewhat inelegantly to “Maximum Extractable Value” when people realized that miners are not the only one who can influence block production and in particular transaction sequencing. MEV corresponds to the value that players in the block production chain can extract from submitted transactions by virtue of choosing where and when to include them into a block, and what other transactions to include ahead or after them.

Arguably the two most important MEV-able transactions in relation to online trading are arbitrage snipes and sandwich attacks. The case of arbitrage snipes has been nicely described by Dan Robinson in his Dark Forest Medium post. Arbitrages (on-chain) are by definition transactions that can be submitted by everyone and that yield a guaranteed profit. Dealing with those is hard, and Carbon does not offer any particular protections in this respect.

No-fee sandwich attacks

The more interesting case is that of sandwich attacks. Those are akin to front running in tradfi markets. Their mechanics are as follows: assume that a trader submits a transaction to sell 1,000 TKN for USDC on a constant-product AMM like Uniswap v2 or Bancor. Further assume that this (a) is currently the only such transaction in the mempool, (b) there are no fees, and (c) the current price after slippage is 100, so the trader gets 100,000 USDC. A sandwich attacker would front and back run this transaction, meaning that they would (1) sell a large amount of TKN on the exchange, then (2) insert the transaction into this “sandwich” and then (3) buy the same amount of TKN back.

The sell transaction (1) will have pushed the price in the AMM lower, and we assume (d) that the sandwiched transaction (2) has now been executed at a price of 90 after slippage rather than 100, so the trader only gets 90,000 USDC. Because after transaction (3) the AMM is in exactly the same state as after only executing the un-sandwiched transaction, this is a zero sum game, so the 10,000 USDC loss of the trader is a 10,000 USDC gain of the sandwichooor.

This is the essence of a sandwich attack: the attacker pushes the price of a submitted transaction into a less favorable area, and keeps the difference. It is easy to see that whoever controls the sequencing — and therefore can ensure that all three transactions are included in the right order — can make a lot of money from unsuspecting traders.

Sandwich attacks in the presence of gas

In the presence of gas, transactions (1) and (3) are not costless, but instead incur a constant cost, ie a cost independent of the volume traded. As the gain on the sandwich attack is always proportional to the volume it is clear that the attack is not viable below a certain minimum volume. For a standard constant product case this volume is very low and likely to be exceeded, but for the other cases discussed below this may differ.

Sandwich attacks with concentrated liquidity

Provided the attacker has enough liquid funds — flash loans do not work here because all three transactions are individually signed and the loan can only be paid back in transaction (3) — the gain in a constant product scenario is in principle unlimited: with sufficient liquidity the attacker can push the price to a point where the trader sells their token for (almost) nothing, so the attacker gains (almost) the entire amount the trader was sending into the AMM.

A concentrated liquidity AMM runs out of liquidity at a finite and non-zero price, so the maximum amount the attacker can contribute under (1) is such that the attacked transaction (2) just does not fail. This sets a minimum or maximum execution price for this transaction, and therefore a maximum profit that can be achieved with a sandwich attack.

Sandwich attacks in the presence of fees

The presence of fees changes the above analysis in that an AMM can never return to its original state because every transaction will leak value in terms of fees that accrue to the LPs. This fee can either be capitalized (ie increase the amount of liquidity in the AMM) or distributed which changes the exact mechanics of the transaction, but which does not make a practical difference for our analysis.

Even in a constant product case, fees may make a sandwich attack not viable if the pool is very liquid. The reason is that the profit generated is proportional to the slippage generated and the amount of TKN in the sandwiched transaction, whilst the fees paid are proportional to the amount of TKN in the attacking transaction. For very liquid pools the fees paid — in currency terms, not in percentage terms — may outpace the profits generated by the additional slippage they generate. In case of concentrated liquidity — which massively increases the “virtual” liquidity of the pool and reduces slippage— this effect is of course even stronger.

Sandwich attacks on Carbon

Carbon strategies and fees

We have discussed above how Carbon works, specifically how recurring strategies that recycle liquidity between sell and buy curves work. For simplicity, we will first look at strategies which are composed of single-price orders where all the buying and selling happens at a single price. Furthermore, we first consider a rather narrow strategy, like “buy at 99, sell at 101” or even “buy at 99.9, sell at 100.1”. It is clear that, as far as the trader trading against this strategy is concerned, those are trades “at 100” with fees of 1% or 0.1% respectively. There is of course no qualitative difference between a 99/101 strategy, and a 50/150 or even a 1/199 one. Mathematically they can all be expressed as mid-price plus/minus a fee — again, only as far as the taker trader is concerned. So whilst those strategies would not usually be thought of as “mid plus/minus fees”, mathematically they are.

For Carbon ranges, this still more or less holds true. If we stick to the interpretation that a range is “$1 at 100, $1 at 100.1 and $1 at 100.2” etc then the mid and fee are somewhat dependant on how the range has been exhausted / refilled, ie the mid and the fee are not constant but change over time when the state of the strategy changes. This is more relevant for wider ranges — eg “buy 99–89.9, sell at 100–100.1” is essentially still a range with mid 100 and fee about 1%. In summary — the mid plus/minus fee view still applies, except it changes over time with the state of the strategy.

Sandwich attacks on Carbon

As we just have seen, Carbon strategies can be seen as concentrated liquidity AMMs with, usually very large, fees. As we have seen above, for concentrated liquidity positions with large fees, sandwich attacks are typically not viable. So the short version here is: typical Carbon ranges can not be viably attacked using sandwich attacks; however, very narrow overlapping ranges — which are possible in Carbon but not very “Carbon’y” — may still be susceptible to sandwich attacks.

It is worth looking at a number of specific examples. The first one is a very “Carbon’y” strategy, say buying ETH for USDC between 1,800–1,500, and selling it back between 2,200–2,500, and we assume the strategy is currently fully funded in USDC. In this case, the first USDC converted to ETH will be at 1,800, and it will be placed on a curve selling it back at 2,200. Firstly — the strategy owner here is a maker, so they can not be front run at all. They expressed the “intent” to buy and sell in two specific ranges, and this intent will either be fulfilled or not. Ex post they may of course no longer like this intent — say if ETH goes all the way down to 1,000 then having bought between 1,800–1,500 looks like a bad idea in hindsight — but this is no different from any other trading decision.

The question we are trying to answer here is whether takers trading against Carbon strategies can be sandwiched. Takers in the above model sell the first dollar worth of ETH at 1,800 and the last at 1,500. In other words, their price gets increasingly worse, and someone front running them does take money away from them. The issue is that anyone front running them, ie selling ETH ahead of them in step (1), must buy back this ETH in step (3). In this situation the ETH is placed back for sale at 2,200, ie at a price difference of 400 initially, and 1,000 at the end. This difference, which is a cost to the attacker, is too big to pay for the cost increase imposed on the taker in step 2, and therefore the sandwich attack is not viable.

However, if we have a strategy buying at 2000–1500 and selling at 1501–2001 (meaning the buy and sell ranges are overlapping, and the implied fee is around 5bp) then this behaves very similar to a 5bp Uniswap v3 range, and a sandwich attack is possible.

Conclusion

Sandwich attacks work best on constant product AMMs with no fees. Both introducing concentrated liquidity and fees makes sandwich attacks less profitable, with the profitability being the lower the higher the concentration and the higher the fees. Beyond certain points profitability is negative, ie the attack is no longer viable.

Carbon strategies can be mathematically thought of as AMM strategies with a current mid price and fee, both the price and the fee changing when trades happen against a strategy. For typical Carbon strategies those parameters are such that sandwich attacks are not viable. For others — in particular those mimicking Uniswap v3 positions which are a subset of Carbon strategies — sandwich attacks are however viable and therefore possible.

Cover Image

Cover Image


메타데이터
post_id
2ec7800dde68
slug
carbon-the-mev-sandwich-is-toast-2ec7800dde68
url
https://medium.com/carbondefi/carbon-the-mev-sandwich-is-toast-2ec7800dde68
canonical_url
https://medium.com/carbondefi/carbon-the-mev-sandwich-is-toast-2ec7800dde68
author_url
https://medium.com/@odtorson
status
ok
fetched_at
2026-07-25 11:00:36