Exploring Vulnerabilities in Solidity Smart Contract

Exploring Vulnerabilities in Solidity Smart Contract

Exploring Vulnerabilities in Solidity Smart Contract Phitchayaphong Tantikul and Sudsanguan Ngamsuriyaroj a Faculty of Information and Communication Technology, Mahidol University, Nakhon Pathom, Thailand [email protected], [email protected] Keywords: Smart Contract, Solidity, Security, Vulnerability. Abstract: A smart contract is a decentralized program executed automatically, reliably, and transparently on a blockchain. It is now commonly used in financial-related applications, which require heavily secure operations and transactions. However, like other programs, smart contracts might contain some flaws. Thus, developers are encouraged to write secure smart contracts, and some approaches are proposed to detect vulnerabilities of smart contracts before deployment. Due to the immutability property of a blockchain, developers can- not modify the smart contract even though there is a vulnerability which may cause financial losses. In this paper, we propose the comparison of vulnerability detection tools to deployed smart contracts on the Ethereum blockchain. We also present the analysis of the state of vulnerabilities in smart contracts as well as their char- acteristics. 1 INTRODUCTION crowd-funding smart contract by triggering a vulner- able function to send all Ethers inside the contract to A smart contract is a small piece of codes operating themselves. In the case of Parity’s wallet bug (Parity on a blockchain system and now has various usages, Technologies, 2017), an attacker triggered a flaw to for example, as a currency token, as an escrow, as a set an uninitialized variable of a smart contract used market exchange or as a game. Due to the character- as the main library of smart contract wallets of other istics of the blockchain, the smart contract’s code is Parity customers. The damage caused all Ethers in- stored immutably inside a block. In addition, when side those wallets to be frozen, and there is no way to the code starts to be executed, the result will be stored withdraw any Ether from them. in the form of a transaction in the blockchain. Since Several efforts had gathered and created a list anyone can read the code and see the results, the trans- of vulnerabilities of smart contracts. For instance, parency property is given to the smart contracts and Solidity, the most popular language for smart contract their execution process. The code can also be exe- development, has listed vulnerabilities on its official cuted by every responsible machine to ensure the con- document (Ethereum, 2019). Moreover, Consensys, sistency of the execution results. Although the storage one of the smart contract audit firms, collected of most blockchain systems and the smart contract’s Solidity’s coding flaws into Solidity Best Prac- code are immutable, the state of variables inside the tice (Consensys, 2019), and Mythril team has cre- smart contract’s code is not. Specifically, such vari- ated Solidity Weakness Repository (Smart Contract ables could be changed by the execution of the pro- Security, 2019). Such lists could help smart contract gramming logic of the code. If the code has some developers in avoiding repetitions of similar mistakes. vulnerabilities, anyone with malicious intentions can Another approach is to compose a secure library for manipulate the code for his gain or for disrupting the common coding patterns. Zeppelin, a smart contract functions of the smart contract. Thus, it is crucial to audit firm, created an open-source project named identify the vulnerabilities of a smart contract so that OpenZeppelin (OpenZeppelin, 2019) to provide a li- the code can be secured properly. brary of audited smart contracts for developers to use. There are many cases caused by programming By extending the audited smart contract library, po- flaws of the smart contracts. For example, in the DAO tential bugs could be minimized, and the time to code case (Siegel, 2016), attackers stole about $150 million a smart contract could be reduced as well. However, worth of Ethers (Ethereum’s currency unit) from a a developer could still make the same mistakes while writing the code. Therefore, approaches to analyze a https://orcid.org/0000-0002-7079-2408 smart contracts to detect their vulnerabilities using au- tomation methods are proposed. Oyente (Luu et al., 2016), the first tool in detecting vulnerabilities in Solidity, uses symbolic execution to test for vulnera- bilities. SmartCheck (Tikhomirov et al., 2018) uses static analysis, which parses the source code of the smart contract to find out whether the code contains Figure 1: Ethereum State Transition. common vulnerability patterns. Although many works are invented to detect EVM operates on the machine-level code, called byte- vulnerabilities of smart contracts, there is still no re- code, which is difficult for a human to write. There- search in investigating the current state of vulnera- fore, Ethereum invented several new programming ble smart contracts. Our research aims to discover languages for developers to use and later compiled common occurrences and trends of vulnerabilities in to bytecode for deployment. These languages are smart contracts as well as identify common charac- LLL, Serpent, Tiger, Solidity and Vyper, and Solidity teristics of vulnerable smart contracts. We have col- which is currently the most popular language. lected the source code of 38,982 smart contracts from Calling to a function in a smart contract is a form Etherscan.com. We analyze smart contracts written of a transaction. The caller can create a transaction in Solidity in the Ethereum blockchain as it is widely with data part containing function signature and ar- well-adopted. From those smart contracts, we have guments. The caller can choose to send some Ether found common occurrences and trends of vulnera- along with the transaction. When a transaction is bilities in already deployed smart contracts. In ad- committed to a block and distributed to nodes in the dition, we have suggestions for developers when de- network, each EVM will extract calling function and veloping a smart contract. arguments, and then execute the callee function with The remainder of this paper is organized as fol- the extracted information. The Ether sent along with lows. Section 2 gives the background of smart the transaction will be added to the smart contract’s contract vulnerabilities. Section 3 explains the pro- account balance. posed work of this research. Section 4 shows the re- sults and discussions. Finally, we conclude our work 2.2 Smart Contract’s Vulnerabilities in Section 5. Analysis Information on vulnerabilities of Solidity Smart 2 LITERATURE REVIEW Contracts has been collected ( (Ethereum, 2019), (Consensys, 2019), (Atzei et al., 2017), (Luu et al., 2.1 Ethereum Smart Contract 2016), (Tikhomirov et al., 2018)). Most studies focus on the analysis of previous weaknesses found in var- Unlike Bitcoin, the most successful implementation ious incidents such as the DAO case (Siegel, 2016), of a blockchain system, that only uses the blockchain King of Ether case (King of Ether Throne, 2016), and to store currency-transferring transactions, and the ac- Parity case (Parity Technologies, 2017). The follow- cumulation of those transactions becomes a ledger ings explain the most important vulnerabilities. where the balance of every account on the system is kept. The goal of Ethereum(Wood, 2014) is to 2.2.1 Re-entrancy use a blockchain to implement distributed applica- tions. In Ethereum, an account’s balance is a state In Solidity, there are three functions used to transfer that changes values by transactions. In other words, some currency to an external address; they are send, a transaction is a state transition operator. The global transfer, and call. However, in a case that the state is where Ethereum uses to store its own currency, destination address is a smart contract, these func- Ether, on each account. Moreover, Ethereum allows tions also act as a function call to “fallback func- each account to store code and has inner state vari- tion” in the destination smart contract. A malicious ables, and that becomes a smart contract. The inner contract might use this fact to create a “crafted fall- state variables are changed by processing a transac- back function” to execute something back in the orig- tion that contains a function call, probably with ar- inal contract. guments, against the account’s code as shown in Fig- Figure 2 shows an example of the re-entrancy ure 1. All Ethereum’s transactions, including smart attack on a withdrawing function, and it is similar contracts, are operated by Ethereum virtual machine to the cause of the incident happened in the DAO (EVM). case (Siegel, 2016). The attacker starts by creat- ing his/her own malicious smart contract (2b) and 2.2.3 Timestamp Dependency calls to the withdraw function of the victim’s smart contract. After passing some validation on the first Since a smart contract operates on an Ethereum Vir- line, the contract sends Ether to the attacker’s smart tual Machine (EVM) that only provides information contract. Since the destination of the transfer is regarding the smart contract itself, i.e. its transactions a smart contract, the fallback function is executed, and blocks. It does not provide information about which in turn, calling to the withdraw function again. environment, such as its host operating system, IP Because the balance of the attacker is not deducted yet address, or even time. A smart contract developer (in Line 11 of Figure 2a), the victim’s smart contract would seek to find the information from the times- will send out Ether again. The execution loop con- tamp field in the block’s metadata. Unfortunately, the tinues until either the balance of the victim’s smart block’s timestamp field is arbitrary and the block’s contract is zero or the transaction gas is depleted. miner can write any timestamp he wants without any verification from other nodes in the network.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    8 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us