Finding Concurrency Exploits On Smart Contracts, Yue Li
Finding Concurrency Exploits On Smart Contracts, Yue Li
TU*OUFSOBUJPOBM$POGFSFODFPO4PGUXBSF&OHJOFFSJOH$PNQBOJPO1SPDFFEJOHT *$4&
$PNQBOJPO
1 contract EtherStore {
Abstract—Smart contracts have been widely used on Ethereum 2 address Owner ;
to enable business services across various application domains. 3 address Creator ;
4 mapping ( address = > uint256 ) balances ;
However, they are prone to different forms of security attacks 5 uint price ;
due to the dynamic and non-deterministic blockchain runtime 6 constructor () {
7 Owner = msg . sender ;
environment. In this work, we highlighted a general miner- 8 Creator = msg . sender ;
side type of exploit, called concurrency exploit, which attacks 9 }
smart contracts via generating malicious transaction sequences. 10 function foo ( address newOwner ) {
11 Owner = newOwner ;
Moreover, we designed a systematic algorithm to automatically 12 }
detect such exploits. In our preliminary evaluation, our approach 13 function bar () {
14 price = msg . value ;
managed to identify real vulnerabilities that cannot be detected 15 balances [ msg . sender ]+= price ;
by other tools in the literature. 16 // tranfer ether to owner
17 Owner . call . value ( price ) () ;
I. P ROBLEM A ND M OTIVATION 18 }
19 function upgrade ( address currentVersion ) {
Ethereum smart contracts are programs running on the 20 require ( msg . sender == Owner ) ;
21 // contrat currentversion code injection
blockchain to operate on Ethereum cryptocurrencies (i.e., 22 if (! currentVersion . delegatecall ( msg . data
) ) revert () ;
ether) and a set of persistent data (i.e., storage) [1]. Figure 1 23 }
shows a simple smart contract EtherStore with four storage 24 function destruct () {
25 require ( msg . sender == Creator )
variables and public functions except the constructor. External 26 // contract termination
27 selfdestruct ( Creator ) ;
accounts can use EtherStore by sending transactions to 28 } }
it. For example, a possible transaction data may look like Fig. 1: A motivating example of smart contract
a9059cbb7adee867ea91533879d083dd4ea81f0eee3a37e.
Specifically, the first four bytes a9059cbb point to the to directly manipulate storage of the current contract, e.g.,
hash of the foo function and the remaining bytes indicate Creator variable. In such cases, transactions of upgrade
the parameter used by foo, i.e., a 20-byte address. In the and destruct will produce uncertain scenarios of contract
execution of foo, the storage Owner will be updated to the destruction as in 2b, since Creator is used as a receiver
value passed from the transaction (line 11) and permanently of the remaining balance after the contract is cleared by the
stored on blockchain. Commonly, transactions submitted to selfdestruct API at line 27. The last case of 2d describes
the Ethereum network are ordered and packaged by a miner two transactions of bar from both Alice and Bob, where
node to optimize its own benefit, e.g., efficiently get the most different transaction orders will generate the same final storage
transaction fee. From this perspective, smart contracts can be values of balances no matter which one is executed first.
seen as a form of concurrent software since their executions While such concurrency enables normal miners to flexibly
are non-deterministic to transaction senders. make profits, it introduces great security threats to Ethereum.
We further explain such concurrency via Figure 2 based on In the aforementioned cases, only the last one is considered
the contract in Figure 1. Particularly, we describe four cases secure since the concurrent execution of transactions can com-
in this context to explain the transaction ordering and storage mute, e.g., different transaction orders will yield the same state
state transitions accordingly. In 2a, Alice first submitted a transition. The other three cases are all viewed as potentially
transaction to call the foo function, which sets the storage malicious, because attackers can employ specific sequence of
Owner to Alice. The following two transactions are from transactions to make undesired benefits, e.g., transfer money
Alice (call bar) and Bob (call foo). If Bob’s transaction to themselves, pollute the contract storage etc. In this work,
is ordered before Alice’s as in 2a, the call to bar will we refer such attacks as concurrency exploits and highlight an
lead to a money transfer to Bob (line 17) because Owner informal definition below. Given two accesses p and q from
has been updated to Bob. Otherwise, the money goes to two transactions tp and tq on storage sp and sq respectively,
Alice. Similarly in 2c, when Alice acquired the Owner, tp and tq can be exploited by a concurrency attack if
the order of calls to foo and upgrade from Bob will cause • p and q include exact one write and one read operation.
the sanity check at line 20 to fail or not. If the check is • sp and sq point to the same storage index.
passed, Bob would be able to further invoke a delegated • p and q are not mutually exclusive.
call (line 22), i.e., use a delegate contract (currentVersion • At least one security-critical operation is dependent on
in this case) to process the transaction input instead of the sp or sq (explained later).
current contract. In Ethereum, the delegate contract is allowed Our work aims to detect concurrency exploits in smart
¥*&&&
%0**$4&$PNQBOJPO
Authorized licensed use limited to: UNIVERSIDADE DE BRASILIA. Downloaded on June 25,2021 at 14:53:44 UTC from IEEE Xplore. Restrictions apply.
6WDWH 6WDWH 6WDWH 6WDWH
2ZQHU B$ 2ZQHU B% 2ZQHU B$ 2ZQHU B%
$OLFH %RE $OLFH $OLFH %RE $OLFH
IRRQR IRRQR EDU FRQVWUDFWRU XSJUDGHFY GHVWUXFW
(a) 6WDWH
(b) 6WDWH
6WDWH 6WDWH
EDODQFHV>B$@ PVJYDOXH EDODQFHV>B$@ PVJYDOXH
2ZQHU B$ 2ZQHU B% EDODQFHV>B%@ EDODQFHV>B%@ PVJYDOXH
$OLFH %RE %RE $OLFH %RE
IRRQR IRRQR XSJUDGHFY EDU EDU
(c) (d)
Fig. 2: Possible transaction sequences and state transitions
Authorized licensed use limited to: UNIVERSIDADE DE BRASILIA. Downloaded on June 25,2021 at 14:53:44 UTC from IEEE Xplore. Restrictions apply.
R EFERENCES
[1] G. Wood, “Ethereum: A secure decentralised generalised transaction
ledger,” Ethereum Project Yellow Paper, vol. 151, 2014.
[2] I. Sergey and A. Hobor, “A concurrent perspective on smart contracts,” in
International Conference on Financial Cryptography and Data Security.
Springer, 2017, pp. 478–493.
[3] L. Luu, D.-H. Chu, H. Olickel, P. Saxena, and A. Hobor, “Making smart
contracts smarter,” in Proceedings of the 2016 ACM SIGSAC Conference
on Computer and Communications Security. ACM, 2016, pp. 254–269.
[4] K. Delmolino, M. Arnett, A. Kosba, A. Miller, and E. Shi, “Step
by step towards creating a safe smart contract: Lessons and insights
from a cryptocurrency lab,” in International Conference on Financial
Cryptography and Data Security. Springer, 2016, pp. 79–94.
[5] P. Tsankov, A. Dan, D. D. Cohen, A. Gervais, F. Buenzli, and M. Vechev,
“Securify: Practical security analysis of smart contracts,” arXiv preprint
arXiv:1806.01143, 2018.
[6] K. Bhargavan, A. Delignat-Lavaud, C. Fournet, A. Gollamudi,
G. Gonthier, N. Kobeissi, A. Rastogi, T. Sibut-Pinote, N. Swamy,
and S. Zanella-Beguelin, “Formal verification of smart contracts,” in
Proceedings of the 2016 ACM Workshop on Programming Languages
and Analysis for Security-PLAS’16, 2016, pp. 91–96.
[7] S. Kalra, S. Goel, M. Dhawan, and S. Sharma, “Zeus: Analyzing safety
of smart contracts.” NDSS, 2018.
[8] I. Nikolic, A. Kolluri, I. Sergey, P. Saxena, and A. Hobor, “Finding
the greedy, prodigal, and suicidal contracts at scale,” arXiv preprint
arXiv:1802.06038, 2018.
[9] B. Jiang, Y. Liu, and W. Chan, “Contractfuzzer: Fuzzing smart contracts
for vulnerability detection,” in Proceedings of the 33rd ACM/IEEE
International Conference on Automated Software Engineering. ACM,
2018, pp. 259–269.
[10] Ethereum, “Solidity — solidity 0.4.19 documentation,” 2017. [Online].
Available: https://solidity.readthedocs.io/en/develop/
[11] E. Team, “Etherscan: The ethereum block explorer,” 2017.
Authorized licensed use limited to: UNIVERSIDADE DE BRASILIA. Downloaded on June 25,2021 at 14:53:44 UTC from IEEE Xplore. Restrictions apply.