Predicting Risk - Leveraging AI to Analyze Smart Contracts
ETHCC 7 · 8 Jul 2024 · 18:05
Maika Isogawa, co-founder and CEO of Webacy, explains how AI can help analyze smart contracts as deployments grow, citing an estimate of four and a half to five million on Ethereum this year. She says manual audits struggle with complexity and scale, then covers three approaches: graph neural networks that model code as nodes and edges, transformers that read long-range dependencies, and federated learning for private data. She gives an example of Fuzzland's AI-driven fuzzing finding a lending protocol exploit.
Speakers
Topics
From ETHCC 7, hosted by Ethereum France.
Transcript
That's gonna do. All right, hello. Happy Monday, happy first day of ETCC. Hopefully, some of you had some events over the weekend, but officially starts today. And I the number of people I saw drinking last night, hopefully you're all having a good time also. Today I'm going to talk about something that is very hyped up within the crypto space right now. I personally live in San Francisco, so A high has been the talk of the town. If you've been on Twitter or really anywhere in this industry or tech, you've been thinking about AI, maybe talking about decentralized AI as a topic, talking to VCs that are very excited about AI. My background's actually in AI, so this is something I was really excited to talk about.
I like to come to these conferences every year because you get a flavor of what's popular during that time. So last year in Paris, I was actually speaking about the way to secure your your seed phrase, self-custody, and then this year it's actually about how you can leverage AI to now analyze smart contracts. This QR code, we only have 20 minutes to get there today, and some of these topics get really complex. So if you'd like to review any of the papers that I pulled some inspiration from or techniques if you want to dive in further, the first tweet of my profile, which this links to will give you some details into the actual techniques that I talk about in today's talk. I am the co-founder and CEO of a company called Webacy.
Our aim is to make the crypto space safer, and we do that through a consumer-facing app and as well as APIs that integrate into other companies. This is the number of smart contracts deployed on Ethereum only every single year. And you can really see that it kind of starts off with real numbers, these are all in millions. In 2017 with the ICO boom, and then over time, even with the ups and downs of the cycle, you still see it pretty much exponentially or linearly increasing over time. 2021 was basically when Uniswap and Compound came into play, a lot of DeFi protocols.
And then in 2021, that's when NFTs kind of popped off in the space. And so you see general increase over time. It's estimated that even this year, in ETH alone, it's gonna be around four and a half to five million smart contracts deployed over the year. Just kind of a crazy number. Chain analysis produces a risk report or a security report every single year. They're actually very good because they have an excellent amount of data. And this chart shows over time the amount of value stolen through hacks and scams and so on over time, and you can see it go up and down. 2024, we're kind of on track to be around comparable to 2023 or slightly more.
And there's two things to think about here. Number one, there's more money in the space, hence more money to be stolen, but also again, more smart contracts in the space, and you'll see on this screen, this shows the breakdown of where that hack money is coming from. So early on, you see that the dark blue here, these are centralized exchanges. So you have Mt. Gox, you have a lot of these companies that are holding a lot of crypto that got wrecked, and then they started to kind of figure it out, but then also more money became locked into came in to be locked into DeFi protocols. So you see that lighter blue take more of that percentage over time. And that matches with the smart contracts that are deployed.
When it comes to this and the pure volume of smart contracts, we're kind of coming across two major challenges in that smart contract safety and risk mitigation space. The first is the complexity of those smart contracts, and then the second is the limitations of manual analysis when it comes to analyzing all of those smart contracts. So the first one, complexity, especially when it comes to DeFi protocols and smart contracts, these are not within an echo chamber. So you can test against them, but really it's open to open markets, which makes them so exciting as a DeFi protocol. So you have everything from general code flaws, you have growing attack surfaces, and then if you start to go cross-chain, you have bridging, a lot of these hacks actually happen to come from bridges and exposures there, as well as financial loopholes, contracts are generally just getting more complicated, and we're we're all getting more complicated as the ecosystem grows.
So then you come across things like re-entric re-entrancy attacks, flash loans, even just general seed generation flaws and a lot more. On the manual analysis side, general recommendations for code security is get an audit. But at this point, a lot of auditing companies, maybe you've heard about the news of things that have been happening in this space, but there's a lot of different audit companies. You have to pick one, first of all, and then these are human beings auditing the smart contracts. And then even if you get audited, number one, there might be flaws still that are left that you just were not aware of. And then number two, things change in the ecosystem.
So maybe there's long-term relationships within your code that you just weren't aware of when you're initially getting the code tested. And then once you have real users, it kind of changes the dynamics of things. So you have, first of all, also just human scalability. There's not enough people for the amount of contracts that you see going exponentially. So two major problems. There's more, of course, but these are the major ones that I've identified. Which brings us to today's talk: how can we actually leverage these new technologies to improve the smart contract analysis that we're doing? So we'll talk about just three. There's many more: GNNs, transformers, and federated learning.
Graphical neural networks are modeled after neural networks, which you may have heard of before. This is kind of malmodeled after the way that our brains think. And it's really about having edges and nodes, it's more of a graph problem to be able to represent code and how things are interacting with the code. So to break this down, and this is very common in any kind of breakdown structure if you're trying to train a model, you're starting with the code, and then you're going to model that as a graph. There's a couple different methodologies listed here, but you have edges and nodes, and you can decide how you want to model those edges and nodes. For example, a node could be a function, or a node could be a relationship between a function.
It's kind of up to you to decide how to do that. Then there are some techniques to limit that, because these graph spaces can become very complex depending on how challenging or how complex that smart contract is. And then finally, you extract features from that. And again, it's all coming from a representation of code. Once you do that, then you have to train the model. And this is another large big debate in machine learning in general is that when you're training the model, all the data is from past hacks and past scams that have been labeled and found. So when you're then applying that to new smart contracts, all you really have is that past data set of hacks and scams that have occurred before, which makes it really challenging to find new ones until the hackers find them and then we find them.
But then eventually you can actually train that model and then see how it performs against new smart contracts. There's a lot of really good research. Out of all the three categories, I would say graphical neural networks are probably the most researched against, which has been really awesome to see. There's again links in the tweet, uh the tweet thread that I'd posted before. Really, really interesting if you want to dive into the methodologies. This paper in particular findings were that it performed way better than the traditional AI methodologies that have been out there for finding issues in smart contracts. Transformers are really fun. So this is leveraging advanced natural language processing models that are adapted for code analysis.
So as a human being, you're writing code, you're probably writing code in a way that you can understand in natural language for the most part, and then you're hoping that the auditor is able to read the code, especially if you're going to get it audited in the first place. And so transformers leverage this NLP understanding power to be able to understand long-range dependencies as well as leveraging the code semantics to be able to figure out problems within the code itself. Next slide has some examples. But on the long range dependency side, sometimes when you're reviewing code, it's challenging to understand states of the code itself, especially let's say DeFi protocol. You want to stake over time, there's some rules involved, and then unstaking later, it actually gets quite complicated.
So leveraging transformers allows you to understand this entire process from a linguistic point of view. And then code semantics, of course. And then this is all based on if you are writing code in a way that's actually human readable. So that's a caveat there. When you're applying transformers to smart contract analysis, there's many, many other use cases here, but these are three applications that I like to talk about. Re-entrancy detection. So this analyzes for a sequence of function calls and as well as recursive calls or opportunities for recursive calls as well. Integer overflow and underflow is another one that understands the pattern recognition around arithmetic operations of where numbers should be versus where they could be.
So that's another big vulnerability that this is useful for. And then finally, my personal favorite is actually access control. Who can do what in the smart contract? And is there ever an opportunity for someone to have permissions that they're not supposed to have? That's another one where Transformers can be quite useful. The third one is federated learning. This is distributed machine learning. I think we've heard a lot about decentralized AI. It's a little bit different, but within a very similar category. And this one's also slightly different from GNNs and Transformers in terms of application. This is more about data and access to it.
So for the first part, it's data privacy and security. So if you have super sensitive code bases or access to private data sets, it also supports compliance, like if you have a GDPR region as well, but you want to work with other regions that don't necessarily have that regulation, regulation or compliance ruling. And then for distributed data. So if you have access to diverse code bases or expanding your range of detection in general, these are actually methodologies that have been mirrored in, let's say, healthcare. If you want access to sensitive databases, having more of a distributed model for access to that data can keep it private, but also give you access to train your models on that data without having to actually have the data in the first place. So very powerful if you have private data sets.
And then the last thing I'll mention about the distributed data, it can give you access to ways of writing code or code contracts that might be slightly different in different contexts. So if you have one group over here write smart contracts in one way, one group over here writes smart contracts in a different way, you can actually get both of those methodologies without having to be exposed to all of the information that they have. So really powerful when it comes to model training as well. Now, all of that is really, really cool. Not too many companies are leveraging the full amount of AI methodologies that are out there today, but I did want to call upon one that's actively working in the space. If you see this bottom left corner, it's kind of small.
Fuzzland is one of WebAC's partners in the space. And this is a company that uses AI methodologies for fuzzing and dynamic analysis of contracts in real time. Really excellent company. And there's a couple different ways that they secure different other partners in the space, smart contracts, companies, and so on. But the main thing that I want to call out here is that there's a large leading DeFi lending protocol that was recently they discovered a exploit in for hundreds of thousands of dollars. And the way they were doing this by was by continuously attacking that smart contracts with random inputs over time. So this was leveraging AI, of course, leveraging some of the AI technologies that I had mentioned in this talk, and they were able to discover and mitigate that vulnerability with this company.
And this is really bad quality, but the reason I'm showing this slide is that when you're in the security or safety space, it's a very interesting category to be working in because if you're doing your job well, people are asking, uh, people probably will not ask if you need to be there in the first place. You don't really notice if a security company is doing a really good job if they're doing their job because nothing ever happens. But there is high importance to have some sort of safety and security protocol working with your company or working with your founders, whatever you're building, because there's real value associated with these things. So Fuzzland, for example, just from their inception has prevented over $15 million in hacks.
It's a lot more than that in my mind. They've rescued over six million dollars in funds and have detected over 200 million in losses. That's another big issue in crypto, is sometimes money's gone and you don't even know. So that's another one in the first place. But again, just there's a there's a lot in security and safety to keep an eye on, and companies like FuzzLAN are doing a really good job doing that. So to close out, I do want to talk about what we are doing to leverage new tools like this, as well as working with partners like Fuzzland to make the space safer overall. So there's four main ways that we work with uh that kind of gives us an edge as a safety company in the crypto space.
The first is a real user army. So I mentioned that in the very beginning, we integrate with other companies, but we also have this really exceptional consumer facing platform for users like you and me who self-custody to keep ourselves safe. They do around two to three million transactions every single month, as well as uh they have around a billion dollars in assets protected. And the reason this is important is because this gives us access to all of the new activity and new addresses in crypto based on real users. So if you're a machine learning person, you know that this is a really viable and valuable data set if you want to train any kind of model on real human activity. The second is a research army, so we work with real college age students that are trained on safety and security practices and code and smart contract code to go and look at the hacks, the scams, any kind of social data and analyze and label the data.
We have a really big data problem in crypto, and it's kind of getting bigger as the smart contract space expands, but it's really useful if you're able to have a human verified, human readable version of the code that's separated by labels. The third way is through vertical partners. So there's two ways here. One, we work with companies that give us data that's specialized within their data set. So if it's DeFi and they're in the DeFi space, we get that. If it's SocialFi, we get that. And we are able to aggregate across and understand the complexities between. As well as we integrate into other companies through our APIs.
So when users connect, they get to see the safety score of their wallet, but we also get that data of these users coming in, how safe are these wallets, what is their activity on chain. And then finally, if you or you have a portco, anyone who's actually building in the space, want to integrate a safety layer to help protect your users, with WebAssembly, you're getting all of the data possible across DeFi, across custody, SocialFi, GameFi, everywhere, as well as if you have data and you want to participate in a network to make the safe space, this space safer entirely, we would be who you'd want to join. So I will pause there.
Again, the QR code if you want to read all the list of activities that we've done today. But I'll pause there and stay safe in crypto. If there's any questions, I'll have like a minute or two. Hi. Thanks for the super interesting uh talk. Uh when you were mentioning that one of the issues when you're using GNNs uh is that you're training on data that has already been labeled as a hack, so the hacker probably already knows that that's not a reasonable way of hacking.
Could you maybe use like some uh reinforcement learning to improve that? Like is there a way to use that part of uh AI to fix it or you don't see any benefit on it. I so yes. I think first um hackers, even though a hack has occurred, they may still try the same technique because that doesn't mean anyone's fixed it at all. Uh so you've see the same re-engency attack happen across the space. Um there's different ways that you can perhaps like test on new like uh inputs. So, for example, Fuzland does a really good job of inputting different kinds of data across the board uh to be able to test these smart contracts.
So there there's definitely like a non-a-no answer when it comes to using reinforcement learning, but until a new hack occurs, it's hard to have any kind of um feedback or data that has to do with that hack, if it makes sense. Hi. Thanks for the for the talk. I was wondering if well, you mentioned that you need to learn from previous hacks. And that is a way to build the neural networks.
So my question is more related to future hacks and to predict if that is possible with neural networks, or if you are trying with neurosymbolic AI or symbolic AR more efficiently for that sort of things, and also to give sort of uh inform this is more related to the previous question. Yeah, I think um for this one, the the transformers example was actually probably more relevant. Um so when it comes to understanding what could potentially happen as a human being, especially for auditors, you have to think about all the cases that could happen.
Um but it's kind of impossible as a human to understand all of the states that could possibly happen. And when you're testing the smart contracts, you need to be able to have the rules that you know are happening. So you need to know this uh permission order has to stay correct. So maybe you could test permission order to understand those hacks. Integer overflow and underflow, those you can test against because you could tell it these are the bounds which it needs to stay between. Does it ever go out of those bounds? Um, but if you're thinking from that perspective, then you really need to have a laundry list of all of the different potential situations and then check against them. But even in my head, like I can't possibly list out all the potential hacks and uh attack vectors that are happening in the space because then again, if you add a new bridge, add a new layer to interact with your smart contract, then you just really don't know what's happening in the first place.
Last question. No one? Thank you, Micah. Thank you.
Related talks
- Smart Contract Security and On-Chain Fraud Prevention with AI
- Sebastian Banescu - Drained Before any Code Exploit: The Non-Code Risks of Web3
- Security - Today and Tomorrow with Ronghui Gu
- From Description to Exploit AI Agents for Smarter Audits
- DeFi Security Summit 2024: Day 2, 9 November
- 【Uzumaki勉強会】自動バグ発見AIを開発してIntmax2のZKPライブラリのバグを見つけた話
- Enhancing Large Language Models for Smart Contract Security - DeFi Security Summit 2025
- Auditing with Machines: A Practical Exploration of AI-Augmented Security Work
- DeFi Security Summit 2026: Amber Room, Day 1