The Gas Siphon Attack: The Technical and Economic Realities Behind Hacking Exchanges (Devcon5)
Devcon·Fri, Oct 9, 2020, 12:00 AM
Visit the https://archive.devcon.org/ to gain access to the entire library of Devcon talks with the ease of filtering, playlists, personalized suggestions, decentralized access on IPFS and more. https://archive.devcon.org/archive/watch/5/the-gas-siphon-attack-the-technical-and-economic-realities-behind-hacking-exchanges The Gas Siphon Attack allows anyone to siphon value from many exchanges in the form of gas refunds, a mechanism built directly into the Ethereum protocol. Users can write a simple script that continuously drains unprotected exchange hot wallets of all of their ETH. Until this was responsibly disclosed, many exchanges were affected with varying degrees of severity. How it happened, who was affected, and the technical details behind the attack are discussed during the presentation. The talk dives into the details of the refund mechanism built into the Ethereum network, and how it can be maliciously abused. The presentation explains who is vulnerable and what they can do about it. A number of these types of technical exploits exist on both centralized and decentralized exchanges, and one may find that responsibly disclosing these attacks are harder than the actual exploit itself. Getting in touch with exchanges, continuous communication with services, and helping fix different systems may be a month-long journey that yields very little in return. Hacks, front-running, misaligned miner incentives, and economic disparities are all issues for exchanges and services that are discussed in this presentation. Finally, the talk covers different ways to protect yourself and your dapp from both known and unknown exploits. Preventative measures are presented that will allow for protection from these types of attacks. Speaker(s): Shane Fontaine Skill level: Beginner Track: Security Follow us: https://twitter.com/efdevcon, https://twitter.com/ethereum Learn more about devcon: https://www.devcon.org/ Learn more about ethereum: https://ethereum.org/ Devcon is the Ethereum conference for developers, researchers, thinkers, and makers. Devcon 5 was held in Osaka, Japan on Oct 8 - 11, 2019. Devcon is organized and presented by the Ethereum Foundation, with the support of our sponsors. To find out more, please visit https://ethereum.foundation/
Transcript
[Applause] okay this is the gas light and attacked it with all the technical and economic realities behind acne changes it's a little bit of an intro to Gaston game and then the story about the club's McShane exploits we found last year and then how that all came about and what you do to protect yourself against it we're going to start with a live demo so if you have a take out your phone and scan this is a cryptocurrency are the Imperium address that's a contract if you send any money to it you will I don't know if you'll get it back so don't have very much but it it does make you gasp token so the whole point of this vlog is about gas token so if you send a transaction what you'll do is make yourself five dollars in gas token so you will lose my color if you do this but you will get it so try that out if you want in Walpole this is up on the screen I'm going to basically take a second to describe book gas token is what the the half was and then now it all all played out so it looks like everyone's all done so so what this was what the gas second attack was was an unemployed basically anyone who subsidized costs of the theory of transactions were honorable to this in that someone could use the subsidizes payments to print out gas no guests okay is this mechanism let me take a step back a bit and etherium this mechanism in which you can be rewarded for refunding for removing space from the network and so when you were going to say from the network one of the etherium does is that a vacuum in gastrique months and what this effect is is taking advantage of those those refunds then that are built into the system and so in order to execute this kind of attack it's very simple you deploy a contract we'll go over in a minute in the same kind of contract you guys just transact with you initiator withdrawal from an exchanger from someone who pays for your transaction fees you send the withdrawal to this contract and the contract does it's magic and at the end of the transaction you get into guessed again the money comes straight from the exchange independent of your actual holding on a change and a little background about myself so myself and Chris our co-founders the gas I can attack so we kind of found this in helped bring it to the attention of the public I'm also co-founder of etherium which is a wall combiner that logs as well as zero trust which is a nodding firm and we audit a bunch of smart contracts this is a little definition against okay but like I said it's basically a token that represents a refund on the etherium network the refund is and gas and the idea being if you spend a hundred thousand gas on a transaction you can use this free fun to actually only pay fifty thousand reasons it exists that we'll get into in a minute and then one big question I always get is says is gas doping good so is it good to offer someone an incentive to clear the state on the network and it sounds like a good idea the reason it exists and aetherium is because the developers should create stain on the network and then clear the state later on so that if the chains not as big so the incentive is there but the problem is people are starting to use it for that their 40 guests tokens that are floating the state so that in the future when when the network is very bloated and gas is very expensive they can get these refund set at a much more efficient price and so so the idea of gas tokens very good idea the implementation as we've seen it isn't so good so we'll see how it plays out in the end and in how people are using gas tokens today a lot of the law has to do with the arbitrage so the idea being if I want to make a transaction on unit swap and make some arbitrage through exchanges and I might have a dollar profit to be made someone else with gas so they might be able to make that same transaction what they can do is use gas token and like I said it reduces the piece sorry the gas cost and so what that $1 downstairs in the one dollar ten cents for someone and when that happens they they now effectively got an advantage in arbitrage that no one else who doesn't have gas no so it's pretty dangerous in that sense that's usually a pretty well coupled with from running so a lot of people do front running and guests of an arbitrage in the same thing in it it works for them it no one really knows how it really affects the network finally exchanges can use guess token as kind of a hedge or gas futures so you can imagine if exchanges prints a bunch of gas token now or in the future when one gas is very expensive they might be able to even that output basically having bought gas futures now so that when the network squad they can still provide their customers with a very constant gas brother I'm gonna run through the cover with me at the Gaston candidates it's quite simple and you don't really need to understand code to understand this but it here's the whole contract you just interacted with and there's only four functions so so here's a set in ranked seventh in rank and all this does is set a rate tokens you want a min so this would say you need 17 five tokens per transaction so that when you withdrew from from an exchange you meant five tokens and you can change this and the higher the rate the higher your guests limit of the transaction would be the actual mint function again this is just a 12 token it's in the air see 20 token and so you just call toke it up mint and then the number of tokens that you pass it so that's also very simple this is the fallback function so the reason this works what the changes is when you don't provide data to a transaction the contract automatically calls the fallback function in this case that is mint so now it takes it calls the min function given the memory you previously provided you don't need to do anything these change now is basically paying for you and finally you can with for all the tokens so so the tokens will live on the on the contract and then you would throw them and so this is just transferring the tokens out as well as an ether there's some in there so it's very simple to execute this it's dangerously simple someone say here is an example transaction and then you probably can't see this but it's an ether scan contract and this is a withdrawal home an exchange and so we throw all a point on one ether so not nothing too crazy but if you look here there's a transaction fee of $34 0.2 ether and the Gas Limited six and a half million and so this is from a big exchange and it basically went straight to the contract and the exchange made six and a half million gas at 30 people a gas price appropriate and and what people can do with this not taking advantage of it in print yeah so and so this is the first transaction we did when when finding the exploit and so it's a you can look it up if you want but it's pretty dangerous and so who is affected by this and it changes like you've just been talking about meta transaction three layers who subsidized gas costs this thing can be scoped out to just anyone who subsidizes gas costs if someone's paying for your gas or your transactions there's a really really good chance that you can print gas token on their dime so if any of you are doing this just watch out for this you can set limits to the transactions but we'll go over that in a minute in any really EVM base chain that that again subsidizes the transactions it has this kind of mechanism built into it how can they fix it don't pay for users guess I know it's a really nice of you X to be able to pay for your users gas but if you are paying for gas they are gonna try to take advantage of the free money and this is one of the best ways for them to do it now getting into a lot of pictures and a lot more interactive stuff so here's a bunch of pictures of mobile wallet so this is you can see here but trust one point made some MMS and what what why these exist is because I'm showing you that they don't they try to abstract gas away from users and when they do this they make the user vulnerable so you can see here they have this positive network the transaction fee and users can almost guarantee both so you don't look at that too closely and but what these are saying is hey I'm 7.00 money but the PD QC is three dollars and 85 cents and if you're just looking and you think this is a normal transaction you're not going to see 385 it possibly $30 or up to $300 maybe and you're gonna basically pay that and then you're gonna have no idea because you're gonna see point o money and I don't know if there's a good answer these wallets are all trying to abstract the gas away from the user and that's a really good idea but on the same at the same time it's also dangerous this is also argent and the reason it's by itself is because they they kind of do it the worst and that they say it's pretty it's made by argent so they don't even give the user the idea that there is a fee associated with transaction and it's dangerous it's nice but it's dangerous and so it's just something to look out for and then going to what we actually did last year so so the happened would be the exploit happened last year at Def Con around this time and we were basically realizing that every exchange was vulnerable to an extent so some exchanges you could take in 50 million to third sorry $50 per transaction from some $2 but if you were a script you could basically take a million transactions and so when we found this we went to one of the more prominent members of the ether community and when you realized what this was he basically said he smiling said oh well code is law and he walked away meaning you guys should take all money and run but it's a lot of the exchanges are interesting jurisdictions and we just really wanted to pass work with different people to kind of get this resolved we got in touch with all the exchanges and want you to see here in we figured a name will be the good guys and maybe we'll collect some bug bounties for this we'll put in a lot of work but we'll get paid a little bit and so here's an example of one of the changes bounty pages you don't even read about what what is good to see it's as if you find an external or narrowly severe issue we can pay up to $100,000 and so we did the math could have taken ten million from them that's pretty severe they would have something and they can just give us a hundred thousand dollars instead and so we worked with them and we got in touch with all of them and we had telegram cats and more cats and more cats it actually went on for a month and so we all these exchanges we talk about this from about a month it is two to three maybe even four engineers almost full-time job for a month and so this is one exchange in particular and we've got through this whole thing and basically save them and they offer eight hundred dollars worth of their token and so that was a little frustrating so we responded with a very large email or large telegram message you can read later but what it's saying as incentives are really hard in the space you guys are one of the biggest changes and this is what you're all bringing if you can't do it right no one else is going to do it right I didn't say it but it kind of sounds like next time we find something we're just going to take the money and give you what we want but it's hard to this was it we say it something like this they ended up responding and they gave us much more money a couple thousand dollars not anywhere near a hundred thousand dollars but it was something and that's to say all you can really do with this kind of stuff unfortunately this is another example of an exchange and that this one's quite funny again don't worry at all but I'll highlight some things in the next slide but what we ended up doing was sending an email to a ton of different exchanges is very hard to get ahold of them so we basically sent an email that maybe fifty or a hundred different people with the same message hey there's a vulnerability we can't get in touch with you but if you get in touch with us we'll help you out so we got this email from from this exchange and this was the CEO and Chris time to email and said hey here's Who I am because what we found we think you're vulnerable and he responded with do for you we are not fraudulent there's nothing wrong with our security and that was in response to a tweezers it wasn't anything we know your change is vulnerable so that was not a not a good response these nine minutes later we got this email from the same company but this was from an engineer saying oh well we really appreciate this we'll give you a shout if there's any questions so the same company two different people two different responses we think we ended up sending boarding this email to the CEO and we never heard from them again so so we got so that's kind of the history of the attack you know gasps token but there's a lot of interesting metrics and stuff going on with gas and gas markets and guests so get it now and and here's gonna be a bunch of screenshots I kind of describe that a pretty interesting way I'm sure you guys have all seen this but one fair one was going on the gas prices were pretty high they're lower now but I assume they'll be higher at some point when these prices are high people can really start taking advantage of gas tokens people printed gasps opens when they received when guests was maybe one gig away they can out prints it they can out start using this at much higher price this is the block gas limit again this was made about two weeks ago when we were rising the the block gas them into about eight and a half up and we've got up to ten million and I think since then expect on the eighth but but this is basically showing that gas usage is really increasing on the network and good or bad maybe it's a Ponzi scheme maybe we have a lot of actual usage but but my intuition is that etherium is going to grow and the usage is also going to grow this is actually pretty interesting so so after the mud this stuff stem from fill dance talk last have fun but once that happened and what's the sex what happened what a lot of miners started doing was mining blocks and only filling it with gas token printing and so you can see here at all most of these transactions are all zero transaction fee meaning the miner included his own transaction and you paid zero for it so he didn't have to pay a single dime for any gas in development 88 million gas worth of gas token which is a if someone like you or meter me were to do it we'd have to pay the normal gas gas price and so what we're seeing now is a lot of miners are actually basically filling blocks with with zero gas limit or miss our gas price and what's happening with that is it's a win-win for the miner because they get gas tokens but what happens is they also start clogging up the network because they're not propagating normal transactions and so that's one of the reasons why this is could be a dangerous thing if you have all the miners are just including their own transactions for a gas token they're not sending actual transactions through and this is a graph of the transactions both gasp token I didn't put the line in here but right around this time with Def Con last year and you can see that people started getting interesting interested in it fill Diane had a great speech about gas so get some from running our exploit article came out about a month later so that I think a lot of people started recognizing in and then a little later on it just kind of became a thing and it looks like it's growing and it's going to become more and more ubiquitous it was also used yes so we're also use a little bit during the career computing space for our jobs like I explained earlier on let me get into that but there's a lot of articles on it better super interesting it's also happening on Eve classic miners are also basically paying nothing and getting gas tokens eat the plastics a little more interesting or a little interesting in a different way in that it's really cheap for five dollars you can basically print tons and tons of gas tokens now the proportionate price of each classic verse means that these aren't worth much or anything and it doesn't totally matter that you you don't need to pay much but this is kind of showing that hey it is happening on these classic to the like to keep their skin page this is an equal classic Explorer that's just the same thing with no no gas payments and just gas missing in most interesting is is you can imagine this is in the air see 20 token and so people could trade it so this is an example of exchange on each classic and it doesn't look like it's too highly used but it is an exchange and people are trading gas tokens the price is it's an interesting market because you have an exchange you can also emit the gas so can open so you can natively price the token you can also trade it basically two different markets going on maintenance there cerium doesn't necessarily have a marketplace at this time though I did see right before this talk that there is a unit swap gas token marketplace so it's coming I don't know when it's gonna happen there's a good chance it might be removed there's a whole concept of storage rent debt that may actually know by all of this but but it's all in the future and we'll see if it actually happens finally that there's a package that you can just install and start running it's called the gas okay minor rooms that are networked and you click one button on your computer and it just starts making a something for you you have to fund it obviously but it's it's about as easy to make gas open at this point it's just clicking a button on your computer so I think it's gonna become more and more prevalent as time goes on this is more of a reference light but but here's a few addresses that are currently arbitrage check the network on different dpi changes some of them are using gas token if you want to see how people are using it try to kind of look into these these addresses and the transactions and how they they process it because it's pretty complicated a lot of transactions going on I'm sorry a lot of blood calls are being made in one transaction it's really really fascinating but it'll give you an insight to how this is actually being used finally how to protect yourself pay attention to your gas limits like I showed with the the mobile interfaces if the app is obstructing the way gas from you it's it's almost dangerous it's almost more dangerous than knowing what you're getting into so maybe it's more of a social thing about learning about this instead of abstracting the way transact with only trusted parties this is hard this is like saying only gives money to your friends and not emergent obviously it's not realistic but it but if you do know that they are interacting with unit swap that I know them to be good there's a really good chance you're not going to get psyched when you're subsidizing costs set a gas limit if you do set a gas limit as factors you can really not take much from you if you have civil protection like an email and username if it's really negligible and so that is the best way to do it but that's not always possible in crypto the last two are a little more interesting looking all contracts interactions and learn to code it's not for everyone but if you are playing in this space there's a good chance that you're interacting with potentially malicious code and if you really don't know how to protect yourself it's it's hard and learn to code doesn't mean like sit there and become a developer but at least understand the basics of what's going on a very simple understanding could save you from a lot of this stuff and maybe not even coding but understanding the ecosystem around coding and then where to look to see hey this might be an X point that's not on a news site or something and so so basically being more more familiar with everything is the one of those last two finally you can look at these later but there's references here and a lot of this these slides came from this and in our own experiences back [Music] [Applause] there's a few things available so for example with etherion specifically you can check if the interaction is going on with the contract and be a change we should probably assume hey I'm only interacting with an on contract and they can actually check that in non-contract can't can't do this stuff but it contract can so in a change cam check am i interacting with the contracts there are ways around it for example if you deploy a contract and make that withdrawal in the same transaction it doesn't look like a contract at that point but it's pretty far out there the gas limit is the best but then that also get something questions like what abuser is trying to withdraw into a contract safely and it's a really hard question then we don't really know the answer thank you just challenging things they think you charge you and some exchanges actually charging withdrawal fee that is greater than the amount of tokens that they meant they submit for you and that is a really good answer but again did it it's not the perfect answer how good is the notice of estimating this stuff it's nice if you're running a node you can go and estimate the gospel kind of usage of a fun for long period they estimate you whether or not to contract them to me gasps turkey contract is going to go create X amount of data unchanged I want to say it's it's super easy I just don't think people are doing it okay yeah so - so yeah that is a clue we got one more yeah so I know there's two different variants can you Marian yeah so there's the the deeper answer to that is go to guest opium die oh I think the quick answer is there's two ways to get a refund on aetherium one is to reduce states so setting a variable from one to zero excess refund another way to do it is to self destruct a contract I think that's the more efficient way and so if you basically create what gasps spoken to does it creates the thousand contracts for you and when you go to use it you just destroy some contracts and that's the peppery one so but but Gaston can not io that they have a very very in-depth analysis of all of that and I think that's all my time thank you [Applause]
Automatic transcript — names and jargon may be misspelled.