Uniswap—and other constant product markets—appear to work well in practice despite their simplicity. In this paper, we give a simple formal analysis of constant product markets and their generalizations, showing that, under some common conditions, these markets must closely track the reference market price. We also show that Uniswap satisfies many other desirable properties and numerically demonstrate, via a large-scale agent-based simulation, that Uniswap is stable under a wide range of market conditions.
Smart contract systems such as Ethereum  and Tezos  have allowed for the design and implementation of decentralized versions of traditional financial primitives. The use of these primitives has grown dramatically in 2019: in January, less than $20 million of Ethereum-based assets were utilized in these systems, a number which increased to $750 million by December . Decentralized financial primitives allow for censorship-resistant participation in a number of digital markets, expanding the reach of lending , stable assets , and exchanges  past the conventional financial world. In particular, a secure decentralized exchange for cryptocurrencies has been desired almost since the advent of Bitcoin as centralized exchanges, such as Mt. Gox , Quadriga (Error), and Bitfinex , have suffered catastrophic losses aggregating to billions of dollars’ worth of depositors’ funds.
Historically, many different decentralized exchanges (DEXs) have been proposed using different market maker mechanisms, ranging from classic order book mechanisms  to other, more complicated approaches with particular bonding curves . Yet, a simple but surprisingly effective market maker appears to be the constant product market maker used by Uniswap , likely the first and possibly the most popular implementation. These markets provide a simple approach for trading between pairs of coins in a decentralized fashion, and have, in recent years, become a popular (and practically useful) alternative to other types of DEXs.
Additionally, other protocols (such as Celo ) have used the idea of constant-product markets as a decentralized price oracle — a contract that can be queried to find the relative price between two coins of interest. These protocols make use the fact that, if the price indicated by the oracle differs from the true market price of the traded coins, an arbitrageur can always make a profit by trading with this oracle, implying that the price indicated by this oracle is likely close to the reference market price.
While order book mechanisms are the dominant medium of exchange of electronic assets in traditional finance , they are challenging to use within a smart contract environment. The size of the state needed by an order book to represent the set of outstanding orders (, passive liquidity) is large and extremely costly in the smart contract environment, where users must pay for space and compute power utilized . Moreover, the matching logic for order books is often complicated as it must often support several different order types (such as icebergs, good-till-cancel, and stop-limit orders ).
In order to avoid the costly on-chain execution costs (paid to miners/validators of the smart contract by agents executing trades) a variety of designs for decentralized exchanges use the blockchain underlying a smart contract for settlement, while executing trades off-chain . These exchanges, however, have a number of drawbacks. First, the complicated interaction between off-chain and on-chain mechanisms, coupled with the transaction ordering ambiguity inherent in blockchain-based systems, allows for front-running, which has been observed in practice . Second, keeping the order book state in the hands of multiple participants (such as ‘relayers,’ in 0x parlance ) often leads to stale orders and latency arbitrage that is many orders of magnitude worse than that of high-frequency trading. Finally, these exchanges have a more complicated threat model than that of a smart contract which does not have to interact with an exogenous, non-blockchain system to determine state transitions. Due to this, users must often take extra security precautions when trading or potentially use complicated exit games to release their funds.
On the other hand, automated market makers (AMMs) have been studied extensively in algorithmic game theory, beginning with Hanson’s logarithmic market scoring rule (LMSR) , often used in practice as an AMM for prediction markets. Such AMMs are constructed by first having liquidity providers deposit assets in some fixed ratio to specify an initial distribution of beliefs over possible outcomes. An AMM then provides a scoring rule which specifies the cost of changing the distribution of beliefs from its current state to a new, desired state. This scoring rule incentivizes traders to report their true belief such that the expected value of adjusting the distribution is positive. Since the state of the exchange depends only on the total amount of quantities deposited, the corresponding storage requirements are much smaller than those of traditional exchanges. Additionally, pricing a trade requires only a single function evaluation, as opposed to more complicated matching algorithms, as in the case of order books.
In general, LMSRs (and similar AMMs) are designed to predict the outcome of some set of (disjoint) events rather than predict a specific price. In many cases, the proposed mechanism cannot be directly used to price arbitrary assets without requiring a large state space and often suffers from other practical issues such as attracting liquidity .
To solve this problem, early Ethereum-based AMMs such as Bancor  moved to a second model for pricing assets: in this model, the function specifies the cost of an asset based on the total available supply (as, for example, its tokens are minted or burned), rather than specifying the cost of changing a given distribution. The function itself is called a bonding curve, and the resulting equilibrium price of the asset is then equal to the market price under certain conditions.
Another possible model for pricing assets, first introduced by Uniswap , does not require the ability to change the supply of an asset in order to measure its price. Rather, an AMM holds some quantity of assets whose relative price we wish to measure in its reserves. The AMM then specifies a pricing function, which maps the quantities of the assets in reserves to their marginal price (with respect to any numéraire). Agents are then allowed to trade with this contract at the price specified by the pricing function, and this price is continually updated as its reserves change after each trade. For example, constant product markets such as Uniswap are specific cases in which the pricing function is exactly equal to the ratio of the reserves available to the contract, when no trading fees are taken (§2.1).
While Uniswap, and its associated class of AMMs, is similar in spirit to bonding curve-based AMMs, we will distinguish them as a separate class of AMMs with a fairly distinct range of applicability. We will focus only on Uniswap-like AMMs—the constant product and constant mean AMMs—and leave the discussion of bonding curves and their theoretical properties for future research.
In this paper, we present optimal arbitrage actions and bounds under some simple reference market models for Uniswap’s AMM model, which we call the constant product markets, showing that Uniswap must closely track the reference market price under common market conditions. We also show that a recent generalization of constant product markets, the constant mean markets, first proposed in , have nearly identical theoretical properties and may be of future interest. Finally, we run a large-scale simulation of agents interacting with the Uniswap contract over a wide range of market parameters, suggesting that the system may be stable under a variety of market conditions. These results help us conclude that Uniswap serves as a censorship resistant price oracle for smart contracts, provided that there exists an external reference market with sufficient liquidity.
[sec:const-prod] A constant product market  is a market for trading coins of type for coins of type (and vice versa). This market has reserves and , constant product , and percentage fee . A transaction in this market, trading coins for coins , must satisfy
After each transaction, the reserves are updated in the following way: , , and . We will always require that , such that any trade that results in a nonpositive reserve is never fulfilled (equivalently, we say that such a trade has infinite cost).
The name ‘constant product market’ comes from the fact that, when the fee is zero (, ), any trade to must change the reserves in such a way that the product remains equal to the constant .
In this section, we derive bounds on the marginal price of the market relative to a reference market and show that this market maker has other desirable properties.
In the optimal arbitrage problem, we have two coins, and , which we can trade either with a reference market or a Uniswap contract. In this problem, we seek to maximize the profit made from trading, say, some amount of loaned coin, , of coin , to some amount, , of coin via the Uniswap market. We then trade back the received for and pay back the loan to receive profit .
If our profit is positive (that is, if ), then we say that there is an arbitrage opportunity, since we have made money ‘for free’ (, by only trading coins within different markets) without taking on any risk. The optimal arbitrage problem then asks: what is the maximum profit that can be made by this scheme?
In the infinitely liquid market case, , in the case that (where is the reference market price of coin ), we can phrase the optimal arbitrage problem as the following optimization problem:
with optimization variables and , constrained to be nonnegative. Here, is the Uniswap exchange fee, and the constraint is the definition of a constant product market [eq:const-prod].
When written in this form, problem [eq:main] is not obviously convex, though we show in appendix 6 that it can easily be written in a convex form and then derive an analytical form for the optimal trade amounts and .
Assuming that the no-arbitrage condition is satisfied (which often approximately holds in practice; see ), we can show that the Uniswap market price deviates from the market price by at most a factor of .
The marginal price of coin in Uniswap is defined as the price of an infinitesimally small trade. This price can be found by differentiating the constant-product market formula:
where we have written for the Uniswap price of coin without the fee.
We can always make a nonzero profit if the Uniswap marginal price of , is smaller than the market marginal price , by performing a small enough trade. Assuming there is no arbitrage, this means we must have
Similarly, by swapping for and combining the resulting statements we get the following bounds on the Uniswap market price, relative to the true market price, :
assuming no-arbitrage conditions.
This suggests that, in practice, the larger the trade fees are, the larger the gap between the true market price and the Uniswap market price may be. For example, in the case that the trade fee is small, the inequalities in [eq:no-arb] are approximately equivalent to
While we derived these conditions using a simple argument, we can also easily derive them by analyzing problem [eq:main] and noting that its optimal value is nonzero if, and only if, there is an arbitrage opportunity. For more details, see appendix 6.
There are several natural extensions to the optimal problem [eq:main], which retain most of its useful properties.
There are many factors which could potentially cause an agent to fail to close an arbitrage opportunity, including noisy information, front-running , and delay in trades—the latter of which is quite common in distributed platforms. In particular, it may not be desirable for an agent to perform a trade with the exact solution of problem [eq:main].
In this case, we can add an additional term penalizing large trades: in other words, we can assign some ‘cost of risk’ which can be any convex function which is nondecreasing in its second argument. This gives a problem of the form:
One example of a risk function could be a model of the resulting changes in market price due to the arbitrage trade. A common (and simple) model for the marginal market price after a trade of size is that the resulting price is
with any , . The resulting risk function, , is convex. See appendix 6.1 for more details and extensions.
Additionally, in this model, unlike in problem [eq:agent-arb], an arbitrageur is not guaranteed to reach the no-arbitrage condition in a single round if the penalty function does not reflect the true underlying market movement.
For every trade, the product constant is nondecreasing (and strictly increasing if ). Let , , and be the reserve of , , and the constant product at trade . If trade sells coins for coins , we have (by definition, see [eq:const-prod]):
where inequality always holds strictly except when . So, if , we have that , always.
Whenever , any agent agent trading some amount for some output and immediately trading another amount for will always have smaller output than if the agent had traded for some output all at once (this property is also sometimes called path-dependence ). This can easily be proven, though it is mostly an exercise in algebra. We outline the steps in appendix 9.
This fact implies that, in the case where the reference market is infinitely liquid (as in §2.1), an arbitrage agent who considers a strategy several steps into the future cannot do better than simply solving [eq:main] and executing the corresponding trade.
It turns out to be impossible to fully deplete Uniswap of all coins only by trading and , even if the attacker has an unbounded amount of coins. We can easily show that the total reserve is always bounded from below. This follows immediately from applying the arithmetic-geometric mean inequality :
Since this is true and is nondecreasing (and usually strictly increasing) after each trade, then the total number of coins in Uniswap can never decrease below the twice the square root of the initial product by only trading between coins and .
Intuitively, the larger the amount of reserves, the less any one trade will cost. The marginal cost change of Uniswap (the negative of the infinitesimal price change of the Uniswap market after an infinitesimal trade) can be computed by differentiating [eq:const-prod] twice and is given by
where is the Uniswap price without fees. Note that [eq:slippage] is strictly decreasing as increases (assuming , the Uniswap price, stays constant).
We can similarly show this property directly by assuming that we have two markets, one with strictly larger reserves , and both with price
In this case, assuming we trade coins with both markets, we can show that the markets will have a price gap of
In the no-fee case with an infinitely liquid reference market, the cost of manipulating the price of a constant product market can be bounded from below.
If the attacker wishes to manipulate the constant product market to be , where is the true market price and is some desired constant, then the attacker requires an amount of, at least
coin for each period (here, a period could be, , the time taken for a block to be mined) with a universal constant.
This result implies that the cost of manipulation scales linearly with the reserve amounts, marking the importance of having large reserve pools. Additionally, the result extends immediately (as a lower bound) to the case with fees. For a derivation of [eq:manipulation-cost] and an explicit bound on , see appendix 10.
In the no fee case (, when ), we can easily compute the portfolio value of the Uniswap contract (and, correspondingly, any liquidity provider). Let , , and be the reserves for coin , coin , and the market price of coin , respectively, at each time .
We can use this expression to write a simple form for the relative return for Uniswap between time to , given by
This implies that the total relative gain for a Uniswap contract is
and the total portfolio value is
Since depends only on the relative ratios of and , the result holds even when liquidity providers add tokens or remove tokens from the reserves—although in practice, as suggested by [eq:slippage], the price is likely to be less stable in the case of smaller reserves. See appendix 8 for further discussion.
Because the arbitrage problem [eq:main], and its risky variant, problem [eq:agent-arb], are convex, we suspect that the no-arbitrage assumption is very likely to be met in practice. The convexity of this problem additionally implies that arbitrage can be efficiently performed even across several Uniswap markets (see appendix 6 for more details).
As shown in [eq:no-arb], we analytically observe the effect that the Uniswap market fee has on the price of the market: the bounds guaranteed by the no-arbitrage assumption become looser. In other words, as the fee increases (or, equivalently, decreases), we expect the Uniswap market to deviate further from the price of a given reference market.
Result [eq:manipulation-cost] implies that, when the reserves are large, the cost of manipulation is generally expensive for all but the smallest of changes—though, due to the quadratic scaling when is small, we can expect small changes to the price to be relatively inexpensive. This implies that protocols which depend on Uniswap (or other constant product markets) as a price oracle should not be extremely sensitive to small price fluctuations; otherwise, it may be possible for an attacker with moderate resources to exploit this for their own gain.
These properties, combined with results [eq:increasing-constant] and [eq:asymptotic], suggest that constant product markets are likely to be robust in the the practical setting where the number of tokens in reserve is large and the number of trades is also large.
A constant mean market is a market which generalizes constant product markets. First introduced in , constant mean markets satisfy the following equation in the absence of fees:
where are the reserves of coin , are the weights associated with each coin, and is the constant product. In this case, the weights all satisfy with . In other words, in the absence of fees, constant product markets ensure that the product of its reserves stays constant, while constant mean markets ensure that the weighted geometric mean of the reserves, for , stays constant.
Similar to constant product markets, trading amount of coin for some amount of a distinct coin should always satisfy the equation,
where is the percentage fee associated with trading coin . The corresponding reserves, and are updated as in §[sec:const-prod], as is the mean constant, .
Note that constant product markets are a special case of a constant mean market where and we have and , with the constant product of [eq:const-prod] replaced with its square root.
We can write the optimal arbitrage problem for constant mean markets in the following way:
where we will assume that is constrained to be zero for notational convenience.1 The variables in this optimization problem are the amount whose entries state how much of each coin to purchase from the external market, while th entry of states how much of coin to trade for coin .
Since the weighted geometric mean is a concave function that is increasing in all of its arguments , it turns out that the equality constraint in problem [eq:const-mean-opt] can be relaxed to an inequality constraint to get an equivalent, but convex, optimal arbitrage problem . See appendix 11 for more details.
Surprisingly, almost all conditions and properties (except the no-arbitrage condition [eq:no-arb]) that hold for constant product markets also hold for constant mean markets in a similar form. We describe a few cases below.
All of the same extensions given in section §2.2 hold for problem [eq:const-mean-opt]. More specifically, for any convex function , which is increasing in its first arguments and decreasing in the remaining arguments, the following convex relaxation of [eq:const-mean-opt] is an equivalent (but convex) problem with the additional penalty term, :
with the same variables, and , as problem [eq:const-mean-opt].
Additionally, some of the same properties given in §2.3, hold essentially in their exact form for constant mean markets: all instances will have an nondecreasing product constant and satisfy the corresponding no-depletion property. The notion of increasing liquidity with increasing reserves also holds and can be easily derived from .
It is, in general, not clear that there exists a closed-form solution for the no-arbitrage conditions specified in §2.1. It is possible to give simple necessary (but not sufficient) conditions on each pair of coins found in a given constant-product market via a similar argument to the one in §2.1, but we expect the general conditions are more complicated.
We present these results for constant mean markets as they carry over nearly immediately from those given in §[sec:const-prod]. Though we suspect that markets which satisfy the constant mean property, such as Balancer —where the idea originated—may become more important in the near future, we focus on the specific case of Uniswap (and, more generally, constant product markets) as other protocols such as Celo  heavily depend on the robustness of this particular market maker mechanism.
While the properties presented in §[sec:const-prod] lead us to believe that the Uniswap market is likely well-behaved under most scenarios, it is hard to make stronger claims about the robustness of the Uniswap market mechanism without making assumptions that are unlikely to be realistic.
To verify this experimentally, we created an agent-based simulation by using the Gauntlet DSL to specify how several types of agents interact with the current Uniswap contract2 on a simulated Ethereum blockchain. The simulation environment interacts with the Uniswap contract deployed on a simulated blockchain via Python bindings. The environment allows for configuration of the network’s initial conditions, including distributions of agent behaviors and agent-specific parameters.
The simulation is run for a pre-defined number of time steps. For each simulated time step, environment state variables are updated based on the state of the on-chain contracts. We additionally evaluate policies for adding new agents to the environment. We evaluate the utility of an action for a given agent, and execute agent actions that have positive utility by submitting the corresponding transaction to the blockchain.
In the current simulation, we have two possible markets for agents to trade with: one is given by the Uniswap contract and the other is given by a simple stochastic market model.
When interacting with the Uniswap contract, an agent has a few possible actions they can perform: the agent can either (a) trade coins for (and vice versa) subject to the constant product market equation [eq:const-prod], or (b) add or remove liquidity.
In the latter case, an agent is able to add, say, amount of coin to reserve and is required to also add of coin to reserve . The agent is then awarded
where is the total amount of outstanding UNI coins given by the contract. The agent can also similarly remove liquidity by burning coins. The contract then gives the agent
and burns the given coins.
This market mechanism allows the agents who purchase these UNI coins, often called liquidity providers, to earn a profit given by the exchange fee, assuming the market price stays constant. Additionally, it provides a mechanism for adding and removing to reserves, thus making the Uniswap market more liquid, as shown in section §2.3.
For the remainder of this section, we will assume the price of a UNI token is exactly given by the market prices of the equivalent amount of coins and that would be received by burning the token. Additionally, the Uniswap contract defines , which is the value we use from here on out.
The reference market follows a simple power law model where the price of some coin , is updated in the following way:
where and are given in the problem data. While it is possible for an arbitrageur to solve the arbitrage problem exactly (as it is a special case of [eq:agent-arb]), we choose a simpler risk model for the arbitrageur as the true market price model is not known in practice.
We additionally update the market price every time step (after all agents have completed their actions) in the following way:
Here is drawn from a normal distribution and represent the mean returns and volatility of the market when no trades are performed.
There are three broad classes of agents used in this simulation: arbitrageurs (who attempt to profit from deviations between Uniswap and the market), liquidity providers (who hold portfolios of UNI coins and currencies and ), and traders (who trade coins with the Uniswap market, subject to simple rules). We describe each type of agent in detail below.
Arbitrageurs seek to maximize their profit by trading between the Uniswap market and a reference market. An arbitrageur agent solves an instance of problem [eq:agent-arb] with a simple quadratic cost of risk model:
and performs the necessary trades. Here, are parameters which control the penalty incurred for a trade.
We use this model instead of the riskless case of problem [eq:main], as live systems have noise during trades (, network delays) such that opportunities found by exact minimization of the riskless problem [eq:main] may not be easily executed or may close during the time it takes to perform the trade.
Additionally, we are able to model a wide variety of risk-taking behavior by arbitrageurs by, for example, increasing the parameters and to have an arbitrageur who is less prone to perform risky (large) trades, even with large arbitrage opportunities available.
There are two types of liquidity providers we model in this simulation.
The first are the initial liquidity providers, who begin the simulation by providing some amount of coins , and to the reserve and seek to gain profits by taking fees from Uniswap trades. We assume these liquidity providers will not withdraw their position until the end of the simulation.
The second are rational liquidity providers. These agents perform Markowitz portfolio optimization (see ) on the three possible coins in the market: , , and the corresponding UNI coin minted from the Uniswap market. Each agent then solves the (convex) portfolio optimization problem,
and makes the appropriate trades to rebalance their portfolio. In this problem, is the vector containing the portfolio positions of , , and UNI respectively. The problem data is the vector of exponentially-weighted average returns for each of the three coins (with respect to the reference market), is the exponentially-weighted covariance of returns, and is the penalty incurred by the risk. Since [eq:markowitz] is not known to have a closed form solution, we set up and solve problem [eq:markowitz] using the CVXPY  modeling language and the ECOS solver  in our simulation.
The rational liquidity providers simulate agents who seek to maximize profits by trading their positions in each coin and holding the respective coins to maximize their expected return on investment, based on observed historical averages.
The final agent we model is a trader. In this case, the trader seeks to trade some amount of coin for some second amount (or vice versa), so long as the price of trading coins on Uniswap differs no more than a constant percentage off from the same trade in the reference market.
In a way, traders embody the ‘demand for liquidity,’ or the fact that trades on Uniswap might happen due to exogenous influences. In our case, a trader will draw (or ) from some probability distribution and check if performing this trade in the Uniswap market is at most some percentage more expensive than performing it in the reference market. If not—, if the agent is able to trade with Uniswap for a reasonable price—then the agent makes the trade using the Uniswap contract. Otherwise, no trade is performed.
The results of our simulations suggest that the theoretical results derived above hold in practice under a wide variety of market conditions.
Figures 1 and 2 show that, even under the presence of outside noise—such as random noise, or changes in reserves due to rational liquidity providers—the marginal Uniswap price stays within the predicted no-arbitrage bounds. In particular, figure 1 shows when the market has a small amount of noise and little drift, while figure 2 shows this when there is large negative drift with moderate noise. We find that these bounds hold in our simulations, even under large amounts of market noise and large drift rates, so long as the trades performed are not large.
Due to the discrete nature of the simulation, if a trader is the last agent to run at each time step, the no-arbitrage bounds could be broken as an arbitrageur may not have yet been able to perform arbitrage. While this is true (and is due to the nature of the simulation), the final result still clearly tracks the market price, as shown in figure 3.
In the simulation, we also record the utility of the initial liquidity providers, defined as the difference between the value of the respective UNI coin the agents hold, as defined in §4.1, and a portfolio composed of the coins and traded in for UNI at the start of the simulation.
As shown in figure 4, we find that in almost all of our simulations, initial liquidity providers end up having negative utility (using this definition), over most varying conditions. More specifically, we note that initial liquidity providers only have positive expected value when the mean market return is close to zero, as they earn revenue from all transaction fees while not falling behind an equivalent portfolio of the given pairs of coins. This approximately follows the result given in [eq:uniswap-returns], except that liquidity providers earn fees in this case.
Though simple, constant product markets and their generalizations have very nice theoretical properties (such as fairly strict no-arbitrage bounds on the reference price) which appear to hold in practice. Our simulations confirm that this is the case under a wide range of different market parameters and conditions, implying that the use of constant product markets as price oracles is, at least at first glance, sound.
Additionally, we suspect that there is an even larger class of automated market maker mechanisms which satisfy the above properties, and it would be interesting to further explore its mathematical properties. We leave this possible generalization for future work.
The authors would like to thank Tony Salvatore for the initial implementation of the market model used in the simulation and Jonathan Tuck, Hayden Adams, Alex Evans, and Dan Robinson for helpful comments and edits on the paper. The authors would also like to thank Regina Cai, Georgios Konstantopoulos, and Merrick Wong for pointing out some inconsistencies in the text, reviewers 1 and 2 for their comments and suggestions, and Thoma Zoto for pointing out that the original proof in appendix 9 was incorrect.
We can easily show that this problem is convex by using [eq:const-prod] to solve for ,
Note that is then a convex function of as is convex for positive, and a convex function composed with an affine function is convex . The resulting (equivalent) problem,
with variable is then convex.
Since the problem is one-dimensional, the fact that problem [eq:main] is convex is not immediately useful, but it can lead to several simple generalizations. For example, the optimal -stage trading strategy with several interacting constant product markets can be efficiently evaluated in this case.
Note that a maximum of a concave function over an interval happens either at (a) the interior of an interval, or (b) at its boundary. In the latter case, it is not hard to show that a maximum is attained at the point on the boundary closest to the unconstrained maximum.3 Because of this, we only have to consider the unconstrained version of problem [eq:Uniswap-cvx], over the interval .
In this case, the unconstrained optimal points are those for which the objective of [eq:Uniswap-cvx] has zero derivative. This happens when
By the statement above, then the optimal solution to [eq:Uniswap-cvx] is
where for . The optimal can be easily derived using the given above and the constant product formula [eq:const-prod].
Now, note that is zero if, and only if
where is the marginal Uniswap market price of without fees.
Since the objective of [eq:Uniswap-cvx] is zero whenever there is no arbitrage opportunity (and the objective is only zero at , by strict convexity), then the above implies there is no arbitrage in the presence of an infinitely liquid market. Swapping for yields the same result derived via no-arbitrage in the general case:
In a similar vein to [eq:Uniswap-cvx], we can add any penalty given by a convex function which is nondecreasing in its second argument to the objective. This yields yet another convex optimization problem:
with variables and . This problem is equivalent to problem [eq:agent-arb] as the objective function is decreasing with respect to , implying that the first inequality constraint is always tight at an optimal point. Additionally, problem [eq:Uniswap-penalty-cvx] is also convex as it is maximizing a concave function, subject to convex constraints. 
One particularly useful example of such a function is for modeling the market response of trading coin for coin . In particular, if the marginal market price is some decreasing function of the total amount of coin traded, satisfying , then the slippage cost of trading coin for is given by,
with convex (as its derivative, , is increasing by definition). While several simple market models exist, the one we use in this paper is a special case of
with and . This results in
By definition [eq:const-prod], the output of can be written as
Dividing the numerator and denominator by and using the fact that we get the (nearly final) result:
Subtracting from and using the fact that then yields the statement given in [eq:asymptotic].
Assume the trajectory of the market price follows a geometric Brownian motion process 
where is the drift, is the volatility, and is a standard Brownian motion . Without loss of generality, let . The portfolio value then has expectation
where we have used the fact that the th moment of a log-normal random variable is given by 
This argument shows one could replicate the time payoff of a no-fee liquidity provider with less initial capital than that required in the constant product market itself, which, in turn, implies that the portfolio value at time must grow at a rate of under the no-arbitrage hypothesis. The choice of that gives this growth rate is the no-arbitrage fee. A simple replication of a volatility harvesting strategy can be used to show that some such exists under mild conditions on and .
Given two sequentially-feasible trades and , we will show that the ‘aggregate trade’ always satisfies for any fee with . In other words, the total output for trading and sequentially is always smaller than the output of trading all at once.
To show this, note that after the trade is performed, the new reserves are given by and . So, since is a feasible trade when performed after (by definition) we have that
while, by definition, is feasible for reserves , , and we have
Since is also feasible for these reserves, we have that so,
Solving for , we find
while solving for gives
where the inequality follows from the fact that combined with the inequality:
whenever for any .
We can derive the cost of manipulation in the case where the reference market is infinitely liquid (, when ). We will derive this cost in the no-fee case as this lower bound on the cost is still a lower bound in the case with fees.
First, assume that an attacker wishes to increase the Uniswap price of a pair of coins and , by adding coins to the system and removing coins such that
where is some desired constant. Using the fact that (where the second equality follows from [eq:no-arb] with ), we get that
or, after some simplification, that
is required to increase the price. Since the attacker receives as a result of this trade, the total cost of the attack is then
where is the cost of carrying out the attack for a single time period.
Since is twice differentiable in over with and is increasing, then,
where the second equality follows since is decreasing over .
The case is simple to bound by noting that
for all whenever (this can be verified by multiplying the above inequality by to receive a convex quadratic whose largest root is ). Therefore,
so the claim follows,
For an explicit bound on , note that
follows from the above.
The bounds, as stated, are tight up to a constant multiplicative factor (which follows from the asymptotic behavior of as and , respectively) although they are—in their current state—only useful as a theoretical tool, as the provided constants are very loose.
Clearly, if any optimal point of [eq:const-mean-cvx] has the first inequality constraint holding at equality, then this point is optimal for [eq:const-mean-opt]. Because the objective is decreasing in for each and increasing in for each , while the geometric mean function in the inequality constraint is decreasing in and increasing in , then the inequality constraint is always tight at equality at any optimal point.
Since the weighted geometric mean function is concave , then problem [eq:const-mean-cvx] is a convex problem.
We also note that problem [eq:const-mean-opt] is log-log convex  with the obvious change of variables. While we do not explore this connection here, we suspect that this approach might provide a simple way of stating what class of functions can be used as an automated market maker mechanism such that the resulting no-arbitrage bounds are useful.