Alpha for Auditors: The Vulnerabilities of Tomorrow
DeFi Security Summit 2022 · 27 Aug 2022 · 21:46
Anton Permenev, an engineer at ChainSecurity, surveys the vulnerability classes he expects auditors to meet as DeFi grows more interconnected. He covers tokens that stray from the ERC-20 standard, such as double entry point tokens, insecure getters that return a wrong price during an ERC-777 callback, and hidden assumptions about USDC blocklists, fee-on-transfer tokens and negative Chainlink prices. He also warns that protocol upgrades such as self-destruct changes, gas repricing and account abstraction can break deployed contracts, and argues for formalized standards and a plan to drain a protocol if assumptions change.
Speakers
Topics
From DeFi Security Summit 2022, hosted by DeFi Security Summit.
Transcript
hey everyone my name is Anton I'm a family part of chain security and doing the technical work there as an engineer as well and today I'm going to talk about the topic Alpha 4 Auditors or abilities of tomorrow but yeah it's not only Auditors who are will be interested in my speech I believe it's also on developers you know uh guys who are somewhat interested in or writing a code because I mean if you're developing a protocol of first auditor is yourself right so it's I believe could be interesting and speaking about future I would just want to do a motivation or what is a ethereum
state now like what is the defy State uh I mean in general is not only Define ethereum but yeah it's basically a number of companies that's connected together right they are connected by different Innovations I mean in this case you see there is a bunch of tokens as I used as assets for uni swap sorry just collateral but and then the uni swap pair as well are used as a price feeds and also as a mean to link we did some of these tokens in other protocols so it's basically a bunch of stuff connected together somehow with their interfaces and this is basically like kind of what we call D5 right and if one of the components is somehow hacked I
mean I know what kind of hack it can be like minting whatever amount you want or transferring amount from somebody who doesn't want it to be transferred away you basically One Way can manipulate the price then after the price manipulation you can get a loan on a platform using manipulated price and basically the effect of this small bug in one of the dependencies can be basically uh affecting other systems as well and yeah if you look even on bigger scale there is way more tokens they're all connected even with more different types of variations than what you saw and to add up it's not only now we have a main net for zero and we have multiple chains
there is a uh either uh D5 is a multi-chain as you can say there is the Optimus polygon other networks that's basically all have kind of the same and yet different setup and it's all connected by bridges that are also hard to design as like previous concept talk mentioned right and it's uh really uh really hard to to even measure what can happen if some thing goes wrong on a big protocols how the effect will be all over the systems all over the chains and so now speaking about what can go wrong and this is a crystal Balling on
what kind of vulnerabilities we have as you saw like everything is connected and it's disconnected according to the standards and standards is kind of a way for developers to make their life easier right and yeah there is on the right side you can see one of the popular standards that people know like your C20 nft tokens like seven to one one five five and yeah there's a bunch of also eips in the final stages kind of standardized interfaces for like we say flash phones and other stuff so this is kind of stuff was developed to make the life of developers easy to make these components are easier compatible together but even if you look at what is
erc20 types and behaviors are I'm gonna go through this list but yeah I would say if you're a protocol and you're developing uh something you need to know exactly what kind of token you want to deal with just knowing that the token in the erc20 doesn't provide you much stuff yesterday I learned like there is certain even had the classifications there's like 35 different types of tokens right and they all need to be treated differently they all needed to be treated carefully and yeah I mean the problem is standards do not fully Define the behavior of a smart contracts it's kind of a truce that you need to dive into each dependency you have separately and look what can happen there and the
examples like there was like it's historic one that's for example people who know that synthetic uh tokens like susd they were basically Double Entry talking double entry point tokens uh which basically allowed users to submit transaction not only on like the proxy contract but the analogy contract itself and effect would be same and that thanks got not endangered any funds but it still there could be some uh bad behavior that people could do with these double entry points and the balancer and I think social swap were a bit vulnerable to it this was like founded in a maze this year by like one hour of
Engineers but this Buck was in a while for more than a year or so and and it's kind of anomaly as it was just there sitting nobody kind of took uh enough attention to look at it and I believe there is a lot of such bugs and one anomalies that people are just missing because because there's just as not so many developers who know how to write this smart contracts and also know so many people who have attention and the kind of time to look into all the small details so yeah to summarize the first class it's contracts handle any erc20 doesn't tell you much because they are not equal and it's the
abstraction in general not only for erc20 for any standard is not much things you can do second class of vulnerabilities is uh like insecure Getters this is partially what I believe also comes from Sparks that's very integrating project together and this is uh like the smaller code example uh if you know solidity you probably can quickly understand it but on story short there is a getter it returns you some price and assume all the state modifying functions are non-reinterns so you kind of feel safe to use a 777 tokens there right and uh if you like look from the
perspective of systems this is a secure system right uh and the the system never can end up in a state where uh tokens or assets are not uh properly handled right uh but what actually can happen is that if you have some external systems it's like the blue one the system under audit it can actually uh read the wrong price from the uh from this third-party system which is the exchange because I mean you can walk all this I probably can walk over this because it's interesting example so long story short if there's one of the assets inside this exchanges erc77 token you actually can execute this sequence of transaction like you
start removing the liquidity as attacker and you also get a callback from erc77 token uh when the liquidity has been transferred to you and when you try to to deposit in a third-party system if this third party is the system under audit sorry how there's a laser yeah if the system under audit is a relying on this exchange for getting the price even though it's statical and you it may seem like static code cannot modify your state so you also have some sense of security but actually you're reading wrong price right and quite often like how audits are structured like we cannot check everything right because it's quite
quite hard right but this is this example is something like gives us chills sort of actually in this insecurities that's uh you would just if you were to audit the blue system right since around it you just say that yeah the querying the price correctly right without knowing that this could be actually really dangerous in integration right the Integrations that could basically completely break your system so yeah it's as I think previous slide was telling uh in the title it's box of your dependencies IO box right so you are uh sadly rely on by on the uh any security of any underlying components
right so uh fortunately how did the way they are handled now are not covering in the scope such external systems just because it's so time consuming this is uh like multiple levels of complexity you need to go down to uh I mean I'm not sure like even the developers will be ready to pay for that so it's way more work needs to be done so yeah to conclude um the routed boundaries are usually not unclear because they are not fully covering the all the possible ways how the protocols can be hacked and yeah this is basically Integrations at risk are often like unaware about the
actual details of how the stuff are done so the third class of vulnerabilities of future it's non upgradable assumptions is there something uh Gonzalo mentions quite often there is a certain kind of thing that people take for granted for example this is was uh like a bit function for some uh like auction I can simplified it but it's basically sort of uh somebody is a bidder and new bidder come with more money and becomes the new uh the new bidder and old bidder gets his bit back right but uh if recent events there was a lot of new
addresses added to the block list of the usdc token it because it's blockable right and the guys always thought that okay if the bidder became better he basically can transfer funds right then we always can transfer the funds back right this is kind of assumptions that the protocol had and they basically were surprised when they actually couldn't execute this transfer back to the current bidder because it was blocked right and this is kind of a assumption that you even though you know in advance it's uh like it's the pro the usdc has a block list but you kind of maybe didn't consider uh assumptions that uh it can happen in between right that it's
something that uh handled that way right and actually there is a lot of such tokens and a lot of such behaviors that we behave weirdly for example uh Little People knows it's like use this T token potentially can have fees right feeds and transfers and uh like uni swap has all the functionality to handle such tokens right when you swap router it's on the left side that has the special functions code uh they have the suffix uh tokens supporting fee on transfer right tokens right so this kind of functions exists there but if you look at the protocols many of non-gradable protocols only rely on the first three functions inside the uni swap the ones that don't handle it right and this is kind of a
non upgradable assumption on those protocols that uh the usdt or tokens they will be working with will never have uh fits right and there's a bunch of other similar assumptions exist in a while I'm gonna probably go over this list because it's always quite uh fun and it's something that we usually see in our code of our clients and that is the Assumption for them they say that they are okay visit and as Auditors I mean we are not somebody who tells you like that is uh like if you if this is kind of a decision that you're aware about I mean we're not gonna argue with you a lot
right it's your risk you just need to understand it and we of course write it in our reports but it's up to you how to act on it right and quite often they take it as yeah because the alternative will be kind of doing more gas inefficient transactions and it will be not competed not uh uh cheaper than our competitors so yeah there's many such things people say but for example some contracts are fully upgradable usdc can always change and whatever contract is hard coded and integrated with usdc can have problems right and I wonder how many of them are where if not upgradable designed in a
way where they are okay to kind of dump all the usdc funds one way of another if the assumptions change similar other compound uh other tokens are kind of have known perks like usdc block list or EDS DT ability to start charging the fees but also like people are treating them as this is something will never happen right like can you swap V2 can also start charge meeting fees but yeah for now it holds but we would hold in future yeah we don't know another like more weird assumptions is like chain link non-negative price assumption this is uh
kind of a bit a bit more extreme because usually like usdt you channeling can potentially do the prices of any real world asset and sometimes they can have negative prices there is even the traditional exchanges have the problems when like oil price was negative for seriously and uh yeah I also like uh who knows like later in hours they have a staking for the uh the beacon chain for ethereum and uh they quite often have this kind of rebalancing they're amazing where the price of token kind of goes up and many protocols assume that it will be forever and they don't even Implement any way to kind of um
compensate for the fact that there's gonna be a you know Black Swan event where the stakes will be actually uh slashed so going forward a third class of assumptions summarized protocols assume something that can actually change in future and yeah that's potentially can lead to all sorts of problems first and it also can lead to potential attackers acting in this moments of upgrade to profit uh first first class of of vulnerabilities is the protocol upgrades is this similar to the previous one but this is something that's way serious on other level because it affects everyone
and now there is a a lot of contracts all contracts have different right assumptions about the gas prices about the potential uh you know features do they rely on a self-destruct up code to always remove the bytecode right because this is potential like there is like for example suggested potential remove changes in the second list is uh self-destruct can no longer destroy the bytecode right just because it's actually causes sort of problems [Music] evm gas cost changes I'll go a bit later about it in deep house call is like the potential change that you do account obstruction to allow kind of any
user executes the transaction from like a special house out outscore basically but what it means is something like relying on the transaction originally will be no longer a safe option um so yeah there is always constant pressure for such uh features to the protocol because I mean ethereum where it is now where why it's so used is partially because these features were implemented and we cannot say no to them right but this features potentially can break things and there was already history of such things right there was a instable hard Fork that reprise certain op codes and there was a basically some problems because of this this were
discovered prior to the actual uh deployment of the like card Fork there was also a worse example is Constantino be hard for words because it's happened basically the day before I think or it was basically really close to the actual hard fork and had to be delayed and I think because of that even like is your um total market price like or total value locked dropped by like 1 billion so is this kind of uh protocol updates was actually happening uh in this particular constantly open hard Fork I think uh uh some protocols were really affected because the entrancy was like not something they
wanted I think it was Argo on contracts uh I'm not sure uh but yeah that's the history shows this actually happened and in future we only can crystal ball what will happen again uh to summarized it's uh underlying protocol changes can really lead to new kind of vulnerabilities and just because of how many smart contracts we deployed at this point it's so hard to uh for any new change that is proposed to the ethereum protocol to estimate what will be the consequences and yeah to conclude the complexity of D5 systems is enormous there is a anomalies that are remain un
observed because of vlack the attention right there is a not enough attention to go through all the problems standards that we kind of come up with and trying to integrate with are quite informal and they are ambitious uh ambiguous sorry and because it's uh not something we can use as a good foundation in my opinion this probably need to be some sort of formalization or some sort of uh stricter defined Behavior uh to actually know what what erc20s are what years is how each your C20 behave for example um yeah audits are uh the kind of status
quo what people most of the protocols are using for establishing the security but uh the way the scope is structured is a bit unclear there is a complex vulnerabilities that can come from like a relying even on Getters that visually is out of scope for most of the most of the audits dependencies also can change this time assumptions do not hold I mean yeah to summarize whatever assumption you come up with when you're doing a code you can almost always be sure that at some point it will change and yeah it's a safe practice a safe thing is always to plan
how would you do if uh what is your backup plan right I mean is the Gonzalo told like it's not that you need to make everything upgradable but at least you need to plan ahead that's your protocol can have billions of assets locked for a while and then you need to completely drain the system right this is kind of a scenario not every protocol change thinks about the sometimes thinking only a positive scenario where people are depositing funds they sit there and the actual people who leave the system are some kind of a fraction of uh as it's a time right it's complete flush of a system it's a kind of a scenario we barely see that people
testing against uh yep I think should have been one exercise but yeah I'm also had a extra side edit but I maybe forgot to download it about the kind of new systems that's coming which is uh have like a near which have sort of uh concurrency problems uh that ethereum is right now doesn't have and this is kind of a behavior that is really hard to predict also with the development on ZK uh and ZK protocols it will be super hard to actually even Trace if bugs are happening right because this will be like a black box no one knows what's going on there so
um yeah for future it's really I think we need to step careful in future just because already now status quo is that we're probably missing a lot of uh bucks and we haven't paid enough attention to how the things were built and connected together yep thank you [Applause]