This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

MEV Makes Everyone Happy under Greedy Sequencing Rule

Yuhao Li111Equal contribution.
Columbia University
[email protected]
   Mengqian Zhang
New York University
[email protected]
   Jichen Li
Peking University
[email protected]
   Elynn Chen
New York University
[email protected]
   Xi Chen
New York University
[email protected]
   Xiaotie Deng
Peking University
[email protected]
Abstract

Trading through decentralized exchanges (DEXs) has become crucial in today’s blockchain ecosystem, enabling users to swap tokens efficiently and automatically. However, the capacity of miners to strategically order transactions has led to exploitative practices (e.g., front-running attacks, sandwich attacks) and gain substantial Maximal Extractable Value (MEV) for their own advantage. To mitigate such manipulation, Ferreira and Parkes recently proposed a greedy sequencing rule such that the execution price of transactions in a block moves back and forth around the starting price. Utilizing this sequencing rule makes it impossible for miners to conduct sandwich attacks, consequently mitigating the MEV problem.

However, no sequencing rule can prevent miners from obtaining risk-free profits. This paper systemically studies the computation of a miner’s optimal strategy for maximizing MEV under the greedy sequencing rule, where the utility of miners is measured by the overall value of their token holdings. Our results unveil a dichotomy between the no trading fee scenario, which can be optimally strategized in polynomial time, and the scenario with a constant fraction of trading fee, where finding the optimal strategy is proven NP-hard. The latter represents a significant challenge for miners seeking optimal MEV.

Following the computation results, we further show a remarkable phenomenon: Miner’s optimal MEV also benefits users. Precisely, in the scenarios without trading fees, when miners adopt the optimal strategy given by our algorithm, all users’ transactions will be executed, and each user will receive equivalent or surpass profits compared to their expectations. This outcome provides further support for the study and design of sequencing rules in decentralized exchanges.

Keywords: Decentralized Finance, Maximal Extractable Value, Sequencing Rule

1 Introduction

Decentralized finance (also known as DeFi), as the main application of blockchain and smart contracts, has grown incredibly popular and attracted more than 40 billion dollars [1]. Within the DeFi ecosystem, decentralized exchange (DEX) becomes a fundamental service that allows users to trade cryptocurrency directly without any centralized authority. Nowadays, the daily volume of these DEXs has reached billions of US dollars [2].

Most DEXs (e.g., Uniswap, SushiSwap, Curve Finance, and Balancer) are organized as constant function market makers (CFMMs). Uniswap [3], for example, utilizes a constant product formula to make sure that the product of the quantity of two tokens remains constant before and after a swap. The exchange rate, or say the price that the swap executes at, is automatically determined by the reserves of the pair. So the outcome of each trade is sensitively influenced by system status at execution time.

In the blockchain, it is the block builders (also referred to as miners or validators) that select pending transactions and specify their execution order. This gives an exploitable chance for miners to extract profit by strategically including, excluding, and reordering transactions in a block. This is known as Maximal Extractable Value (MEV) [4]. A prevalent MEV example is the sandwich attack [5] on DEX transactions: the attacker “sandwiches” a profitable victim transaction by front-running and back-running it and earns from the spread between buying and selling prices.

To mitigate this market manipulation by miners, Ferreira and Parkes [6] recently introduced a greedy sequencing rule. Simply put, when dealing with a bunch of transactions from the liquidity pool of tokens 𝒳\mathcal{X} and 𝒴\mathcal{Y}, this sequencing rule requires miners to take the starting price as a benchmark. Then at any point during the execution in the block, if the current price of 𝒴\mathcal{Y} is higher than the benchmark, the priority should be given to the transactions selling token 𝒴\mathcal{Y}. Conversely, the transactions selling token 𝒳\mathcal{X} should be executed next. This sequencing rule structurally makes the sandwich attack impossible. It restricts miners from manipulating transaction orders, thus mitigating the impact of MEV. More importantly, it introduces verifiability by allowing users to efficiently verify whether the execution order of transactions complies with the rule.

1.1 Our Contributions

As mentioned in [6], miners can always obtain risk-free profits in some cases under arbitrary sequencing rule. In this paper, we systematically study the computation of miner’s optimal MEV strategy under the greedy sequencing rule. The study is based on the utility model where the worth of miners is the overall value of all their tokens. Like the similar work [7] aiming to maximize extractable value without rules or limits, the value of a token is measured by its price, which is exogenous, given by an oracle, and fixed throughout the attack. It was explicitly emphasized by Ferreira and Parkes [6] to also consider miner’s utility as a real-valued function when studying sequencing rules. The monetary function we considered is arguably the most natural choice.

We highlight our results on the computation of miners’ optimal strategies, as well as their surprising consequences. We give a computation dichotomy, supported by our two main theorems (Theorem 1 and Theorem 3). For the scenario where there is no trading fee, a polynomial time algorithm for a miner to compute an optimal strategy is given (Theorem 1); In contrast, when the fraction of trading fees is any constant larger than 0 (e.g., f=0.3%f=0.3\% in most Uniswap pools), we prove it is NP-hard to find an optimal strategy (Theorem 3).

The computational intractability implies hardness for a miner to hope for optimal MEV. More surprisingly, in the f=0f=0 regime, when miners adopt the optimal strategy provided by our algorithm (Algorithm 1), users will also benefit in the following sense: all users’ transactions will be executed (Corollary 1), and every user gets at least as good as if their transaction was the only transaction in the block (Corollary 2). The latter was one of the main motivations to propose the greedy sequencing rule, even though it is generally not true when the miner truthfully follows the greedy sequencing rule.

We conclude this paper by discussing many interesting future directions and open problems in the last section (Section 5).

1.2 Related Work

1.2.1 Sequencing Rules

Typically, miners organize transactions based on their gas prices. In order to protect users from order manipulation, Kelkar et al. [8] investigate the notion of fair transaction ordering for Byzantine consensus, which is further extended to the permissionless setting in [9]. Cachin et al. [10] introduce a new differential order-fairness property and present the quick order-fair atomic broadcast protocol which is much more efficient than previous solutions. The general idea of these approaches is to rely on a committee rather than a single miner to order transactions. A main threat to fair transaction ordering is the Condorcet attack [11]. Vafadar and Khabbazian [11] show that an attacker can undermine fairness by imposing Condorcet cycles even when all others in the system behave honestly.

Another category is content-oblivious ordering [12, 13] which guarantees that the transaction data is not accessible to the committee responsible for sequencing them until an order has been determined. This could be achieved using methods like threshold public key encryption schemes.

1.2.2 MEV Mitigation

It has long been discovered that miners could exploit transaction ordering for their own benefit  [14]. The term Maximal Extractable Value (MEV) was introduced in [4], formally defined in [15], and its growth has resulted in network congestion and high gas prices [4, 16]. Besides the sequencing rules, some other approaches are also explored to mitigate the impact of MEV. To avoid sandwich attacks, users are suggested to reduce the trading volume by splitting transactions [17] and to restrict the slippage tolerance [18]. This method, however, may also increase the transaction costs for users. Zhou et al. [19] propose a new DEX design called A2MM, which helps users to immediately execute an arbitrage following their swap transactions. It also allows users to benefit from MEV atomically. Another popular way is to rely on the service from trusted third parties like flashbots [20], Eden [21], and OpenMEV [22]. Then can help to order transactions without broadcasting them to the whole network, thus protecting from front-running and sandwich attacks.

2 Preliminaries

2.1 Constant Function Market Makers

Let AA be an AMM for trading between token 𝒳\mathcal{X} and token 𝒴\mathcal{Y}. The exchange has state s=(x,y)s=(x,y), where xx and yy are current reserves of token 𝒳\mathcal{X} and 𝒴\mathcal{Y}, respectively. When AA is a CFMM, the trading invariant can be modeled by a constant function with two variables F(x,y)=CF(x,y)=C. We will focus on CFMMs that satisfy Axiom 1 and Axiom 2, which are defined as follows. We note that all currently known CFMMs are consistent with these two properties.222This also includes Uniswap v3, which is less trivial.

Axiom 1.

For different pairs (x,y)(x,y) and (x,y)(x^{\prime},y^{\prime}) such that F(x,y)=F(x,y)=CF(x,y)=F(x^{\prime},y^{\prime})=C, we have x<xx<x^{\prime} if and only if y>yy>y^{\prime}.

By this axiom, we know that for any xx (reserves of token 𝒳\mathcal{X}), there is a unique yy such that F(x,y)=CF(x,y)=C and vice versa. So we will use Fy(x)F_{y}(x) to denote the yy such that F(x,y)=CF(x,y)=C and similarly define Fx(y)F_{x}(y).

Axiom 2.

Fy(x)F_{y}(x) is differentiable and the marginal exchange rate |dFy(x)/dx||dF_{y}(x)/dx| is decreasing with respect to xx.

In the rest of the paper, we use r(x)r(x) to denote the marginal exchange rate of swapping tokens 𝒳\mathcal{X} for 𝒴\mathcal{Y}, i.e., r(x)|dFy(x)/dx|r(x)\coloneqq|dF_{y}(x)/dx|.

2.2 Execution of Transactions

Users can submit a transaction of the following two types: Sell(𝒳,)\texttt{Sell}(\mathcal{X},\cdot) and Sell(𝒴,)\texttt{Sell}(\mathcal{Y},\cdot), where \cdot is a real parameter representing how many units of token the user wants to trade.

To be more concrete, suppose that the current state of CFMM AA is s=(x,y)s=(x,y). For each swap, part of tokens are charged as fees and we use f[0,1)f\in[0,1) to denote the fraction of this trading fee. When executing a transaction Sell(𝒳,q)\texttt{Sell}(\mathcal{X},q), the user will pay qq units of token 𝒳\mathcal{X} and get yFy(x+(1f)q)y-F_{y}(x+(1-f)q) units of token 𝒴\mathcal{Y}. Similarly, when executing a transaction Sell(𝒴,q)\texttt{Sell}(\mathcal{Y},q), the user will pay qq units of token 𝒴\mathcal{Y} and get xFx(y+(1f)q)x-F_{x}(y+(1-f)q) units of token 𝒳\mathcal{X}.

The executing of multiple transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]} will be well-defined if an order among them is determined. In particular, suppose that τ:[n][n]\tau:[n]\rightarrow[n] is a permutation. Then the execution will work as follows: Let s0=(x0,y0)s_{0}=(x_{0},y_{0}) be the initial state and iteratively execute each transaction TXτ(i)\textsf{TX}^{\tau(i)}. For the ii-th iteration, if TXτ(i)=Sell(𝒳,q)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{X},q), then si=(xi,yi)s_{i}=(x_{i},y_{i}) where xi=xi1+(1f)qx_{i}=x_{i-1}+(1-f)q and yi=Fy(xi)y_{i}=F_{y}(x_{i}); if TXτ(i)=Sell(𝒴,q)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{Y},q), then si=(xi,yi)s_{i}=(x_{i},y_{i}) where yi=yi1+(1f)qy_{i}=y_{i-1}+(1-f)q and xi=Fx(yi)x_{i}=F_{x}(y_{i}).

It is easy to see the order under which the transactions are executed crucially influences the trades outcomes. However, due to the same reason, it is also well-known that the decentralized exchange systems suffer from order manipulation, where an anonymous miner can manipulate the context of a block, even including inserting their own attacking transactions. Ferreira and Parkes [6] considered the notion of verifiable sequencing rules and proposed a greedy sequencing rule to limit miners’ ability to manipulate (therefore in general it also benefits users). We recap their definitions below.

2.3 Sequencing Rules

We start with the definition of the verifiable sequencing rule.

Definition 1 (Verifiable sequencing rule, [6]).

A sequencing rule RR is a map from initial state s0s_{0} and a set of transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]} to a set of permutations {τ:[n][n]}\{\tau:[n]\rightarrow[n]\}, where each permutation is a valid order to execute these transactions under this sequencing rule.

A sequencing rule is efficiently computable, if there is a polynomial time algorithm that can compute a permutation τ:[n][n]\tau:[n]\rightarrow[n] that satisfies RR (i.e., τR(s0,{TXi}i[n])\tau\in R(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]})) for any initial state s0s_{0} and transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]}.

A sequencing rule is efficiently verifiable, if there is a polynomial time algorithm such that for any permutation τ:[n][n]\tau:[n]\rightarrow[n], the algorithm accepts τ\tau if and only if τR(s0,{TXi}i[n])\tau\in R(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]}).

Along this way, Ferreira and Parkes [6] proposed a greedy sequencing rule (we use GSR to denote it), which is efficiently computable and verifiable.

Definition 2 (Greedy sequencing rule, [6]).

A permutation τ\tau satisfies the greedy sequencing rule (τGSR(s0,{TXi}i[n])\tau\in\texttt{GSR}(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]})) if the following conditions hold for all i[n]i\in[n]:

  • TXτ(i)\textsf{TX}^{\tau(i)} is a Sell(𝒳,)\texttt{Sell}(\mathcal{X},\cdot) transaction only if either xi1x0x_{i-1}\leq x_{0} or TXτ(j)\textsf{TX}^{\tau(j)} is Sell(𝒳,)\texttt{Sell}(\mathcal{X},\cdot) for all i<jni<j\leq n; and

  • TXτ(i)\textsf{TX}^{\tau(i)} is a Sell(𝒴,)\texttt{Sell}(\mathcal{Y},\cdot) transaction only if either yi1y0y_{i-1}\leq y_{0} or TXτ(j)\textsf{TX}^{\tau(j)} is Sell(𝒴,)\texttt{Sell}(\mathcal{Y},\cdot) for all i<jni<j\leq n,

where si1=(xi1,yi1)s_{i-1}=(x_{i-1},y_{i-1}) is the state before executing TXτ(i)\textsf{TX}^{\tau(i)}.

Besides efficiency, the greedy sequencing rule enjoys the property that for every transaction, either its receive is as good as it was the only transaction in the block or it does not suffer from a sandwich attack.

However, it is totally possible for a miner to gain profits by manipulating the content of the block, even if it follows some given sequencing rule (e.g., the greedy sequencing rule). In the rest of the paper, we study the computation of miners’ optimal strategies.

3 Miner’s Strategy Space

We define the miner’s strategy space in the most general way. To make the profits of the miner comparable, we assume that there are exogenous prices of 𝒳\mathcal{X} (denoted by pxp_{x}) and 𝒴\mathcal{Y} (denoted by pyp_{y}) and the miner wants to collect as much money as possible. Like previous work [7], pxp_{x} and pyp_{y} are assumed to remain the same during the attack (usually the timeslot for a block, e.g., about 12 seconds in Ethereum).

Definition 3 (Strategy Space).

Given a sequencing rule RR, an initial state s0=(x0,y0)s_{0}=(x_{0},y_{0}), and a set of users’ transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]}, a miner could create mm number of its own transactions {TXi}i[n+1:n+m]\{\textsf{TX}^{i}\}_{i\in[n+1:n+m]}, select a subset of all these n+mn+m transactions S[n+m]S\subseteq[n+m], compute an order τR(s0,{TXi}iS)\tau\in R(s_{0},\{\textsf{TX}^{i}\}_{i\in S}) (here instead of permutation, τ\tau should be a one-to-one mapping from [|S|][|S|] to SS) that satisfies the sequencing rule, and execute them under the order τ\tau.

The miner’s profit U({TXi}i[n+1:n+m],S,τ)U(\{\textsf{TX}^{i}\}_{i\in[n+1:n+m]},S,\tau) is defined as

i[|S|],τ(i)[n+1:n+m]xi1xi1f𝟙{xi>xi1}px+yi1yi1f𝟙{yi>yi1}py,\sum_{i\in[|S|],\tau(i)\in[n+1:n+m]}\frac{x_{i-1}-x_{i}}{1-f\cdot\mathbbm{1}_{\{x_{i}>x_{i-1}\}}}\cdot p_{x}+\frac{y_{i-1}-y_{i}}{1-f\cdot\mathbbm{1}_{\{y_{i}>y_{i-1}\}}}\cdot p_{y},

where f[0,1)f\in[0,1) is the fraction of trading fees.

Here, 𝟙{xi>xi1}\mathbbm{1}_{\{x_{i}>x_{i-1}\}} indicates that TXτ(i)\textsf{TX}^{\tau(i)} is a Sell(𝒳,)\texttt{Sell}(\mathcal{X},\cdot) transaction and 𝟙{yi>yi1}\mathbbm{1}_{\{y_{i}>y_{i-1}\}} indicates that TXτ(i)\textsf{TX}^{\tau(i)} is a Sell(𝒴,)\texttt{Sell}(\mathcal{Y},\cdot) transaction. These two events will not happen simultaneously.

3.1 Arbitrage-Free Interval

In this subsection, we present a clean lemma that characterizes (what we call) arbitrage-free interval, which provides the first intuition behind the proofs later. It may also serve as the first step in other scenarios of decentralized exchanges when concerning the miner’s strategies, e.g., optimal sandwich attacks of a miner who wants to collect money.

Before we state and prove the lemma, we first introduce a notation, which is also used in the subsequent sections. We use LxL_{x} to denote the xx such that the marginal exchange rate r(Lx)=11fpxpyr(L_{x})=\frac{1}{1-f}\frac{p_{x}}{p_{y}} and RxR_{x} to denote the xx such that r(Rx)=(1f)pxpyr(R_{x})=(1-f)\frac{p_{x}}{p_{y}}.

Lemma 1.

Given the exogenous prices pxp_{x} and pyp_{y}, and the current state s=(x,y)s^{*}=(x^{*},y^{*}), miner’s optimal profit is positive if and only if x[Lx,Rx]x^{*}\not\in[L_{x},R_{x}]. Furthermore, when x<Lxx^{*}<L_{x}, miner’s optimal strategy is to execute Sell(𝒳,(Lxx)/(1f))\texttt{Sell}(\mathcal{X},(L_{x}-x^{*})/(1-f)); when x>Rxx^{*}>R_{x}, miner’s optimal strategy is to execute Sell(𝒴,(Fy(Rx)y)/(1f))\texttt{Sell}(\mathcal{Y},(F_{y}(R_{x})-y^{*})/(1-f)).

Proof.

We first argue that it suffices for the miner to execute at most one transaction. This is because if miner executes two transactions with the same type (say Sell(𝒳,q1)\texttt{Sell}(\mathcal{X},q_{1}) and Sell(𝒳,q2)\texttt{Sell}(\mathcal{X},q_{2})), then it is equivalent to execute Sell(𝒳,q1+q2)\texttt{Sell}(\mathcal{X},q_{1}+q_{2}); if miner executes two transactions with different types (say Sell(𝒳,q1)\texttt{Sell}(\mathcal{X},q_{1}) and Sell(𝒴,q2)\texttt{Sell}(\mathcal{Y},q_{2})), then it is better to replace them by one single transaction since miner can avoid additional cost of trading fees.

So next we consider the case where the miner executes one of its transactions TX. Suppose that TX=Sell(𝒳,q)\textsf{TX}=\texttt{Sell}(\mathcal{X},q), then miner’s profit is

U(𝒳,q)=(xx+(1f)qr(x)𝑑x)pyqpx.U(\mathcal{X},q)=\left(\int_{x^{*}}^{x^{*}+(1-f)q}r(x)dx\right)\cdot p_{y}-q\cdot p_{x}.

We show below that when xLxx^{*}\geq L_{x}, U(𝒳,q)0U(\mathcal{X},q)\leq 0 for all q0q\geq 0.

U(𝒳,q)\displaystyle U(\mathcal{X},q) =(xx+(1f)qr(x)𝑑x)pyqpx\displaystyle=\left(\int_{x^{*}}^{x^{*}+(1-f)q}r(x)dx\right)\cdot p_{y}-q\cdot p_{x}
r(x)(1f)qpyqpx\displaystyle\leq r(x^{*})(1-f)q\cdot p_{y}-q\cdot p_{x}
r(Lx)(1f)qpyqpx\displaystyle\leq r(L_{x})(1-f)q\cdot p_{y}-q\cdot p_{x}
=11fpxpy(1f)qpyqpx\displaystyle=\frac{1}{1-f}\frac{p_{x}}{p_{y}}(1-f)q\cdot p_{y}-q\cdot p_{x}
=0.\displaystyle=0.

Symmetrically we can define U(𝒴,q)U(\mathcal{Y},q) when miner executes Sell(𝒴,q)\texttt{Sell}(\mathcal{Y},q) and conclude that when xRxx^{*}\leq R_{x}, U(𝒴,q)0U(\mathcal{Y},q)\leq 0 for all q0q\geq 0. This finishes the proof that when x[Lx,Rx]x^{*}\in[L_{x},R_{x}], miners cannot obtain positive profits.

Then we consider what is an optimal attack when x[Lx,Rx]x^{*}\not\in[L_{x},R_{x}]. Suppose that x<Lxx^{*}<L_{x}, then by previous argument, the miner should not execute Sell(𝒴,)\texttt{Sell}(\mathcal{Y},\cdot) (as x<LxRxx^{*}<L_{x}\leq R_{x}). So let’s focus on the case where the miner executes Sell(𝒳,q)\texttt{Sell}(\mathcal{X},q).

Letting x=x+(1f)qx^{\prime}=x^{*}+(1-f)q, note that

U(𝒳,q)\displaystyle U(\mathcal{X},q) =(xx+(1f)qr(x)𝑑x)pyqpx\displaystyle=\left(\int_{x^{*}}^{x^{*}+(1-f)q}r(x)dx\right)\cdot p_{y}-q\cdot p_{x}
=(xLxr(x)𝑑x+Lxxr(x)𝑑x)pyqpx,\displaystyle=\left(\int_{x^{*}}^{L_{x}}r(x)dx+\int_{L_{x}}^{x^{\prime}}r(x)dx\right)\cdot p_{y}-q\cdot p_{x},

where (xLxr(x)𝑑x)py(Lxx)/(1f)px\left(\int_{x^{*}}^{L_{x}}r(x)dx\right)\cdot p_{y}-(L_{x}-x^{*})/(1-f)\cdot p_{x} is the profits that miner can get by executing Sell(𝒳,(Lxx)/(1f))\texttt{Sell}(\mathcal{X},(L_{x}-x^{*})/(1-f)) as states in the lemma. Next we show that

g(x)=(Lxxr(x)𝑑x)py(xLx)/(1f)px0g(x^{\prime})=\left(\int_{L_{x}}^{x^{\prime}}r(x)dx\right)\cdot p_{y}-(x^{\prime}-L_{x})/(1-f)\cdot p_{x}\leq 0

for all xx^{\prime}.

Note that

g(x)=(Fy(Lx)Fy(x))py(xLx)/(1f)px.g(x^{\prime})=\left(F_{y}(L_{x})-F_{y}(x^{\prime})\right)\cdot p_{y}-(x^{\prime}-L_{x})/(1-f)\cdot p_{x}.

So we have

g(x)=Fy(x)pypx/(1f)=r(x)pypx/(1f),g^{\prime}(x^{\prime})=-F_{y}^{\prime}(x^{\prime})p_{y}-p_{x}/(1-f)=r(x^{\prime})p_{y}-p_{x}/(1-f),

which is a decreasing function as r(x)r(x^{\prime}) is decreasing. Since g(Lx)=0g^{\prime}(L_{x})=0, we have the maximal value of gg is at LxL_{x}, which is 0.

This finishes the proof. ∎

4 Strategies under Greedy Sequencing Rule

In this section, we systemically analyze the strategic behaviors of the miners who follow the greedy sequencing rule.

We specifically focus on the case that the initial state s0=(x0,y0)s_{0}=(x_{0},y_{0}) satisfies r(x0)=px/pyr(x_{0})=p_{x}/p_{y}. Note that this is without loss of generality in our context: On the one hand, when f=0f=0, Lx=RxL_{x}=R_{x} (i.e., the arbitrage-free interval becomes an arbitrage-free point). Supported by Lemma 1, if the current 𝒳\mathcal{X} reserves are not LxL_{x} (RxR_{x}), anyone can make money by a single arbitrage transaction, namely, by selling 𝒳\mathcal{X} or 𝒴\mathcal{Y} to reach the arbitrage-free point. Thus, it is reasonable to think the last transaction ends up with the state s0=(x0,y0)s_{0}=(x_{0},y_{0}) satisfying r(x0)=px/pyr(x_{0})=p_{x}/p_{y}, which is also the initial state of this attack; On the other hand, when f>0f>0, we show that the NP-hardness holds even if r(x0)=px/pyr(x_{0})=p_{x}/p_{y}, let alone the more general case. It is still interesting to consider the case r(x0)px/pyr(x_{0})\neq p_{x}/p_{y}, and we discuss it in the last section (Section 5).

In Section 4.2, we show a polynomial time algorithm to compute an optimal attack in the regime that the fraction of trading fee f=0f=0. Interestingly, it will also benefit the users if the miner follows such a strategy compared to truthfully following the greedy sequencing rule.

In contrast, Section 4.3 shows that when the fraction of trading fee ff is any constant larger than 0 (say f=0.3%f=0.3\% as being used in most Uniswap pools), it is NP-hard to find an optimal strategy.

4.1 Upper Bounds of Optimal Profits

Our main results in this section (Theorem 1 and Theorem 3) will be crucially based on the following lemma, which provides an upper bound of miner’s optimal profit (using arbitrary strategy) under the greedy sequencing rule.

Before presenting the lemma, we first define the arbitragable profit for one transaction, inspired by Lemma 1.

Definition 4 (Arbitragable Profit).

Given an initial state s0=(x0,y0)s_{0}=(x_{0},y_{0}) and a user’s transaction TX, we define the arbitragable profit AP(s0,TX)\texttt{AP}(s_{0},\textsf{TX}) as follows:

  • If TX=Sell(𝒳,q)\textsf{TX}=\texttt{Sell}(\mathcal{X},q), let x=max{x0+(1f)q,Rx}x^{\prime}=\max\left\{x_{0}+(1-f)q,R_{x}\right\}. Then AP(s0,TX)(xRx)px(Fy(Rx)Fy(x))/(1f)py\texttt{AP}(s_{0},\textsf{TX})\coloneqq(x^{\prime}-R_{x})\cdot p_{x}-\left(F_{y}(R_{x})-F_{y}(x^{\prime})\right)/(1-f)\cdot p_{y};

  • If TX=Sell(𝒴,q)\textsf{TX}=\texttt{Sell}(\mathcal{Y},q), let x=min{Fx(y0+(1f)q),Lx}x^{\prime}=\min\left\{F_{x}(y_{0}+(1-f)q),L_{x}\right\}. Then AP(s0,TX)(Fy(x)Fy(Lx))py(Lxx)/(1f)px\texttt{AP}(s_{0},\textsf{TX})\coloneqq\left(F_{y}(x^{\prime})-F_{y}(L_{x})\right)\cdot p_{y}-(L_{x}-x^{\prime})/(1-f)\cdot p_{x}.

Refer to caption
Figure 1: Illustration of Arbitrage-Free Interval and the intuition behind Arbitragable Profit.

Figure 1 illustrates the intuition behind Arbitragable Profit.

The lemma below shows that the miner’s optimal profit is upper-bounded by the sum arbitragable profits of all users’ transactions.

Lemma 2.

Given an initial state s0=(x0,y0)s_{0}=(x_{0},y_{0}) with r(x0)=px/pyr(x_{0})=p_{x}/p_{y}, a set of users’ transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]}, the miner’s profit (using arbitrary strategy) under the greedy sequencing rule is upper bounded by M(s0,{TXi}i[n])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]}), where

M(s0,{TXi}i[n])i=1nAP(s0,TXi).M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]})\coloneqq\sum_{i=1}^{n}\texttt{AP}(s_{0},\textsf{TX}^{i}).
Proof.

Fix arbitrary sequence of (users’ and miner’s) transactions (TXτ(1),,TXτ(k))(\textsf{TX}^{\tau(1)},\cdots,\textsf{TX}^{\tau(k)}), where TXτ(i)\textsf{TX}^{\tau(i)} is a user’s transaction if τ(i)[n]\tau(i)\in[n] and it is the miner’s transaction otherwise. Let si=(xi,yi)s_{i}=(x_{i},y_{i}) be the state after executing TXτ(i)\textsf{TX}^{\tau(i)}. Without loss of generality, we assume that TXτ(i)=Sell(𝒳,)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{X},\cdot) if and only if xi1x0x_{i-1}\leq x_{0} and TXτ(i)=Sell(𝒴,)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{Y},\cdot) if and only if yi1y0y_{i-1}\leq y_{0} for all i{2,,k}i\in\{2,\cdots,k\}. To see it, suppose that for k<kk^{\prime}<k we have TXτ(i)=Sell(𝒳,)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{X},\cdot) and xi1>x0x_{i-1}>x_{0} for all i{k+1,,k}i\in\{k^{\prime}+1,\cdots,k\}. Then by Lemma 1, we know that miner’s profit obtained from TXτ(k+1),TXτ(k)\textsf{TX}^{\tau(k^{\prime}+1)},\cdots\textsf{TX}^{\tau(k)} is at most 0 (and possibly negative). It means the miner can always choose not to execute these transactions and the profit is as good as before.

We will inductively show that after executing the first ii transactions, the miner’s profit UiVij[i],τ(j)[n]AP(s0,TXτ(j))U_{i}\leq V_{i}\coloneqq\sum_{j\in[i],\tau(j)\in[n]}\texttt{AP}(s_{0},\textsf{TX}^{\tau(j)}). This will imply that after executing all kk transactions, miner’s profit is upper bounded by i[n]AP(s0,TXi)\sum_{i\in[n]}\texttt{AP}(s_{0},\textsf{TX}^{i}).

We define ϕi\phi_{i} as follows:

ϕi={(xiRx)px+Fy(xi)Fy(Rx)1fpy,xi>Rx;xiLx1fpx+(Fy(xi)Fy(Lx))py,xi<Lx;0,xi[Lx,Rx].\phi_{i}=\left\{\begin{array}[]{ll}(x_{i}-R_{x})\cdot p_{x}+\frac{F_{y}(x_{i})-F_{y}(R_{x})}{1-f}\cdot p_{y},&x_{i}>R_{x};\\ \frac{x_{i}-L_{x}}{1-f}\cdot p_{x}+\left(F_{y}(x_{i})-F_{y}(L_{x})\right)\cdot p_{y},&x_{i}<L_{x};\\ 0,&x_{i}\in[L_{x},R_{x}].\end{array}\right.

We will show that (Ui+ϕi)(Ui1+ϕi1)ViVi1=AP(s0,TXτ(i))(U_{i}+\phi_{i})-(U_{i-1}+\phi_{i-1})\leq V_{i}-V_{i-1}=\texttt{AP}(s_{0},\textsf{TX}^{\tau(i)}) for all i[k]i\in[k], which will imply our desired statement UiViU_{i}\leq V_{i} as ϕi0\phi_{i}\geq 0 for all i[k]i\in[k]. (Here we define AP(s0,TXτ(i))=0\texttt{AP}(s_{0},\textsf{TX}^{\tau(i)})=0 if it is a miner’s transaction.)

The basis of the induction is trivial as U0+ϕ0=0U_{0}+\phi_{0}=0. For the induction step, let’s consider arbitrary i[k]i\in[k].

Case 1: TXτ(i)\textsf{TX}^{\tau(i)} is a user’s transaction. Then we have Ui=Ui1U_{i}=U_{i-1}. So it suffices for us to show ϕiϕi1AP(s0,TXτ(i))\phi_{i}-\phi_{i-1}\leq\texttt{AP}(s_{0},\textsf{TX}^{\tau(i)}). Suppose that TXτ(i)=Sell(𝒳,q)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{X},q). Then it must be the case xi1<=x0x_{i-1}<=x_{0} due to the greedy sequencing rule. (The other case TXτ(i)=Sell(𝒴,q)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{Y},q) will be symmetric.) If xix0x_{i}\leq x_{0}, then we have that ϕ\phi in fact didn’t increase, which means ϕiϕi10AP(s0,TXτ(i))\phi_{i}-\phi_{i-1}\leq 0\leq\texttt{AP}(s_{0},\textsf{TX}^{\tau(i)}). If xi>x0x_{i}>x_{0}, then since xi1x0x_{i-1}\leq x_{0}, we have ximax{x0+(1f)q,Rx}x_{i}\leq\max\left\{x_{0}+(1-f)q,R_{x}\right\}. So that ϕiAP(s0,TXτ(i))\phi_{i}\leq\texttt{AP}(s_{0},\textsf{TX}^{\tau(i)}), concluding the first case.

Case 2: TXτ(i)\textsf{TX}^{\tau(i)} is a miner’s transaction. Then we have Vi=Vi1V_{i}=V_{i-1}. So it suffices for us to show UiUi1+ϕiϕi10U_{i}-U_{i-1}+\phi_{i}-\phi_{i-1}\leq 0. Suppose that TXτ(i)=Sell(𝒳,q)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{X},q), then it must be the case xi1<=x0x_{i-1}<=x_{0} due to the greedy sequencing rule. (Again, the other case TXτ(i)=Sell(𝒴,q)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{Y},q) will be symmetric.)

If xi1xiLxx_{i-1}\leq x_{i}\leq L_{x}, then we have in fact UiUi1+ϕiϕi1=0U_{i}-U_{i-1}+\phi_{i}-\phi_{i-1}=0 since UiUi1=ϕi1ϕi=(xixi1)/(1f)px+(Fy(xi1)Fy(xi))py.U_{i}-U_{i-1}=\phi_{i-1}-\phi_{i}=-(x_{i}-x_{i-1})/(1-f)\cdot p_{x}+\left(F_{y}(x_{i-1})-F_{y}(x_{i})\right)\cdot p_{y}.

Now, let’s consider the case LxxiL_{x}\leq x_{i}. To simplify the analysis, we consider an intermediate state ss^{\prime} with UU^{\prime} and ϕ\phi^{\prime}. If xi1Lxx_{i-1}\geq L_{x}, then we just set s=si1s^{\prime}=s_{i-1} with U=Ui1U^{\prime}=U_{i-1} and ϕ=ϕi1\phi^{\prime}=\phi_{i-1}. If xi1<Lxx_{i-1}<L_{x}, we split TXτ(i)\textsf{TX}^{\tau(i)} into two transactions: TX=Sell(𝒳,(Lxxi1)/(1f))\textsf{TX}^{\prime}=\texttt{Sell}(\mathcal{X},(L_{x}-x_{i-1})/(1-f)) and TX′′=Sell(𝒳,(xiLx)/(1f))\textsf{TX}^{\prime\prime}=\texttt{Sell}(\mathcal{X},(x_{i}-L_{x})/(1-f)), and we define ss^{\prime}, UU^{\prime} and ϕ\phi^{\prime} as that after executing TX\textsf{TX}^{\prime}.

Note that we have UUi1=ϕi1ϕU^{\prime}-U_{i-1}=\phi_{i-1}-\phi^{\prime}. So we only need to show UiUϕϕiU_{i}-U^{\prime}\leq\phi^{\prime}-\phi_{i}. Note that in fact ϕ=0\phi^{\prime}=0.

If xiRxx_{i}\leq R_{x}, then ϕi=ϕ=0\phi_{i}=\phi^{\prime}=0. In addition, by Lemma 1, we know that UiU0U_{i}-U^{\prime}\leq 0. So we conclude UiUϕϕiU_{i}-U^{\prime}\leq\phi^{\prime}-\phi_{i} as desired.

The last possibility is that xi>Rxx_{i}>R_{x}, where we have

ϕi=(xiRx)px+Fy(xi)Fy(Rx)1fpy.\phi_{i}=(x_{i}-R_{x})\cdot p_{x}+\frac{F_{y}(x_{i})-F_{y}(R_{x})}{1-f}\cdot p_{y}.

Moreover, by Lemma 1, we know that UiU(Rxxi)/(1f)px+(Fy(Rx)Fy(xi))py<ϕiU_{i}-U^{\prime}\leq(R_{x}-x_{i})/(1-f)\cdot p_{x}+\left(F_{y}(R_{x})-F_{y}(x_{i})\right)\cdot p_{y}<-\phi_{i}.

This finishes the proof. ∎

4.2 Polynomial Time Algorithm When f=0f=0

In this subsection, we show a polynomial time algorithm to find an optimal strategy for the miner when f=0f=0. Interestingly, when adopting our algorithm, users will also benefit in the following sense: all users’ transactions will be executed (a.k.a they will be included in the block), and every user gets at least as good as if their transaction was the only one in the block. The latter is generally not true if the miner truthfully follows the greedy sequencing rule.

Input: An initial state s0=(x0,y0)s_{0}=(x_{0},y_{0}), and a set of users’ transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]}.
Output: An optimal strategy for miner to obtain M(s0,{TXi}i[n])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]}) profits, which is the best possible.
1
2Sort these nn transactions in any order τ:[n][n]\tau:[n]\rightarrow[n].
3for each ii from 11 to nn do
4       Execute user’s transaction TXτ(i)\textsf{TX}^{\tau(i)}.
5      if TXτ(i)=Sell(𝒳,q)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{X},q) then
6             Execute a transaction Sell(𝒴,y0Fy(x0+q))\texttt{Sell}(\mathcal{Y},y_{0}-F_{y}(x_{0}+q)).
7      if TXτ(i)=Sell(𝒴,q)\textsf{TX}^{\tau(i)}=\texttt{Sell}(\mathcal{Y},q) then
8            Execute a transaction Sell(𝒳,x0Fx(y0+q))\texttt{Sell}(\mathcal{X},x_{0}-F_{x}(y_{0}+q)).
9      
10
Algorithm 1 Algorithm for optimal strategy when f=0f=0
Theorem 1.

When the fraction of trading fee f=0f=0, Algorithm 1 finds an optimal strategy under the greedy sequencing rule in polynomial time, and the optimal profit is equal to the upper bound M(s0,{TXi}i[n])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]}).

Remark 1.

Before going into details of the proof, we note that our algorithm can obtain the optimal profit M(s0,{TXi}i[n])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]}) under arbitrary order of users’ transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]}. So it still works even if there are some constraints on the execution order of certain transactions (e.g., a user may create two transactions {TX1,TX2}\{\textsf{TX}^{1},\textsf{TX}^{2}\} and specify that TX1\textsf{TX}^{1} must be executed before TX2\textsf{TX}^{2}).

Proof of Theorem 1.

We first show that the sequence given by Algorithm 1 satisfies the greedy sequencing rule. Note that after executing each user’s transaction TXτ(i)\textsf{TX}^{\tau(i)}, we always execute a miner’s transaction with the opposite direction, shown between line 1 and 1. Besides, at the end of ii-th iteration, we have the state s2i=s0s_{2i}=s_{0} (we use 2i2i because we execute two transactions in each iteration). So our sequence satisfies the greedy sequencing rule. Furthermore, during the ii-th iteration, we obtain exactly AP(s0,TXτ(i))\texttt{AP}(s_{0},\textsf{TX}^{\tau(i)}) profits by executing the transaction on line 1 or 1. Then the optimality follows from the same upper bound provided by Lemma 2. ∎

Now we turn to the positive effects on users when a miner launches an optimal strategy given by Algorithm 1. We summarize them as the following two corollaries and omit the proofs as they are relatively straightforward from the proof of Theorem 1.

Corollary 1.

When a miner launches an optimal strategy given by Algorithm 1, all users’ transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]} will be executed.

Corollary 2.

When a miner launches an optimal strategy given by Algorithm 1, each user’s profit is as good as if their transaction was the only transaction in the block.

As shown in Theorem 1, Corollary 1, Corollary 2, both miner and users are satisfied when miner adopts our Algorithm 1.

4.3 NP-hardness When f>0f>0

In this subsection, we show the computational hardness of finding an optimal strategy when the fraction of trading fees is any constant larger than 0 (say f=0.3%f=0.3\%).

We will mainly focus on the proof of the NP-completeness of the following decision problem, then Theorem 3 will follow directly.

Theorem 2.

Let f(0,1)f\in(0,1) be any universal constant. It is NP-complete to decide if there is a strategy that can obtain profits M(s0,{TXi}i[n])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]}) for any initial state s0=(x0,y0)s_{0}=(x_{0},y_{0}) and users’ transactions {TXi}i[n]\{\textsf{TX}^{i}\}_{i\in[n]}.

Proof.

The NP-membership is easy. Given any strategy, we can efficiently simulate the execution of the sequence of transactions and check if the final profit is M(s0,{TXi}i[n])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n]}) or not.

For the NP-hardness, we reduce the Partition problem to our problem. Recall that the instance of the partition problem contains nn positive integers and ask if it can be partitioned into two subsets S1S_{1} and S2S_{2} such that the sum of numbers in S1S_{1} equals that in S2S_{2}.

Suppose we are given arbitrary nn positive integers {a1,,an}\{a_{1},\cdots,a_{n}\}. Let tt be half of the sum of these integers, i.e., 12i=1nai\frac{1}{2}\sum_{i=1}^{n}a_{i}. Without loss of generality, we assume that aita_{i}\leq t for all i[n]i\in[n] otherwise the answer to the decision problem will directly be “no”.

We first construct a CFMM AA and initial state s0s_{0}. Concretely, we can consider the constant curve of AA as F(x,y):xy=kF(x,y):xy=k, and our goal is to choose parameters such that x0Lx=(1f)tx_{0}-L_{x}=(1-f)t. Precisely, we know that Lx=1fx0L_{x}=\sqrt{1-f}x_{0}, since r(Lx)=11fr(x0)r(L_{x})=\frac{1}{1-f}r(x_{0}). This means x0Lx=(11f)x0x_{0}-L_{x}=(1-\sqrt{1-f})x_{0}. So choosing x0=1f11ftx_{0}=\frac{1-f}{1-\sqrt{1-f}}t would suffice.

Next, we construct users’ transactions. For each integer aia_{i}, we construct TXi=Sell(𝒳,ai)\textsf{TX}^{i}=\texttt{Sell}(\mathcal{X},a_{i}). Clearly, we have AP(s0,TXi)=0\texttt{AP}(s_{0},\textsf{TX}^{i})=0 as (1f)ai(1f)t=x0LxRxx0(1-f)a_{i}\leq(1-f)t=x_{0}-L_{x}\leq R_{x}-x_{0}. Then we construct two Sell(𝒴,)\texttt{Sell}(\mathcal{Y},\cdot) transactions. Precisely, we construct TXn+1=TXn+2=Sell(𝒴,q)\textsf{TX}^{n+1}=\textsf{TX}^{n+2}=\texttt{Sell}(\mathcal{Y},q^{*}) where qq^{*} is large enough such that Fx(y0+(1f)q)<LxF_{x}(y_{0}+(1-f)q^{*})<L_{x}. Then we know AP(s0,TXn+1)=AP(s0,TXn+2)>0\texttt{AP}(s_{0},\textsf{TX}^{n+1})=\texttt{AP}(s_{0},\textsf{TX}^{n+2})>0. This finishes the construction. And we know M(s0,{TXi}i[n+2])=2AP(s0,TXn+1)M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n+2]})=2\texttt{AP}(s_{0},\textsf{TX}^{n+1}).

Finally, we argue that there exists a strategy obtaining profits M(s0,{TXi}i[n+2])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n+2]}) if and only if there exists a subset S[n]S\subseteq[n] such that the sum of the numbers in SS equal tt. And this will conclude the theorem.

One direction is easy: if there exists S[n]S\subseteq[n] such that the sum of the numbers in SS equal tt, then we execute transactions as follows:

  1. 1.

    Execute user’s transaction TXn+1\textsf{TX}^{n+1}; Execute miner’s transaction Sell(𝒳,LxFx(y0+(1f)q)1f)\texttt{Sell}(\mathcal{X},\frac{L_{x}-F_{x}\left(y_{0}+(1-f)q^{*}\right)}{1-f});

  2. 2.

    Execute TXi\textsf{TX}^{i} for all iSi\in S;

  3. 3.

    Repeat item (1) except replacing TXn+1\textsf{TX}^{n+1} by TXn+2\textsf{TX}^{n+2}.

It is easy to verify that this sequence satisfies the greedy sequencing rule, and the miner can obtain M(s0,{TXi}i[n+2])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n+2]}).

For the other direction, we show that the sequence of transactions constructed above is essentially the only way to obtain M(s0,{TXi}i[n+2])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n+2]}). So a miner can obtain M(s0,{TXi}i[n+2])M(s_{0},\{\textsf{TX}^{i}\}_{i\in[n+2]}) only if the answer to the given Partition problem is “yes”.

We adopt a proof scheme similar to that of Lemma 2. Fix a sequence of (users’ and miner’s) transactions (TXτ(1),,TXτ(k))(\textsf{TX}^{\tau(1)},\cdots,\textsf{TX}^{\tau(k)}) such that miner’s profit U=2AP(s0,TXn+1)U=2\texttt{AP}(s_{0},\textsf{TX}^{n+1}). Recall that in the proof of Lemma 2, we defined ϕi\phi_{i} and showed Ui+ϕi(Ui1+ϕi1)AP(s0,TXi)U_{i}+\phi_{i}-(U_{i-1}+\phi_{i-1})\leq\texttt{AP}(s_{0},\textsf{TX}^{i}) for all i[k]i\in[k]. Since Uk=2AP(s0,TXn+1)U_{k}=2\texttt{AP}(s_{0},\textsf{TX}^{n+1}) at the end, it must be the case Ui+ϕi=ViU_{i}+\phi_{i}=V_{i} for all i[k]i\in[k] and ϕk=0\phi_{k}=0. As a result, the sequence of transactions must satisfy that

  • The miner does not lose profit for any transaction; otherwise the loss of the profit is strictly larger than the gain of the ϕ\phi function, and this will result in Ui+ϕi<ViU_{i}+\phi_{i}<V_{i} for some ii.

  • There are i1i2[k]i_{1}\neq i_{2}\in[k] such that ϕi1=ϕi2=AP(s0,TXn+1)\phi_{i_{1}}=\phi_{i_{2}}=\texttt{AP}(s_{0},\textsf{TX}^{n+1}). This means when execute TXn+1\textsf{TX}^{n+1} and TXn+2\textsf{TX}^{n+2}, the corresponding state must be (x0,y0)(x_{0},y_{0}).

To achieve both items simultaneously, it must be (xi11,yi11)=(x0,y0)(x_{i_{1}-1},y_{i_{1}-1})=(x_{0},y_{0}) and TXn+1\textsf{TX}^{n+1} is executed as TXτ(i1)\textsf{TX}^{\tau(i_{1})}. To get the first AP(s0,TXn+1)\texttt{AP}(s_{0},\textsf{TX}^{n+1}) profit, miner executes Sell(𝒳,LxFx(y0+(1f)q)1f)\texttt{Sell}(\mathcal{X},\frac{L_{x}-F_{x}\left(y_{0}+(1-f)q^{*}\right)}{1-f}) in the (i1+1)(i_{1}+1)-th iteration. To make sure that (xi21,yi21)=(x0,y0)(x_{i_{2}-1},y_{i_{2}-1})=(x_{0},y_{0}) (and TXn+2\textsf{TX}^{n+2} is executed as TXτ(i2)\textsf{TX}^{\tau(i_{2})}) while the miner does not loss any profit in this process, we must use users’ transactions to change the state from xi1=Lxx_{i_{1}}=L_{x} to xi21=x0x_{i_{2}-1}=x_{0}, which means we need a subset SS of users’ transactions such that the sum of numbers in SS is exactly tt.

This finishes the proof. ∎

Theorem 3 follows directly by simulating any algorithm that computes an optimal strategy and calculates the profits to solve the decision problem.

Theorem 3.

Let f(0,1)f\in(0,1) be any universal constant. It is NP-hard to compute the strategy that can obtain the optimal profits.

5 Discussion and Open Problems

Refined Sequencing Rule. Our first question is related to mechanism design, motivated by a revisit of our polynomial time algorithm when f=0f=0. Recall that our algorithm can always obtain the upper bound profits, even if the miner is asked to follow the greedy sequencing rule such that the sequence is additionally under a descending order. Thus, we would like to ask if there is some sequencing rule (that is computationally efficient and verifiable) that can further mitigate the miner’s incentive to manipulate. We propose the following way to build a theoretical foundation when considering real-world applications. We could consider the case where users’ transactions are drawn from a certain distribution 𝒟\mathcal{D} (witnessed by real-world DeFi scenarios), and show that under the refined greedy sequencing rule, miners cannot obtain large profits with high probability. We leave it as a promising open question.

Approximation Algorithm for Miners. It is also worth to study about approximation algorithm design for miners. Our NP-hardness rules out the possibility for a miner to have a polynomial time algorithm for an optimal strategy (assuming P\neqNP). However, it remains possible to design a polynomial time algorithm with a good approximation guarantee. This strategy exploration allows miners to develop efficient algorithms that can yield sufficient MEV close to the optimal strategy. As the optimal MEV problem shares a similar spirit with the Knapsack problem, one promising direction is to apply the classic approximation algorithms to our setting.

User’s Strategies. The third question is about strategic analysis from the perspective of users. In this work, we systematically studied the optimal strategies of miners. We also note that there is fruitful space for a user to adopt strategies. For example, a user who wants to sell a large amount of 𝒳\mathcal{X} tokens may have an incentive to split it into several smaller transactions, and this may lead them to a higher profit under the greedy sequencing rule. Generally speaking, we wonder what is an optimal strategy for a user under certain sequencing rules. Different from the miner’s incentive, multiple users are making decisions simultaneously, which forms a multi-agent system. One step further than one user’s optimization, we ask what the equilibrium is when all users behave strategically. The game theory problem between users and miners under specific sequencing rules is also an intriguing question.

Other Scenarios where MEV Makes Everyone Happy. Finally, recall our exciting journey about the positive effects of MEV: when a miner attracts MEV (optimally), users are also benefited in a reasonable sense (Corollary 1 and Corollary 2). The intuition behind this phenomenon is that although the existence of MEV incentivizes miners to engage in attacking behaviors when a good sequencing rule can restrict miners’ actions and prevent them from affecting users’ profits, the presence of MEV itself can benefit users. In this case, MEV not only does not harm users but can expedite the execution of user transactions as miners have the motivation to execute more transactions (to obtain MEV). We expect and are eager to know a wider range of scenarios where the same conceptual result also holds. We leave this as the most important future work.

References

  • [1] DeFiLlama, “Defi overview,” August 1st 2023. [Online]. Available: https://defillama.com/
  • [2] DeFiprime, “Decentralized exchanges trading volume,” August 1st 2023. [Online]. Available: https://defiprime.com/dex-volume
  • [3] H. Adams, N. Zinsmeister, M. Salem, R. Keefer, and D. Robinson, “Uniswap v3 core,” Tech. rep., Uniswap, Tech. Rep., 2021. [Online]. Available: https://uniswap.org/whitepaper-v3.pdf
  • [4] P. Daian, S. Goldfeder, T. Kell, Y. Li, X. Zhao, I. Bentov, L. Breidenbach, and A. Juels, “Flash boys 2.0: Frontrunning in decentralized exchanges, miner extractable value, and consensus instability,” in 2020 IEEE Symposium on Security and Privacy, SP 2020, San Francisco, CA, USA, May 18-21, 2020.   IEEE, 2020, pp. 910–927. [Online]. Available: https://doi.org/10.1109/SP40000.2020.00040
  • [5] L. Zhou, K. Qin, C. F. Torres, D. V. Le, and A. Gervais, “High-frequency trading on decentralized on-chain exchanges,” in 42nd IEEE Symposium on Security and Privacy, SP 2021, San Francisco, CA, USA, 24-27 May 2021.   IEEE, 2021, pp. 428–445. [Online]. Available: https://doi.org/10.1109/SP40001.2021.00027
  • [6] M. V. X. Ferreira and D. C. Parkes, “Credible decentralized exchange design via verifiable sequencing rules,” in Proceedings of the 55th Annual ACM Symposium on Theory of Computing, STOC 2023, Orlando, FL, USA, June 20-23, 2023, B. Saha and R. A. Servedio, Eds.   ACM, 2023, pp. 723–736. [Online]. Available: https://doi.org/10.1145/3564246.3585233
  • [7] M. Bartoletti, J. H. Chiang, and A. Lluch-Lafuente, “Maximizing extractable value from automated market makers,” in Financial Cryptography and Data Security - 26th International Conference, FC 2022, Grenada, May 2-6, 2022, Revised Selected Papers, ser. Lecture Notes in Computer Science, I. Eyal and J. A. Garay, Eds., vol. 13411.   Springer, 2022, pp. 3–19. [Online]. Available: https://doi.org/10.1007/978-3-031-18283-9_1
  • [8] M. Kelkar, F. Zhang, S. Goldfeder, and A. Juels, “Order-fairness for byzantine consensus,” in Advances in Cryptology - CRYPTO 2020 - 40th Annual International Cryptology Conference, CRYPTO 2020, Santa Barbara, CA, USA, August 17-21, 2020, Proceedings, Part III, ser. Lecture Notes in Computer Science, D. Micciancio and T. Ristenpart, Eds., vol. 12172.   Springer, 2020, pp. 451–480. [Online]. Available: https://doi.org/10.1007/978-3-030-56877-1_16
  • [9] M. Kelkar, S. Deb, and S. Kannan, “Order-fair consensus in the permissionless setting,” in APKC ’22: Proceedings of the 9th ACM on ASIA Public-Key Cryptography Workshop, APKC@AsiaCCS 2022, Nagasaki, Japan, 30 May 2022, J. P. Cruz and N. Yanai, Eds.   ACM, 2022, pp. 3–14. [Online]. Available: https://doi.org/10.1145/3494105.3526239
  • [10] C. Cachin, J. Micic, N. Steinhauer, and L. Zanolini, “Quick order fairness,” in Financial Cryptography and Data Security - 26th International Conference, FC 2022, Grenada, May 2-6, 2022, Revised Selected Papers, ser. Lecture Notes in Computer Science, I. Eyal and J. A. Garay, Eds., vol. 13411.   Springer, 2022, pp. 316–333. [Online]. Available: https://doi.org/10.1007/978-3-031-18283-9_15
  • [11] M. A. Vafadar and M. Khabbazian, “Condorcet attack against fair transaction ordering,” CoRR, vol. abs/2306.15743, 2023. [Online]. Available: https://doi.org/10.48550/arXiv.2306.15743
  • [12] D. Malkhi and P. Szalachowski, “Maximal extractable value (MEV) protection on a DAG,” in 4th International Conference on Blockchain Economics, Security and Protocols, Tokenomics 2022, December 12-13, 2022, Paris, France, ser. OASIcs, Y. Amoussou-Guenou, A. Kiayias, and M. Verdier, Eds., vol. 110.   Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2022, pp. 6:1–6:17. [Online]. Available: https://doi.org/10.4230/OASIcs.Tokenomics.2022.6
  • [13] Sikka, August 1st 2023. [Online]. Available: https://sikka.tech/projects/
  • [14] S. Eskandari, S. Moosavi, and J. Clark, “Sok: Transparent dishonesty: Front-running attacks on blockchain,” in Financial Cryptography and Data Security - FC 2019 International Workshops, VOTING and WTSC, St. Kitts, St. Kitts and Nevis, February 18-22, 2019, Revised Selected Papers, ser. Lecture Notes in Computer Science, A. Bracciali, J. Clark, F. Pintore, P. B. Rønne, and M. Sala, Eds., vol. 11599.   Springer, 2019, pp. 170–189. [Online]. Available: https://doi.org/10.1007/978-3-030-43725-1_13
  • [15] K. Babel, P. Daian, M. Kelkar, and A. Juels, “Clockwork finance: Automated analysis of economic security in smart contracts,” in 44th IEEE Symposium on Security and Privacy, SP 2023, San Francisco, CA, USA, May 21-25, 2023.   IEEE, 2023, pp. 2499–2516. [Online]. Available: https://doi.org/10.1109/SP46215.2023.10179346
  • [16] K. Kulkarni, T. Diamandis, and T. Chitra, “Towards a theory of maximal extractable value I: constant function market makers,” CoRR, vol. abs/2207.11835, 2022. [Online]. Available: https://doi.org/10.48550/arXiv.2207.11835
  • [17] P. Züst, T. Nadahalli, and Y. W. R. Wattenhofer, “Analyzing and preventing sandwich attacks in ethereum,” ETH Zürich, 2021. [Online]. Available: https://pub.tik.ee.ethz.ch/students/2021-FS/BA-2021-07.pdf
  • [18] L. Heimbach and R. Wattenhofer, “Eliminating sandwich attacks with the help of game theory,” in ASIA CCS ’22: ACM Asia Conference on Computer and Communications Security, Nagasaki, Japan, 30 May 2022 - 3 June 2022, Y. Suga, K. Sakurai, X. Ding, and K. Sako, Eds.   ACM, 2022, pp. 153–167. [Online]. Available: https://doi.org/10.1145/3488932.3517390
  • [19] L. Zhou, K. Qin, and A. Gervais, “A2MM: mitigating frontrunning, transaction reordering and consensus instability in decentralized exchanges,” CoRR, vol. abs/2106.07371, 2021. [Online]. Available: https://arxiv.org/abs/2106.07371
  • [20] Flashbots, August 1st 2023. [Online]. Available: https://docs.flashbots.net/
  • [21] Eden, August 1st 2023. [Online]. Available: https://www.edennetwork.io/
  • [22] OpenMEV, August 1st 2023. [Online]. Available: https://openmev.xyz/