{'fraction_non_alphanumeric': 0.03902985192310725, 'fraction_numerical': 0.014468642076545819, 'mean_word_length': 4.991449357520786, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
A Survey on Ethereum Systems Security: Vulnerabilities, Attacks and Defenses

The blockchain technology is believed by many to be a game changer in many application domains, especially financial applications. While the first generation of blockchain technology (i.e., Blockchain 1.0) is almost exclusively used for cryptocurrency purposes, the second generation (i.e., Blockchain 2.0), as represented by Ethereum, is an open and decentralized platform enabling a new paradigm of computing --- Decentralized Applications (DApps) running on top of blockchains. The rich applications and semantics of DApps inevitably introduce many security vulnerabilities, which have no counterparts in pure cryptocurrency systems like Bitcoin. Since Ethereum is a new, yet complex, system, it is imperative to have a systematic and comprehensive understanding on its security from a holistic perspective, which is unavailable. To the best of our knowledge, the present survey, which can also be used as a tutorial, fills this void. In particular, we systematize three aspects of Ethereum systems security: vulnerabilities, attacks, and defenses. We draw insights into, among other things, vulnerability root causes, attack consequences, and defense capabilities, which shed light on future research directions.


I. INTRODUCTION
The notion of blockchain was implicitly introduced in 2008 as the key underlying technique of the cryptocurrency known as Bitcoin [1], which uses a transaction-centered model known as unspent transaction outputs (UTXO). In this model, a blockchain is a distributed and public ledger, which records the payment transactions between parties over a peer-to-peer (P2P) network. Unlike traditional digital cash systems [2], in which there is a trusted third party (e.g., bank), there is no trusted third party in a blockchain system in general and in Bitcoin in particular. Bitcoin is often referred to as Blockchain 1.0 because it only offers payment services. The innovation of the Bitcoin system is its consensus protocol, which allows mutually distrusting nodes in a P2P network to eventually reach a consensus on the outcome after executing payment transactions. Unlike traditional consensus protocols [3], the participants are from an open network and are incentivized by the payment of Bitcoins (or BTCs), which are "mined" through a clever cryptographic hash function known as Proof-of-Work (PoW), an idea originally proposed as an anti-spam technique [4]. Perhaps inspired by the success of Bitcoin as well as the need to support semantically richer (than just payment) applications, the notion of smart contracts has been introduced H. Chen  to represent autonomous programs, leading to a new paradigm of Decentralized Applications (DApps) that run on top of blockchains and consist of many interacting smart contracts. The Ethereum system was launched in 2015 to support smart contracts, while offering its inherent cryptocurrency known as Ether [5] and using an account-centered model (rather than the UTXO model mentioned above). Ethereum has become the de facto standard platform for DApps. At the moment of writing, the market value of Ethereum is over US$31B with approximately one million smart contracts executing on top of the Ethereum blockchain [6], [7]. The success of Ethereum ushers in Blockchain 2.0, which goes much beyond the payment-centered Blockchain 1.0.
While Ethereum facilitates semantically richer applications than Bitcoin, it also enlarges the threat surface, as evidenced by the many high-profile attacks. One example is the DAO [8] attack in year 2016, in which case an attacker exploited the socalled reentrancy vulnerability (which will be detailed later) to steal approximately US$60M. In July 2017, a vulnerability in the Parity wallet contract caused the loss of US$31M [9]. In April 2018, the MyEtherWallet wallet fell victim to a BGP and DNS hijacking attack, enabling the hacker to steal approximately US$17M [10]. These attacks highlight that our capabilities in securing the Ethereum system are limited. This should not be taken as a surprise because Ethereum is a new programming paradigm with DApps running on top of blockchains with many autonomous contracts.
The motivation of the present survey is in three-fold of researchers, practitioners, and students. From the standpoint of a researcher who wants to investigate Ethereum security, there is a need for a source of systematized treatment on the problems related to Ethereum security. Despite the fact that there have been some surveys, they did not offer a systematic and comprehensive view on Ethereum vulnerabilities, attacks, and defenses as we do. While referring to the related prior work in Section I-B for details, we mention the following: there is neither systematic understanding of the Ethereum vulnerabilities that have been discovered, nor systematic understanding of their root causes; this may explain why there are still a number of vulnerabilities that are completely open. From the standpoint of a practitioner, there is a need for a source of best practices and guiding principles. Industry has conducted due diligence in summarizing many best practices [11], which however may overwhelm practitioners. Therefore, it might be more useful to have a small number of guiding principles that are easier to adopt in practice. From the standpoint of a student who wants to learn about Ethereum security, there is a need for a succinct yet comprehensive and systematic source that also offer references to materials of greater details.

A. Our contributions
We provide a systematic and comprehensive survey on Ethereum systems security. It is systematic in the sense that vulnerabilities, attacks, and defenses as well as the relationships between them are accommodated. It is comprehensive in the sense that it covers both the Ethereum platform via a layered architecture and the environment in which the Ethereum platform operates. In terms of vulnerabilities, we enumerate 44 types of Ethereum vulnerabilities according to the layers of the Ethereum architecture and the environment in which Ethereum operates. Perhaps more importantly, we analyze and systematize the root causes of those vulnerabilities. This allows us to provide insights into how to prevent some Ethereum vulnerabilities and how to cope with the inevitable vulnerabilities, including those that are largely open. Some of our findings and insights are highlighted as follows: 1) Ethereum smart contracts introduce new kinds of vulnerabilities that do not have counterparts in traditional paradigm of applications. 2) It is important to design more secure programming languages and supporting tools for programmers to write more secure smart contracts.
3) The vulnerabilities caused by the design and implementation of the Ethereum blockchain are harder to cope with than vulnerabilities in the traditional paradigm. 4) The vulnerabilities in the Ethereum environment are largely caused by human, usability, and networking factors. 5) There are many vulnerabilities (e.g., outsourceable puzzle, 51% hashrate, and under-priced opcodes) that must be tackled in order to adequately defend Ethereum or blockchain-based DApp systems in general. In terms of attacks, we systematize 26 attacks against Ethereum according to the layers of the Ethereum architecture. Perhaps more importantly, we relate these attacks to the vulnerabilities and systematize the attack consequences. Some of our findings are highlighted as follows: 1) The largest single-incident financial loss thus far was caused by a denial-of-service (DoS) attack against the Parity wallet. This attack disabled a library that is used by many contracts and is therefore quite different from traditional DoS attacks. 2) DApps running on top of blockchains are not fully decentralized when they use centralized web interfaces, even if the underlying blockchain is fully decentralized. 3) Ethereum application-layer attacks have caused the largest financial losses. In terms of defenses, we systematize 47 defenses into two classes: proactive defenses, which aim to prevent attacks as much as possible; and reactive defenses, which aim to cope with the hidden vulnerabilities (i.e., their existence may not be known to the defender). Perhaps more importantly, we present a deeper analysis of the defenses according to (i) their capabilities in mitigating the damages that can be incurred by exploiting vulnerabilities, and (ii) the defense effort that has been investigated to cope with each kind of vulnerabilities. Some of our findings are highlighted as follows: 1) Industry has come up with a significant set of best practices for guiding the development of smart contracts. These best practices, if adequately executed, can indeed avoid many vulnerabilities. 2) Existing proactive defenses can defend against attacks that exploit many vulnerabilities; in contrast, existing reactive defenses can only defend against attacks that exploit a few vulnerabilities. 3) There are large discrepancies between levels of effort and investment into different kinds of attacks (i.e., much more investment into defending against high-profile attacks than low-profile attacks). 4) Existing studies focus on defending against attacks that attempt to exploit vulnerabilities in the DApp back-end (i.e., smart contracts), but largely ignore the protection of the DApp front-end (i.e., browser) and the interactions between the front-end and the back-end. Although the present paper focuses on the Ethereum system, the aforementioned findings related to vulnerabilities, attacks and defenses might be applicable to blockchain-based systems in general. Moreover, we discuss some fundamental research problems that must be adequately tackled in order to secure and defend Ethereum and blockchain-based systems, including: 1) There is a lack of deep understanding on the rigorouslydefined properties of blockchain-based systems. 2) There is a lack of deep understanding on the rigorous analysis methodologies that are necessary and sufficient for analyzing the desired properties of blockchain-based systems. 3) There is a lack of deep understanding on the metrics that are necessary and sufficient for analyzing the security and risk of blockchain-based systems. In order to improve readability and ease the reference to the large number of vulnerabilities, we denote the vulnerabilities by  1 , … ,  44 , respectively. Similarly, we respectively denote the attacks by  1 , … ,  26 and the defenses by  1 , … , 47 . Moreover, we use " ( , ⋯)" to denote that attack  exploits vulnerabilities  and possibly others.
The preceding discussion justifies how the present paper would adequately serve the needs of students and researchers. For practitioners, we mention that we systematize the best practices into a small number of principles that may be easier to adopt in practice. Table I highlights the relationship between the present work and related prior surveys, which accommodate some of vulnerabilities, attacks, defenses, and building-blocks. The most closely related survey is Atzei et al. [12], which discussed 12 types of vulnerabilities, 9 attacks, and 3 defenses in the context of Ethereum smart contracts (i.e. Blockchain 2.0). In contrast, we present a much more systematic treatment, by accommodating 44 types of vulnerabilities, 26 attacks, and 47 defenses. From a methodological standpoint, we further discuss the root causes of vulnerabilities (e.g., the root cause of the unchecked call return value vulnerability is the inconsistent ✓ [18] yes [19], [20], [21], [22] yes exception handling of Solidity). Moreover, we draw insights from the perspectives of vulnerability, attack, and defense.

B. Related work
There are a number of surveys on blockchain security and privacy which however have different perspectives than ours. First, Li et al. [13] reviewed security of blockchain technologies through the lens of 20 types of vulnerabilities, 6 attacks, and 5 defenses, without distinction between Blockchain 1.0 and 2.0 aspects. Similarly, Zhu et al. [14] reviewed 11 smart contract vulnerabilities, 11 attacks against blockchain data, and 30 defenses. On the contrary, we focus on the Ethereum blockchain system by accommodating 44 types of vulnerabilities, 26 attacks, and 47 defenses.
Second, Saad et al. [15] explored blockchains' attack surface in terms of cryptographic constructions, distributed system architecture, and applications; they cover 22 attacks and 33 defenses in Blockchain 1.0 and 2.0, but not vulnerabilities. Their survey is orthogonal to ours because (i) we focus on the Ethereum system, rather than multiple implementations of blockchains; (ii) we discuss vulnerabilities and their root causes as well as the attacks exploiting them, rather than attack surface; (iii) we provide insights into, and contrast, the vulnerabilities at different layers of the Ethereum architecture.
Third, Harz et al. [16] discussed 10 smart contract verification tools. Similarly, Angelo et al. [17] discussed 27 tools for analyzing Ethereum smart contracts. On the contrary, we focus on the defenses of the Ethereum systems security, rather than purely on smart contracts.
Fourth, Zhang et al. [18] presented a comprehensive review on Bitcoin-like transactions and the underlying (cryptographic) mechanisms. Their review is geared towards the abstract blockchain model for Bitcoin-like transactions (i.e., Blockchain 1.0); in contrast, we focus on the Ethereum ecosystem, including the design and implementation of the blockchain platform and DApps. There are surveys that focus on Bitcoin and cryptocurrencies [23], [24], [25], which use a transaction-centered model known as unspent transaction outputs (UTXO). In contrast, we focus on Ethereum, which uses an account-centered model.
Fifth, Orthogonal to the purpose of the present survey and tutorial, there are several surveys purely on blockchain consensus protocols [19], [20], [21], [22]. In contrast, we focus on the overall Ethereum system.

C. Paper outline
Section II briefly reviews the Ethereum system and discusses the survey methodology. Section III presents the 44 Ethereum vulnerabilities according to the layers of the Ethereum architecture and a deeper analysis of their root causes. Section IV presents the 26 attacks against Ethereum and a deeper analysis on their consequences. Section V presents the 47 defenses, classified as proactive or reactive and a deeper analysis on their capabilities and investments. Section VI discuss future research directions towards securing blockchain-based systems, including Ethereum as a special case. Section VII conclude the present paper. Figure 1 highlights a 4-layer architecture of the Ethereum blockchain, operates across these 4 layers. At the application layer, Ethereum clients execute smart contracts, which are associated to Ethereum accounts, in EVM. The data layer contains the blockchain data structures. The consensus layer assures a consistent state of the blockchain. Note that Ethereum plans to replace its current use of Proof-of-Work (PoW) with a Proof-of-Stake (PoS). The network layer formulates a Ethereum peer-to-peer (P2P) network of nodes or clients such that a node can always get the updated state of the blockchain from some of the active nodes. The environment serves these 4 layers via a corresponding component: a web user interface to interact with applications; databases for storing blockchain data; cryptographic mechanisms for supporting the consensus protocols; and Internet service for the network layer.

A. A brief review of the Ethereum system
1) The application layer: Ethereum supports two types of accounts: externally owned accounts (EOA) and contract accounts. An EOA is used to keep a user's funds in Wei, which is the smallest subdenomination of Ether and is worth 10 −18 Ether. An EOA is associated with, and addressed by, a public key; access to an EOA is authenticated by showing the ownership of the corresponding private key. In contrast, a  Fig. 1: Architecture of the Ethereum blockchain and its environment in which the Ethereum blockchain runs.
contract account is associated with a piece of executable bytecode (i.e., smart contracts), which defines some business logic of interest. An EOA or contract account has a dynamic state, which is defined by: (i) , which tracks the number of transactions that have been initiated by the owner of the EOA or the number of contracts created by the contract account; (ii) , which is the amount of Wei (i.e., 10 −18 Ether) owned by the EOA or contract account; (iii) , which is the hash of the root of the account's storage data structure trie that records a contract's state variables associated to the corresponding piece of bytecode (i.e., not applicable to EOA); (iv) ℎ, which is the hash value of a contract account's bytecode (i.e., not applicable to EOA). The state of a blockchain is defined by the states of the accounts on the blockchain.
Smart contracts are building-blocks of decentralized applications (DApps) running on top of the Ethereum blockchain. A DApp often has a user interface as its front-end and some smart contracts as its back-end. At the moment of writing, 2,497 DApps are running on top of Ethereum, including finance, governance, gambling, exchange, and wallet applications [26]. Some DApps issue their own cryptocurrency, called tokens, for purposes like Initial Coin Offering (ICO) and exchanges. A Ethereum-based token is a special kind of smart contract (e.g., ERC-20 [27]).
Smart contracts execute in EVMs, which are quasi-Turingcomplete machines using a stack-based architecture; the term "quasi" means that the execution is limited by the amount of gas offered by the transaction in question [28].
2) The data layer: A transaction is an interaction between an EOA (called sender) and anther EOA or contract account (called recipient). A transaction is specified by: (i) , which is a counter for tracking the total number of transactions that have been initiated by the sender; (ii) , which specifies a transaction's destination EOA or contract account; (iii) , which is the amount of money (unit: Wei) to be transferred from the sender to the recipient (if applicable); (iv) , which is the bytecode or data corresponding to the purpose of the transaction; (v) and , which respectively specify the unit price and the maximum amount of gas the sender is willing to pay the winning miner of a block containing the transaction; (vi) ( , , ), which is the Elliptic Curve Digital Signature Algorithm (ECDSA) signature of the sender. The execution of a transaction updates the states of the accounts involved and therefore the state of the blockchain. Figure 2 depicts the lifecycle of a transaction. (i) A sender constructs a transaction and digitally signs it. (ii) The sender submits the signed transaction to an Ethereum client via a JSON-RPC call. (iii) The client validates the received transaction and broadcasts it to the Ethereum P2P network. (iv) Any client that receives the transaction and is a miner adds the transaction to its transaction pool. (v) A miner executes a sequence of transactions chosen from its transaction pool, formulates a new block, and updates the state of the blockchain as follows. For a money-transfer transaction, the specified is transferred from the sender's EOA to the recipient's EOA or contract account; for a contract-creation transaction where is a piece of bytecode, a new contract account is created and is associated with the bytecode; for a contract-invocation transaction where is a callee contract and uniquely identifies the callee function (and possibly some associated arguments), the bytecode associated to the callee contract account is loaded into the EVM. (vi) The miner solves a PoW by finding a random nonce such that the hash value of the block metadata in question is smaller than a certain threshold, which reflects the difficulty of creating a block. Unlike Bitcoin's computation-intense PoW [1], Ethereum uses a memory-intense puzzle called "Ethash" [5]. (vii) Upon creating a block, the miner broadcasts it to the Ethereum P2P network so that other clients can validate the block. (viii) Upon validating a block, the client in question appends the block to the blockchain.
Trie [5] is the data structure for storing Ethereum blockchain data (e.g., account states). Like a Patricia tree [29], a trie stores ( , ) pairs while facilitating search as follows: the path from the root to a leaf node corresponds to a and the leaf node contains a (e.g., the state of an account). As illustrated in Figure 3, a block header may point to a state trie, a transaction trie (for bookkeeping transaction data), and a receipt trie (for bookkeeping the data related to the execution of transactions). Each contract account corresponding to a leaf or branch node on the state trie uses a separate storage trie to bookkeep the persistent data of the contract; this storage trie also use a ( , ) structure, where the position of each slot corresponds to a and the contract's state variable in each slot corresponds to a . Note that an Ethereum blockchain has a single state trie because the state of the blockchain dynamically evolves.
3) The consensus layer: At the moment of writing, Ethereum takes about 14 seconds to create a block, meaning that multiple miners could create valid blocks simultaneously and that there could be many stale blocks. Ethereum uses a variant of the GHOST consensus protocol [30] to select the "heaviest" branch as the main chain where the "heaviest" branch is the sub-tree rooted at the fork in question and has the highest cumulative block difficulty [31], [32], while noting that stale blocks are not on the main chain.
Ethereum rewards not only the regular blocks on the main chain, but also the stale blocks referred by a regular block. As illustrated in Figure 4, an uncle block is a stale block referenced by a regular block called nephew (via a dashed arrow). The distance between two blocks is their height difference on the tree. The miner of a regular block receives one unit of "static block reward," which is worthy of 2 Ethers  Fig. 4: A sub-tree of an Ethereum blockchain (adapted from [33]), where a value beneath a node is the total award to the miner of the node (unit: static block reward).

4) The network layer:
The Ethereum network is a structured P2P network where each node (i.e., client) stores a copy of the entire blockchain. For node discovery and routing purposes, each node maintains a dynamic routing table of 160 buckets and each bucket contains up to 16 entries of other nodes' IDs, IP address, UDP/TCP ports. Ethereum uses the RLPx protocol [34], [35] to discover target clients and uses the Ethereum Wire Protocol [36] to facilitate the exchange of Ethereum blockchain information (e.g., transactions, blocks) between clients.
5) The environment: The Ethereum blockchain runs in an environment, which naturally operates across the 4-layers to provide respective services, namely: a web interface for users to interact with the Ethereum blockchain; a database for Ethereum clients to store the blockchain data; cryptographic mechanisms for security purposes; and the Internet infrastructure to support blockchain networking and communication among Ethereum nodes. We separate the Ethereum blockchain architecture from the environment because attacks against the Ethereum blockchain may come from the environment and these attacks may be better addressed in the environment rather than by the Ethereum blockchain, leading to a clean and modular abstraction.
B. Survey methodology 1) Scope: Since our focus is on Ethereum security, we will systematize the vulnerabilities of, the attacks against, and the defenses for Ethereum. Since these aspects are related to the programming language for writing smart contracts and the client software, we focus on the widely-used Solidity and Geth [37] as well as Parity [38], respectively.
2) Methodology: Our methodology can be characterized as follows. First, we use a layered architecture to present the Ethereum ecosystem, from the application down to the data, the consensus, the network, and the environment layers. This layered view allows us to describe matters at the most appropriate layer.
Second, we consider security from three perspectives (i.e., vulnerabilities, attacks, and defenses) as well as the relationships between them. For each vulnerability, we discuss, among other things, its root cause and status (i.e., eliminated, can be eliminated by best practice, or still open). For each attack, we discuss, among other things, its cause, tactic, and direct impact. For each defense, we discuss its mechanism and the (hidden) vulnerabilities it aims to protect from exploitation. We aim to provide insights into the design and implementation of Ethereum as well as future research directions in order to address the range of open problems. A. Vulnerabilities at the application layer 1) Reentrancy ( 1 ): This vulnerability was first observed from the DAO attack [39]; its variants were later reported in [40]. The vulnerability occurs when an external callee contract calls back to a function in the caller contract before the execution of the caller contract is completed (i.e., cyclic calls in a sense). This allows the attacker to bypass the due validity check until the caller contract is drained of Ether or the transaction runs out of gas. The vulnerability is caused by: (i) a contract's control-flow decision relies on some of its state variable(s) that should be, but are not, updated by the contract itself before calling another (i.e., an external) contract [40]; and (ii) there is no gas limit when handing the control-flow to another contract. The vulnerability can be prevented by one of the following methods [41]: (i) assuring that a contract's state variables are updated before calling another contract; (ii) introducing a mutex lock on the contract state to assure that only the lock owner can change the state; (iii) using the transfer method to send money to other contracts because this method only forwards 2,300 gas to the callee contract.

III. VULNERABILITIES
2) Delegatecall injection ( 2 ): This vulnerability was first observed from an attack against the Parity wallet [42]. In order to facilitate code-reuse, EVM provides an opcode, DEL-EGATECALL, for embedding a callee contract's bytecode into the bytecode of the caller contract as if it's a piece of the latter's bytecode [43]. As a consequence, a malicious callee contract can directly modify (or manipulate) the state variables of the caller contract. This vulnerability is caused by the ability that the state variables of a caller contract can be updated by the bytecode of a callee contract. The vulnerability can be completely prevented by declaring a contract that is meant to be shared via the delegatecall as a library, which is stateless [44].
3) Frozen Ether ( 3 ): This vulnerability was first observed from another attack against the Parity wallet [45]. The vulnerability results from the ability of users to deposit their money to their contract accounts with the inability to spend their money from those accounts, effectively freezing their money. The vulnerability is caused by [46]: (i) contracts not providing any function for spending money relying on the money-spending function of another contract (as a library) and (ii) the callee contract (i.e., the library) being killed accidentally or deliberately. The vulnerability can be prevented by assuring that mission-critical functions, or money-spending functions in this case, are not outsourced to another contract.

4) Upgradable contract ( 4 ):
This vulnerability was first discussed in [12]. The idea of contract upgrading was introduced to mitigate the problem that smart contracts, once deployed, cannot be modified even if they are later found to have vulnerabilities. In order to allow contract upgrading, there are two approaches: (i) splitting a contract into a proxy contract and a logic contract such that developers can upgrade the latter but not the former; and (ii) using a registry contract to bookkeep the updated contracts. While effective, these approaches introduce a new vulnerability: when the contract developer is malicious, the updated (logic) contract can be malicious. The vulnerability is caused by one contract being able to call another contract, which can be malicious. This vulnerability (i.e., unsecure contact updating) remains to be an open problem. 5) DoS with unexpected revert ( 5 ): This vulnerability was first reported in [41]. It occurs either when a transaction is reverted due to a caller contract encountering a failure in an external call, or the callee contract deliberately performs the revert operation to disrupt the execution of the caller contract. This vulnerability is caused by the execution of a caller contract being reverted by a callee contract. This vulnerability can be prevented by letting a recipient invoke a transaction to "pull" the money that was set aside by a sender for the recipient, which effectively prevents a sender's transaction from being reverted [47].
6) Integer overflow and underflow ( 6 ): This vulnerability was first observed from the attack against the BEC tokens [48]. It occurs when the result of an arithmetic operation falls outside of the range of a Solidity data type, causing (for example) unauthorized manipulation to the attacker's balance [48] or other state variables. The vulnerability is caused by that Solidity source code does not perform proper validation on numeric inputs, and that neither the Solidity compiler nor the EVM enforces integer overflow/underflow detection. This vulnerability can be prevented by using the SafeMath library [49] that handles these issues. 7) Manipulated balance ( 7 ): This vulnerability was first reported in [50] and was also known as the "forcing Ether to contracts" vulnerability. This vulnerability occurs when a contract's control-flow decision relies on the value of this.balance or address(this).balance, which can be leveraged by an attacker to cause (for example) that only the attacker can obtain the money; see [44] for a detailed description. This vulnerability can be prevented by not using a contract's balance in any condition check [50]. 8) Authentication through tx.origin ( 8 ): This vulnerability was first discussed in [51]. The tx.origin is a global variable in Solidity and refers to the original EOA that initiates the transaction in question. This vulnerability occurs when a contract uses tx.origin for authorization, which can be compromised by a phishing attack. Figure 6 provides an example of this vulnerability (Line 6) in function withdrawAll, which uses tx.origin to confirm that it is the owner of contract UserWallet that is calling the function. However, if the owner of contract UserWallet is tricked to transfer money to a malicious AttackContract, the fallback function (Line 14) will be automatically executed, which in turn calls the withdrawAll() function. Since the condition check (Line 6) validates the EOA that initiated the transaction rather than the intermediate caller (i.e., AttackContract), the attacker can pass the authority check and steal the money in  , has yet to be eliminated).
contract UserWallet. This vulnerability can be prevented by using msg.sender, instead of tx.origin, for authentication [52] because msg.sender returns the account that incurred the message. 9) Erroneous visibility ( 9 ): This vulnerability was first observed in an attack against the Parity wallet [42]. It occurs when a function's visibility is incorrectly specified and thus permits unauthorized access. Specifically, Solidity provides four types of visibility to restrict access to a contract's functions, namely public, external, internal, and private, which respectively says a function can be called arbitrarily, only externally, only internally (i.e., within the contract and its derived contracts), or only within the contract. Functions that should not be called from an external contract should be specified as private or internal. However, Solidity makes functions as public by default, which allows attackers to directly call these improperly specified functions. Solidity  (starting version 0.5.0) mitigates the vulnerability by making it mandatory for programmers to explicitly specify function visibility [53]. Still, this vulnerability cannot be completely prevented unless programmers correctly specify their functions' visibilities.
10) Unprotected suicide ( 10 ): This vulnerability was first observed from an attack against the Parity wallet [45]. A contract account can be killed by the contract's owner (or a trusted third party) using the suicide or self-destruct method. A contract may have an "owner" whose privileges are typically specified when creating the contract. When a contract account is killed, its associated contract bytecode and storage are deleted forever. This vulnerability is caused by the inadequate authentication enforced by a contract. The vulnerability can be mitigated by enforcing advanced authentication (e.g, multifactor authentication) to assure that a suicide operation must be approved by multiple parties [54]. 11) Leaking Ether to arbitrary address ( 11 ): This vulnerability was first reported in [55]. The vulnerability occurs when a contract's funds can be withdrawn by any caller, who is neither the owner of the contract nor an investor who deposited funds to the contract. This vulnerability is caused by the failure in checking an caller's identity when the caller invokes a function to send Ether to an arbitrary address. This vulnerability can be prevented by enforcing an adequate authentication on the functions for sending funds.
12) Secrecy failure ( 12 ): This vulnerability was first observed from a multi-player game in [56] and was also called keeping secrets in [12]. It can be exploited to benefit an attacker. In blockchain, restricting the visibility of a variable or function does not assure that the variable or function is secret, because of the public nature of blockchain (i.e., details of transactions are publicly known). Although restricting a state variable to be private can prevent other contracts from accessing it, any one can see the value of a state variable from the relevant transaction data. This vulnerability is caused by the lack of secrecy of sensitive data in an untrusted environment. A possible solution to preventing this vulnerability is to use cryptographic techniques, such as timed commitments [56], [12].
13) Insufficient signature information ( 13 ): This vulnerability was first exploited in a replay attack against smart contracts [57]. The vulnerability occurs when a digital signature turns out to be valid for multiple transactions, which can happen when one sender (say Alice) sends money to multiple recipients through a proxy contract (instead of initiating multiple transactions) [58]. In the proxy contract mechanism, Alice can send a digitally signed message off-chain (e.g. via email) to the recipients, similar to writing personal checks in the real world, to let the recipients withdraw money from the proxy contract via transactions. In order to assure that Alice does approve a certain payment, the proxy contract verifies the validity of the digital signature in question. However, if the signature does not give the due information (e.g., nonce, proxy contract address), a malicious recipient can replay the message multiple times to withdraw extra payments. This vulnerability can be prevented by incorporating the due information in each message [59].
14) DoS with unbounded operations ( 14 ): This vulnerability was first observed from the GovernMental contract [60] and its variants were later discussed in [61], [62]. Recall that each block has a "gas limit" field that specifies the maximum total amount of gas that can be consumed by the transactions in a block. This vulnerability occurs when the amount of gas that is required for executing a contract exceeds the block gas limit. This vulnerability is caused by improper programming with unbounded operations in a contract (e.g., loop over a large array). This vulnerability can be mitigated by assuring (i) contracts should not use loops over data structures, especially those data structures that can be operated by EOA; and (ii) when a contract has to use loop over data structure, the contract should keep track of the loop and resume the aborted execution when the sender of the transaction re-invokes the same contract (in order to finish the execution of the contract) [61].
15) Unchecked call return value ( 15 ): This vulnerability was first discussed in [63], [54] and is also known as mishandled exceptions. It has two variants, called gasless send and unchecked send [12], [64]. Recall that Solidity provides two methods for a contract to call another: (i) directly referencing to a callee contract's instance; (ii) using one of the following four low-level methods: send, call, delegatecall and callcode. There is a discrepancy in Solidity's handling of exceptions occurring in the execution of callee contracts [63]: if an exception occurs in case (i), the exception is automatically propagated back to the caller and the transaction is reverted entirely; if an exception occurs in case (ii), the callee contract returns FALSE back to the caller contract. This discrepancy can lead to unintended transactions unless the caller contract carefully addresses the discrepancy. At the moment of writing, neither the Solidity compiler nor the EVM addresses the discrepancy. This vulnerability can be prevented by letting a caller contract check and address the discrepancy mentioned above.
16) Uninitialized storage pointer ( 16 ): This vulnerability was first reported in [65]. Recall that in Solidity, the contract state variables are always laid out consecutively in storage, starting from slot 0. For a complicated local variable (e.g., struct, array, or mapping), a reference is assigned to an unoccupied slot in the storage to point to the state variable. If the local variable is not explicitly initialized, then the local variable's reference points to slot 0 by default, causing the content starting from slot 0 to be overwritten [66]. This vulnerability is caused by Solidity's treatment of uninitialized complicated local variables. This vulnerability has been eliminated by Solidity compiler, starting version 0.5.0, by reporting an error to contracts that contain uninitialized storage pointers [53].

17) Erroneous constructor name ( 17 ):
This vulnerability was first observed from the Rubixi contract [67], where the constructor function has an incorrect name that allows anyone to become the owner of the contract. Prior to Solidity version 0.4.22, a function declared with the same name as the contract's is considered as the contract's constructor, which is only executed one-time upon the creation of the contract. If the constructor's name is misspelled by a programmer for whatever reason, the intended constructor becomes a public, normal function that can be invoked by any EOA. This vulnerability is caused by that Solidity does not provide a special syntax to distinguish a constructor function from a regular function [68]. The vulnerability has been eliminated, starting Solidity version 0.

18) Type casts ( 18 ):
This vulnerability was first reported in [12]. Recall that a contract written in the Solidity language can call another contract by directly referencing to the callee contract's instance. As illustrated in Figure 7, contract Game calls the function add() in contract CounterLibrary by referencing to its instance c (Line 5). When function play() (Line 4) is invoked, the argument specifying the callee contract's address is cast to CounterLibrary. However, the Solidity compiler can only check whether or not the CounterLibrary contract declared function add(), but cannot check whether or not the address argument conforms to that of the CounterLibrary contract's. If the address associated to the CounterLib contract (Line 2) contains a function that is named add() and has the same declaration, then the add() function in contract CounterLib is executed, instead of the desired add() function in contract CounterLibrary. As a consequence, the EVM can be misled to run the attacker's contract. This vulnerability is caused by the incompetent type system of Solidity. Currently, there is no feasible way to avoid the vulnerability.

19) Outdated compiler version ( 19 ):
This vulnerability was first reported in [54]. It occurs when a contract uses an outdated compiler, which contains bugs and thus makes a compiled contract vulnerable. This vulnerability can be prevented by using an up-to-date compiler.

20) Short address ( 20 ):
This vulnerability was first discussed in [70]. Recall that in a contract-invocation transaction, the function selector and arguments are orderly encoded in the input field, where the first four bytes specify the callee function and the rest data arranges arguments in chunks of 32 bytes. However, if the length of the encoded arguments is shorter than expected, EVM will auto-pad extra zeros to the arguments to make up for 32 bytes. Consider function transfer(address addr, uint tokens) as an example. If the trailing one (i.e., last) byte of addr is left off, two extra hex zeros will be added to the end of tokens, which amplifies the number of tokens being sent. This vulnerability is caused by that EVM does not check the validity of addresses [71]. This vulnerability can be prevented by checking the length of a transaction's input (i.e., msg.data) [72].

21) Ether lost to orphan address ( 21 ):
This vulnerability was first reported in [12]. When transferring money, Ethereum only checks whether the length of the recipient's address is no greater than 160-bit but not the validity of the recipient's address. If money is sent to a non-existing orphan address, Ethereum automatically registers for the address than terminating the transaction. Since the address is not associated to any EOA or contract account, there is no way to withdraw the transferred money, which is effectively lost. This vulnerability is caused by that EVM is not orphan-proof. At the moment of writing, this vulnerability can only be prevented by manually assuring the correctness of the recipient's address.

22) Call-stack depth limit ( 22 ):
This vulnerability was first reported in [73]. Recall that in the original specification of Ethereum execution model [5], EVM's call-stack has a hard limit of 1024 frames. When a contract calls another contract, the call-stack depth of the transaction increases by one; when the number of nested calls exceeds 1024, Solidity throws an exception and aborts the call. An attacker can recursively call a contract, which may be deployed by the attacker, for 1023 times and then calls a victim contract to reach the stack depth limit, which fails any subsequent external call made by the victim contract. Since Solidity does not propagate exceptions in low-level external calls, the victim contract may not be aware of the failure. This vulnerability is caused by EVM's inadequate execution model, and has been eliminated by the hard fork for EIP-150, which re-defines the gas-consumption rules of external calls to make it impossible to reach 1024 in call stack depth [74].

23) Under-priced opcodes ( 23 ):
This vulnerability was first observed from two DoS attacks [75], [76], [77]. Recall that Ethereum uses the gas mechanism to prevent the abuse of computing resources (e.g., CPU, disk, network). This vulnerability occurs when a contract contains a lot of under-priced opcodes that consume a large amount of resources at a low gas cost, meaning that the execution of the contract wastes a lot of computing resources. This vulnerability is caused by the failure in properly setting the gas cost for consuming computing resources. In order to mitigate this vulnerability, Ethereum has raised the gas cost for the opcodes that were abused to launch the two DoS attacks described in [74]. However, it is not clearly whether or not the vulnerability can be completely prevented by this mechanism or not [77].

24) Transaction ordering dependence (a.k.a. front running;
 24 ): This vulnerability was first discussed in [63]. It refers to the concurrency issue that the forthcoming state of blockchain depends on the execution order of transactions, which is however determined by the miners. Typically, miners group and order transactions into a new block based on the reward offered by the transactions. Since transactions are publicly broadcast to the network, a malicious EOA can offer a higher gasPrice to have its transactions assembled into blocks sooner than the others'. Moreover, a malicious miner can always pick up its own transactions regardless of the gasPrice. This vulnerability is caused by that the state of a contract depends on how minors select transactions to assemble blocks. This vulnerability can be mitigated by using a cryptographic commit-reveal scheme to hide the information (e.g., gasPrice, value) offered by transactions [78], [79], or by introducing a guard condition to assure that an invocation of a contract either returns the expected output or fails [63].

25) Timestamp dependence ( 25 ):
This vulnerability was first reported in [63]. It occurs when a contract uses the block.timestamp as a part of the triggering condition for executing a critical operation (e.g., money transfer) or as the source of randomness, which however can be manipulated by a malicious miner. The vulnerability is caused by that Ethereum only prescribes that a timestamp must be greater than the timestamp of its parent block and be within future 900 seconds of the current clock. If a contract uses a timestamp-based condition (e.g., block.timestamp %25 == 0) to determine whether or not to transfer money, a malicious miner can slightly shift the timestamp to satisfy the condition to benefit the attacker. This vulnerability can be prevented by not using block.timestamp in any decision-making conditions. 26) Generating randomness ( 26 ): This vulnerability was first reported in [80]. Many gambling and lottery contracts select winners randomly, for which a common practice is to generate a pseudorandom number based on some initial private seed (e.g., block.number, block.timestamp, block.difficulty or blockhash). However, these seeds are fully controlled by miners, meaning that a malicious miner can manipulate these variables to make itself the winner [81], [82]. This vulnerability is caused by manipulable entropy sources. There are several proposals for addressing this problem, and each proposal has its own pros and cons. For example, the Oracle RNG proposal [83] uses existing external services to generate random numbers off-chain and then send back to the requesting contract, meaning that there is a single-point-offailure in the Oracle RNG; the RANDAO proposal [84] uses a collaborative cryptographic commit-reveal scheme to generate a random number by multiple participants altogether, meaning that it achieves a limited throughput.
B. Vulnerabilities at the data layer 1) Indistinguishable chains ( 27 ): This vulnerability was first observed from the cross-chain replay attack when Ethereum was divided into two chains, namely ETH and ETC [85]. Recall that Ethereum uses ECDSA to sign transactions. Prior to the hard fork for EIP-155 [86], each transaction consisted of six fields (i.e., nonce, recipient, value, input, gasPrice and gasLimit). However, the digital signatures were not chainspecific because no chain-specific information was even known back then. As a consequence, a transaction created for one chain can be reused for another chain. This vulnerability has been eliminated by incorporating and signing a chainID.
2) Empty account in the state trie ( 28 ): This vulnerability was first observed from a DoS attack reported in [76], [77]. An empty account is an account that has zero nonce, zero balance, no code associated to it, and no storage associated to it. An empty account is functionally equivalent to a non-existing account, except that an empty account needs to be bookkept in the Ethereum state trie and thus increases the synchronization and transaction processing time. This means that an attacker can incur a large number of empty accounts to substantially increase the the synchronization and transaction processing time, effectively causing a DoS attack [76], [77]. An empty account can be incurred by an attacker using the SUICIDE opcode to transfer zero Ethers to a non-existing account. This vulnerability was caused by the lack of control over that an empty account should not be included in the state trie. This vulnerability has been eliminated by the hard fork for EIP-161 [87], which removes those empty accounts from the state trie and prevents any empty account from being stored in the state trie.
C. Vulnerabilities at the consensus layer 1) Outsourceable puzzle ( 29 ): This vulnerability was reported in [32]. Recall that Ethereum adopts the PoW puzzle called Ethash, which was meant to be ASIC-resistant and be able to limit the use of parallel computing (owing to that the vast majority of a miner's effort will be reading a dataset via the limited memory bandwidth). However, a crafty miner can still divide the task of searching for a puzzle solution into multiple smaller tasks and then outsource them. This vulnerability is caused by that Ethash only makes the puzzle solution partially sequential in preimage search, rather than relying on an inherently sequential PoW. Several puzzles are proposed to cope with this problem [88], [89], which however have not been adopted by the Ethereum community.
2) 51% hashrate ( 30 ): This vulnerability is inherent to PoW-based blockchains, where an attacker controlling a majority of the mining power can take over the blockchain [90], [91]. Such an attacker can reverse transactions by formulating blocks and performing double-spending at will. This vulnerability is inevitable to PoW-based consensus protocols.
3) Fixed consensus termination ( 31 ): This vulnerability was first discussed in [92]. It refers to the fact that Ethereum's consensus protocol achieves a probabilistic agreement with a deterministic termination, meaning that a block is considered persistent in the main chain with a high probability if it is followed by a fixed number of blocks. In other words, the consensus for block will terminate when the chain depth reaches + and all of the transactions contained in block are committed (i.e., a merchant can take an external action, such as shipping goods). However, the probability of agreement can be affected by various factors [92]. For example, in the presence of communication delay, applications should wait for more blocks to be confirmed so as to achieve a higher security against double-spending. This vulnerability is caused by that no deterministic protocol can simultaneously guarantee agreement, termination, and validity in an asynchronous network [93].

4) DoS with block stuffing ( 32 ):
This vulnerability was first observed from the Fomo3D contract [94]. The vulnerability is that during a period of time, only the attacker's transactions are included in the newly-mined blocks and the other transactions are abandoned by the miners. This can happen when the attacker offers a higher gasPrice to incentivize the miners to select the attacker's transactions. This vulnerability is caused by the greedy mining incentive mechanism. At the moment of writing, there is no solution to prevent this vulnerability. 5) Rewards for uncle blocks ( 33 ): This vulnerability was independently reported in [95], [33], [96]. The vulnerability refers to that the uncle-rewarding mechanism reviewed above can lower the security of Ethereum when compared with Bitcoin. In particular, the uncle-rewarding mechanism reduces the risk for selfish miners that selectively release blocks to maximize their own profit because stale blocks may become uncle blocks and then receive rewards; this essentially incentivize selfish mining and double-spending. At the moment of writing, it is not clear how to eliminate this vulnerability.
D. Vulnerabilities at the network layer 1) Unlimited nodes creation ( 34 ): This vulnerability was reported for the Geth client prior to its version 1.8 [35]. In the Ethereum network, each node is identified by a unique ID, which is a 64-byte ECDSA public key. An attacker could create an unlimited number of nodes on a single machine (i.e., with the same IP address) and use these nodes to monopolize the incoming and outgoing connections of some victim nodes, effectively isolating the victims from the other peers in the network. This vulnerability is caused by the weak restriction on the node generation process. This vulnerability can be eliminated by using a combination of IP address and public key as node ID. This countermeasure has not been adopted by the Geth developers who argue that it has a negative impact on the usability of the client.
2) Uncapped incoming connections ( 35 ): This vulnerability was in the Geth client prior to its version 1.8 [35]. Each node can have a total number of maxpeers (with a default value 25) connections at any point in time, and can initiate up to ⌊(1 + maxpeers)∕2⌋ outgoing TCP connections with the other nodes. However, there was no upper limit on the number of incoming TCP connections initiated by the other nodes. This gives the attacker an opportunity to eclipse a victim by establishing an maxpeers many of incoming connections to a victim node, which has no outgoing connections. This vulnerability has been eliminated in Geth v1.8 by enforcing an upper limit on the number of incoming TCP connections to a node, with a default value ⌊maxpeers∕3⌋ = 8.
3) Public peer selection ( 36 ): This vulnerability was detected in Geth client prior to its version 1.8 [35]. Recall that the Ethereum P2P network uses a modified Kademlia DHT [97] for node discovery and that each node maintains a routing table of 256 buckets for storing information about the other nodes. The buckets are arranged based on the XOR distance between a node's ID and its neighboring node's ID [98]. When a node, say , needs to locate a target node, queries the 16 nodes in its bucket that are relatively close to the target node and asks each of these 16 nodes, say , to return the 16 IDs of 's neighbors that are closer to the target node. The process iterates until the target node is identified. However, the mapping from node IDs to buckets in the routing table is public, meaning that the attacker can freely craft node IDs that can land in a victim node's buckets and insert malicious node IDs into the victim node's routing table [35]. This vulnerability can be limited by making the "node IDs to buckets" mapping private. This countermeasure has not been adopted by the Geth developers who argue that it has a negative impact on the usability of the client.

4) Sole block synchronization ( 37 ):
This vulnerability was first reported in [99]. It allows an attacker to partition the Ethereum P2P network without monopolizing the connections of a victim client. Recall that each block header contains a difficulty field, which records the mining difficulty of the block. The total difficulty of the blockchain, denoted by totalDifficulty, is the sum of the difficulty of the blocks up to the present one. When a client, say , receives from, say client , a block of which the difference totalDifficulty − difficulty is greater than the totalDifficulty at the blockchain stored on client (meaning that client missed a number of blocks), should start a block synchronization with . Ethereum only allows a client to synchronize with one other client at a time (for network load considerations). This means that if client is malicious and deliberately delays the synchronization in response to 's request, the blockchain at client is stalled and rejects every subsequent block, which may facilitate double-spending and DoS attacks. This vulnerability can be mitigated by synchronizing with multiple nodes, which however increases the network load.

5) RPC API exposure ( 38 ):
This vulnerability was first observed from the attack against the Geth and Parity clients [100]. The JSON-RPC of Ethereum clients provide various APIs for EOAs to communicate with the Ethereum network. For security purposes, the interface should only open locally and not be accessible from the internet. However, the standard port 8545 assigned to JSON-RPC can be accessed remotely in the Geth and Parity clients by default, which makes it possible for an attacker to call these remote clients via a JSON request [101]. Once having access to the remote client, the attacker can obtain sensitive data and perform certain unauthorized actions on the remote client. The vulnerability is caused by insecure API design and improper configuration. The vulnerability can be prevented by configuring the listening port (rather than using the default one) and adding access control to filter remote RPC calls.

E. Vulnerabilities in the Ethereum environment
We propose considering vulnerabilities in the environment with which Ethereum interacts because they also pose as threats to Ethereum.
1) Weak password ( 39 ): This vulnerability was first observed from an attack against the DApp called Enigma [102]. The vulnerability refers to not only low-entropy passwords but also password reuse and insecure password storage. When the password of a DApp administrator is compromised, the attacker can manipulate the DApp's webpage at will to attack others.
2) Cross-Site Scripting (XSS;  40 ): This vulnerability was first observed from the attack against a cryptocurrency exchange, EtherDelta [103]. XSS is a browser-side vulnerability which allows an attacker to inject malicious JavaScript code into a HTTP webpage. To initiate a transaction via web-based DApp, an EOA may need to fetch its private key from a local file to the browser. An attacker can steal the private key by uploading a malicious JavaScript to the webserver, while claiming (for example) that the attacker is publishing information about exchanging some tokens. The webserver pushes the attacker's token-exchange content to a victim's browser, which executes the malicious JavaScript code, causing the private key to be exposed to the attacker. This vulnerability can be prevented by letting a user sign transactions offline and then initiate transaction online, meaning that the private key is never loaded into the browser and cannot be compromised by the attack mentioned above.
3) Unvalidated URL redirection ( 41 ): This vulnerability was first observed from an attack against the Ethereum wallet called MyEtherWallet [10]. Web applications frequently redirect users to other webpages. If the target URL is not authenticated, an attacker can replace the target URL with a phishing or malicious website, which renders the users vulnerable to attacks.

4) Broken access control ( 42 ):
This vulnerability was first observed from an attack against the decentralized application called CoinDash [104]. The access control failure at the server side causes an unauthorized access to the web application, which may result in the manipulation of the web page. Many DApps start with an Initial Coin Offering (ICO). A common practice is that participants obtain tokens by depositing Ether to a certain contract account, whose address is published on the website of the DApp. If an attacker breaks into the webserver and replaces the original contract address with its own, then the coin buyers will pay the attacker.

5) Unreliable Border Gateway Protocol (BGP) messages ( 43 ):
This vulnerability was first observed from an attack against MyEtherWallet [10]. Each BGP router maintains a routing table with routing paths between ASes. BGP peers broadcast IP prefixes they own and dynamically update their routing tables according to the IP prefixes they received from their neighbors. However, BGP has no mechanism for validating messages communicated between ASes, and therefore simply treats them as trusted [105]. An attacker can announce ownership of any prefix to its neighbor routers to redirect traffic towards the malicious ASes under its control. Then, the attacker can pretend to be a DNS server and redirect victims to malicious websites at IP addresses under the attacker's control.

6) Sensitive Domain Name System (DNS) servers ( 44 ):
This vulnerability was also observed from the attack against EtherDelta [106]. A wide range of vulnerabilities that can be exploited to incorrectly resolve DNS queries and redirect users to malicious websites, which can be achieved by hijacking DNS through cache poisoning, stale records, and compromising the resolver configuration file. [107].

F. Further analysis of vulnerability causes
Now we present a taxonomy of the root causes of the vulnerabilities reviewed above. As highlighted in Figure 5, the vulnerabilities are caused by incompetence or flaws in smart contract programming, solidity language and toolchain, Ethereum design and implementation, and human, usability, and networking factors.
1) Smart contract programming: These causes can be further divided into four sub-causes: external dependence, meaning a contract's execution relies on the behavior of an external contract; improper validation, meaning a failure in checking a condition allows the passing of an invalid input; inadequate authentication or authorization, causing failures in checking a caller's identity or privilege when the caller attempts to access a protected data item or functionality; and uncontrolled gas consumption, meaning a failure in gas allocation permits a DoS attack. These causes led to 14 types of vulnerabilities. Among these 14, only 4 (i.e., Integer overflow and underflow ( 6 ), erroneous visibility ( 9 ), secrecy failure ( 12 ), DoS with unbounded operations ( 14 )) exist in traditional software, meaning that the other 10 are unique to Ethereum smart contract programming. This leads to: Insight 1: Ethereum smart contracts introduce new kinds of vulnerabilities.
Insight 1 is interesting because it says that a new programming paradigm demands adequate training for programmers' secure coding practice. Indeed, among the 26 types of application-layer vulnerabilities, 20 can be prevented by using best practices, highlighting the importance of engineering best practices.
2) Solidity language and tool chain: These causes can be further divided into five sub-causes, among which four subcauses are related to the improper design of the Solidity language (i.e., inconsistent exception handling between direct call and low-level calls; undefined behavior of uninitialized storage pointers; improper syntax of constructor function; and weak type system with flexible typing rules) and the other subcause is buggy compiler (i.e., insufficient tool chain support). These five causes contributed 5 types of vulnerabilities. This leads to the following insight, which is clearly interesting and important.
Insight 2: It is important to design more secure programming languages and have more secure supporting tools for programmers to write secure smart contracts.
3) Ethereum design and implementation: These causes can be further divided into 14 sub-causes, which are related to, among other things, EVM, blockchain, PoW consensus, incentive mechanism, and P2P protocol. These causes cut across the application layer, the data layer, the consensus layer, and the network layer. The root causes related to EVM include: (i) missing input check, meaning no check on the validity of a transaction's data; (ii) missing orphan proof, meaning no check on a nonexistent recipient address; (iii) improper execution model, meaning the behavior of EVM is not properly specified; and (iv) improper gas costs, meaning the gas costs of EVM opcodes are not properly specified.
The root causes related to blockchain include: (i) flexible block creation, meaning there are no restrictions on miners when they creating blocks, allowing them to create blocks to favor themselves; (ii) insufficient transaction information, meaning that a transaction can be accepted by multiple Ethereum blockchains (e.g, ETH, ETC, Ropsten), rather than a specific blockchain, owing to the lack of information specifying a unique blockchain; and (iii) uncontrolled state trie, meaning that there are no restrictions on the accounts that can be stored in the state trie.
The root causes related to the PoW consensus protocol include: (i) partially sequential PoW, meaning that Ethereum's PoW puzzle can still be outsourced to different miners; (ii) inherent defect of PoW, meaning that a miner with 51% hashrate can extend the main chain at will; and (iii) termination first, meaning that the Ethereum consensus protocol prefers termination to agreement.
The root causes related to incentive mechanism include: (i) greedy incentive, meaning that a miner always selects transactions with higher ; and (ii) incompatible incentive, meaning that a miner can get a higher payoff by deviating from the consensus protocol.
The root causes related to the P2P protocol include: (i) improper RLPx protocol, meaning that the node discovery and routing algorithms are not properly designed; and (ii) improper Ethereum wire protocol, meaning that the blockchain synchronization algorithm is not properly designed.
The root causes mentioned above contributed 18 vulnerabilities, cutting across the application layer, the data layer, the consensus layer, and the network layer; 9 out of these 18 vulnerabilities are still largely open (i.e., having yet to be eliminated). In summary, we draw: Insight 3: The vulnerabilities caused by the design and implementation of the Ethereum blockchain are harder to cope with than the other vulnerabilities.
Insight 3 is interesting because it highlights the difficulty in designing and implementing a secure blockchain platform, despite (as we will see later) that the vulnerabilities in blockchain may not cause as big losses as the vulnerabilities at the application layer.

4) Human, usability and networking factors:
These causes can be further divided into four sub-causes: improper configuration, meaning that an Ethereum client is installed with incorrect permissions; insufficient authentication, meaning the use of weak or exposed passwords; faulty web development, meaning that a DApp's web interface is vulnerable; and exposed Internet service, meaning attacks coming from the Internet are not blocked. These causes led to seven vulnerabilities. In summary, we draw the following interesting insight.
Insight 4: Vulnerabilities in the Ethereum environment are largely caused by human, usability, and networking factors, which however consist of a smaller fraction of the vulnerabilities when compared with the vulnerabilities that are inherent to the Ethereum blockchain and smart contracts.

5) Cross-cutting analysis:
We observe that there are 13 vulnerabilities that are largely open. In order to draw insights into the approaches that may be able to eliminate them, we look deeper into their root causes (than what were mentioned above). First, we consider the vulnerabilities that are inherent to the Ethereum blockchain design, including: under-priced opcodes ( 23 ), which are inherent to the EVM gas cost mechanism; outsourceable puzzle ( 29 ), 51% hashrate ( 30 ), and fixed consensus termination ( 31 ), which are inherent to the PoW consensus mechanism; and DoS with block stuffing ( 32 ) and rewards for uncle blocks ( 33 ), which are inherent to the Ethereum incentive mechanism. In order to eliminate or mitigate these vulnerabilities, alternate gas cost mechanisms, consensus mechanisms, and incentive mechanisms may have to be used.
Second, we consider the vulnerabilities that are inherent to the implementation of Ethereum clients, including unlimited nodes creation ( 34 ), public peer selection ( 36 ), and sole block synchronization ( 37 ). In order to eliminate or mitigate these vulnerabilities, alternate network protocols may have to be used without sacrificing platform usability or network performance.
Third, we consider the vulnerabilities that are inherent to the insecure environment in which Ethereum runs, including unreliable BGP messages ( 43 ) and sensitive DNS servers ( 44 ). In order to eliminate or mitigate these vulnerabilities, extra effort must be made to defend the environment regardless how Ethereum is designed and implemented.
Fourth, we consider the vulnerabilities that are inherent to the application-layer flexibility, including upgradable contract ( 4 ) and type casts ( 18 ). In order to eliminate or mitigate these vulnerabilities, alternate contract design pattern and type system may have to be used.
Summarizing the preceding discussion, we draw: Insight 5: There are many vulnerabilities that are yet to be tackled in order to adequately defend Ethereum (or blockchainbased DApp systems in general), cutting across of every layer of the architecture, from the application layer, the data layer, the consensus layer, the network layer, down to the environment layer.

IV. ATTACKS
Corresponding to the presentation of vulnerabilities, we group the 26 attacks we consider according to the locations of the vulnerabilities they exploit. We describe each attack from the following perspective: its history, cause, tactic, and direct impact (i.e., the consequence when the attack succeeds). For ease of reference, we denote the 26 attacks by  1 , … ,  26 , respectively. Note that some of these 26 attacks may correspond to the same type of attacks (i.e., sharing the same name), but they exploit different vulnerabilities or vulnerability combinations and/or cause different consequences. For example, both  2 and  3 correspond to the parity multisignature wallet attack; however,  2 exploits the delegatecall injection vulnerability ( 2 ) and the erroneous visibility vulnerability ( 9 ) to cause the consequence of unauthorized code execution, while  3 exploits the frozen ether vulnerability ( 3 ) and the unprotected suicide vulnerability ( 10 ) to cause the consequence of DoS.
A. Attacks at the application layer 1) The DAO attack ( 1 ): The contract DAO is a financial application running on top of Ethereum. In June 2016, it was attacked to cause the loss of US$60M [8]. The financial application is that investors (i.e., token holders) vote on investment proposals for spending their money (i.e., "investment crowdsourcing"). Once a proposal is approved by a majority, the amount of money approved by the supporting investors is moved to the proposer's account, and the amount of money owned by the minority that opposes the proposal is respectively "refunded" to each of them via some newly created contract accounts. This mechanism was implemented in the splitDAO() function in Figure 8, which shows how the attack exploits the reentrancy vulnerability ( 1 ). Specifically, the attack proceeds as follows: When a minority investor who opposes the proposal requests for a "refund", the DAO contract creates a new DAO contract account (Step 1-2) and transfers the requesting investor's money to the new DAO contract account (Step 3-4). The requesting investor may receive a reward for its past contribution or activity (Step 5-6). The vulnerability is that the number of tokens "refunded" to the requesting investor depends on the state variables balances[msg.sender] and totalSupply, which are updated in the end of the splitDAO() function after the external call msg.sender.call.value(). This allowed the attacker to recursively call the splitDAO() function (Step 7) before the state variables are updated, causing a malicious investor to draw more money than it deserves [39].  2) Parity multisignature wallet attacks ( 2 and  3 ): In Ethereum, a multisignature wallet is a smart contract which requires multiple private keys to unlock a wallet in order to safeguard Ether or tokens. As shown in Figure 9, a multisignature wallet supported by the Parity client consists of two contracts: (i) a library contract called WalletLibrary, which implements all of the core functions of a wallet; and (ii) an actual Wallet contract, which holds a reference (i.e., _walletLibrary) that forwards all of the unmatched function calls to the library contract via delegatecall (Line 7). The Parity multisignature wallet was compromised twice in 2017, which are briefly reviewed below.
The first attack, denoted by  2 , exploited the delegatecall injection vulnerability ( 2 ) and the erroneous visibility vulnerability ( 9 ) to drain Ethers approximately worthy of US$31M. The attacker took over the ownership of contract Wallet by sending a transaction to the contract with msg.data containing initWallet() as the callee function (Line 13). Since contract Wallet did not provide a function named initWallet(), the contract's fallback function was triggered to delegate the wallet initialization task to the function initWallet() in WalletLibrary, which replaced the original multi-owner of contract Wallet with the attacker's address specified in msg.data. This attack succeeds when the following four conditions are satisfied simultaneously [42], [108]: (i) the function initWallet() in the library was not specified as an internal one, 1   meaning that it can be externally called via delegatecall; (ii) the WalletLibrary was actually a stateful contract, meaning that it can change the state of Wallet; (iii) the function initWallet() did not check whether the Wallet contract had already been initialized (if so, no more initialization should be done); (iv) the Wallet's fallback function did not check the function being called, but unconditionally forwarded any unmatched calldata to WalletLibrary, allowing unintended invocations.
The second attack, denoted by  3 , exploited the unprotected suicide vulnerability ( 10 ) and the frozen Ether vulnerability ( 3 ), freezing approximately US$280M in the affected wallets forever [109]. In response to the first attack, the Parity developers added a modifier, only_uninitialized, to protect function initWallet() such that a re-initialization of Wallet via delegatecall will throw an exception and be rejected by the modifier [110]. However, the shared WalletLibrary itself was left uninitialized, which allowed an attacker to bypass the only_uninitialized modifier and set himself as the owner of the WalletLibrary [111]. Once taking over the library, the attacker invoked the suicide method to kill the library, causing all of the Wallet contracts relying on the library unusable.

3) BECToken attack ( 4 ):
BECToken, an ERC-20 contract, was attacked in April 2018 by an exploitation of the integer overflow vulnerability ( 6 ), causing a massive amount of tokens stolen and a temporary shutdown of token trading at exchange [112]. The vulnerability was in the function batchTransfer() shown in Figure 10, and the function was meant for users to transfer tokens to multiple recipients via two arguments, one specifying the array of the recipients' addresses and the other specifying the respective number of tokens. The statement at Line 3 calculates the total number of tokens the sender should pay for a particular transaction, but may have the following integer overflow: By setting _value to 2 255 and _receivers to two accounts controlled by the attacker, the attack overflows the 256-bit variable amount and makes it zero [113]. As a consequence, the attack bypasses the two checks at Lines 4-5 and causes sending the two receivers extremely large numbers of tokens.    [114]. The contract has four vulnerabilities [12], which allowed the following four attack tactics and explains why  5 ,  6 ,  7 , and  8 belong to the same type of attacks. The first attack, denoted by  5 , exploits the DoS with unbounded operations vulnerability ( 14 ) that when the array bookkeeping the number of participants becomes too large, the amount of gas required for operating on the array will go beyond the maximum gas that is permitted for assembling a block. This effectively halts the transaction and the winner cannot receive the 1,100 ETH jackpot. The second attack, denoted by  6 , exploits the unchecked call return value vulnerability ( 15 ) that the contract does not check the returned value when sending profits to the winner and the call-stack depth limit vulnerability ( 22 ). As a consequence, the owner of contract GovernMental to fail the payment as follows: (i) Calling 1024 contracts before calling the target callee contract of the payee, which causes the callee contract to return FALSE to the caller contract, meaning that the callee contract does not receive the payment. (ii) The caller contract is supposed to check this returned value and then proceeds correspondingly but it does not. This causes the callee contract to lose money, which now belongs to the owner of the caller contract. The third attack, denoted by  7 , exploits the transaction-ordering dependence vulnerability ( 24 ) that a malicious miner can abandon some transactions related to GovernMental or reorder transactions to make itself the last player (i.e., winner) in each round. The fourth attack, denoted by  8 , exploits the timestamp dependence vulnerability ( 25 ) that a malicious miner can manipulate block.timestamp so that its own block appears to be the last block to make itself win.

5) HYIP attack ( 9 ):
The contract HYIP was another Ponzi scheme, which pays existing investors from funds contributed by new investors at the end of each day. This mechanism is implemented by the function performPayouts() highlighted in Figure 11, which contains the DoS with unexpected revert vulnerability ( 5 ) (Line 7) [114]. The attack proceeds as follows: (i) The attacker, say Alice, writes an exploitation contract, named Mallory, in which the attacker invests and throws an exception in the fallback function (Line 14). (ii) When function performPayouts() is called to pay the investors, the fallback function is invoked and throws an exception, causing a reversion of the money transfer (Line 7) and thus DoS to contract HYIP. (iii) The attacker can blackmail HYIP to pay a ransom for halting its attack, by undoing the throw operation (Line 15) via function stopAttack (Line 18), which can only be done by the contract owner, Alice. 1   6) Fomo3D attacks ( 10 and  11 ): The contract Fomo3D was an extremely popular Ponzi game in year 2018, where the last participant who buys a key before the timer runs out won the jackpot. The price of keys gradually grows with the number of buyers. When a key was sold, the countdown extends for 30 seconds. In addition to the jackpot winner, Fomo3D implemented an airdrop lottery to attract participants. For each purchase over 0.1 ETH, the participant (i.e., buyer) had a random chance to be picked up for a tiny profit from the prize pool. These two incentive mechanisms can be attacked as follows [115].
The first attack, denoted by  10 , is against the airdrop mechanism. Specifically, the attack exploited the generating randomness vulnerability ( 26 ). As shown in Figure 12, function airdrop() generates a random seed by performing a deterministic computation on the current block state (i.e., block.timestamp, block.difficulty, etc.) and the address of msg.sender (Line 2-8). If the seed satisfies a certain condition (Line 10), the current key buyer wins an airdrop. However, since the block information is predictable, an attacker can simply pre-compute the addresses of new contracts and brute-forces for the winning seed (Line 2).
The second attack, denoted by  11 , is against the winning mechanism [115]. Specifically, the attack exploited the DoS with block stuffing vulnerability ( 32 ) and causes the attacker to win the prize of approximately US$3M [94]. The attack proceeds as follows: When the timer of the game reached about three minutes, the attacker bought a key and then sent multiple transactions to his own accounts with high enough gasPrice.
Owing to the choice of miners, these transactions were first assembled into blocks. Since the maximum amount of gas consumption for a block is limited, any transactions related to Fomo3D were not assembled into blocks. By congesting the network until the game was over, the attacker succeeded in becoming the last player. ))); 7) ERC-20 signature replay attack ( 12 ): This attack, which was first reported in [116], exploits the insufficient signature information vulnerability ( 13 ). When a user transfers ERC-20 tokens, the user must have enough Ether to pay the transaction fee, which can be inconvenient when the user does not own any Ether. In order to alleviate the problem, the proxytransfer method is introduced such that a user can authorize a proxy to carry out a transaction and pay the proxy some extra tokens as its service fee. As shown in Figure 13, when Alice is to transfer 100 MTC tokens to Bob, she can send a signed message off-chain to a proxy (Step 1) such that the proxy launches a transaction to transfer 100 tokens to Bob and receives 3 token from Alice for the service (Step 2). A signature is verified using function transferProxy(), which uses the Solidity function ecrecover() (Line 5) to identify Alice's account address that issued the signature. However, Alice's off-chain message may not provide her token contract address, which should be bound to her signature. As a consequence, the signature can be accepted as valid with respect to any token contract address (e.g., MTC, UGToken, and GGoken), meaning that Bob can replay the signed message to other kinds of token contracts, such as UGToken (Step 4), to obtain extra money from Alice (Step 5) [57].

8) Rubixi attack ( 13 ):
The Rubixi contract is a Ponzi scheme which contains the erroneous constructor name vulnerability ( 17 ). The contract was originally named DynamicPyramid and was later renamed by the developer to Rubixi. However, the contract's constructor name was not updated accordingly, allowing anyone that calls the public function DynamicPyramid() to become the owner of the contract and therefore steal the funds of the contract.

B. Attacks at the data layer 1) ETH and ETC cross-chain replay attack ( 14 ):
Ethereum had a hard fork after the DAO attack, splitting into ETH and ETC that share the same transaction history. This means that a transaction that was validated by the ETH network could also be accepted by the ETC network when the recipient immediately rebroadcast the transaction on the ETC network, and vice versa [117]. Since both ETC and ETH networks did not implement any defense against this attack that exploited the indistinguishable chains vulnerability ( 27 ), exchanges participating in both chains (e.g., Coinbase and Yunbi) lost a large amount of money [85].
Specifically, the first attack, denoted by  15 , exploited the under-priced opcodes vulnerability ( 23 ) owing to the improper gas cost of EVM's EXTCODESIZE opcode. Prior to the EIP 150 hard fork, the EXTCODESIZE opcode only charged 20 gas for reading a contract's bytecode from disk and then deriving its length. As a consequence, the attacker can repeatedly send transactions to invoke a deployed smart contract with many EXTCODESIZE opcodes to cause a 2-3x slower block creation rate [75].
The second attack, denoted by  16 , exploited the underpriced opcodes vulnerability ( 23 ) owing to the improper gas cost of EVM's SUICIDE opcode and the empty account in the state trie vulnerability ( 28 ). The SUICIDE opcode (renamed to SELFDESTRUCT after EIP 6) is meant to remove a deployed contract from the blockchain and send the remaining balance of Ether to the account designated by the caller. When the target account does not exist, a new account is created even though no Ether may be transferred; this consumes merely 90 gas [76]. Since an existing empty account is stored in the Ethereum state trie, the attacker created 19 million new empty accounts via the SUICIDE opcode at a low gas consumption, which wasted considerable disk space while increasing the synchronization and transaction processing time.
C. Attacks at the consensus layer 1) Ethereum Classic (ETC) 51% attack ( 17 ): In January 2019, ETC suffered from a 51% attack that exploited the 51% hashrate vulnerability ( 30 ), in which the attacker carried out double-spending transactions against several exchanges, causing an estimated loss of US$1.1M [118]. Since 2018, ETC's mining hashrate had dropped significantly due to the declining in its price, which lowered the amount of computing resources that are required for launching a 51% attack. Moreover, cloud mining services (e.g., NiceHash) make it even easier to launch 51% attacks. The attack was disrupted when exchanges increased the number of blocks that are required for transaction confirmation and limited the participation of malicious addresses in ETC trade.

2) Selfish-mining attack ( 18 ):
The selfish-mining attack, which exploits the rewards for uncle blocks vulnerability ( 33 ), means that miners may withhold their newly mined blocks and selectively publish some of their blocks to earn an unfair share of reward. A selfish miner continuously monitors the situation on a blockchain's public branches, estimates its advantages, and reveals its private blocks accordingly. When the public branches are shorter than the selfish-miner's private branch, the honest miners will switch to latter, rendering their previous mining effort useless and making the selfish-miners receive a higher reward. Ritz et al. [96] conducted a Monte Carlo simulation to emulate the block generation process in Ethereum and quantified the impact of uncle rewards on selfish-mining. Their simulation results showed that the uncleblock reward mechanism not only lowered the threshold of computational power at which selfish-mining becomes profitable, but also weakened the overall resilience against other attackers such as double-spending. Niu et al. [33] developed a mathematical analysis on a selfish-mining strategy through a 2-dimensional Markov process model, showing that Ethereum is more vulnerable to selfish-mining than Bitcoin.

3) Balance attack ( 19 ):
This attack exploits the fixed consensus termination vulnerability ( 31 ) owing to the probabilistic PoW consensus in the presence of communication delays (or asynchronous networks) and the unreliable BGP messages vulnerability ( 43 ). This attack was first reported in [119] via a theoretic analysis and testnet demonstration. The attack is to transiently partition the network into multiple subgroups of similar mining power so as to launch the doublespending attack at a subgroup of lower mining power. This allows the attacker to initiate transactions with merchants in one subgroup, while mining blocks in another subgroup to make its subtree outweighs the subtree mined in the victim group. After transactions in the victim subgroup get confirmed, the attacker reconnects the network. Since the mining power is roughly equally distributed among the subgroups, the subtree broadcast by the attacker has a good chance to be selected as the main chain, meaning that the attacker can double-spend in the victim subgroup. This attack was later deemed only theoretically possible because partitioning a public Ethereum network (e.g., using BGP-hijacking) may not be feasible in practice [120].
D. Attacks at the network layer 1) Account hijacking attack ( 20 ): This attack exploits the RPC API exposure vulnerability ( 38 ). In order to sign transactions, an EOA must first decrypt its private key that is stored on the local host and encrypted with a passphrase. This can be achieved by using the unlockAccount() API of an Ethereum client, which uses the passphrase to obtain the private key and loads it into the memory for 300 seconds (by default). The private key in memory can be accessed by any Ethereum API without authentication. This can be exploited as follows. Ethereum clients (e.g., Geth, Parity) typically use the default ports 8545 (HTTP) and 8546 (WebSocket) for the JSON-RPC interface. However, these client software neither configure those ports as local-only by default, nor adopt precautions (e.g., disabling remote calls). This allows an attacker to scan open Ethereum nodes and invoke eth_sendTransaction() API to transfer victims' money to the attacker's account. Once a victim types its passphrase to unlock its account, the eth_sendTransaction() API will be successfully executed. By the time the attack was observed in March 2018 [100], attackers had already stolen around US$20M from exposed Ethereum clients.
2) Eclipse attacks ( 21 and  22 ): This attack allows an attacker, who can hijack the connections of some victim nodes in the P2P network, to create a virtual partition to isolate those victim nodes from the rest of the network. Victim nodes' connections can be hijacked at least by connection monopolization and poisoning victims' routing tables [35]. The connection monopolization attack, denoted by  21 , exploits the unlimited nodes creation vulnerability ( 34 ) and the uncapped incoming connections vulnerability ( 35 ). When a client reboots, it has no incoming or outgoing connections. An attacker can create plenty of node IDs in advance and initiate enough incoming connections to the victim node immediately after its reboot. A node is eclipsed when its connection slots (25 by default) are occupied by incoming connections from the attacker. Despite the response to the aforementioned connection monopolization attack in imposing an upper limit on the number of incoming TCP connections, the following attack, denoted by  22 , still can succeed. Specifically, an attacker still can exploit the public peer selection vulnerability ( 36 ) to poison the victim nodes' routing tables when these tables are reboot and reset (e.g., the attacker could craft fake nodes and insert them into those routing tables to make the victim nodes' outgoing TCP connections point to the fake nodes controlled by the attacker). The attacker can further occupy the victim nodes' remaining connection slots by initiating connections to the victim nodes.
E. Attacks against the environment 1) EtherDelta attack ( 23 ): EtherDelta is a popular exchange for users to trade ERC-20 tokens. It suffered from a code injection or EtherDelta attack that exploited the Cross-Site Scripting vulnerability ( 40 ) in September 2017, causing a loss in cryptocurrency worth of thousands of dollars [103]. The attacker constructed a new token contract, which contains a piece of malicious JavaScript code in the token's name. Recall that EtherDelta extracts a newly created token's name from the token contract's code and displays the name on the exchange's website. Recall also that when performing a tokentrade transaction, a user needs to load its private key and account address to the web browser for signing the transaction. As a consequence, when the name of a newly created token was displayed on the user's browser, the malicious JavaScript code was executed to steal the user's private key from the browser, causing the loss of money protected by the private key.
2) CoinDash attack ( 24 ): CoinDash, a portfolio management platform, was compromised due to an exploitation of the broken access control vulnerability ( 42 ) during the course of its ICO in Jul 2017, causing the loss of US$7M worth of Ether within a few minutes. The attack proceeds by getting into the infected web application that hosts CoinDash's webpage, and replacing the ICO contract address with one that is controlled by the attacker [104].
3) Enigma attack ( 25 ): Enigma, a decentralized investment platform, was attacked prior to its ICO in August 2017 [102], owing to the exploitation of the weak password vulnerability ( 39 ). Through social engineering means, the attacker successfully stole an Enigma founder's password, which was disclosed in an unrelated attack and reused in Enigma. As a consequence, the attacker took control of the company's Slack channel, email lists, and Google account hosting the ICO's presale. The attacker replaced the official ICO contract address with the attacker's own address and sent messages to solicit buyers in fake presales.

4) MyEtherWallet attack ( 26 ):
MyEtherWallet, a popular web-based wallet, was attack in April 2018 owing to the exploitation of the unreliable BGP messages vulnerability ( 43 ), the sensitive DNS vulnerability ( 44 ), and the unvalidated URL redirection vulnerability ( 41 ). The attack exploits a joint BGP and DNS hijacking to mislead users to a fake version of the website and compromised the victims' private keys [10]. The hacker then emptied the victims' wallets and stole approximately US$17M. The attacker first exploited a routing weakness in BGP and hijacked the traffic to Amazon's Route 53 servers, which provided DNS service to MyEtherWallet. When users visit their MyEtherWallet, their requests were rerouted to the fake DNS servers controlled by the attacker, which returned IP addresses to direct users to a phishing website. The unsuspecting users, who neglected the TLS/SSL certificate warning sign, proceeded to login to the phishing site, causing their passphrases and private keys exposed.

F. Further analysis of attack consequences
Now we present a taxonomy of the attack consequences mentioned above: unauthorized code execution, DoS, unfair income, double-spending, private key leakage, and webpage manipulation, which are elaborated below. Figure 14 highlights the relationship between these attack consequences, attacks, and vulnerabilities, where the vulnerabilities and attacks are ordered in such a way that allows us to clearly present the relationships between them (i.e., neither the vulnerabilities nor the attacks are ordered as they are discussed in the text). For ease of reference, we use " ( , ⋯)" to denote that attack  exploits vulnerabilities  and possibly others.
2) DoS: This consequence can be further divided into two sub-consequences: DoS against smart contracts and DoS against Ethereum network. The former sub-consequence occurs in one of the following four scenarios: (i) The attacker wages the second Parity multisignature wallet attack ( 3 ) to exploit the frozen Ether vulnerability ( 3 ) and the unprotected suicide vulnerability ( 10 ), namely  3 ( 3 ,  10 ). (ii) The attacker uses the HYIP attack ( 9 ) to exploit the DoS with unexpected revert vulnerability ( 5 ), namely  9 ( 5 ). (iii) The attacker uses the GovernMental attack ( 5 ) to exploit the DoS with unbounded operations vulnerability ( 14 ), namely  5 ( 14 ). (iv) The attacker uses the Fomo3D attack ( 11 ) to exploit the DoS with block stuffing vulnerability ( 32 ), namely  11 ( 32 ). The latter sub-consequence occurs in one of the following scenarios: (i) The attacker uses the underpriced DDoS attack ( 15 ) to exploit the under-priced opcodes vulnerability ( 23 ), namely  15 ( 23 ). (ii) The attacker uses the under-priced DDoS attack ( 16 ) to exploit the under-priced opcodes vulnerability ( 23 ) and the empty account in the state trie vulnerability ( 28 ), namely  16 ( 23 ,  28 ). The biggest financial loss caused by a single DoS attack is US$280M, owing to the second attack against the Parity wallet ( 3 ) [109].
3) Unfair income: This consequence occurs in one of the following scenarios: (i) A malicious contract owner uses the GovernMental attack ( 6 ) to exploit the unchecked call return value vulnerability ( 15 ) and the call-stack depth limit ( 22 ) vulnerability to hold the money that should be transferred to a callee contract or EOA, namely  6 ( 15 ,  22 ). (ii) A malicious miner wages the GovernMental attack ( 7 ) to exploit the transaction-ordering dependence vulnerability ( 24 ), namely  7 ( 24 ). (iii) A malicious miner wages the GovernMental attack ( 8 ) to exploit the timestamp dependence vulnerability ( 25 ), namely  8 ( 25 ). (iv) The attacker wages the Fomo3D attack ( 10 ) to exploit the generating randomness vulnerability ( 26 ) to make itself the winner, namely  10 ( 26 ). (v) An attacker uses the ERC-20 signature replay attack ( 12 ) to exploit the insufficient signature information vulnerability ( 13 ), namely  12 ( 13 ). (vi) The attacker uses the ETH and ETC cross-chain replay attack ( 14 ) to exploit the indistinguishable chains vulnerability ( 27 ) to repeatedly withdraw money, namely  14 ( 27 ). (vii) A malicious miner wages the selfish mining attack ( 18 ) to exploit the rewards for uncle blocks vulnerability ( 33 ) to get a higher mining reward, namely  18 ( 33 ). The biggest financial loss caused by a single unfair income attack is US$0.5M, owing to an ETH and ETC 7) Summary and insights: Table II summarizes the aforementioned attacks, the layers at which the vulnerabilities they exploit reside, attack consequences, and financial losses incurred by those attacks. This allows us to draw the following insights: Insight 6: The biggest financial loss in the Ethereum system is $280M, which is caused by a DoS attack against the Parity wallet that disabled a library that is used by many contracts.
Insight 6 is interesting at least from two points of view. First, DoS often causes indirect economic losses incurred by the unavailability of services. The DoS attack against Ethereum manifests direct economic losses. Second, the DoS attack is caused by code-reuse, which is a widely adopted practice in the traditional paradigm of programming. However, in the paradigm of DApps, code-reuse may impose a higher risk than ever, highlighting the importance of security auditing for popular contracts as well as the libraries they use. Insight 7: DApps running on top of the Ethereum blockchain are not fully decentralized when they use centralized web interfaces.
Insight 7 is interesting because it points out one scenario that manifests that blockchain-based systems are not necessarily decentralized, despite the popular view. Indeed, vulnerabilities in those web interfaces can cause large financial losses. This highlights the importance of decentralizing the web interfaces to the blockchain-based systems.
Insight 8: Application-layer attacks have caused the largest financial losses among the attacks against Ethereum.
Insight 8 is interesting because a vulnerability at a lower layer would often cause a larger damage than a vulnerability at a higher layer. This rule of thumb does not necessarily apply to Ethereum or blockchain-based systems in general. This can be (at least partly) attributed to the fact that DApps operate directly on the digital assets, and highlights the importance of assuring application-layer security.

V. DEFENSES
In this section, we describe the 47 defenses that have been proposed for securing the Ethereum ecosystem, which are denoted by  1 , … ,  47 , respectively. Unlike vulnerabilities and attacks which naturally correspond to some layer of the Ethereum architecture, defenses are by no means geared towards the layers. Therefore, we propose categorizing them into two classes: proactive defenses and reactive defenses.

A. Proactive defenses
We categorize existing proactive defense mechanisms into the following five sub-classes based on the respective focuses of these mechanisms: contract programming language, contract development, contract analysis, contract and Ethereum enhancement, and consensus protocols.
1) Language-based security: Programming language approaches to securing smart contracts can be divided into two categories: high-level languages for developing more secure smart contracts and intermediate-level languages for facilitating contract formal analysis.
a) High-level languages: Vyper [121] ( 1 ) removes a number of functionalities provided by Solidity (e.g., recursive calling, infinite loops, modifiers) and adds several new features (e.g., bounds and overflow checking) to eliminate vulnerabilities, such as the DoS with unbounded operations vulnerability ( 14 ), the erroneous visibility vulnerability ( 9 ), and the Integer overflow and underflow vulnerability ( 6 ). Bamboo [122] ( 2 ) uses polymorphism to mitigate the transactionordering dependence vulnerability ( 24 ), while eliminating the reentrancy vulnerability ( 1 ) and the DoS with unbounded operations vulnerability ( 14 ). Obsidian [123] ( 3 ) models smart contracts as finite state machines and tracks contracts' states to eliminate the reentrancy vulnerability ( 1 ). Flint [124] ( 4 ) uses an Asset type to assure the atomicity of operations and introduces restrictions on callers' capabilities to protect contract functions from unauthorized access, while aiming to eliminate the reentrancy vulnerability ( 1 ), the erroneous visibility vulnerability ( 9 ), the Integer overflow and underflow vulnerability ( 6 ), and the timestamp dependency vulnerability ( 25 ).
b) Intermediate-level languages: Simplicity [125] ( 5 ) is an intermediate representation between high-level languages and low-level virtual machine. It provides formal semantics using the proof-assistant Coq [126], thus allowing formally analysis of contracts properties (e.g., safety and liveness). Scilla [127] ( 6 ) distinguishes in-contract computation from inter-contract communication to disentangle contract-specific effects from each other.
2) Contract development: Since smart contracts are a new programming paradigm, these defenses can help developers in avoiding or mitigating common vulnerabilities. a) Principles and best practices: A number of Solidity best practices were recommended in [11], such as check, update, then interact (i.e., checking conditions first, then updating state variables, and finally interacting with other contracts); favor pull over push for external calls (i.e., letting a recipient withdraw or "pull" the money set by the sender, rather than letting the sender directly transfer or "push" the money to the recipient). In order to make it easier for practitioners to adopt those best practices, we systematize 19 best practices ( 7 ) according to the vulnerabilities towards which they are geared, while noting that 15 of these 19 best practices were scattered in [11], [54], [44]. Our systematization leads to 4 general principles or 6 specific sub-principles in total. Figure 15 highlights these (sub-)principles. Intuitively, a programmer should be conscious of four kinds of controls: call control, data control, resource control, and tool control. (i) The call control principle says that a programmer should secure the interactions between smarts contracts and the interactions between EOAs and smart contracts. This principle is further divided into two sub-principles: one coping with the callee's unexpected behaviors and the other coping with the caller's access control. (ii) The data control principle says that a programmer should secure the data flow of a contract. This principle is further divided into two sub-principles: one dealing with the protection of sensitive data and the other dealing with the prevention of malformed data from entering a smart contract. (iii) The resource control principle says that a programmer should mitigate the exhaustion of available gas in Ethereum. (iv) The tool control principle says that a programmer should use updated tools (e.g., compiler, debugger) to eliminate known vulnerabilities. b) Software engineering mechanisms: In order to defend against attacks that may exploit unknown vulnerabilities, several blockchain-oriented software engineering mechanisms were introduced [128] ( 8 ), such as: the rate limit mechanism, which restricts the number of consecutive actions incurred by an EOA or restricts the amount of Ether sent by a contract within a period of time; the balance limit mechanism, which regulates the maximum amount of funds that can be held by a contract; the speed bump mechanism, which postpones some potentially-damaging operations.
3) Smart contract analysis: These defenses aim to enhance security of smart contracts via the following approaches: symbolic execution, abstract interpretation, formal verification, fuzzing and model-based vulnerability detection. a) Symbolic execution: It works on a program' controlflow graph (CFG) and traverses all of the feasible execution paths on the graph to identify vulnerabilities [129]. This approach achieves neither soundness (i.e., zero false-negatives) nor completeness (i.e., zero false-positives), owing to the omission of some execution paths and the exploration of unreachable paths in real executions. Oyente [63] ( 9 ) can detect four types of vulnerabilities -the reentrancy vulnerability ( 1 ), the mishandled exceptions vulnerability ( 15 ), the transaction-ordering dependence vulnerability ( 24 ), and the timestamp dependence vulnerability ( 25 ) -but incurs a high false-positive rate [64]. Maian [55] ( 10 ) extends Oyente by considering multiple invocations of a contract, rather than a single invocation. It can detect three types of vulnerabilities: the frozen Ether vulnerability ( 3 ), the leaking Ether to arbitrary address vulnerability ( 11 ), and the unprotected suicide vulnerability ( 10 ). Mythril [130] ( 11 ) uses "concolic analysis", which integrates symbolic and concrete execution of a smart contract, to detect 8 types of vulnerabilities, such as the manipulated balance vulnerability ( 7 ), the authentication through tx.origin vulnerability ( 8 ), and the generating randomness vulnerability ( 26 ). The teEther tool [43] ( 12 ) can detect vulnerabilities like the erroneous visibility vulnerability ( 9 ) and the erroneous constructor name vulnerability ( 17 ). The sCompile tool [131] ( 13 ) reduces the number of suspicious execution paths that are not related to money-transfer. It can detect 4 types of vulnerabilities: the reentrancy vulnerability ( 1 ), the frozen Ether vulnerability ( 3 ), the unprotected suicide vulnerability ( 10 ), and the Ether lost to orphan address vulnerability ( 21 ). ECF [132] ( 14 ) focuses on detecting callback-related vulnerabilities, such as the reentrancy vulnerability ( 1 ).  b) Abstract interpretation: Abstract interpretation aims to over-approximate the semantics of a program so as to achieve soundness in program analysis [133]. Securify [134] ( 15 ) defines a set of compliance and violation patterns to characterize how contract comply and violate security properties extracted from some known vulnerabilities, such as the reentrancy vulnerability ( 1 ), the delegatecall injection vulnerability ( 2 ), and the frozen Ether vulnerability ( 3 ). Figure 16 highlights how these patterns can be used to detect vulnerabilities. Zeus [64] ( 16 ) defines a set of correctness and fairness policies and then embeds them as assert statements into the source code of contracts. It can detect six types of vulnerabilities, such as the reentrancy vulnerability ( 1 ) and the unchecked call return value vulnerability ( 15 ). FSolidM [135] ( 17 ) abstracts smart contracts as finite state machines and can detect the reentrancy vulnerability ( 1 ) and the transaction-ordering dependence vulnerability ( 24 ). MadMax [62] ( 18 ) disassembles EVM bytecode into an intermediate representation and then leverages both dataflow analysis and context-sensitive flow analysis to detect gas-related vulnerabilities, such as the DoS with unbounded operations vulnerability ( 14 ). Vandal [136] ( 19 ) translates EVM bytecode into logic relations and use them to detect a number of vulnerabilities, such as the reentrancy vulnerability ( 1 ), the authentication through tx.origin vulnerability ( 8 ), the unprotected suicide vulnerability ( 10 ), and the unchecked call return value vulnerability ( 15 ).
In order to facilitate the aforementioned high-level contract analysis, several reverse engineering tools have been developed to convert EVM bytecode to source code or intermediate presentation. Porosity [137] ( 20 ) is a decompiler for producing Solidity source code from EVM bytecode. Erays [138] ( 21 ) lifts EVM bytecode to a high-level pseudocode by recovering the control-flow structure and transforming EVM from a stack-based machine to a register-based machine. EthIR [139] ( 22 ) decompiles EVM bytecode to a high-level rule-based representation, which can then be fed into an automated static analyzer to infer high-level properties of the EVM bytecode.
Interactive theorem prover c) Formal verification: Formal verification proves the correctness of contract implementation with respect to a specification. This approach assures the completeness (i.e., no false positives). Figure 17 illustrates how to use theorem-proving to verify smart contracts at the EVM bytecode-level. Hirai [140] ( 23 ) took the first step towards formalizing the EVM semantics, which can be accommodated by interactive theorem provers like Isabelle/HOL [141] to prove invariants and safety properties of smart contracts. Amani et al. [142] ( 24 ) extend the work in [140] by splitting a contract into some basic blocks and then using a Hoare-style program logic to reason about semantic properties of contracts from properties of its parts. Hildenbrandt et al. [143] ( 25 ) present a complete semantics of the EVM, referred to as KEVM, using the framework [144] to achieve language-independent program verification. Park et al. [145] ( 26 ) optimize the KEVM verifier by introducing EVM-specific abstractions and lemmas to avoid non-tractable reasoning in the underlying theorem prover. Grishchenko et al. [146] ( 27 ) define a complete smallstep semantics of EVM bytecode and formalize most of the semantics in the proof assistant F* [147]. Grishchenko et al. [148], [149] ( 28 ) leverage the complete small-step semantics of EVM bytecode to build EtherTrust, which is the first sound and automated static analyzer to achieve formal security related to the reachability properties of EVM bytecode. Other early-stage investigations include [150], [151], [152]. d) Fuzzing: Fuzz testing has been used to detect vulnerabilities in smart contracts. ContractFuzzer [46] ( 29 ) can detect five types of smart contract vulnerabilities, such as the reentrancy vulnerability ( 1 ) and the unchecked call return value vulnerability ( 15 ). It generates inputs by crawling the ABI interfaces of smart contracts to extract their function selectors and data types of each argument, and instruments EVM to log contract execution behaviors for inspection. Re-Guard [153] ( 30 ) aims to detect the reentrancy vulnerability ( 1 ) in smart contracts by transforming smart contracts to semantically equivalent C++ program and generating random transactions via a fuzzing engine to check the execution traces of the C++ program. e) Model-based vulnerability detection: Tann et al. [154] ( 31 ) use sequence learning to detect three types of vulnerabilities, namely the frozen Ether vulnerability ( 3 ), the leaking Ether to arbitrary address vulnerability ( 11 ), and the unprotected suicide vulnerability ( 10 ). Tikhomirov et al. [155] ( 32 ) propose SmartCheck to detect vulnerabilities in Solidity contracts by translating Solidity source code into an XML-based parse-tree and checks it against specific XPath patterns; they can detect 10 types of vulnerabilities, such as the DoS with unexpected revert vulnerability ( 5 ), the manipulated balance vulnerability ( 7 ), but incur a high false-positives rate.

4) Contract and Ethereum enhancement:
Kosba et al. proposed the Hawk [156] ( 33 ) framework for incorporating cryptographic mechanisms to hide transaction data, effectively allowing contract developers to build privacy-preserving smart contracts without asking them to implement any cryptography. This framework can be used to defend against attacks that exploit the secrecy failure vulnerability ( 12 ) and the transaction-ordering dependence vulnerability ( 24 ). Zhang et al. [157] ( 34 ) designed an authenticated data feed system, dubbed Town Crier, for smart contracts that require access to external data. This system can be used to mitigate the generating randomness vulnerability ( 26 ). Adler et al. [158] ( 35 ) extended Town Crier by implementing a voting-based decentralized oracle to address the centralized point-of-failure that is inherent to Town Crier. Chen [77] ( 36 ) proposed an adaptive gas cost mechanism, which dynamically adjusts the cost of EVM operations according to their execution times, so as to defend against DoS attacks that exploit the under-priced opcodes vulnerability ( 23 ). In order to harden the Ethereum network against eclipse attacks, Marcus et al. [35] ( 37 ) proposed a set of countermeasures for eliminating some complicated artifacts of the Kademlia protocol used by Ethereum. Wang et al. [101] ( 38 ) proposed some countermeasures for defending Ethereum clients against the attacks that may exploit the RPC API exposure vulnerability ( 38 ).

5) New blockchain protocols:
In order to tackle the outsourceable puzzle vulnerability ( 29 ), Miller et al. [88] ( 39 ) formalized the notion of non-outsourceable puzzles and employed Merkle-tree-based proofs for puzzle design. The basic idea underlying non-outsourceable puzzles is: If a pool operator outsources the mining task other miners, the miners can collect the full credit while the pool operator gets nothing, which effectively disincentivizes pool operators from outsourcing their mining tasks. Zeng et al. [159] ( 40 ) extended the work of [88] by proposing a non-outsourceable puzzle that is compatible with the GHOST protocol used by Ethereum. Daian et al. [89] ( 41 ) designed a two-stage non-outsourceable puzzle where the outer puzzle relies on the solution to the inner puzzle.
In order to mitigate the 51% hashrate vulnerability ( 30 ), Eyal et al. [160] ( 42 ) proposed the two-phase proof of work (2P-PoW) mechanism to disincentivize large mining pools, by incorporating two separate puzzles (instead of one) for miners to solve. Luu et al. [161] ( 43 ) implemented a new decentralized pooled mining protocol to defend against mining centralization, by replacing the traditional mining pool operator with an Ethereum smart contract.

B. Reactive defenses
Reactive defenses aim to react to potential exploitations of (unknown) vulnerabilities during the contract runtime to mitigate the damage. A runtime verification method monitors the execution traces to detect and possibly react to suspicious activities that may violate certain properties. DappGuard [162] ( 44 ) actively monitors the incoming transactions to a smart contract and leverages the aforementioned tool Oyente [63] to decide whether or not an incoming transaction can cause a security violation and if so, a counter transaction can be invoked to kill the contract in question. ContractLarva [163] ( 45 ) generates a new Solidity contract from the original contract and its specification, checks the original contract's runtime behaviors against this new contract's, and takes appropriate actions in the case of any discrepancy. Sereum [40] ( 46 ) uses taint analysis to monitor runtime data flows during smart contract execution for detecting and preventing the reentrancy vulnerability ( 1 ).
When detecting a violation, various mechanisms ( 47 ) have been proposed for mitigating the damage: (i) disabling the vulnerable smart contract or sensitive functionalities by using (for example) the emergency stop mechanism [164]; (ii) adopting a stake-placing mechanism to assure that any invocation, which potentially violates some properties, should pay a stake of compensation before running the contract and returns the stake back to the caller after the contract terminates normally; (iii) replacing vulnerable contracts with secure ones using the virtual upgrade mechanism [128], which can be realized by using a registry contract to hold the address of the latest version of a contract or by introducing a proxy contract to delegate calls to the latest version of a contract.

C. Further analysis based on defense capabilities
Now we present an analysis of defenses from the perspective of defense capabilities, meaning which defense can defend against the attacks that exploit certain vulnerabilities. Figure 18 plots the Vern diagram of the 6 kinds of defenses discussed above, including 5 kinds of proactive defenses (i.e., alternate language, contract analyzer, security enhancement, contract best practices, blockchain protocols) and 1 kind of reactive defenses (i.e., runtime verification). For proactive  defense, we observe the following: (i) using contract best practices in the course of developing contracts can prevent or mitigate attacks that attempt to exploit 22 types of applicationlayer vulnerabilities; (ii) using smart contract analyzer can detect or mitigate attacks that attempts to exploit 18 types of application-layer vulnerabilities; (iii) using security enhancement can prevent or mitigate attacks that attempts to exploit 8 types of vulnerabilities, including 4 application-layer vulnerabilities and 4 network-layer ones; (iv) using betterdesigned contract programming language (i.e., alternate languages for short) can prevent or mitigate attacks that attempt to exploit 6 types of application-layer vulnerabilities; (v) using better-designed blockchain protocols can mitigate attacks that attempt to exploit 2 types of consensus-layer vulnerabilities. For reactive defense, we observe that using runtime verification can mitigate attacks that attempt to exploit 4 types of application-layer vulnerabilities. In total, proactive defenses can defend against attacks that attempt to exploit 29 types of vulnerabilities, whereas reactive defenses can defend attacks that attempt to exploit 4 types of vulnerabilities, which are also covered by proactive defenses. Moreover, we observe that the vulnerabilities that can be defended by alternate languages and runtime verification are subsets of the vulnerabilities that can be defended by contract analyzers, which are in turn a subset of the vulnerabilities that can be defended by contract development best practices. We draw the following insights. Insight 9: Industry has come up with a significant set of best practices for guiding the development of smart contracts.
Insight 9 highlights the importance of adopting best practices in the process of developing software. Nevertheless, these best practices alone are not adequate in assuring security.
Insight 10: Proactive defenses can defend against attacks that attempt to exploit many vulnerabilities. In contrast, reactive defenses can defend against attacks that attempt to exploit a few vulnerabilities.
Insight 10 reflects the state-of-the-art. Nevertheless, reactive defenses are still important because they may be able to defend attacks that attempt to exploit vulnerabilities that survived proactive defenses.

D. Further analysis based on defense investment
Now we present an analysis of defenses from the perspective of defense investment, meaning how much effort has been invested in designing defense against attacks that exploit a certain vulnerability. However, we note that some defenses are not geared towards any specific vulnerabilities or attacks; for example, software engineering mechanisms (i.e.,  8 ) are neither geared towards any specific vulnerability nor geared towards any specific attack.  Figure 19 plots the summary of the number of defense mechanisms with respect to individual vulnerabilities. Table  III elaborates which vulnerabilities may be protected by which defenses. For example, Figure 19 shows that  1 can be defended by 17 defenses; Table III shows which these 17 defenses are. On one hand, we observe that the most extensively investigated vulnerability is the reentrancy vulnerability ( 1 ), which can be mitigated by 17 kinds of proactive and reactive defense mechanisms. Other vulnerabilities that have been substantially investigated include: the unchecked call return value vulnerability ( 15 ) and the transaction-ordering dependence vulnerability ( 24 ), each of which can be defended by 9 kinds of proactive and reactive defense mechanisms; the frozen Ether vulnerability ( 3 ) and the timestamp dependence vulnerability ( 25 ) can be defended by 7 kinds of proactive defense mechanisms. It appears that the vulnerabilities that have been thoroughly investigated are (i) the ones that have caused large financial losses, (ii) the ones that are inherent to the design of the Solidity language, and (iii) the ones that are inherent to the profit-making factor for assembling blocks. This is so because the reentrancy vulnerability ( 1 ) has caused the loss of US$60M in the DAO attack (i.e., attack  1 in Figure 14), the frozen Ether vulnerability ( 3 ) has caused the loss of US$280M in the Parity wallet attack (i.e., attack  3 ), the unchecked call return value vulnerability ( 15 ) is inherent to the exception handling mechanism in the Solidity language, the transaction-ordering dependence vulnerability ( 24 ) is inherent to the unpredictable nature of the Ethereum blockchain, and the timestamp dependence vulnerability ( 25 ) is inherent to the manipulable block in-formation of the Ethereum blockchain. On the other hand, we observe 19 vulnerabilities that have zero or one defense mechanism. Most of these vulnerabilities are either caused by the Ethereum design and implementation, or reside in the Ethereum environment. This leads to: Insight 11: There is a large discrepancy between the effort that has been invested to defend against attacks that exploit different vulnerabilities.
Insight 11 is interesting because it seems that the defense effort has been driven by the consequential financial loss incurred by the exploitation of certain vulnerabilities. This prioritization strategy is not adequate because it suggests in a sense that the defender is always chasing behind the attacker, who detects and exploits an vulnerability that then becomes known to the defender.
Insight 12: Existing studies focus on defending against attacks that attempt to exploit vulnerabilities in the DApp backend (i.e., smart contracts), but largely ignore the protection of the DApp front-end (i.e., browser) and the interactions between the front-end and the back-end.
Insight 12 says that in order to adequately defend DApps, a good solution should consider the front-end interface, the backend contracts, and their interactions. It is worth mentioning that attacks  23 ,  24 ,  25 , and  26 have exploited either the front-end interface or the front-end and back-end interactions to cause the loss of over US$24M in total.

VI. DISCUSSION: GOING BEYOND ETHEREUM
The preceding discussion is geared towards the Ethereum system and offers a number of open problems for future research. While the findings and (some of) the open problems might be applicable to blockchain-based systems in general, in what follows we discuss future research directions that are equally applicable to Ethereum and blockchain-based systems.

A. Rigorous definition of properties
We observe that in order to adequately defend Ethereum and blockchain-based systems, there is an urgent need to understand the desirable security properties, which are however extremely difficult to formalize for a complex system like Ethereum. Some informal properties have been discussed in [165], which represents a very preliminary first step towards the ultimate goal. This leads to: Insight 13: There is a lack of deep understanding on the rigorously-specified desirable security properties that should be possessed by Ethereum and blockchain-based systems.

B. Rigorous analysis methodologies
Having defined the rigorous properties that should be satisfied by Ethereum and blockchain-based systems, we need principled and rigorous methodologies to analyze that the desirable properties are indeed satisfied. For properties that are geared towards building-blocks, cryptography and formal methods have been two successful approaches, while noting that they have their own limitations. Since blockchain-based systems, such as Ethereum, as indeed complex systems, it is  probably infeasible to prevent all attacks, meaning that attacks are inevitable and their risks must be adequately understood manageable. This calls for rigorous analysis methodologies from a holistic perspective. Towards this ultimate goal, the recently proposed approach of cybersecurity dynamics [166], [167], [168], [169], [170], [171], [172], [173], [174] has a great potential, although we are not aware of any results that have been published in the literature. This leads to: Insight 14: There is a lack of deep understanding on the rigorous analysis methodologies that are necessary and sufficient for analyzing the desired properties of blockchainbased systems.

C. Metrics
It is a notoriously difficult problem to rigorously define metrics to systematically measure security properties of interest. However, given the high likelihood that blockchainbased systems will become digital infrastructures for the future society, if not already, there is an urgent need to define metrics to measure their security and risk. We are not aware of any systematic study on this matter, despite substantial efforts [175], [176], [177], [178], [179], [180], [181]. This leads to:

Insight 15:
There is a lack of deep understanding on the metrics that are necessary and sufficient for quantifying the security and risk of blockchain-based systems.

VII. CONCLUSION
We have presented a systematic survey on the security of the Ethereum system, including its application, data, consensus, and network layers. The survey considered three perspectives, namely vulnerabilities, attacks and defenses, while correlating them. We discussed not only the locations of the vulnerabilities, but also their root causes. We systematized the attacks against, and the defenses for, the Ethereum system. We further systematized the best practices proposed by industry into a small number of guiding principles, which might be easier to adopt by practitioners. We provide insights into the state-ofthe-art and into future research directions.