All Your Contract Are Belong to Us: Analyzing All Deployed SCs | Yannis Smaragdakis - Dedaub
Ethereum Denver·Wed, Oct 9, 2024, 12:00 AM
Speaker
Dedaub develops technology to analyze all EVM smart contracts ever deployed. Cool uses/stories: a) Solidity compiler bug: "most deployed contract addresses contain mostly junk code!" b) Helping the Ethereum Foundation study EVM changes c) Ecosystem-level threats: use in major "war rooms", e.g. ThirdWeb vulnerability. APPLICATIONS FOR ETHDenver 2024: #YearOfTheSpork ARE OPEN APPLY NOW https://ethdenver.com/apply
Transcript
okay welcome everyone thank you for coming uh I'm Janis from ddob and uh I'm going to talk about our technology for analyzing all deployed smart contracts I'm going to tell you about some of the cool things we've been doing for the past year uh basically I'm going to go over three stories of where technology has come very handy and hopefully they're going to be interesting stories uh so to start with I know this is not the best setting for interaction but who has heard of of ddob not many people so excellent so my talk is is not going to go to waste so who are we uh we do research we and technology in program analysis and we've leveraged this for a smart contract security so we've become one of the uh successful uh security firms in the smart contract space in the web 3 space uh we've become a major auditor for many of the services that you know and love uh you know we we audit nearly everything from chain link for instance but many other organizations as well we AIT uh we audited igen layer just uh last month so we've been a pretty successful auditor at the same time we've been pretty successful in bug bounties so we've uh disclosed many vulnerabilities so since 2021 you may have seen some of these articles but uh basically uh We've uh we've found 11 well we've found hundreds but we've gotten 11 bug bounties uh from vulnerabilities in uh in deployed code so we've received more than 3 million in bug bounties alone so we've been pretty successful in this space now but what most people know us for is app. dd.com or library. dd.com it's the same application it's our tool people have started calling it just ddop uh and it's a lot of things it's an explorer that decompiles all deployed smart contracts and runs various analysis on them uh anyone who wants to explore contracts that don't have source code for instance uh comes to our tool anyone who wants to explore me Bots or hacks or anything like that uh and this is all based on our decompilation technology primarily so we have the best decompiler for evm bite code smart contracts on any ethereum VM chain ethereum but also all its relatives uh they are deployed in the form of evm bite code we can reverse and engineer that better than pretty much everyone else so we are the leader in this space now why is this interesting that we have a de compiler uh well why do I care I deploy my smart contracts and my smart contracts have source code well you care about having a decompiler because it offers a unified platform for automatically analyzing smart contracts so the decompiler is just the great unifier that enables automation over the smart contracts that why you care so what I'm going to do today is talk about where we've been invaluable in the space uh and specifically these are all stories from the past year so generally whenever there's a question that needs to apply to all contracts all deployed contracts on ethereum but also other networks uh arbitrum optimism Phantom base etc etc anything evm based uh people come to us so let's look at a few applications where our technology has come pretty handy so Story number one this was about a year ago this was February of 2023 uh this was the finding that over onethird of deployed smart contracts have more than 50% of their deployed bite code be junk code so sometime a year ago uh we tweeted this finding uh there's a solidity compiler a C bug that resulted in most code for many many contracts out there uh most bite code being junk never being used so what's the bug like how did this come to be uh it's kind of an esoteric thing it's a all C bug where Library code was only called in the Constructor so it's never used while the contract is running but the solidity compiler does not throw away that code so it's includes it in the runtime bite code in the actual code of the contract that goes on the blockchain even though it was never used while the contract is running it's only going to be called while the contract is being deployed and this is particularly important for small contracts like proxies so if you have little proxies uh that you know basically have this shape here and I don't have a pointer it seems uh they have a Constructor that calls a bunch of libraries but then they have code that just forwards to an implementation and they never need these libraries again the code for this proxy contract will include all the libraries that are called in the Constructor even though they're entirely unnecessary so this was kind of a surprising finding uh this was fixed after our report in salce 0819 so uh this was a finding that leverage uniquely our technology uh in in the past year moving on to to Story number two uh the ethereum foundation often asks itself what will be the impact of this uh Improvement proposal this AIP on all deployed smart contracts and whenever this happens uh we are the natural people to ask so we've done lots of studies for the ethereum foundation uh over multiple eips or things that don't even have an EIP code like uh the upcoming vericle tree uh transition uh all sorts of upgrades we study their impact over all deployed contracts so we are been commissioned to study the impact of all of that of all of that and it's kind of interesting because the general pattern of this is to ask us which smart contracts are going to break if we apply this and that chains to the evm and which of these contracts are important and the important part uh we'll have to discuss because it's going to come up again and again uh so that that's also part of our technology not just uh find what the contract can possibly do which is part of our uh static analysis technology but also what impact will this have to the overall ecosystem in terms of uh tokens that are being held in terms of importance of the code to other contracts etc etc uh now this is important because upgrading the evm is a pretty dangerous task if if you want to change the itics of the evm it's like upgrading a car while it's still running and that's exactly what the ethereum foundation has to do and that's where our these questions become particularly valuable so in detail let's say what we do is ask ourselves if I get an upgraded evm let's call it evm prime it runs smart contracts and we want to ask for all executions over all smart contracts how many will break that didn't use to break before and how many are important and there our technology comes to answer different questions such as what is for all executions what does it mean to break and what does it mean to be important so let's have an idea first of all for all executions that's where we use static analysis technology we have lots of research Publications on static analysis that's part of our DNA as a company uh it it effectively answers the question what will a smart contract do under all possible conditions so our particular technology starts from turning a program into a database so you can think of it as the decompiled program on the left it has a loop and then we insert elements from the program inside tables and you don't need to parse all of that but think of it as having tables like induction V and flows and lo loop with conditions so we represent now the program as a database and then we can run pretty important queries pretty pretty uh convoluted queries over that database so we actually use a language that supports recursion it's called data log so we have a logic based language that queries this database ited can ask things like well can you find me all the loops uh and their bound and if they satisfy certain conditions and again I'm not going to go uh into detail but you get an idea of how we actually specify these algorithms from the little fragment on the left which is a fragment of the query that we run on the database that represents the program and then this will actually tell us well this program on the right has a loop and it's bound by variable end times okay so this is how we answer the question of what is all executions how do we answer the question what is all interesting executions programs are one side of the coin uh and actual executions of programs transactions are the other side of the program of of the coin and what our technology does is also encode transactions as a database so this is dynamic analysis we go over all past transactions we squeeze them we distill them down to their Essence so to speak and we go and store everything in a database that we can query pretty effectively so for instance a query may be give me all the past executions of function so and so that have a fixed gas budget when they are called the gas that's being P passed to the call is say 2,300 so it's a bounded gas allocation uh so when we have the technology so we have the program as a database we have the executions as a database still to answer the interesting questions we need to apply some Ingenuity and I'll I'll show here an example from a recent study uh and the study is over the question does this smart contract or find me all the smart contracts that have logic that parses rlp rlp is it doesn't matter too much it's recursive length uh prefix it's a particular kind of serialization particular kind of encoding of data uh that's used for blockchain dat so effectively this tries to find all smart contracts that analyze transactions over ethereum or other blockchains so it's kind of a weird thing the contract itself takes in signatures of transactions and analyzes them so how do we find this well what we do is we come up with clever ways to use our technology like static analysis queries over this question so for instance in this case uh to find contracts that Implement rlp decoder libraries we'll look for specific elements in that code like specific constants that are used in the rlp specification and that's not too clever that's pretty straightforward but again it shows that we use the technology and then we have to somehow Be Clever about how we query the technology this part is a little more clever uh if we want to find past transactions that actually had rlp encoded data uh we we came up with a with a clever technique there that basically says I'll parse the call data and I'll see if I find a byes array whose length matches what should be inside the array which is also some length fields in the case of the rlp specification so this is kind of a clever query tuned to that particular analysis again the point is not to discuss this query the point is to kind of illustrate how we use this technology which can answer all sorts of questions to answer a particularly interesting question over all deployed contracts and past transactions and putting it all together we have all important contracts we have all executions of contracts all potential executions we have all past transactions and in the end anything we report we have to filter uh by importance of contracts so we have to ask ourselves well we found all the contracts that may be affected which of them are important because there's lots of contracts deployed out there that have no importance whatsoever they don't hold money nobody transacts with them anymore so what's the importance of a contract well it's a complex question but for instance it could depend on any of these factors it could be that the contract is part of a major protocol it holds fans it holds funds uh it transiently holds funds so has some privileges some permissions with some other contract it's used as implementation and someone else who is important calls it uh has approvals etc etc so lots of criteria can tell us that a contract is important and that's also part of our vocabulary that's also part of our database technology that one can write queries over and this requires fairly specialized data infrastructure and much of this is actually showcased in our public tool so if you go to app.
dd.com most of what you see is based on the exact same database that we use internally or as part of our Security Suite for program analysis of these kinds so that's Story number two these are the studies that uh we run for the ethereum foundation find the impact over all deployed contracts what's Story number three well that's kind of the most obvious one uh War rooms for major hacks if there's ever a hack that can affect effect the whole ecosystem more likely than not we are being called in so you've seen those movies that talk about extinction level events well in in this space we talk about ecosystem level vulnerabilities and that's exactly the same thing could there be a bug that will wipe out much of the value held in a specific blockchain in on the main net or on some other chain and whenever something like that happens when there whenever there's a threat discovered that's widespread it's not limited to one protocol uh we can participate and we often participate in war rooms to apply the same technology and expertise as in the ethereum foundation studies and help answer the question who is affected so very recent example from uh a couple of months ago from December of 2023 uh the third web vulnerability you may have seen uh the disclosures from open Zepp there's a bad interaction between a couple of libraries that implement the 2771 standard uh and multicol and if you saw the postmortem we're being credited there for uh for the crisis management for the queries so what did we do there basically again same pattern as what we did with ethereum Foundation studies uh we ask ourselves what are all the affected contracts out there how did we do it in this case well in English it looks a bit like this for all contracts that contain these elements in their decompiled code so they contain a delegate call they contain some specific call data array manipulation uh that indicates a trusted forwarder which is part of the of this attack of this vulnerability and they also support a certain interface that indicates uh multic calling find the contracts themselves and if their implementation contracts also find their proxies including diamond proxies and Report the union of all of those every single step I defined here every single step I I presented uses one part of our technology it uses the decompiler because we want to unify all deployed contracts to find these code patterns regardless of what they've been compiled with and how exactly they they specify it in the source code whether they use an extra parenthesis or something uh so we normalize everything we match patterns on the decompilation we uh check signatures that's also part of a technology uh we check in our database all the relationships between contracts whether we have proxies uh whether we have uh Diamond patterns everything and then in the end we also need to ask what are the important contracts and I'll get back to that in a second but let's just to give you an idea just to give you a glimpse of the of the technology and what it looks like internally uh which is also the same language that you can use for monitoring bots in our system if you are a user of our uh integrated uh Security Suite here's what the query looks like now again I don't think you can parse this very quickly but this is the same thing that I described before in English uh so it basically looks at the specific pattern in the decompiled code and then it queries the database for all proxies that call contracts that have these patterns including all diamond patterns uh that may involve the contract that has these patterns in so that's what we actually did uh for the third web vulnerability two months ago and we combined this with important contracts because if you just run this over the 800,000 different code bases that have been deployed on E eum alone you actually get over 10,000 contracts that are potentially vulnerable so you have to ask what are important what which ones are important so again you have to combine it with is it part of a major protocol does it hold funds does it have permissions does it have approvals uh can it is it involved in some way in something that could control a lot of funds and in the end that's what human inspectors analyze so we report a small subset of the contracts and people go in and they analyze them for vulnerabilities with manual inspection so that's all I had to do I had to say it's basically I took you over uh our unique technology strengths uh and I kind of gave you examples with these three stories uh from what we've been doing for the past year and the the main idea again is we have technology to normalize deployed smart contracts so we can run automated queries over them we do the same for transactions and by combining the two we can capture a lot of the potential for either bad effects of vulnerabilities or of the potential for anything that could happen when a contract or uh the theum VM itself evolves thank you very [Applause] much
Automatic transcript — names and jargon may be misspelled.