Cyclic Arbitrage in Decentralized Exchanges

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Cyclic Arbitrage in Decentralized Exchanges

Ye Wang Yan Chen Haotian Wu


[email protected] [email protected] [email protected]
ETH Zurich Zhejiang University Xi’an Jiaotong University
Zurich, Switzerland Hangzhou, China Xi’an, China

Liyi Zhou Shuiguang Deng Roger Wattenhofer


[email protected] [email protected] [email protected]
arXiv:2105.02784v3 [q-fin.TR] 14 Jan 2022

Imperial College London Zhejiang University ETH Zurich


London, United Kingdom Hangzhou, China Zurich, Switzerland
ABSTRACT KEYWORDS
Decentralized Exchanges (DEXes) enable users to create mar- Blockchain, Ethereum, Decentralized Exchanges (DEXes),
kets for exchanging any pair of cryptocurrencies. The di- Cyclic Arbitrage
rect exchange rate of two tokens may not match the cross-
ACM Reference Format:
exchange rate in the market, and such price discrepancies
Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng,
open up arbitrage possibilities with trading through differ- and Roger Wattenhofer. 2022. Cyclic Arbitrage in Decentralized
ent cryptocurrencies cyclically. In this paper, we conduct a Exchanges. In Proceedings of ACM Conference (Conference’17). ACM,
systematic investigation on cyclic arbitrages in DEXes. We New York, NY, USA, 12 pages. https://doi.org/10.1145/nnnnnnn.
propose a theoretical framework for studying cyclic arbitrage. nnnnnnn
With our framework, we analyze the profitability conditions
and optimal trading strategies of cyclic transactions. We fur-
ther examine exploitable arbitrage opportunities and the
1 INTRODUCTION
market size of cyclic arbitrages with transaction-level data Decentralized finance (DeFi) in the blockchain ecosystem has
of Uniswap V2. We find that traders have executed 292,606 attracted a surge of interest with a total gross value locked
cyclic arbitrages over eleven months and exploited more (GVL) of up to 120 billion USD by October 2021 [3]. DeFi
than 138 million USD in revenue. However, the revenue of applications are smart contracts deployed on blockchains,
the most profitable unexploited opportunity is persistently which support a wide variety of financial services [29, 38].
higher than 1 ETH (4,000 USD), which indicates that DEX One of the important applications is decentralized exchange
markets may not be efficient enough. By analyzing how (DEX). DEXes allow users to exchange their crypto-assets
traders implement cyclic arbitrages, we find that traders can and ensure decentralized and non-custodial trading. Traders
utilize smart contracts to issue atomic transactions and the sell and buy assets on DEXes by interacting with smart con-
atomic implementations could mitigate users’ financial loss tracts on the blockchain with no centralized authority being
in cyclic arbitrage from the price impact. involved. In an automated market maker (AMM) DEX, the
exchange rate of each trade is determined by predefined
CCS CONCEPTS algorithms and market liquidity reserves. Most prominent
DEXes in the blockchain ecosystem are AMM DEXes, such
• General and reference → Empirical studies; Measure-
as Uniswap [7] and SushiSwap [4].
ment; • Applied computing → Economics.
The exchange rates between different pairs of cryptocur-
rencies (also known as tokens) in AMM DEXes are not always
Permission to make digital or hard copies of all or part of this work for in sync perfectly, which opens up arbitrage possibilities for
personal or classroom use is granted without fee provided that copies are not
made or distributed for profit or commercial advantage and that copies bear
cyclic trading. Assume we have three tokens 𝐴, 𝐵, 𝐶, and
this notice and the full citation on the first page. Copyrights for components three markets between any two tokens: 𝐴 ⇌ 𝐵, 𝐵 ⇌ 𝐶 and
of this work owned by others than ACM must be honored. Abstracting with 𝐶 ⇌ 𝐴. Traders are able to trade tokens cyclically: Traders
credit is permitted. To copy otherwise, or republish, to post on servers or to can exchange 𝐴 for 𝐵 in 𝐴 ⇌ 𝐵, then 𝐵 for 𝐶 in 𝐵 ⇌ 𝐶,
redistribute to lists, requires prior specific permission and/or a fee. Request and finally 𝐶 for 𝐴 in 𝐶 ⇌ 𝐴 again, to benefit themselves
permissions from [email protected].
from the price discrepancies. The combination of these three
Conference’17, July 2017, Washington, DC, USA
© 2022 Association for Computing Machinery.
trades of tokens is a cyclic arbitrage (transaction).1 Figure 1
ACM ISBN 978-x-xxxx-xxxx-x/YY/MM. . . $15.00
https://doi.org/10.1145/nnnnnnn.nnnnnnn 1 The particular case with three tokens is called triangular arbitrage [19, 33].
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer

shows an example of cyclic arbitrage happened on October cyclic arbitrage, with the theoretical analysis of the arbi-
30, 2020. trage model, the measurement of exploitable arbitrage op-
portunities, the measurement of exploited cyclic arbitrage,
and the measurement of cyclic arbitrage implementations.
Second, we provide the measurement of state-of-the-art in
terms of (cyclic) arbitrages in DEXes. Finally, we reveal that
blockchain technology enables users to explore more trading
strategies. Further studies in DEXes may provide us with
novel understandings of user behaviors in financial markets.

2 BACKGROUND AND RELATED WORK


2.1 Ethereum and Smart Contract
Figure 1: An example cyclic arbitrage on Uniswap V2: Ethereum is a public blockchain platform, which supports
The trader traded 285.71 USDC through four differ- Turing complete functions [44]. In contrast to earlier blockchain
ent exchange markets across USDC, USDT, Seal, Kp3r, systems such as Bitcoin, Ethereum allows for decentralized
and finally received 303.68 USDC. The revenue of this peer-to-peer transactions, and has generic computation ca-
cyclic arbitrage is 17.97 USDC (18 USD). pabilities through smart contracts. A smart contract is a set
of programs written in high-level languages, e.g., Solidity.
In this paper, we provide a systematical study on cyclic Creators compile these programs into executable byte-code
arbitrage, with (a) theoretical analysis and (b) empirical eval- and deploy the smart contract on Ethereum.
uation with transaction-level data. We first propose a theoret- There are two kinds of accounts in Ethereum: (a) exter-
ical framework for studying cyclic arbitrage in AMM. Then, nally owned accounts (EOAs), i.e., those controlled by hu-
we use the theoretical model to analyze the profitability man users with the corresponding private key, and (b) smart
conditions and optimal trading strategies of cyclic arbitrage contract accounts (CAs), i.e., those controlled by executable
in the most common AMM, the constant product market code [44]. An Ethereum transaction is broadcast by an EOA
maker (CPMM). We further utilize our theoretical results to to the Ethereum network, while miners then collect transac-
investigate market data. We examine exploitable arbitrage tions and record them in blocks. EOAs can send three types
opportunities on Uniswap V2 [7] from May 4, 2020, to April of transactions: simple transaction, to transfer the native cur-
15, 2021. We find that in almost every block, the revenue of rency, ETH; smart contract creation transaction, to create a
the most exploitable arbitrage opportunity is higher than 1 new smart contract; and smart contract execution transaction,
ETH (4,000 USD). The total revenue of exploitable arbitrage to execute a specific function of a smart contract.
opportunities is persistently higher than 10 ETH over four When a transaction is included in blocks by miners, the
months, which suggests that the market efficiency of DEXes operation corresponding to the message takes effect. The
might be limited. Later, we measure the market size of ex- miner who creates the block modifies the state of correspond-
ploited cyclic arbitrage in Uniswap V2. We observe 292,606 ing accounts. Each step of the miner’s operation consumes a
cyclic transactions over eleven months. Traders receive a to- certain amount of gas, and the amount of gas consumed in
tal revenue beyond 34,429.11 ETH and pay 8,458 ETH as gas each block is capped. Users need to specify a gas price for
fees. The market size of exploited cyclic arbitrage is signifi- the operation execution when sending transactions. The fee
cantly smaller than the exploitable opportunities because of paid by the initiator of transactions to miners is determined
the wide variety of tokens and the high gas fees. Finally, we by the amount of gas consumed and the gas price (gas fee =
investigate the implementations of cyclic arbitrage. We find gas price × gas consumption). The miner records receipts of
that only 0.03% of traders submit trades sequentially with the executed transactions in Ethereum blocks, including the
multiple blockchain transactions for a single cyclic arbitrage. information of the gas fee, the identity of the transaction,
Alternatively, traders always utilize smart contract technol- and other information generated by smart contracts during
ogy to submit a cyclic arbitrage within a single blockchain the execution.
transaction. Such atomic implementations mitigate the fi-
nancial loss of users in cyclic arbitrage. 2.2 Decentralized Exchanges (DEXes)
To the best of our knowledge, this is the first paper to Based on the support of the smart contract, users can create
study the traders’ arbitrage behavior of cryptocurrency the- cryptocurrencies on Ethereum in addition to the native coin
oretically and empirically. We make the following contri- ETH [12]. As of October, 2021, more than 450,000 tokens
butions. First, we provide a systematical understanding of exist on Ethereum platform [5]. Such development of the
Cyclic Arbitrage in DEXes Conference’17, July 2017, Washington, DC, USA

blockchain ecosystem incentives the emergence of on-chain market segmentation among different countries and sug-
financial systems, i.e., Decentralized Finance (DeFi). DeFi ap- gested that capital controls are the main reasons for market
plications are smart contracts deployed on Ethereum, which segmentation. Nan and Kaizoji [34] studied the potential
support sophisticated financial services, such as borrowing triangular arbitrage with Bitcoin, Euro and U.S. dollar and
and lending [27], asset exchanges [7], leverage trading [1], analyzed market data with a bivariate GARCH model. Never-
as well as novel applications such as flash loans [40]. theless, previous studies have only investigated exploitable
Decentralized exchanges (DEXes) are one of the finan- arbitrage opportunities in CEXes, and none of them have
cial infrastructures of the blockchain ecosystem. Compared measured exploited arbitrages in the market. Meanwhile,
to centralized exchanges (CEXes), DEXes do not involve the arbitrage strategy they studied has many constraints
any centralized operators. Users do not need to transfer to be implemented in markets, such as cross-border capital
their assets to the operator before conducting market op- controls and instantaneous transfers between CEXes.
erations [22]. In contrast, they send on-chain transactions Recently, DEXes have attracted attention worldwide as
to DEXes smart contracts to place orders while they keep an emerging alternative of CEXes for exchanging cryptocur-
control of their assets during the entire process. DEXes sup- rencies. Daian et al. [13, 14] have analyzed the fundamental
port mutual trades among different cryptocurrencies. The weakness of DEXes: slow (on-chain) trading. Since transac-
prevalent DEX mechanisms operate through so-called au- tions are broadcast in the Ethereum network, adversaries
tomated market makers (AMM), which aggregate liquidity can observe profitable transactions before they are executed
(i.e., cryptocurrencies) within liquidity pools contributed and place their own orders with higher fees to front-run the
by liquidity providers. Traders can exchange cryptocurren- target victim. Front-running attackers bring threats to the
cies with the liquidity pool and pay commission fees to the market and system stability. Arbitrageurs optimize network
liquidity providers. For example, when traders want to ex- latency aggressively and conduct priority gas auctions to
change cryptocurrency 𝐴 for 𝐵, they can call a smart contract front-run profitable trades [28], which results in excessive
function that transfers 𝐴 from the traders’ accounts to the transaction fees affecting normal users in blockchain ecosys-
liquidity pool between 𝐴 and 𝐵. The liquidity pool then sends tems. Moreover, because of the high miner-extractable value,
𝐵 to the traders’ account. The exchange process does not fee-based forking attacks and time-bandit attacks are created
involve the participation of any other traders. The exchange and bring systemic consensus-layer vulnerabilities. Zhou et
rate between 𝐴 and 𝐵 is determined by transparently prede- al. [45] and Torres et al. [18] studied sandwiching attacks, i.e.,
fined functions encoded in the DEX smart contract. combinations of front and back-running, in DEXes. When
The constant product function is one of the most widely observing a victim transaction, attackers place one order just
used pricing mechanism. Assume a trader want to exchange before it (front-run) and place an order just after it (back-run)
𝛿𝑎 of 𝐴 for 𝐵 token and the liquidity of 𝐴 and 𝐵 are 𝑎 and 𝑏, to benefit themselves through the variance of the exchange
respectively. The following equation always hold during the rates. Qin et al. [39] quantified the revenue of arbitrages in
transaction: 𝑎 · 𝑏 = (𝑎 + 𝛿𝑎 · 𝑟 1 ) · (𝑏 − 𝛿𝑟𝑏2 ), where 𝑟 1 and 𝑟 2 DEXes. However, this work lacks a systematic analysis of
denote the commission fee in asset 𝐴 and 𝐵 respectively. In arbitrage behavior and only measures the exploited arbitrage
Uniswap [7], 𝑟 1 = 0.997 and 𝑟 2 = 1, which indicates that the opportunities of 144 cryptocurrencies.
commission fee is equal to 0.3% · 𝛿𝑎 . The remaining liquidity Compared to previous studies, our work fills the follow-
·𝑟 2 ·𝑏 ·𝛿𝑎
in the pool equals to (𝑎 + 𝛿𝑎 , 𝑏 − 𝑟 1𝑎+𝑟 1 ·𝛿𝑎
). ing two research gaps to provide a more comprehensive
understanding of cyclic arbitrage. First, we do not only con-
sider potential arbitrage opportunities in the market but also
compare with exploited arbitrage opportunities. Second, we
2.3 Arbitrage in Cryptocurrency Markets examine different implementations of arbitrage strategies
Research on arbitrage in cryptocurrencies is still in its begin- in DEXes and discuss how smart contract technology could
ning. Previous studies focus on either theoretical analysis help traders to mitigate the financial loss from the price
of the behavior of miners and traders in blockchain sys- impact.
tems [9, 16, 17, 24–26, 30, 32, 35, 41, 42], or the influence
of cryptocurrencies as a potential payment and transaction 3 CYCLIC ARBITRAGE MODEL
mechanism in financial markets [8, 11, 15, 21, 23, 36]. In this section, we propose a theoretical framework of cyclic
Some recent studies [10, 20, 31, 34, 37] have noted the arbitrage, and then examine the profitability and the optimal
prices discrepancies of cryptocurrencies in CEXes. Makarov revenue of cyclic arbitrage in CPMM.
and Schoar [31] studied price deviations and potential ar-
bitrage opportunities of Bitcoin, Ethereum, and Ripple for Arbitrage model: A cyclic transaction between 𝑛 tokens
34 CEXes across 19 countries. They observed significant 𝐴1, 𝐴2, . . . , 𝐴𝑛 is a sequence of 𝑛 trades:
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer

Trade 1: Exchange 𝛿 1 of 𝐴1 with 𝛿 2 of 𝐴2 . Algorithm 1 Compute the equivalent liquidity of the cycle
Trade 2: Exchange 𝛿 2 of 𝐴2 with 𝛿 3 of 𝐴3 . 1: ′ ←𝑎
𝑎 1,𝑛 1,2
... ′ ←𝑎
2: 𝑎𝑛,1 2,1
Trade 𝑛: Exchange 𝛿𝑛 of 𝐴𝑛 with 𝛿 1′ of 𝐴1 . 3: for 𝑖 from 2 to ′𝑛 − 1 do
′ ← 𝑎 1,𝑛 ·𝑎𝑖,𝑖+1
Note that the output of Trade 𝑖 exactly equals to the input 4: 𝑎 1,𝑛 𝑎𝑖,𝑖+1 +𝑟 1 ·𝑟 2 ·𝑎′𝑛,1
of Trade 𝑖 + 1, while the revenue of the cyclic transaction is ′ ←
′ ·𝑎
𝑟 1 ·𝑟 2 ·𝑎𝑛,1 𝑖+1,𝑖
differences between the output of Trade 𝑛 and the input of 5: 𝑎𝑛,1 ′
𝑎𝑖,𝑖+1 +𝑟 1 ·𝑟 2 ·𝑎𝑛,1
Trade 1, i.e., 𝛿 1′ − 𝛿 1 . 6: end for
As we state in the introduction, the exchange rates be-
tween different token pairs may not be synchronized per-

fectly. However, it is not clear under which conditions that 𝑜𝑝 𝑟 1 ·𝑟 2 ·𝑎′ ·𝑎−𝑎
through 𝐴1 → 𝐴2 → . . . → 𝐴𝑛 → 𝐴1 as 𝛿𝑎 = 𝑟1 ,
exploitable arbitrage opportunities exist in the market as 𝑎′ ·𝑎𝑛,1 𝑟 1 ·𝑟 2 ·𝑎 1,𝑛 ·𝑎′
users also need to pay the commission fee for each trade. where 𝑎 = 𝑎𝑛,1 +𝑟
1,𝑛

1 ·𝑟 2 ·𝑎𝑛,1
and 𝑎 ′ = 𝑎𝑛,1 +𝑟 1 ·𝑟 2 ·𝑎𝑛,1
′ . We refer read-
𝑛,1
Therefore, we analyze the profitability and the optimal trad- ers to Appendix B for a detailed analysis.
ing strategy of a cyclic arbitrage in CPMM.
4 CYCLIC ARBITRAGE OPPORTUNITIES
Profitability conditions: Assume we have three tokens 𝐴1, 𝐴2,
and 𝐴3 , and three liquidity pools between three tokens. We From Algorithm 1, we can infer that only the amounts of re-
denote 𝑎𝑖,𝑗 as the amount of reserved 𝐴𝑖 in the liquidity pool served tokens in liquidity pools and the trading direction are
with token 𝐴 𝑗 . Then, the revenue of trading 𝛿 1 of token 𝐴1 needed for determining the optimal trading strategies. When
through the cycle 𝐴1 → 𝐴2 → 𝐴3 → 𝐴1 is an Ethereum block is published, the updated information
𝑟 12 ·𝑟 22 ·𝑎 2,1 ·𝑎 3,2 ·𝑎 1,3 of liquidity pools is available to all traders. Therefore, with
𝑟 1 ·𝑟 2 ·
𝑎 2,3 ·𝑎 3,1 +𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,1 +𝑟 12 ·𝑟 22 ·𝑎 2,1 ·𝑎 3,2
𝛿 1′ − 𝛿1 = ( 𝑎 1,2 ·𝑎 2,3 ·𝑎 3,1 − 1) · 𝛿 1 . our theoretical model, we are able to investigate exploitable
+𝑟 1 ·𝛿 1 cyclic arbitrage opportunities in DEXes. We choose Uniswap
𝑎 2,3 ·𝑎 3,1 +𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,1 +𝑟 12 ·𝑟 22 ·𝑎 2,1 ·𝑎 3,2
Traders can benefit from the cyclic transaction only if V2 as the example for the empirical analysis because Uniswap
the revenue, i.e., 𝛿 1′ − 𝛿 1 , is larger than 0. We generalize the V2 has the longest operation time, the most active traders,
profitability conditions for 𝑛 tokens in Theorem 1. In gen- and the most liquidity pools among all DEXes [2, 6].
eral words, only if the arbitrage index, i.e., the product of 𝑛
exchange rates along the cycle, is larger than the commis- Data collection: Every market operation on Uniswap is
sion fees paid in the 𝑛 pools, there exists exploitable cyclic recorded on Ethereum blocks. We launch go-ethereum, an
arbitrage opportunity. Ethereum client, on our server to collect data from block
10000835 (when Uniswap V2 has been deployed, 4th May
Theorem 1 (cf. Appendix A). For a given cycle 𝐴1 → 2020) to block 12244144 (15th April 2021). We observe that
𝐴2 → . . . → 𝐴𝑛 → 𝐴1 with 𝑛 tokens, there exists an arbitrage a Sync event is recorded in the blockchain receipt when a
opportunity for the cyclic transaction if the product of exchange market operation happens on Uniswap, and the event in-
𝑎 ·𝑎 3,2 ·...·𝑎 1,𝑛
rates 𝑎2,1
1,2 ·𝑎 2,3 ·...·𝑎𝑛,1
> 𝑟 𝑛1·𝑟 𝑛 , where 𝑎𝑖,𝑗 denotes the liquidity of cludes the liquidity of tokens in the pool after the market
1 2
token 𝐴𝑖 in the liquidity pool with token 𝐴 𝑗 . Meanwhile, the operation. Therefore, by collecting all Sync events, we are
arbitrage cannot benefit from the reversed direction 𝐴1 → able to recover the market states of all liquidity pools on
𝐴𝑛 → . . . → 𝐴2 → 𝐴1 for cyclic transactions. Uniswap V2 over time. More preciously, we build a dataset
that includes the liquidity reserved in all liquidity pools on
Optimal trading strategy: In addition to noticing whether Uniswap V2 after the execution of transactions in each block.
there are exploitable cyclic arbitrage opportunities in mar-
kets with Theorem 1, it is also important for traders to find Profitable opportunities: With such a dataset, we find prof-
a proper trading strategy to maximize the revenue. It is intu- itable cycles in the market and compute the optimal trading
itive that if the derivative of the revenue function to the initial input of each exploitable cyclic transaction and the corre-
trading amount is zero, then we acquire the optimal revenue. sponding revenue. We consider exploitable cyclic arbitrage
We design an algorithm to compute the optimal trading vol- opportunities within the cycles with length three that in-
ume of a cyclic arbitrage (cf. Algorithm 1). If we exchange 𝛿 1 volve ETH. As more than 80% liquidity pools in Uniswap V2
of 𝐴1 through the cycle to obtain 𝛿𝑛 of 𝐴𝑛 , we can equate this are between ETH and another cryptocurrency [43], we infer
behavior as exchanging 𝛿 1 of 𝐴1 in another liquidity pool that we provide a reasonable lower bound for estimating the
between 𝐴1 and 𝐴𝑛 where the amount of reserved tokens of exploitable opportunities.
𝐴1 and 𝐴𝑛 are 𝑎 1,𝑛′ and 𝑎 ′ respectively. We then further com- Because most Ethereum transactions pay more than 0.0001
𝑛,1
pute the optimal trading volume for the cyclic transaction ETH as gas fee to miners, we count the number of cycles that
Cyclic Arbitrage in DEXes Conference’17, July 2017, Washington, DC, USA

Figure 2: Number of exploitable opportunities in Figure 3: Exploitable revenue of cyclic arbitrage in


Uniswap V2 over time. The purple line represents the each block. The blue line represents the maximum rev-
number of cycles that provide revenue higher than enue of a single arbitrage opportunity, while the or-
0.0001 ETH. The green represents the number of cy- ange line represents the sum of a set of independent
cles whose revenue is under 0.001 ETH. The blue line cyclic arbitrage opportunities.
represents the number of cycles whose revenue is un-
der 0.01 ETH.
opportunities across a broader range of cryptocurrencies. For
can provide revenue higher than 0.0001 ETH in Figure 2.2 instance, at the time of writing the paper, Uniswap V2 en-
The number of exploitable arbitrage opportunities has in- ables trades between 30,000 tokens while Binance, one of
creased to 1,750 in eleven months. However, we should not the biggest CEX, only supports less than 400 tokens. We find
overestimate the potential revenue as some cyclic strategies that more than 2890 liquidity pools and 1143 tokens have
are mutually exclusive. For instance, if two cycles involve been involved in arbitrage opportunities larger than 0.1 ETH
the same pair of tokens, only one of them can be exploited (400 USD), which indicates that the range of tokens in cyclic
with the optimal trading volume. arbitrage is wider in DEXes than CEXes (1,143 vs. 400).
Therefore, we consider a set of independent cycles (none Larger market size: Compared to the arbitrage market
of them involves the same liquidity pool) at each block and in CEXes, the market size in DEXes are larger. As reported
sum up the revenue of exploiting them, which provides a by Makarov and Schoar [31], the potential arbitrage revenue
lower bound of the total revenue that traders can take from between 34 CEXes is 2 billion USD over four months (16
the market over time (cf. Figure 3). We find that since July million USD per day). However, in a single DEX, i.e., Uniswap
2020, when the market has been developing, the potential V2, as the exploitable revenue of each block exceeds 1 ETH
revenue of cyclic arbitrage in each block reaches 100 ETH, and there are 6,000 blocks per day, the daily revenue is much
while the maximum revenue of a single cycle is higher than higher than 24 million USD, even reaching 240 million USD.
10 ETH. However, between November 2020 and March 2021, Moreover, the arbitrage index in CEXes is always lower than
the total potential revenue per block drops to less than 10 1.1 [31]. However, the maximum revenue of a single arbitrage
ETH. opportunity in Uniswap V2 is persistently larger than 1 ETH
since July 2020, which suggests that it might be more efficient
Remarks: Previous studies on arbitrage opportunities of to exploit arbitrage opportunities in DEXes than in CEXes.
cryptocurrency have mainly focused on CEXes. Compared
with their results, we find the following two characteristics 5 ARBITRAGE MARKETS
of cyclic arbitrage opportunities in DEX.
Wider range of arbitrage: Since CEXes operators will After noticing the exploitable arbitrage opportunities in
audit the cryptocurrencies trading on the platform, and Uniswap V2, we further investigate how many cyclic ar-
DEXes support any trading pairs of tokens, the range of the bitrages have been executed in the market and how much
market is wider in DEXes, which further introduces arbitrage revenue traders have exploited.

2 The basic gas consumption of a Uniswap transaction is higher than 100,000 Data collection: For each successful exchange between
and the gas price is always higher than 1 GWei (10−9 ETH per gas). two tokens, a Swap event will be recorded in the blockchain
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer

4,000

Daily/Cumulative Revenue (ETH)


104

3,000 103
Number of Transactions

102
2,000 101

100
1,000
10−1

0 2020-05-20 2020-08-28 2020-12-06 2021-03-16


2020-05-20 2020-08-28 2020-12-06 2021-03-16
Date
Date

Figure 5: Revenue of cyclic transactions in


Figure 4: Daily number of cyclic arbitrages.
Uniswap (in ETH). The black line shows a daily
market size. The dotted orange line shows the cu-
receipt, and the event includes all trading information, in- mulative market size.
cluding the input amount of tokens and the output amount
tokens. Therefore, we can use the heuristics in Section 3
to determine cyclic transactions. Note that apart from the
heuristics mentioned before, we recognize a cyclic transac-
tion such that all trades are executed within 100 blocks ( 25
minutes). Because of the volatility in the market price, it is
hard to argue that two trades with a time gap of 25 minutes
is for exploiting a cyclic arbitrage opportunity.
Overall statistics: Until April 15, 2021, we find 292,606
cyclic transactions, while 287,241 of them start with ETH. Figure 6: Distribution of gas fee per transaction.
These arbitrages happened in 17,189 different cycles. The
most popular cycle is ETH-LCX-REVV with 4710 arbitrages.
Only 265 cycles have been exploited more than ten times. arbitrage market size, denominated in ETH. The black line
Around 85% of cyclic transactions (247,297) are implemented shows the daily revenue of cyclic transactions, and the dotted
with cycle of length 3. These observations are consistent with orange line shows the cumulative revenue of cyclic trans-
our claims in Section 4 that the DEXes have a broad range of actions. The total revenue of cyclic arbitrage with ETH in
cryptocurrencies in arbitrage, and counting the cycle with Uniswap V2 is 34,429 ETH. At the early stage of the mar-
length three can provide a reasonable lower bound of cyclic ket (from May to July 2020), the market of cyclic arbitrage
arbitrage opportunities. is negligible, i.e., always less than 10 ETH per day. Later
Transaction number: Figure 4 shows the daily number of on, the daily arbitrage market has increased to 1000 ETH,
cyclic transactions in Uniswap. Traders started to perform while traders become strategic, and the average revenue per
cyclic arbitrage from May 20, 2020, two weeks after the start transaction increases to 0.2 ETH until September 2020. Since
of Uniswap V2 (May 04, 2020). From May 2020 to Septem- October 2020, the market has become relatively stable with
ber 2020, the market has been growing, reaching more than 100 ETH revenue per day, and the average revenue of each
3,000 cyclic transactions per day, and then the market enters cyclic transaction is around 0.1 ETH. After January 2021,
a relatively active period with more than 1,000 cyclic trans- although the daily number of cyclic arbitrage decreases, the
actions per day. The market becomes consistent and stable total revenue keeps at the same level as before, which in-
after January 2021, with 600 transactions per day. dicates that traders can exploit more profitable arbitrage
opportunities.
Transaction revenue: Because more than 98% of cyclic trans-
actions start with ETH and there might be error if we sum Transaction cost: Apart from commission fees paid to liq-
up the revenue of different cryptocurrencies, we report the uidity providers that have been considered in our theoretical
revenue of those that start with ETH to provide a reasonable model, traders also need to pay gas fees to miners for execut-
lower bound of the market size. Figure 5 shows the cyclic ing their market operations. Figure 6 shows the distribution
Cyclic Arbitrage in DEXes Conference’17, July 2017, Washington, DC, USA

On the other hand, traders can deploy smart contracts to


group all the 𝑛 trades of a cyclic arbitrage into one blockchain
transaction to realize atomic implementations. These 𝑛 trades
will be executed atomically, and no other transactions can
be inserted in the middle of them. Moreover, during the exe-
cution of smart contract, if some conditions have not been
met, then Ethereum allows the smart contract to cancel the
execution and revert the system state.
Our first observation of the arbitrage implementation is
Figure 7: Distribution of profit and revenue per trans- that 292,518 cyclic transactions are submitted within a single
action. blockchain transaction and execute atomically, while only 88
cyclic arbitrages are conducted sequentially with different
blockchain transactions, which indicates that atomic imple-
of the gas fee of cyclic transactions. Around half of transac- mentation of cyclic arbitrage dominates the entire market.
tions (48%) cost less than 0.02 ETH as the gas fee. The total Because the order of blockchain transaction execution
gas fee (8,458 ETH) accounts for 24.6% of the total revenue is determined by miners, there might be some other trans-
(34,429.11 ETH) of cyclic transactions. Figure 7 compares actions executing in the middle of arbitrage trades if they
arbitrage income and net profit for cyclic arbitrages. Only are submitted separately. These external transactions might
7.1% of cyclic arbitrages result in negative profits. Gas fees change the market price during the arbitrage process and
drive revenue per cyclic arbitrage from 0.01-0.3 ETH gross generate the price impact. Consequently, 46 out of 88 se-
revenue to 0-0.1 ETH net profit, where the majority of cyclic quential implementations of cyclic arbitrage have a negative
arbitrages (78.4%) falling in this range. revenue. In the scenario of cyclic arbitrage within a single
Remarks: Compared to arbitrage opportunities in the mar- transaction, if the output of the last trades is smaller than
ket, we find that although exploitable arbitrage opportunities the input of the first trade because of the price impact of
exist in almost every block, there are much fewer cyclic ar- other transactions before the arbitrage execution, the ex-
bitrage transactions happening in the market, which might ecution of the 𝑛 trades can be canceled, while the market
indicate that DEXes are not efficient enough. Since the DEXes states are reverted to those before the arbitrage. Although
are fully built on the blockchain systems, there is a limitation traders still pay the gas fee to the miner, they do not lose
of trading volume on the market. Moreover, because of the additional money for the non-profitable trades. Only 0.3%
large size of DEXes, it will take traders time to find cycles of atomic implementations have a negative revenue, which
with revenue to cover gas fees, as the gas fee of half cyclic has a better performance than sequential implementations
arbitrage exceeds 0.02 ETH. (52.3% of transactions have negative revenue).

6 ARBITRAGE IMPLEMENTATIONS Successful rate of atomic implementations: If the output


of the cyclic transaction is smaller than the input, then the
After studying exploited cyclic arbitrage opportunities, we
smart contract can cancel the execution of the transaction
continue to analyze how users implement their cyclic arbi-
and result in a failed transaction recorded in the blockchain.
trage strategies in the market. In this section, we study the
Traders also need to pay a gas fee to miners for these failed
implementations of cyclic arbitrage in DEXes from two per-
transactions, which should be considered as the cost of cyclic
spectives. We first analyze how traders interact with smart
arbitrage. Therefore, we investigate the success rate of atomic
contracts to mitigate the financial loss in cyclic arbitrage.
implementations.
Then, we examine the success rate in exploiting arbitrage
For all failed transactions, there is no Swap event recorded
opportunities of different methods.
in the blocks. Therefore, it is challenge to determine whether
Sequential implementation and atomic implementation: In the transaction is aimed at cyclic arbitrage. We consider two
traditional CEXes markets, after observing arbitrage opportu- methods to construct an upper bound and a lower bound
nities, traders may directly submit 𝑛 separate orders to realize for the success rate for each trader. For the lower bound, we
the cyclic arbitrage. In DEXes, traders have different imple- just simply assume that all failed transactions issued by the
mentations with smart contract technology: sequential im- traders who have ever placed a cyclic transaction are failed
plementation and atomic implementation. Sequential imple- implementations of cyclic arbitrage. For the upper bound, we
mentation is similar to arbitrage implementations in CEXes. use a replay algorithm to evaluate all failed transactions [39].
Traders submit 𝑛 orders separately with 𝑛 blockchain trans- As the cyclic transaction might be failed because of the price
actions, while these 𝑛 transactions are executed sequentially. fluctuations between submitting and executing the cyclic
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer

smart contracts. The net profit (including failed attempts) of


cyclic arbitrageurs is 21,360 ETH (upper bound: 25,742 ETH),
while 66% (upper bound: 77.5%) of have a positive balance.
Moreover, for those experienced traders who have performed
more than 100 cyclic arbitrages, 119 (upper bound: 127) out of
129 traders have a positive net profit, suggesting that cyclic
arbitrage is profitable over the long term for experienced
traders.
Figure 8: Lower bound of success rate of traders. The Public smart contracts: Those traders who use public
dotted line show the overall success rate of all traders. functions to perform cyclic transactions have a much lower
success rate than those who deploy private smart contracts.
Because the smart contract is public so we can decode their
transactions although it is failed executed on the blockchain,
which provides us an accurate success rate. They made 36,492
arbitrage attempts interacting with the Uniswap smart con-
tract, yielding a success rate of 27.3% (9,955 out of 36,492).
Moreover, traders cost 224 ETH as gas fees for failed transac-
tions, which is much higher than their cyclic arbitrage profit
(192 ETH) with the public smart contract.
Remarks: Atomic implementations of cyclic arbitrage pro-
vide two advantages over sequential implementations. First,
traders can ensure the completeness of their arbitrage trans-
Figure 9: Lower bound of net profit of traders. actions. Either all trades will be executed, or none of them
will be executed. Although we only find 88 complete cyclic
transaction, we replay the failed transaction upon its previ- arbitrage with sequential implementations, there might be
ous block state. If the result of replaying the failed transaction more attempts which are failed in the middle of the process
with a non-influenced market state is a cyclic transaction, and cannot be identified by us. Second, if the cycle is not
then we determine it as a failed implementation of cyclic profitable at the time of the transaction execution, the smart
arbitrage. With the upper and lower bounds, we can estimate contract can revert to the state when the cyclic trades have
the success rate of atomic implementations. not been executed, which mitigates the financial loss when
In general, traders conduct atomic implementations with conducting cyclic arbitrage. These two advantages motivate
two methods: deploying a private smart contract to call ex- traders to implement arbitrage transactions atomically with
change functions of Uniswap (282,563 transactions, 840 smart smart contracts.
contracts) and directly calling the Uniswap public smart con- Regarding the failure of cyclic transactions, there can be
tract (9,955 transactions). Because each trader may have two reasons: the price impact and front-running attacks [14].
several different EOAs, while only authenticated EOAs can Some traders copy others’ arbitrage strategies by observing
call private smart contracts, we consider all EOAs who use these transactions in the blockchain P2P network and then
the same smart contract to perform cyclic arbitrage belong create their own transactions in front of the original one to
to the same trader. grab the benefits. By noticing the significant difference in
Private smart contracts: We find that traders have called the success rate, we may conjecture that the resistance to
those private cyclic arbitrage smart contract 540,054 times in front-running determines the success rate of the private and
total and 282,563 successful transactions have been observed. public smart contracts as the price impact can be considered
The lower bound of the overall success rate is 52%, while common to all traders. However, this conjecture needs to be
most traders (475 out of 840) have a success rate higher validated more precisely.
than 90% (cf. Figure 8). If we consider the upper bound of
success rates, then the overall success rate is 89.6% as only 7 CONCLUSION
34,236 failed transactions issued by arbitrage smart contracts In this paper, we provide a systematic study on cyclic arbi-
can be recognized as cyclic transaction attempts with our trage in AMM DEXes, including the arbitrage model, arbi-
replay experiments. The number of traders who have an trage opportunities, arbitrage markets, and arbitrage imple-
upper bound success rate beyond 90% is 726. Figure 9 shows mentations. Additional to understanding cyclic arbitrages in
the distribution of the lower bounds of net profit of 840 DEXes, this paper also provides insights into two other areas.
Cyclic Arbitrage in DEXes Conference’17, July 2017, Washington, DC, USA

We compare the arbitrage markets in DEXes and CEXes and REFERENCES


discuss the differences between the two exchanges, which [1] 2021. Alpha Homora V2. https://alphafinancelab.gitbook.io/alpha-
may benefit further study in understanding trader behav- homora-v2/. (2021).
iors in cryptocurrency markets. Second, we examine the ad- [2] 2021. DEX Ranking. https://debank.com/ranking/dex?chain=eth.
(2021).
vantages of smart contract technologies in DEXes markets, [3] 2021. Gross Value Locked (USD). https://debank.com/ranking/locked_
which may inspire further studies to explore how traders value. (2021).
may utilize blockchain technologies in financial markets. [4] 2021. The SushiSwap Project. https://sushiswapchef.medium.com/the-
This paper focuses on the fundamental understandings sushiswap-projectdd6eb80c6ba2. (2021).
of cyclic arbitrage in DEXes and raises many interesting [5] 2021. Token Tracker ERC-20. https://etherscan.io/tokens. (2021).
[6] 2021. Uniswap Analytics. https://v2.info.uniswap.org/home. (2021).
and important questions. For example: how do traders de-
[7] Hayden Adams. 2020. Uniswap V2 Overview. Technical Report.
cide their strategies; how traders’ strategies are affected Uniswap.
by average gas fees and over-time variation in congestion; [8] Susan Athey, Ivo Parashkevov, Vishnu Sarukkai, and Jing Xia. 2016.
how do cyclic arbitrages influence other market participants; Bitcoin pricing, adoption, and usage: Theory and evidence. (2016).
and how do traders combine utilize other services in the [9] Zeta Avarikioti, Lioba Heimbach, Yuyi Wang, and Roger Wattenhofer.
2020. Ride the lightning: The game theory of payment channels. In
blockchain ecosystem to exploit cyclic arbitrage opportuni-
International Conference on Financial Cryptography and Data Security.
ties? We would like to investigate these follow up research Springer, 264–283.
questions in future work to promote understanding of user [10] Sanghyun Bai and Fred Robinson. 2019. Automated Triangular Arbi-
behaviors in the blockchain ecosystem. trage: A Trading Algorithm for Foreign Exchange on a Cryptocurrency
Market. (2019).
[11] Rainer Böhme, Nicolas Christin, Benjamin Edelman, and Tyler Moore.
2015. Bitcoin: Economics, technology, and governance. Journal of
economic Perspectives 29, 2 (2015), 213–38.
[12] Weili Chen, Tuo Zhang, Zhiguang Chen, Zibin Zheng, and Yutong
Lu. 2020. Traveling the token world: A graph analysis of ethereum
erc20 token ecosystem. In Proceedings of The Web Conference 2020.
1411–1421.
[13] Philip Daian, Steven Goldfeder, Tyler Kell, Yunqi Li, Xueyuan Zhao,
Iddo Bentov, Lorenz Breidenbach, and Ari Juels. 2019. Flash boys
2.0: Frontrunning, transaction reordering, and consensus instability in
decentralized exchanges. arXiv preprint arXiv:1904.05234 (2019).
[14] Philip Daian, Steven Goldfeder, Tyler Kell, Yunqi Li, Xueyuan Zhao,
Iddo Bentov, Lorenz Breidenbach, and Ari Juels. 2020. Flash boys 2.0:
Frontrunning in decentralized exchanges, miner extractable value, and
consensus instability. In 2020 IEEE Symposium on Security and Privacy
(SP). IEEE, 910–927.
[15] David Easley, Maureen O’Hara, and Soumya Basu. 2019. From min-
ing to markets: The evolution of bitcoin transaction fees. Journal of
Financial Economics 134, 1 (2019), 91–109.
[16] Ittay Eyal. 2015. The miner’s dilemma. In 2015 IEEE Symposium on
Security and Privacy. IEEE, 89–103.
[17] Ittay Eyal and Emin Gün Sirer. 2014. Majority is not enough: Bitcoin
mining is vulnerable. In International conference on financial cryptog-
raphy and data security. Springer, 436–454.
[18] Christof Ferreira Torres, Ramiro Camino, et al. 2021. Frontrunner Jones
and the Raiders of the Dark Forest: An Empirical Study of Frontrunning
on the Ethereum Blockchain. In USENIX Security Symposium, Virtual
11-13 August 2021.
[19] Henry N Goldstein. 1964. The implications of triangular arbitrage for
forward exchange policy. The Journal of Finance 19, 3 (1964), 544–551.
[20] Paz Grimberg, Tobias Lauinger, and Damon McCoy. 2020. Empirical
analysis of indirect internal conversions in cryptocurrency exchanges.
arXiv preprint arXiv:2002.12274 (2020).
[21] Campbell R Harvey. 2016. Cryptofinance. Available at SSRN 2438299
(2016).
[22] Campbell R Harvey, Ashwin Ramachandran, and Joey Santoro. 2021.
DeFi and the Future of Finance. John Wiley & Sons.
[23] Gur Huberman, Jacob Leshno, and Ciamac C Moallemi. 2017. Mo-
nopoly without a monopolist: An economic analysis of the bitcoin
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer

payment system. Bank of Finland Research Discussion Paper 27 (2017). [43] Ye Wang, Lioba Heimbach, and Roger Wattenhofer. 2021. Behavior
[24] Aggelos Kiayias, Elias Koutsoupias, Maria Kyropoulou, and Yiannis of Liquidity Providers in Decentralized Exchanges. arXiv preprint
Tselekounis. 2016. Blockchain mining games. In Proceedings of the arXiv:2105.13822 (2021).
2016 ACM Conference on Economics and Computation. 365–382. [44] Gavin Wood et al. 2014. Ethereum: A secure decentralised generalised
[25] Elias Koutsoupias, Philip Lazos, Foluso Ogunlana, and Paolo Serafino. transaction ledger. Ethereum project yellow paper 151, 2014 (2014),
2019. Blockchain mining games with pay forward. In The World Wide 1–32.
Web Conference. 917–927. [45] Liyi Zhou, Kaihua Qin, Christof Ferreira Torres, Duc V Le, and Arthur
[26] Yujin Kwon, Dohyun Kim, Yunmok Son, Eugene Vasserman, and Yong- Gervais. 2021. High-frequency trading on decentralized on-chain
dae Kim. 2017. Be selfish and avoid dilemmas: Fork after withholding exchanges. In 2021 IEEE Symposium on Security and Privacy (SP). IEEE,
(faw) attacks on bitcoin. In Proceedings of the 2017 ACM SIGSAC Con- 428–445.
ference on Computer and Communications Security. 195–209.
[27] Robert Leshner and Geoffrey Hayes. 2019. Compound Finance
Whitepaper.
[28] Michael Lewis. 2014. Flash boys: a Wall Street revolt. WW Norton &
Company.
[29] Bowen Liu, Pawel Szalachowski, and Jianying Zhou. 2020. A first look
into defi oracles. arXiv preprint arXiv:2005.04377 (2020).
[30] Hanqing Liu, Na Ruan, Rongtian Du, and Weijia Jia. 2018. On the strat-
egy and behavior of bitcoin mining with n-attackers. In Proceedings of
the 2018 on Asia Conference on Computer and Communications Security.
357–368.
[31] Igor Makarov and Antoinette Schoar. 2020. Trading and arbitrage in
cryptocurrency markets. Journal of Financial Economics 135, 2 (2020),
293–319.
[32] Francisco J Marmolejo-Cossío, Eric Brigham, Benjamin Sela, and
Jonathan Katz. 2019. Competing (semi-) selfish miners in Bitcoin.
In Proceedings of the 1st ACM Conference on Advances in Financial
Technologies. 89–109.
[33] Frank McCormick. 1979. Covered interest arbitrage: unexploited prof-
its? Comment. Journal of Political Economy 87, 2 (1979), 411–417.
[34] Zheng Nan and Taisei Kaizoji. 2019. Bitcoin-based triangular arbitrage
with the Euro/US dollar as a foreign futures hedge: modeling with
a bivariate GARCH model. Quantitative Finance and Economics 3, 2
(2019), 347–365.
[35] Kartik Nayak, Srijan Kumar, Andrew Miller, and Elaine Shi. 2016.
Stubborn mining: Generalizing selfish mining and combining with
an eclipse attack. In 2016 IEEE European Symposium on Security and
Privacy (EuroS&P). IEEE, 305–320.
[36] Emiliano Pagnotta and Andrea Buraschi. 2018. An equilibrium valu-
ation of bitcoin and decentralized network assets. Available at SSRN
3142022 (2018).
[37] Lukáš Pichl, Zheng Nan, and Taisei Kaizoji. 2020. Time series analysis
of ether cryptocurrency prices: Efficiency, predictability, and arbitrage
on exchange rates. In Advanced studies of financial technologies and
cryptocurrency markets. Springer, 183–196.
[38] Kaihua Qin, Liyi Zhou, Yaroslav Afonin, Ludovico Lazzaretti, and
Arthur Gervais. 2021. CeFi vs. DeFi–Comparing Centralized to Decen-
tralized Finance. arXiv preprint arXiv:2106.08157 (2021).
[39] Kaihua Qin, Liyi Zhou, and Arthur Gervais. 2021. Quantifying
Blockchain Extractable Value: How dark is the forest? arXiv preprint
arXiv:2101.05511 (2021).
[40] Kaihua Qin, Liyi Zhou, Benjamin Livshits, and Arthur Gervais. 2021.
Attacking the DeFi Ecosystem with Flash Loans for Fun and Profit. In
International Conference on Financial Cryptography and Data Security.
Springer.
[41] Geoffrey Ramseyer, Ashish Goel, and David Mazieres. [n. d.]. Scaling
On-Chain Asset Exchanges via Arrow-Debreu Exchange Markets. ([n.
d.]).
[42] Ayelet Sapirshtein, Yonatan Sompolinsky, and Aviv Zohar. 2016. Opti-
mal selfish mining strategies in bitcoin. In International Conference on
Financial Cryptography and Data Security. Springer, 515–532.
Cyclic Arbitrage in DEXes Conference’17, July 2017, Washington, DC, USA

A EXISTENCE OF CYCLIC ARBITRAGE


′ ·...·𝑎
OPPORTUNITIES 𝜕𝑈 𝑟 1𝑛 · 𝑟 2𝑛 · 𝑎 1,𝑛+1 · 𝑎 3,1 𝑛+1,𝑛
= ′ ·𝑎 −1
Theorem 1. For a given cycle 𝐴1 → 𝐴2 → . . . → 𝐴𝑛 → 𝐴1 𝜕𝛿 1 𝛿 1 =0 𝑎 1,3 3,4 · . . . · 𝑎𝑛+1,1
with 𝑛 tokens, there exists an arbitrage opportunity for the 𝑟 1𝑛 · 𝑟 2𝑛 · 𝑎 1,𝑛+1 ·
𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2
· . . . · 𝑎𝑛+1,𝑛
𝑎 ·𝑎 3,2 ·...·𝑎 1,𝑛 𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1
cyclic transaction if the product of exchange rates 𝑎2,1 1,2 ·𝑎 2,3 ·...·𝑎𝑛,1
> = 𝑎 1,2 ·𝑎 2,3 − 1 (2)
1 𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 · 𝑎 3,4 · . . . · 𝑎𝑛+1,1
𝑟 1𝑛 ·𝑟 2𝑛 , where 𝑎𝑖,𝑗 denotes the liquidity of token 𝐴𝑖 in the liquid-
ity pool with token 𝐴 𝑗 . Meanwhile, the arbitrage cannot benefit 𝑟 1𝑛+1 · 𝑟 2𝑛+1 · 𝑎 1,𝑛+1 · 𝑎 2,1 · . . . · 𝑎𝑛+1,𝑛
= −1
from the reversed direction 𝐴1 → 𝐴𝑛 → . . . → 𝐴2 → 𝐴1 for 𝑎 1,2 · 𝑎 2,3 · . . . · 𝑎𝑛+1,1
cyclic transactions. By the principle of mathematical induction: the first devia-
𝑟 1𝑛+1 ·𝑟 2𝑛+1 ·𝑎 1,𝑛+1 ·𝑎 2,1 ·...·𝑎𝑛+1,𝑛
tion of the utility function at 𝛿𝑎 = 0 is 𝑎 1,2 ·𝑎 2,3 ·...·𝑎𝑛+1,1 −
We first give a general expression of cyclic transactions with
more than three tokens. 1, for any 𝑛 ≥ 3.

Proof of Theorem 1. Assume that we would like to ex-
Lemma 2. For a cyclic transaction through a path with 𝑛
change 𝛿 1 of token 𝐴1 through the cycle. When 𝛿 1 = 0, both
edges 𝐴1 → 𝐴2 → . . . → 𝐴𝑛 → 𝐴1 , the first deviation of the
the value of 𝑈𝐴1𝐴2𝐴𝑛 𝐴1 and the value of 𝑈𝐴1𝐴𝑛 𝐴2𝐴1 are 0.
𝜕𝑈 𝑟 1𝑛 ·𝑟 2𝑛 ·𝑎 1,𝑛 ·𝑎 2,1 ·...·𝑎𝑛,𝑛−1
utility function at 𝛿 1 = 0 is 𝜕𝛿 1 = 𝑎 1,2 ·𝑎 2,3 ·...·𝑎𝑛,1 − 1. Then we consider the first and the second derivative of
𝛿 1 =0 the utility function at 𝛿 1 = 0.

Proof. We can observe that the transaction through 𝐴1 ⇌ 𝜕𝑈𝐴1𝐴2𝐴𝑛 𝐴1 𝑟 1𝑛 · 𝑟 2𝑛 · 𝑎 1,𝑛 · 𝑎 2,1 · . . . · 𝑎𝑛,𝑛−1
= −1 (3)
𝐴2 and 𝐴2 ⇌ 𝐴3 is equivalent to an exchange of 𝛿 1 through 𝜕𝛿 1 𝛿 1 =0 𝑎 1,2 · 𝑎 2,3 · . . . · 𝑎𝑛,1
𝑎 1,2 ·𝑎 2,3
liquidity pool 𝐴1′ ⇌ 𝐴3′ , where 𝑎 1,3′ = ′
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 , and 𝑎 3,1 =
𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2
If arbitrageurs can make profit in this trading direction,
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 . then,
We prove this lemma by induction. We first show it is
correct when 𝑛 = 3. 𝜕𝑈𝐴1𝐴2𝐴𝑛 𝐴1
We take the utility function of a cyclic transaction of three 0<
𝜕𝛿 1 𝛿 1 =0
tokens and compute the first deviation of the function, (4)
1 𝑎 1,𝑛 · 𝑎 2,1 · . . . · 𝑎𝑛,𝑛−1
<
𝑟 1𝑛 · 𝑟 2𝑛 𝑎 1,2 · 𝑎 2,3 · . . . · 𝑎𝑛,1
,
𝑟 1𝑛 ·𝑟 2𝑛 ·𝑎 1,2 ·𝑎 2,3 ·...·𝑎𝑛,1
𝜕𝑈𝐴1𝐴2𝐴3𝐴1 𝑟 13 · 𝑟 23· 𝑎 1,3 · 𝑏 2,1 · 𝑏 3,2 which implies that 𝑎 1,𝑛 ·𝑎 2,1 ·...·𝑎𝑛,𝑛−1 < 1,
= −1 (1)
𝜕𝛿 1 𝛿 1 =0 𝑎 1,2 · 𝑎 2,3 · 𝑏 3,1 then
𝜕𝑈𝐴1 𝐴𝑛 𝐴2 𝐴1
< 0.
𝜕𝛿 1
𝛿 1 =0
By computing the second derivative of 𝑈𝐴1𝐴𝑛 𝐴2𝐴1 , we know
𝜕2 +
For 𝑛 ≥ 3, the inductive hypothesis is that the equation is that 𝜕𝛿 2 𝑈𝐴1 𝐴𝑛 𝐴2 𝐴1 is negative for all 𝛿 1 ∈ 𝑅 . 𝑈𝐴1 𝐴𝑛 𝐴2 𝐴1 is a
1
true for 𝑛: monotone decreasing function in its domain, and the max-
𝜕𝑈 𝑟 1𝑛 ·𝑟 2𝑛 ·𝑎 1,𝑛 ·𝑎 2,1 ·...·𝑎𝑛,𝑛−1 imum value of 𝑈𝐴1𝐴𝑛 𝐴2𝐴1 is 0 at 𝛿 1 = 0. Therefore, there is
𝜕𝛿 1 = 𝑎 1,2 ·𝑎 2,3 ·...·𝑎𝑛,1 − 1.
𝛿 1 =0 no opportunity for arbitrage through the reversed direction
The inductive step is to prove the equation for 𝑛 + 1: 𝐴1 → 𝐴𝑛 → . . . → 𝐴2 → 𝐴1 for cyclic transactions.
If we exchange 𝛿 1 through 𝐴1 ⇌ 𝐴2 pool to get 𝛿 2 , and Arbitrageurs cannot benefit from trading 𝛿 1 through 𝐴1 →
obtain 𝛿 3 from 𝐴2 ⇌ 𝐴3 by trading 𝛿 2 right after, these two 𝐴𝑛 → . . . → 𝐴2 → 𝐴1 , sequentially. Therefore, arbitrageurs
atomic transactions can is equivalent to a single transaction have at most one direction to benefit themselves with cyclic
𝑎 1,2 ·𝑎 2,3
with 𝛿 1 in a virtual pool 𝐴1′ ⇌ 𝐴3′ , where 𝑎 1,3
′ =
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 , transactions.
′ = 𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2 .
and 𝑎 3,1 □
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1
We assume that the statement is correct for any 𝑛-path
cyclic transaction. Consider a cyclic transaction through a B OPTIMAL TRADE VOLUME
𝑛 + 1-path 𝐴1 → 𝐴2 → . . . → 𝐴𝑛 → 𝐴𝑛+1 → 𝐴1 , which We start from a simple case where cyclic transactions happen
is equivalent to a 𝑛-path cyclic transaction through 𝐴1′ → in a cycle of token 𝐴1 , 𝐴2 , and 𝐴3 . We denote 𝑎𝑖,𝑗 as the
𝐴3′ → . . . → 𝐴𝑛+1 → 𝐴1′ , where the first deviation of the liquidity of token 𝐴𝑖 in the liquidity pool with token 𝐴 𝑗 . If
utility function at 𝛿 1 = 0 is, we directly exchange 𝐴3 with 𝛿 1 of 𝐴1 , then we receive the
Conference’17, July 2017, Washington, DC, USA Ye Wang, Yan Chen, Haotian Wu, Liyi Zhou, Shuiguang Deng, and Roger Wattenhofer

𝑟 ·𝑟 ·𝑎 ·𝛿
output amount of 𝐴3 , 𝛿 3 = 1𝑎1,32+𝑟3,1
1 ·𝛿 1
1
. If we take token 𝐴2
as an intermediate, then the output amount of 𝐴3 is 𝛿 3′ = 𝜕𝑈𝐴1𝐴2𝐴3𝐴1 𝑟 1 · 𝑟 2 · 𝑎 ′ · (𝑎 + 𝑟 1 · 𝛿 1 ) − 𝑟 1 · (𝑟 1 · 𝑟 2 · 𝑎 ′ · 𝛿 1 )
𝑟 12 ·𝑟 22 ·𝑎 2,1 ·𝑎 3,2 ·𝛿 1
= −1
. 𝜕𝛿𝑎 (𝑎 + 𝑟 1 · 𝛿 1 ) 2
𝑎 1,2 ·𝑎 2,3 +𝑟 1 ·𝛿 1 ·(𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 )
Compare 𝛿 3 and 𝛿 3′ , 𝛿 3′ can be written in the format as 𝜕𝑈𝐴1𝐴2𝐴3𝐴1 𝑟 1 · 𝑟 2 · 𝑎 ′ · 𝑎
= −1
𝑟 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2
𝑟 1 ·𝑟 2 · 𝑎1 +𝑟 ·𝑟 ·𝑎 ·𝛿 1 𝜕𝛿𝑎 (𝑎 + 𝑟 1 · 𝛿 1 ) 2
𝛿 3′ = 2,3 1 2 2,1
𝑎 1,2 ·𝑎 2,3 . Therefore, this transaction through (6)
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 +𝑟 1 ·𝛿 1
𝜕𝑈𝐴1 𝐴2 𝐴3 𝐴1
two pools can be considered as a transaction through an To maximize the utilize, we have 𝜕𝛿 1 = 0, therefore,
equivalent pool of 𝐴1 and 𝐴3 where the liquidity of 𝐴1 is
′ = 𝑎 1,2 ·𝑎 2,3 ′ 𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2
𝑎 1,3 𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 and the liquidity of 𝐴3 is 𝑎 3,1 = 𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 . 𝑟1 · 𝑟2 · 𝑎′ · 𝑎
Then, we can rewrite the utility function of a cyclic trans- −1=0
(𝑎 + 𝑟 1 · 𝛿 1 ) 2
action in 𝐴1 → 𝐴2 → 𝐴3 → 𝐴1 with input 𝛿 1 as
𝑟 1 · 𝑟 2 · 𝑎 ′ · 𝑎 = (𝑎 + 𝑟 1 · 𝛿 1 ) 2 (7)
√ ′
𝑟1 · 𝑟2 ·
𝑟 1 ·𝑟 2 ·𝑎 2,1 ·𝑎 3,2 𝑟1 · 𝑟2 · 𝑎 · 𝑎 − 𝑎
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 · 𝛿1 =
𝑈𝐴1 𝐴2 𝐴3 𝐴1 = ( 𝑎 1,2 ·𝑎 2,3 − 1) · 𝛿 1 (5) 𝑟1
𝑎 2,3 +𝑟 1 ·𝑟 2 ·𝑎 2,1 + 𝑟 1 · 𝛿1
We can find the equivalent pool of transactions for longer
𝑎′1,3 ·𝑎 3,1 𝑟 1 ·𝑟 2 ·𝑎 1,3 ·𝑎′3,1
Let us denote 𝑎 = 𝑎 3,1 +𝑟 1 ·𝑟 2 ·𝑎′3,1 and 𝑎 ′ = 𝑎 3,1 +𝑟 1 ·𝑟 2 ·𝑎′3,1
paths between any pair of tokens iteratively as in the first
step of computing pools equivalent to 𝐴1 ⇌ 𝐴2 and 𝐴2 ⇌ 𝐴3
and then determine the optimal input of the cyclic transac-
tion.

You might also like