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

Loading player…

Smart Contract Code Genealogy on Ethereum and Other EVMs | Ren Crypto Fish - Electric Capital

Ethereum DenverWed, Oct 9, 2024, 12:00 AM

APPLICATIONS FOR ETHDenver 2024: #YearOfTheSpork ARE OPEN APPLY NOW https://ethdenver.com/apply

Transcript

hey um I'm Ren I'm an engineer at Electric Capital and today I'll be talking about smart contract genealogy on ethereum and other evm chains so to start off and to frame the reason why we care about smart contract genealogy um the main goal is to try and answer the question where is new code first deployed new code we view new code as a form of innovation and we're really trying to answer the question where is the Innovation coming from so there are a lot of ways to measure Innovation um some are more subjective While others are more objective and today I'll be presenting one possible path that is scalable and a way to measure Innovation across evm chains so to answer the question of how do we detect where Innovation originates we detect when new evm is De is deployed uh via vaguely a three-step process first we identify the logic blocks that determine how a smart contract works by analyzing its source code and bite code second we create a unique identifier which we call a fingerprint for each logic block using a cryptographic function like for example md5 hash um and third since each logic block is uniquely identifiable we can tell which contract first introduced the logic um where it was first deployed and when contracts reuse logic blocks in the future so to be more concrete um about how this actually happens first we determine all of the paths that a contract code can take from start to finish these paths are called a control flow graph so by taking the runtime bik code that is deployed onchain decompiling it generating a control flow graph we end up with a bunch of nodes So within each of these nodes we create a unique identifier for each step of the path so for example a CFG node might look something like jump dust call Value is zero push two pushing a value and then and then a subsequent jump to the next node to execute along that control flow graph well we can take that list of op codes and generate a unique identifier um such as by using md5 um to create this fingerprint that we can attribute to that deployed contract and then track when other contracts deployed on other trains in the future are using that same block of logic and since each CFG node is uniquely identifiable we can tell tell which contract first introduce the logic on chain and which contracts use the logic in the future so before I go into the graphs and some of the analysis some caveats so for instance the reason we think using this CFG fingerprinting uh method is is particularly powerful is that changes to constants function names or variable names produce the same control flow graph nodes because the sequence of logic within the smart contract doesn't actually change so when we stripped away the values pushed or popped to the stack in memory this helps dup and better identify novel blocks of logic so for instance if you had two we contracts and one change some of the function names maybe they change some of the constants that actually produces the same fingerprint this is particularly good for D duping against things like Cil attacks spam Etc however comparing absolute differences in CFG nodes is not a perfect metric so for example changes in compiler versions can introduce differences in CFG nodes amongst other reasons for differences so for example if you were to use the solidity compiler 418 to 421 you would have the same set of CFG nodes but using 422 to 426 you would introduce 13 new CFG nodes compared to4 418 um that's roughly around 13% of the CFG nodes for the we contracts so there are there is a trade-off in using absolute matches for the fingerprinting for CFG nodes um which we view as a good trade-off at the moment because it results in Faster pairwise comparisons at the cost of handling some of this drift in compiler versions over time so here's a summary graph of where net new blocks of logic are being deployed and what we generally see is we had this large runup kind of like the smart contract Revolution um that happened between 2020 and 2021 during defi Summer and the nft wave that happened subsequently and net New Logic deployed per month has roughly held up through the bare market and today we increasingly see that net New Logic um is not only on ethereum but is starting to appear on B&B polygon and arbit in addition to ethereum but if we look at just the contracts deployed in 2023 we decompile those contracts and then we look at where the logic blocks or the CFG nodes originated or were first deployed what we see is that 71% of the logic blocks for contracts deployed in 2023 were first deployed on ethereum followed by 19% from B&B and 7.2% from polygon which is a pretty interesting Insight given that ethereum did not have the most deployed contracts 2023 but the unique aspect of ethereum's code base and ethereum's deployed contracts is that the smart contracts on ethereum are mostly unique and they're homegrown and deployments on other evm chains can often Trace their Origins to to another chain so on the graph on that you see on the screen we can see that the vast majority of the contracts deployed on ethereum contain logic that were first that was first deployed on ethereum whereas if you're looking at bmbb chain polygon arbitrum Bas squirrel Avalanche optimism the vast majority of the logic that comprise the smart contracts deployed on those chains originate from another chain and with this line of analysis we can trace where every block of of New Logic is first deployed and where it is deployed next so we end up with some pretty interesting flow graphs that show where code is pulled and where code is is being used the first takeaway that I highlighted earlier is that most of ethereum's contract logic is only found on ethereum comes from ethereum and gets reused later on in ethereum with a small portion of other chains exporting logic into ethereum and ethereum is also the biggest exporter of New onchain Logic so chains like BMB polygon arbitrum bass Avalanche and optimism the developers on those chains when they're writing their smart contracts are reusing pieces of logic that originated and were first deployed ethereum second to ethereum is bmbb which exports a lot of logic has a lot of deployments but the vast majority of those deployments comes from code that was first deployed on ethereum and lower lower on on the graph you can see that most of the contract on l2s actually just comes from ethereum or was first deployed on ethereum BMB and polygon are the next largest creators and exporters of logic and New Logic that appears on BMB and polygon can make its way onto ium BMB polygon and l2s anecdotally this kind of lines up with some of the things that we've seen where bmbb and polygon due to being low cost chains are often the areas where developers might experiment with New Primitives new ideas due to the lowc cost nature of deployment and large user bases on those chains one of the interesting aspects is we can we can take all of the deployed contracts from 2023 we decompile them we have fingerprints for the logic that comprise those deployments and then we can look and ask the question in what year did those blocks of logic first appear on chain which gives us a sort of vintage like analysis of when when those blocks of logic were first written so for instance contracts deployed in 2023 across evm chains contain a lot more logic that was deployed earlier than 2023 than in 2023 which is a troubling uh uh type of result that we found but it's not necessarily a bad thing because one of the aspects of smart contracts is that the security is really really important and if you have a primitive that's been battle tested that has been that has a sort of lindin because it's been live in production for many many years and has been used by a lot of users custodies a lot of tvl and assets you might not necessarily want to rewrite that that primitive or for instance if you have a math library or other form of Library there isn't necessarily a strong reason to do so to rewrite it but underneath the Aggregates we are seeing a sense of Divergence so we saw earlier that so on the left hand side ethereum and squirrel bucked a trend of 2023 deployments using net New Logic from prior to 2023 and on the right hand side we can see that a lot of the faster l2s and cheaper l1s such as arbitrum Avalanche base B&B chain optimism and polygon the contracts for the percentage of the logic in the contracts deployed in 2023 that were originally and first appeared in 2023 is actually quite low compared to the logic that first appeared in Prior years but on the other side on the on the right hand side with ethereum and scroll you can see that um ethereum actually had a rebound from 2022 and in 2023 we see that a larger proportion of the contracts deployed during that year are using net New Logic that first appeared and first was deployed in that year and scroll shows a similar Trend so some takeaways that that might be valuable for Builders l2s folks working in ecosystems is that decompiling deployed bik codes and fingerprinting the control flow graph nodes provides One path to attribute blocks of logic that removes the effect of trivial changes in source code over the past few months we've seen increase Cil activity on the development side especially with scroll and Bas and one one very easy way to strip away a lot of like trivial changes like changing variable names function names constants is to take a CFG fingerprinting type of approach it's very easy to quickly dup contracts that way in 20123 most logic in smart contracts still originates from ethereum which kind of bucks this idea that the l2s are leading Innovation at the moment but that might still happen in the future and finally there is Divergence in 2023 where ethereum showed the first Rebound in that new logic whereas most other evm chains the contracts that were deployed in 2023 were still sourcing most of their logic from prior to 2023 cool thank you

Automatic transcript — names and jargon may be misspelled.