00:00:00.000-->00:00:06.540 >>Good morning everyone. >>[group response] Good morning. >>Morning. Thank you for 00:00:06.540-->00:00:17.384 attending our talk. This research is about replay attacks on ethereum smart contracts. Now 00:00:17.384-->00:00:26.793 let me give you a brief self introduction. I must emphasize here that Zhenxuan Bai is the 00:00:26.793-->00:00:35.369 primary researcher. He did ma he did more than half of the work. But for some issue with, he 00:00:35.369-->00:00:42.843 couldn't attend this talk today. So the job is ours to introduce the research to you. My name is 00:00:42.843-->00:00:51.084 Yuwei Zheng. I am a security researcher on UnicornTeam. And this is my colleague, Kunzhe 00:00:51.084-->00:01:04.798 Chai. We continue the research group using 360 technology. The team was formed in 2014. We 00:01:04.798-->00:01:11.838 focus on the security issue numerous times with this system. But we also encourage members to 00:01:11.838-->00:01:23.216 do other research that they are interested in. This, this is why we also have this topic. Today’s 00:01:23.216-->00:01:31.625 talk consists of 4 parts. At the beginning we will introduce the background of block, blockchain, 00:01:31.625-->00:01:38.198 smart contract and the ethereum. Then we will discuss security issues about the [indiscernible] 00:01:38.198-->00:01:47.774 in smart contracts. Thirdly, we will talk about the key point, replay attacks. And we are going 00:01:47.774-->00:01:57.784 to show why it exists and how it works. And then the last one, a demonstration on replay attacks 00:01:57.784-->00:02:10.263 and the statistical analysis of simi, of similar vulnerabilities. Now let Kunzhe 00:02:10.263-->00:02:23.410 Chai show you the first part. >>Hello. Hello, Hello. Hello? Hey. Hello everyone. As you 00:02:23.410-->00:02:29.816 know, my name is Kunzhe Chai. Uh, I come from China so. The first topic is in background and 00:02:29.816-->00:02:36.023 mainly about the instruction of [indiscernible] files and replay attacks. Like blockchain, smart 00:02:36.023-->00:02:42.496 contracts or ethereum. So, uh we all heard some news about blockchain but what is 00:02:42.496-->00:02:48.135 blockchain yeah? Mmm, blockchain, so to speak, is uh, largest tech globally 00:02:48.135-->00:02:55.609 degradually uh, computer network users can interact with it by sending transactions. Each 00:02:55.609-->00:03:05.018 transaction is uh, message with, uh, crypt graphic central and uh the other encryption in forest 00:03:05.018-->00:03:14.728 is uh t mined by a mechanism called glocal called global conditions. So, an advantage of 00:03:14.728-->00:03:25.672 blockchain uh, they state here. Uh, it has a um, unified database with rapid consensus 00:03:25.672-->00:03:33.980 which allows uh, segment to be compiled with three obviously from three to sixty uh sixty 00:03:33.980-->00:03:42.456 seconds rather than three days or and more it uh offers or varies uh uh a large-scale fault 00:03:42.456-->00:03:51.932 tolerance in which system can withstand uh, in some cases 33 to 40 nmm percent. Another 00:03:51.932-->00:04:00.440 feature ost operates normally under the control of hackers. Blockchain does not really um, 00:04:00.440-->00:04:08.081 trust. And uh, not controlled by any single uh, administrator or organization except for private 00:04:08.081-->00:04:20.227 chain and consortium chain. Mmm, so it is able to be audited external observer can very, can 00:04:20.227-->00:04:31.671 verify the histor the history of transactions. It can operate uh auto auto autonomous, without 00:04:31.671-->00:04:46.086 any hu any human involvement. So next then what actually can uh, blockchain achieve? What it can 00:04:46.086-->00:04:54.294 uh, actual, actual cryptocurrency which is digital assets on the blockchain drive. 00:04:54.294-->00:05:02.435 Uh, right now sorry sorry public chains offer their own tokens to limit the rates of updating 00:05:02.435-->00:05:11.144 transactions and uh, uh instead use the, the, the limitations of blockchain. Next, it has some 00:05:11.144-->00:05:24.191 non uh, monetary features. You include, or record as based on blockchain and a timestamp is 00:05:24.191-->00:05:33.400 actually to track high value data. Then blockchain systems with some other other 00:05:33.400-->00:05:44.778 fashionality including, including contracts data can I show custom uh, customed uh 00:05:44.778-->00:05:51.418 dignus and uh digi digitoss and um I set exchanger uh digital asset of over of option and uh 00:05:51.418-->00:05:59.426 physical through this and uh generate computer I’m sorry my poor English so, I try to relax. 00:05:59.426-->00:06:07.000 Sorry. [speaker clears throat and takes a deep breath] For now, we have now uh, man, we 00:06:07.000-->00:06:13.573 have now many application of blockchain in the field of the uh many treason how about those 00:06:13.573-->00:06:23.850 in uh now now uh actually field, about 2013 the public realized that blockchain can be used uh, 00:06:23.850-->00:06:31.625 in hundreds of applications besides the come, besides the uh come, besides uh that. And uh, 00:06:31.625-->00:06:41.134 such as, uh [speaker laughs] uh, such as I said domain name registration and ownership 00:06:41.134-->00:06:48.642 registration, market for, uh, market forecasting and uh, internet of things, voting and 00:06:48.642-->00:06:59.119 so on. And uh, how to realize those applications when using smart contract. What is smart 00:06:59.119-->00:07:08.094 contract? It is uh, a computer program running in a secure environment that actually, uh 00:07:08.094-->00:07:17.237 that automatically transfers digital assets according to previous, previous rules. Mmm 00:07:17.237-->00:07:24.244 for example for example I will give you a tips um suppose a bag was your girlfriends and she 00:07:24.244-->00:07:32.385 gave you the bag to see if you can figure out what’s, what’s inside her shopping bag. Maybe 00:07:32.385-->00:07:38.825 that is a dress or T-shirt. And you met it but your girlfriend will not pay you anything, but 00:07:38.825-->00:07:46.299 you have to accept it because you have no other way to get your reward. However, if there 00:07:46.299-->00:07:54.974 is a smart contact Once you've made your guess uh command and uh the coder will automatically 00:07:54.974-->00:08:05.819 be enforced, and as a, and as a reward, in real solution it uh, it might be the token will come 00:08:05.819-->00:08:13.960 into your pocket. So, uh smart contracts are a piece of code early on the blockchain and uh, 00:08:13.960-->00:08:23.002 and uh, enforcing certain fun, certain functionalities. [speaker clears throat] How do 00:08:23.002-->00:08:30.610 you contract the secure environment for a smart contact? Uh, certainly there are uh, many 00:08:30.610-->00:08:38.017 public chains called smart contacts and uh, this is most popular one, ethereum. What is 00:08:38.017-->00:08:43.757 ethereum? It is a blockchain with a built in programming language and it offers maximum 00:08:43.757-->00:08:52.432 abstraction, and uh, and uh, versatility. So it is very ideal to process smart contracts. 00:08:52.432-->00:09:01.941 Ethereum has a secure oper, operating system called ethereum, called ethereum 00:09:01.941-->00:09:11.818 virtual machine also as, also known as uh, EVM. This is not a uh, uh encapsulated by a sandbox 00:09:11.818-->00:09:20.660 but uh, in fact, but uh, in fact it is complete, complete isolated. Well that is a code 00:09:20.660-->00:09:28.468 that runs inside EVM does not have access to the, to the network or file system or 00:09:28.468-->00:09:34.874 another process. Even smart contracts have limited uh, contact with, uh, with another 00:09:34.874-->00:09:46.619 or other smart contracts. With EVM. Uh, so, our smart uh, contracts can be used in many 00:09:46.619-->00:09:54.527 things. Uh, one of them is uh, uh, one of them, one of them is uh financial scenes. A financial 00:09:54.527-->00:10:01.634 scene. Including hedging contracts, saving wallet and other non-financial scene 00:10:01.634-->00:10:09.776 include uh, includes online voting, de-cen, de-centralized managing managing managing, and 00:10:09.776-->00:10:20.887 uh, deastrick connotations. Mmmm, however with a interesting spin of applications of ethereum 00:10:20.887-->00:10:31.264 and a smart contract many security issue come along. Mmm. According to analy, ana, analy, 00:10:31.264-->00:10:39.806 analytical, according to analytics uh 100-->000 new users joining the ethereum uh, 00:10:39.806-->00:10:47.914 ecosystem. They on the, the average they are, they are quite, they, they are quite a 00:10:47.914-->00:10:57.390 team and uh, in for daily transactions over 1-->000-->000-->000 times on the ethereum. This is 00:10:57.390-->00:11:07.867 this is increasing main parts tactic a a a attack many eyes from hackers and uh, security, 00:11:07.867-->00:11:18.311 security issues come up for more frequently. In many parts of our ecosystem such as uh, such as 00:11:18.311-->00:11:24.851 uh, uh exchange, wallet, wallet and smart contract issue. There are, uh, there are several 00:11:24.851-->00:11:30.657 security issues come up including a chain attack and wallet hijacking, wallet 00:11:30.657-->00:11:42.468 hijacking and the overflow attack in smart contract. As to smart contract which is most 00:11:42.468-->00:11:50.577 vulnerability? Uh one one big one in the ethereum there are also many security issues. Uh 00:11:50.577-->00:12:03.523 just for 2018 April contracts such as uh, BS were detected, will detect with vulnerability 00:12:03.523-->00:12:09.729 in May security attacks to several contracts like EDU or other. In June there are another 00:12:09.729-->00:12:17.036 security, there are other, another security issues reported to smart contract like SNS uh, 00:12:17.036-->00:12:27.513 or there’s open uh, uh, loopholes made a huge impact on the module module. It changed it 00:12:27.513-->00:12:37.590 affecting several functions including token uh, as natural token deposit and uh, token 00:12:37.590-->00:12:49.869 deposit and a token withdrawal. According to the most recent uh, research papers from um 00:12:49.869-->00:12:56.976 [indiscernible] and university college London after organizing pretty close to 1-->000-->000 smart 00:12:56.976-->00:13:09.122 contracts and uh, 34,200 of them um um were vulnerable to hacking. Um, and uh, they also 00:13:09.122-->00:13:21.067 sent, they also, they also uh assembled another 3,759 so the pace of the smart contract and 00:13:21.067-->00:13:32.812 the finds that adding, add it and the 9 percent of the uh, currency law pass. So, so how to 00:13:32.812-->00:13:40.286 lower the probability of loss? Uh, first we record and accommodate and uh, objective 00:13:40.286-->00:13:48.494 that for our contract. And second we, uh and second we and second when any loopholes is 00:13:48.494-->00:13:58.638 found we need to make, we need to make any images respond to, uh, respond so that we could now 00:13:58.638-->00:14:07.447 add fast add first , add first time uh, this contract is being attacked. And those are the uh, 00:14:07.447-->00:14:18.157 there need to be some [speaker stutters] a reward for those who deact and report any bugs uh, 00:14:18.157-->00:14:31.604 to, to, positive and send the whole system operate. And uh, so next part is my colleagues my, 00:14:31.604-->00:14:39.445 is uh, has some [indiscernible]. Um, by the way, I’m very sorry my English so. Uh, so, there is 00:14:39.445-->00:14:52.592 next to go on. [speaker laughs] >>Hey I am back now. [audience laughs] Next we’re going to fix 00:14:52.592-->00:15:02.235 on the issues of replay attacks in smart contract. Now let me explain the concepts of replay 00:15:02.235-->00:15:08.241 attack. As distinguished the former replay attack in traditional network world. It’s 00:15:08.241-->00:15:18.985 not to capture and then resend them packing. Uh, this is if a transaction is legitimate on 1 00:15:18.985-->00:15:30.596 blockchain, it’s also legitimate on another blockchain. So when you transfer BTC1, you BTC2 or 00:15:30.596-->00:15:43.709 BTC3 may be transferred at the same time. That is a replay attack in blockchain. Uh, to 00:15:43.709-->00:15:53.753 replay attack, we found that many smart contracts adopt the same way to verify the validity 00:15:53.753-->00:16:05.865 of the signature and it is possible for replay attack. Our motivation of that, we propose 00:16:05.865-->00:16:14.740 replay attacks in smart contracts in which to attract the users attention. We tried to 00:16:14.740-->00:16:22.148 detect the vulnerabilities in smart contracts and make them more secure. Finally we want to 00:16:22.148-->00:16:30.389 enhance the risk awareness for cont, for contract creator and ensure the interests of 00:16:30.389-->00:16:42.368 investors. To add to our goal we have done analyzing that uh, we found in the replay attack 00:16:42.368-->00:16:50.877 problem exists in 52 smart contracts. And we analyzed the smart contract example to verify 00:16:50.877-->00:16:59.285 the replay attack. We analyzed the source and the process of replay attack to expound the 00:16:59.285-->00:17:09.161 feasibility of replay attack in principle. We also verified the replay attack based on the 00:17:09.161-->00:17:18.304 signature vulnerability. And finally, we proposed defense strategy to prevent this 00:17:18.304-->00:17:29.782 problem. Now I am going to show you something. Uh, the first item is vulnerability scanning. 00:17:29.782-->00:17:37.256 Our aim is to get the name and the number of vulnerability or replay attack in smart 00:17:37.256-->00:17:47.166 contracts. And then we set 3 scanning standards to discover the smart contracts which have 00:17:47.166-->00:18:03.516 the vulnerability. First, judging whether the contract is accord with ERC20 standard. This 00:18:03.516-->00:18:15.928 requires the total supply to be greater than 0. Second, get the name of the contract to 00:18:15.928-->00:18:27.907 determine whether the name is valid. Thirdly, filter smart contracts vulnerable to replay 00:18:27.907-->00:18:39.785 attack. [indiscernible] It’s the, they use the ECRECOVER function to wire the signature. 00:18:39.785-->00:18:50.796 If a contract use the ECRECOVER function it was marked as suspicious. This scanning 00:18:50.796-->00:18:58.604 program can be found at the following data, it’s on GitHub storaging. After we audit and 00:18:58.604-->00:19:12.852 verify the scan output we found 52 risky targets. And uh, this is coded to scan ERC20 docking 00:19:12.852-->00:19:27.233 contract. You can take it from the GitHub, from our Github authority. Why does the replay 00:19:27.233-->00:19:40.713 attack occur? The signatures of user were utilized in smart contracts. If the contents of 00:19:40.713-->00:19:48.354 the signature were not correctly limited by the smart contracts there is a possibility of replay 00:19:48.354-->00:20:01.367 attack. Such as the interface transfer proxy. Here is an example, the contents of the MTC 00:20:01.367-->00:20:15.214 contract signature and the contents of the UGT contract signature are exactly the same. 00:20:15.214-->00:20:33.365 This is an example uh, using the contract. They issue lies, lies in this line. The KECCAK256 00:20:33.365-->00:20:40.639 function calculated a hash. And the hash is input of the signature. So we can see in the 00:20:40.639-->00:20:52.351 perimeter of this function it’s just from, to, value, fee and nonce. There is nothing related 00:20:52.351-->00:21:07.600 to the contract itself exactly. Now let me explain the attack process. Let’s suppose that 00:21:07.600-->00:21:21.881 transaction in RAcontract1. Use A1 to transfer 100 tokens to unit B through proxy C and 00:21:21.881-->00:21:32.758 access the tokens to be paid for proxy, as there is a fee. In this process, they input the 00:21:32.758-->00:21:45.404 signature of user A, should it be A, B, 100 and 3 and the laties and months one. Then the 00:21:45.404-->00:21:54.413 transfer would occur by proxy C. After this transaction being completed, the B can get 100 00:21:54.413-->00:22:07.426 tokens from user A. We suppose user A started to carry out the transfer RAcontract2 through 00:22:07.426-->00:22:21.807 proxy so the latest announce is also 1. We suppose user A, notice replay attack starts 00:22:21.807-->00:22:36.288 after receive 100 tokens from unit A, unit B replace the signature of unit A from RA, 00:22:36.288-->00:22:47.399 RAcontract1 in RAcontract2. Now we can get another 100 tokens in RAcontract2 without the premise 00:22:47.399-->00:22:57.142 of user A. That is to say this smart contract, RAcontract2 were attacked by user B and the 100 00:22:57.142-->00:23:05.885 tokens that were there were stolen. Next up, to verify the existence of this vulnerability 00:23:05.885-->00:23:22.935 we conducted an experiment. The experiment consists of a list as follows: we chose 2 ERC20 smart 00:23:22.935-->00:23:32.578 contracts, the UGT contract and the MTC contract. Then we create 2 accounts, Alice and Bob. Next 00:23:32.578-->00:23:44.290 we deposit some tokens in the 2 accounts in corresponding contracts. And the process of 00:23:44.290-->00:23:55.234 this verification is that. In step one the normal transaction records on the ethereum were 00:23:55.234-->00:24:03.976 scanned to find out accounts which both had, which, which had both UGT tokens and uh, MTC 00:24:03.976-->00:24:20.626 tokens. Um, but here we use 2 accounts, Alice and Bob. In step 2, Bob induced Alice to send him 00:24:20.626-->00:24:31.770 2 UGT tokens. And the transaction input data is shown below. The lines 0 to 6 00:24:31.770-->00:24:46.352 corresponds to the augmenting of the function transfer, transfer proxy. In step 3, Bob take out 00:24:46.352-->00:24:55.060 the input data of this transaction on the blockchain. The parameters “from, to, value, 00:24:55.060-->00:25:10.776 fee, V, R and S” were extracted from, from the, this method. The following is the implementation 00:25:10.776-->00:25:20.853 of the transfer function. In step 4, Bob use the input data in step 2 to execute another 00:25:20.853-->00:25:43.609 transfer in the smart contract of MTC. The result of this transaction is shown as below. 00:25:43.609-->00:25:59.224 Bob got not only 2 UGT tokens but also 2 MTC tokens from Alice. In this procedure, the 00:25:59.224-->00:26:12.337 process of 2 MTC tokens was not authorized by Alice. Now we come into the final part, 00:26:12.337-->00:26:22.548 demonstration and uh, analytics. Um, to begin with the demonstration we select 2 00:26:22.548-->00:26:38.831 contracts, the UGT contract and the MTC contract. Then we set to our owner accounts, Alice and 00:26:38.831-->00:26:48.874 Bob. Alice is the sender and Bob is the receiver. Both the 2 accounts own some tokens for 00:26:48.874-->00:27:07.960 transferring. Next, this is a POC code. In the code parameter from 2 value, fee, V are as, are 00:27:07.960-->00:27:16.735 all acquired from UGT. This call is parameter right from the chain. The parameter is, in a 00:27:16.735-->00:27:29.581 way, a signature. In another token replay from 2 fee are exactly the same as last call. 00:27:29.581-->00:27:40.125 And the simple proxy transfer scenario is that first user A delegates the 3rd party user 00:27:40.125-->00:27:46.632 state to help him transfer tokens. You would guess that address of the contracts and 00:27:46.632-->00:27:53.038 creates the instance for the tokens to be transfered. After that, say we’ll get the 00:27:53.038-->00:27:59.578 signature from user A and if you look at the transfer function provided by the contract to send 00:27:59.578-->00:28:09.388 the tokens to the token receiver, user B. Then the proxy C will withhold information that 00:28:09.388-->00:28:20.032 might have downloaded in the package process. And finally, transaction process finishes. 00:28:20.032-->00:28:38.650 Now let me show you the download. For comparison, I carried a balance of, of both of 00:28:38.650-->00:28:58.103 them. On first UGT contract and the MTC contract he has 6 tokens on both the 2 contracts. Now I 00:28:58.103-->00:29:16.521 transfer 3 tokens from Alice to Bob. And the UGT contract has 3 way across [indiscernible] We 00:29:16.521-->00:29:52.924 have a few seconds for the manual to pack. Ok it’s finishing. Now I carry the 00:29:52.924-->00:30:04.069 signature. And I carry the finance of Bob and both UGT contracts and a MTC contract 00:30:04.069-->00:30:19.985 again. The bad news on UGT is none, but on the MTC side still 6. I copied the permit from UGT 00:30:19.985-->00:30:50.582 to MTC and uh, start the replay attack. You can see here I just needed to input the, um, the 00:30:50.582-->00:31:08.300 password of proxy. I don’t need to input the password of Alison. It means that I don’t need the 00:31:08.300-->00:31:45.470 permission of Alice. It’s finishing. Now I carry the balance of both uh, MTC. We can 00:31:45.470-->00:32:02.053 see that balance is 9. It’s 9 now. So Bob stole, stole, stole 3 tokens of Alice’s MTC 00:32:02.053-->00:32:12.030 contracts. To show you the impact of this vulnerability, we also made some related 00:32:12.030-->00:32:24.976 statistics and analysis. By April 27th, the vulnerability of this replay attack risk existed 00:32:24.976-->00:32:34.052 in 52 ethereum smart contracts. Finally, according to the vulnerability of the replay 00:32:34.052-->00:32:48.066 attack [indiscernible] contrasting to three groups. The group 1 they, contracts, they, 00:32:48.066-->00:32:56.408 no specific information is contained in the signature of smart contracts, so the 00:32:56.408-->00:33:07.419 signature can be fully reused. And in group 2, there are 37 contracts. In this contracts 00:33:07.419-->00:33:14.426 it’s best the fixed string is contained into the input of the signature, but the 2nd string 00:33:14.426-->00:33:23.835 can still be reused. In group 3, the address of the contract or the address of the sender is 00:33:23.835-->00:33:32.944 contained in the signature of smart contract. But there are strong restrictions. Such as 00:33:32.944-->00:33:43.021 they will still have the possibility of replay attacks. Secondly, we classified these 00:33:43.021-->00:33:55.433 contracts by feasible replay attack approaches. 5 contracts can be replayed in the specific 00:33:55.433-->00:34:07.646 contract itself. And uh, another 45 contracts can be replayed between different contracts. 00:34:07.646-->00:34:19.224 Besides, we divided these 45 contracts into 3 groups, for the specific prefix data used in the 00:34:19.224-->00:34:27.565 signatures. Cross-contracts replays may happen among any contracts as long as they are in 00:34:27.565-->00:34:41.179 the same group. [audience member coughs] The group 1 and the group 2 both aid a specific 00:34:41.179-->00:34:51.556 identical data to the input of signature. We mark the specific prefix data used in group 1 as 00:34:51.556-->00:35:03.601 data 1 and then we mark the specific prefix data using group 2 as data 2. So, for example, 00:35:03.601-->00:35:15.180 you can see that these 2 in these contracts is the same string. Ethereum signed 00:35:15.180-->00:35:26.591 messaging. In group 2, in group 3, they don’t add any prefix data to the input or signature. 00:35:26.591-->00:35:39.204 Just from, to, value, fee and nonce. And there are 2 chains that can be replayed between 00:35:39.204-->00:35:50.582 test chain and the main chain. Suddenly, according to the trading frequency of above 00:35:50.582-->00:36:02.394 mentioned contracts, by April 30th 24 contracts were found which have the transaction 00:36:02.394-->00:36:10.301 records within 1 week and that 9 contracts were found which have the transaction records from 1 00:36:10.301-->00:36:20.912 week to 1 month. The proportion was nearly 20 percent of the total number of contracts that 00:36:20.912-->00:36:31.623 [indiscernible]16 contracts were found which have the transaction records beyond 1 month. And uh, 00:36:31.623-->00:36:38.763 3 contracts only have the records for deployment. So according to the comprehensive 00:36:38.763-->00:36:51.576 analysis, 60 percent of the contract transactions are still active. The reason for replay 00:36:51.576-->00:37:01.753 attacking smart contract is that the misuse signature when constructing the contract the 00:37:01.753-->00:37:12.864 contractor. So our countermeasures are listed here. First, the designers of smart 00:37:12.864-->00:37:21.072 contracts should always confirm the suitable range of digital signature when designing smart 00:37:21.072-->00:37:29.447 contracts. Secondly, the smart contracts deployed on public chain should add in the specific 00:37:29.447-->00:37:37.755 information of the public chain, such as the chainID, and the name of the public chain and all 00:37:37.755-->00:37:45.997 the identical information. Finally, the users of smart contracts need to pay attention 00:37:45.997-->00:37:59.077 to news and report and reports concerning the vulnerability disclosures. And the conclusion, 00:37:59.077-->00:38:08.319 you have the security problems of smart contracts have been widely concerned. [audience 00:38:08.319-->00:38:15.794 member coughs] As long as the user was misusing smart contracts, there is a 00:38:15.794-->00:38:25.003 possibility of a replay attack. We believe that the vulnerability on the ethereum 00:38:25.003-->00:38:39.517 smart contracts have not totally come to light. Uh, thank you, for [audience applauds] uh, 00:38:39.517-->00:38:53.731 listening to our talk. Um, if some got, has some questions of this attack, and uh you can send 00:38:53.731-->00:00:00.000 email to, uh, you can send the email to us. Thank you.