New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Secureum 🛠 Smart Contract Security The Good, the Bad, and the Ugly - Rajeev

ETHGlobalMon, Oct 9, 2023, 12:00 AM

Join Rajeev from Secureum for a workshop titled "Smart Contract Security The Good, the Bad, and the Ugly". And that wraps up 2022! ETHIndia 2022⎯the biggest Ethereum hackathon to this date with over 459 projects built within 36 hours. 🫂 2000 attendees from 🌆 321 cities that were 🌱 44% new to web3... ...joined forces in Bengaluru to write history. Thank you for taking part in it 🫶🔥 ----------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com

Transcript

foreign [Applause] [Music] so as one of the first speakers I would like to welcome you all to eth India and I'm Rajiv I'm a security researcher and founder of securium I'll be talking more about that later but this this talk it's it's definitely not a workshop it's it's a talk uh 30 minutes is not enough to dig into how to do smart contacts securely but we'll be talking a lot well I'll be talking a lot about the high level aspects uh trying to impress upon you the the status of smart contact Security today what is what is the status is it enough why isn't it enough what what is being done what are the challenges what are the opportunities and so on so hopefully it's going to be very relevant to you all um you know as you hack away your projects you need to pay attention to this so that your projects don't get hacked later on right and the just a quick note about the title um I know how many here are old enough to be fans of the western genre of movies but my dad really likes one of these Wild West Classics The Good Bad and the Ugly with Clint Eastwood and some other characters so that's what we're going to get you know I'm going to talk about that uh well taking inspiration from that but really flipping it and starting with the more skeptical pessimistic Outlook as to what is wrong what the ugly side of security uh the state of security today then get into all the things that are being done badly in smart contact security and then finally we'll end with an optimistic tone of you know the the good parts of why we are here and all the things that we can look up to so if you if you Google um for a stock image of security and swiss cheese so swiss cheese is uh you know what are the favorites of all the security researchers and it looks like this it's you know it's one of the cheeses if you've eaten it has a lot of holes and that's how the security folks see all the platforms right so there are seven layers to the platform there's typically a front-end a middleware a back end and um all of them have bugs vulnerabilities some small some big some of them are patched and you know many are not so when you look at the vulnerabilities right the hazards as this document says so you have a lot of vulnerabilities that are you know being exploited that are attempted to being exploited and if you notice there are a few of them that get prevented because of all the security measures at different layers and then some of them pass through so the arrow that passes through is um is the loss that is not prevented right and in the case of um in the case of the crypto Wild West are we still on can you guys hear me okay so um so in the case of the crypto Wild West this is Amplified I would say like 10x if not more so there are a lot more layers a lot more holes a lot more arrows being shot at the Target and many of them going through right and we have very few plugs that actually prevent these hacks today so security is all about I mean it's all really about assets right the security really looks at three aspects we have assets that are protected by the good actors and then you have the Bad actors who are trying to get those assets right without the right authentication and then we have a lot of actions that make these two things possible right so it's I mean this is this is sort of a way of life but it gets Amplified many many times over in in the crypto Wild West so you have the good actors but wherever there are a lot of assets you obviously attract the Bad actors who go after those assets and many of them actually succeed and you know you have a lot of these wanted posters that we have to deal with later on so how bad is it right how ugly is the situation here's a dashboard from defy llama which you may have heard of um so I think so this was a statistic that was collated by one one researcher over there and uh you know the dashboard was created and we'll also look at the framework later on but this is what it is this is the state and if you can't notice the numbers what this is showing is the top 100 most severe exploits in terms of the funds lost only in the last two years right and if you look at the y-axis I mean that tells a story so this is we're not looking at thousands of dollars we're looking at hundreds of millions of dollars right so every line that you see that access is 100 ml 200 and so on and then the story really starts all the way back to the Dao exploit so that's the first bar that you see that happened in November of 2016 and then um there was I think the one in 2017 was the parity hack and then all the others are really in uh the last two years right so we'll dig deeper but this is the state of Security today or insecurity today and if you look at the total value had it's a non-trivial number right it's close to six billion dollars and most of it uh and we'll talk more about bridges so a lot of it was lost because of Bridges or because Bridges got exploited but close to 5 billion dollars got lost in D5 right across the various protocols and this is all in smart contracts right we are not I mean this discounts any of the centralized exchanges all the mess that you guys have been you know that we all have been uh reading about in the last several months so this is unacceptable right if we want to be a layer that is a financial you know that settles Financial transactions where we want really to trust in code it has to be you know everything else should be trustless or trust minimized and we want to trust in code then the code cannot be this insecure because if this is a state of the art then we cannot expect people right retail institutions to really trust their money and put into these contracts right over time so this has to change so this is really the ugly part now let's sort of dig deeper into few of these statistics um this and this this particular analysis created a framework for um the different types of hacks to categorize the different types of hacks I haven't looked I haven't analyzed if the data is complete or if it is accurate but I think it's a good running example to you know hopefully make the point over to to everyone here but if you look at the frequency of hacks by categories right so the the analyst decided that there are four categories we have infrastructure protocol ecosystem and smart contracts but the way to think about it is infrastructure is really everything that is not related to Smart contracts so anything in the web 2 space anything that is off chain anything to do with custody of private Keys all that falls in that sector right in that bucket and that is non-trivial right so that is 23 in this analysis so the the story here the model here is that yes smart content and all the other three sectors add up to 77 percent right so smart contract security is way way more important but you cannot ignore the infrastructure the web to the off chain parts right so that's the takeaway here and we'll um maybe this is a good point to talk about some of the categories right so protocol according to the analyst the protocol category really is all about the smart contract logic that's been implemented within your protocol right so as you go and hack away your projects whatever the application is you know it could be a decks it could be anything it could be an nft trading platform anything right so the logic that you write in solidity or anything else that is the protocol logic right and there could be bugs there could be vulnerabilities in that logic those could be exploited to really get all the tokens in um you know in your protocol ecosystem according to this analyst is anything where your particular application works with other applications right so think of flash loans and we'll get more into that so that is so anything external to your protocol but that is still on chain oracle's other protocols other dependencies you have all that comes into the ecosystem category and finally the smart contract is actually the smart contract language or platform category that is really all the hacks enabled by virtue of the evm or the language itself in which the smart contacts have been coded up right so let's dig deeper before that so if you look at the frequency over time I mean there is no sort of key takeaway here except that I mean these are happening every month and note that these were the top 100 exploits right the minimum was I think like three or five million dollars exploited so there's a long tail of exploits that have not been considered in this analysis right and day in and day out I mean if if you're active on Twitter just this morning I think there was an incident that was bubbling with one of the protocols on the branch chain where uh I think a deployer key got got stolen and then the attacker actually deployed um you know upgraded the contract which had uh sort of a different mint function that could be rugged and the attacker minted I think billions of those tokens and the you know that was still uh being analyzed right so there are all these things happening on I think the takeaway here is that these hacks are happening every day right I mean every week if not every day right something is growing and the funds stolen are non-trivial right so look at the y-axis it's 200 400 600 million dollars and the and these have been the numbers have been compressed you know uh to to report on a monthly basis so if you look at some of the the longest polls here right the longest bars uh the longest columns here there have been hacks I think the largest amount was north of 600 million dollars right so those were um you know most of them in the 600 500 range were all Bridge related attacks just because they hold so many assets but those are the ones that you see here in uh red and um yellow so this of that into the different uh categories and the hacks uh again the bridges stand out so if you are interacting with the bridge if you're building a bridge if you're you know building a protocol that works with Bridges something to pay a lot of attention to now let's go into the smart contract language that category right so the two things that I would like to call out here are the re-entrancy and the delegate call exploits so the first major exploit on ethereum which is well known well publicized is the Dow exploit right this was in 2016 of November it was I mean it really opened uh our eyes to a re-entracy exploit and since then you'll be surprised to see how often the re-entrancy exploits I mean the vulnerabilities exist in different uh code bases and they're exploited you know on a regular basis and the second one would be the delegate call exploit I mean delegate call is something that you need to wrap you know we need to wrap our heads around because this is a functionality that if you have coded it in any of the other languages you wouldn't have really paid attention to but in in smart contact languages when you do a delegate call there's a lot of things that happens in the background that if you are not paying attention to it could be a recipe for disaster right so those are the big takeaways here and when it comes to the ecosystem hacks uh the keyword like I said earlier is Flash loans and one of the big categories there is the Oracle price manipulation attack right so just just Google for it they're a fantastic ad articles written about it um so this is extremely common right so this is like 50 of this category is all price Oracle manipulation hacks that's still you know that continue to happen the second category is The Flash loan governance attacks so if you have looked at any of the token based governance models then flash loan introduces a new Vector where somebody can you know flash load a whole bunch of tokens that are used for governance and they can make the governance go one way or the other right so all these you know pretty pretty graphs pie charts are there in the source I didn't create them I think it's a very you know good way to sort of convey the point so do do feel free to go and take a look at it later then if you look at the protocol logic so if you do recall I mean this was one of the biggest sectors right of the hacks so in this case there are obviously many many components to this because that is the nature of application logic depending on what what your application is doing you know you could have new ways attackers could have new ways to exploit it right so there are many categories here but the ones that stand out are Access Control exploit so Access Control if if you know is something that is fundamental to security if you don't have the right access controls you know some unauthorized uh in this case an attacker can mend can do something else with your contracts and exploit the funds right and the other one that is really common is the math mistakes so if you're looking at anything in this space right unless it's a very simple contract there is going to be a lot of math especially in the device space right you have numerous protocols that are trying to optimize every aspect of you know D5 lending derivatives uh all those aspects right so those again are places where developers make mistakes and these are not very easy to spot right because these are extremely uh you need to understand the protocol logic you need to understand the math there are certain Corner cases in solidity or the math library that you're using you need to be aware of all of that now the so this is uh this is an interesting one right so if you look at the hacks by Chain the the wrong takeaway from this is to say that oh you know the the biggest change right the biggest sectors here are the most insecure now the reason why you see ethereum or BSC right or uh the the other l1s or any of the other l2s right so these are the places where there is a lot of innovation happening right there are a lot of protocols being deployed you know either Originals or in some cases clones and in the process of cloning you may have copy paste bugs as well so this is where there's a lot of activity this is where you have a lot of assets where a lot of actors a lot of actions are uh you know persisting right over time and so it's natural for the security or for the attackers right to go after places chains where there is a lot of activity happening because or where there are a lot of assets locked because that is how they get to exploit it right so that's sort of the takeaway all right so we talked about sort of the ugly and the bad uh pictures um yeah can we get to the questions at I'll get to it at the end I think there's a different setup I need to use for Q a but I'll get to it um so if you look at so if if you're not convinced that the State of Affairs is bad or ugly right then please please reach out to me after the talk I would like to chat with you but this is you know not the state where we want to be and definitely not the state where we want to head towards right and the reason for why this may be the case so I have sort of listed 10 aspects of web3 which makes thinking about Security in this space very different from web 2 right so let's let's sort of dig into each of them and see why those matter when it comes to thinking about the security of the space keys and tokens I mean this is something that is fundamental to web3 I'm sure you've heard of not your keys not your tokens the way we think about Security in this space right unlike the web 2 space where you think about passwords here we are looking at keys and tokens once you sign a transaction once it's gone right it's not reversible right and the way I mean there are challenges not just with custody of keys there are challenges with how it is used with every aspect of it right and tokens there's a whole bunch of them and that itself over the last five or six years have led to Unique exploits if you've heard of you know erc20 you know the exploits there yeah c721 erc77 so each of them comes with its own flavor of attack surface right so that is that is one that makes us very different but the thing that is fundamentally different in this space when it comes to thinking about security is the threat model so in security you always think about two things trust model and threat model who do you trust who are your threats blockchains are all about the Byzantine threat model so look it up this is a threat model where anything anywhere any place can be arbitrarily malicious there's really no notion of a trusted Insider and everyone else like how we do in the web 2 space anyone right it could be the miners the validators the developers the drug uh the users could abuse the system over time it's really all about the mechanism design so this is something that has to be you know critical I mean that has to be front right and Center when you think about Security in this space and obviously Unstoppable and immutable I mean this is where we are headed to uh definitely with the layer ones smart contracts I think that's the ultimate goal but then you do have the possible features emergency recovery upgradability and other things where a lot of things can go wrong but this aspect I mean imagine if you're a contract that you deploy right is Unstoppable and immutable think about what if there are bugs in it can you fix it can you stop it can you apply a patch right all these are very different I mean the way you need to approach it in this space is very different and we're just I mean we are less in this space ethereum space we are less than 10 years right into this you saw the history of ethereum as you walked along the hall right so like 2013 2014 and we are less than 10 years right so we have a new architecture gvm based 256-bit stack based we have new languages mostly salinity we have wiper bunch of them coming up we have many tool chains uh I don't know what to use hard hat brownie but now there's Foundry a whole bunch of them right so all these things are still very early and they themselves may have bugs that could lead to security exploits the other interesting aspect is that this space the ethos in this space is open source and transparent by default right with smart contracts you deploy them the expectation is that that the source is going to be verified it's going to be open um and it's going to be transparent right so there is no more walled Gardens where you can hide behind security by obscurity right everything is transparent to anyone right to your users to the abusers to the attackers so it's not just in the technical layers but it's also in the social and governance layers where security is different pseudonymous teams reputation has to be thought out in a very different way Dao governance has to be thought out in a very different way the way that you can roll out security patches on a protocol that is governed by a Dao there's going to be a window uh there are in a compound for example had an interesting incident with that then composibility by Design this is again you're not you're not your protocol is not going to operate in a silo right it's going to work with you know maybe an oracle feed maybe other protocols maybe definitely you know the off-chain stuff a lot of lot of things happening so the attack surface here when you think of composability right and this composability is changing over time this makes the attack surface right grow exponentially what your constants are what your constraints are right what what configurations are all these things keep changing so it's really a moving goal post that has to be paid attention to and all this is happening in compressed time scales and what I mean by that is I mean if if you've been in crypto you know that one day or one week in crypto is like 10 for the rest of the world right there's there's so many things uh that happen in crypto that it's really hard to keep track of but then there are all these new things that are happening so how does that affect security becomes an afterthought right so there are a lot of shortcuts that are taken that a lot of Corners that are cut and think of your development right so as you finish your hackathon how much how much time have you spent in thinking about the design do you have a documentation for it have you written a spec for it right what are the invariants what are the properties right all these things sort of get moved to the side or get pushed under the rug and then projects get deployed right which is a significant factor in them getting exploited right so this is not right and this leads to this if you've heard of the test in Broad meme this is what you know causes where the actual test is happening in production so you see failures you see exploits that are undesirable and finally if I mean I have talked to many developers in the space and when we talk about when we say security the first thing that comes up is audit so security has been audits have become synonymous with security in this space which is not desirable right I mean audit being treated as a silver bullet is I mean if you understand security that is not the place to be right I mean audits are critical today but you can't just put it over the fence throw it over the wall and say hey you know what I got an audit great everything is going to be good I mean majority of the hacks that have happened right if you look at the details a lot of them would have got audited right so things would have got missed things I mean a lot of things that would have gone wrong in the process so these I think 10 sort of vectors right really make I mean shoot forces to think about Security in this space with smart contracts in a very different way so it's all I mean it's not all bad um let's let's talk about the good right so there are again insecurity this is something that's very well known right in security you think about three stages things that you can prevent things that get through because you couldn't prevent so you have to detect them so that you can remediate and respond so today a lot of the focus and security is happening in the prevention space which is good right I mean there are still big big gaps so audits for example is something that I mentioned there is a lot of emphasis on audits a lot of Reliance on audits that needs to be tempered with an understanding of what an audit is and what it buys you it is not a guarantee of uh you know zero bucks by any measure so there are multiple multiple teams innovating in the audit space so uh audit contests are something that that is interesting so you may have seen code Arena and Sherlock where you have audit contests where uh the audits are being crowdsourced right so that is that is an interesting sort of innovation that is happening in this space um then there are a bunch of tools and methodologies that are being innovated here you have Slither Echidna from Trailer bits you have uh scribble and others from consensus you have formal verification tools from sartora so I mean this is a space where formal verification actually becomes much more tractable doable and very attractive for various reasons so I won't I won't get into that but sultura has a top tomorrow so if you're interested do attend I think you'll find it interesting so a lot of lot of things happening in the prevention space then we get into detection these are things where projects have been deployed you know on chain and now um you know there may be bugs so what do you do right so you do have bug bounties bug body platforms like uh immunify which you may have heard of the bug bounties I think the last number was like 60 plus million dollars have been handed out by immunified to various white hat hackers who reported these bounties right so that I mean that tells you the the scale of things in the space then you do have Innovation happening with the tenderly um on the monitoring side um and filter uh so look them up so all these you know they monitor on-chain activity for um for what may be anomalies in the behavior and then they send you uh reports right I mean open supplement Defender whole bunch of tools in this space so a lot of lot of things happening response is I would say probably not I mean the the space that hasn't uh I mean it's very ad hoc today right what happens when there is an instant somebody uh somebody notices something wrong with the protocol you know based on on-chain analysis they raise up you know they put they send a message in the protocols Discord or telegram then something you know gets posted on Twitter one of the white hat hackers or security researchers learns about it and then they start diving and discussing this on Twitter and then if there was an exploit I mean an active exploit that could potentially be uh I mean that's still happening that can be stopped then there is an ad hoc war room that is set up and then you do have uh sort of an adult set of white hats who get called into the War Room who try to go and you know front-run the attackers and all this space all these things right so this is I mean this is good that it's being done but there's a lot of scope for improvement in this space in in terms of response right and there are a lot of people a lot of teens that are working on various Solutions in the space I mean I just uh I mean these are like 64 security researchers and teams um who are building tools and services in the space and um they were all uh you know they were all speakers at uh trustex which was an event that secured him hosted in Amsterdam earlier this year so we we do have a lot of people but you know you saw the scale of things right six billion dollars we have like 600 plus protocols being tracked by uh let's say defy Lama right so we need many many more so as you go and hack your projects think about the security and you know if you're really interested in security do come there are many of us here do come and reach out there are many you know ideas that need to be worked on there's a lot of heavy lifting that needs to be done right not necessarily by people dressed like this but there is a lot of work to be done right and we have a long way to go right so how does aquarium fit into the space so securium is the mission is really about educating and evaluating ethereum security it started about a year ago and secureum is known really for its boot camps free smart contract security boot camps entirely online and you see the QR code that's the you know address of the Discord everything happens over there it started about a year ago with a grant from the ethereum foundation where we also collaborated with some leading Partners in this space that you see here um completely free we had you know thousand plus people sign up 600 plus people who took I mean this was a boot camp right this was a boot camp uh for three months right and fantastic fantastic turnout and since then what we have done is we've moved away from a discrete three month one month kind of a boot camp we now have an always running boot camp that is free for all the participants every month there is a smart contact security quiz that is designed by securium or one of the mentors and uh yeah I mean challenge yourself come reach out to us and there are many other security players like I said as well and with that I'm done so I'll be around for the rest of the event so if you have if you want to talk about security do reach out we'll be happy to chat more and I think I have a few minutes for questions for which if you speak I think if you speak into your uh into the microphone then I should be able to hear and respond to you well one there are there any questions I think there was one question from here okay all right let's see if this works now oh does he need a microphone oh I think you have to use a microphone I think you had a question about this so this different color are different protocols or no these are the these are the layer one chains right so you have you have ethereum okay this this doesn't show so you have all the protocols on ethereum that got exploited are in that blue sector okay yeah so there is a protocol so why ethereum is in multiple times those are all the bridges okay so yeah that's the question like the different color represent a different uh protocol and bridges yes so you do have l1s and then you do have the bridges where you have multiple l1's and then you have some l2s as well so you see arbitrim you see polygon um I don't think you see optimism but yeah sure yeah okay uh the question is uh the Oracle is a very critical part of if we want to have a blockchain once currently we have the access of data which are the on chain on all of them but if you want to the accessible the smart contract application over the use case of a normal people so Oracle is one of the key part of that so some of the companies are doing a good Oracle but they are data are not efficient so the modularized as per our application requires so how the Oracle solution are we can improve on a better way in the future maybe like which type of oracles are should be the best and the secure way to use those Oracle actually right so I think I think there's a lot that we can get into the details of the oracles but I mean in general right the things that you want are from an oracle you want it to be decentralized right and uh I I talked about the The Flash loan and the price manipulation really don't want that right so I can I can point you to entire blog articles and research articles that have been written all that right so as a user I mean I don't know if you're asking from a user's perspective or from uh um you know protocol developers perspective but from a protocol developer perspective if you have a choice of oracles right you need to see you need to think about decentralization you need to think about availability um and really dig I mean this is I'm just scratching the surface I mean these are the key points and then how are you using that data right the staleness aspect of oracles right whatever feeds you're getting price feeds anything else that you may be interested if they get stale what is the impact in your protocol right so I think those are all the things Yeah so basically means as Oracle like for example Oracle got hack or some project was good hack as in the you said the response detects and so if you detect after deployment some response so there is one tricky thing like this some people tell that upgradable contract are not good because that are the the basically the the key part of that like uh you don't uh owning that contract anyone can come and the protocol can change this contract so basically uh if we detect the on chain any issue or any security bugs so are you recommended to have the contract of protocol or D5 protocol should we have upgradable or it should be the the migration like migrate to one to other or what was the best so there are yeah so there are pros and cons I think there's the community is divided between upgradability I mean the bad the good thing about upgradability is you can upgrade fix the bugs the bad thing is that process itself very few people understand how to do it in a proper way there are so many you know proxy patterns that you can look at and each one has its has so many new answers right so again happy to chat and to go into the details I don't think there's a clear answer because it's it's about ease of upgradability I mean ease of um you know fixing bugs and anything else versus the downsides being if you don't do it the right way right you're I mean forget about upgrading you right you're you're done yeah so I don't know if you have time but yeah maybe one more uh I said I have two small small questions first thing is in the recent times a lot of hacks have been on the bridges uh end of things yeah so how can we improve on that the security part on the budget side and the second thing is uh like me and my friend here a week R is a part of an in-house auditing team at a service based company and we are extremely interested into security we started doing all the online ctfs that are there and even reading this aquarium blogs as well so what else can we do to you know get uh speed up on the faster uh get speed up on the security side of things like learning that yeah so I think the second part I'll take it offline we can chat more right because that that is uh I mean there are so many things you can do to speed up but I think it's also about how much time you spend and you know the resources and so on but your first question I think the bridges out of the top uh four Bridge hacks I think one was really you know based on um the the web 2 side of things right there was a spear phishing um somebody somebody's um laptop got I mean server whatever it got hacked and then they got access to the validation Keys uh so validator keys and that you know caused you know they got all the five out of the nine and so on right but the others were about smart contracts about the logic right so I don't think there's a simple answer of you know would one thing have prevented every you know each each one of those um but I think it's really all about the entire process right so there are many things that can be done and we are still working on it all right I think I had one question yeah uh oh okay sorry I think I'm done we should find me outside yeah happy to talk to you thank you

Automatic transcript — names and jargon may be misspelled.