Clear as Mud
DeFi Security Summit 2022 · 27 Aug 2022 · 10:26
Gonçalo Sa of ConsenSys Diligence offers an auditor's advice on what not to do when building a DeFi protocol. He argues against obfuscated, sprawling code that cannot be read and so cannot be audited, against hidden upgrade backdoors such as those enabled by the diamond standard, and against slapping reentrancy guards on code that does not need them. At DeFi Security Summit 2022.
Speakers
Topics
From DeFi Security Summit 2022, hosted by DeFi Security Summit.
Transcript
hi guys my name is Gonzalo a skirt presented and I was going to bring to you um kind of like a talk similar to what Neville was presenting about like evm traps and and how the the solidity like there's a lot of mistakes coming from like uh dubious things about like the compiler and the evm itself and how they mix and match and like create problems there but um over the last couple weeks I had a lot of uh you know like not not awful but not good interactions with clients and also we put out a new a new product called turn and people were very opinionated about our code people people were teaching us how to do security and so I thought that like since our crypto overlords gave us that present I I
thought I could compile uh top three of things that you shouldn't do when you're building your D5 protocol but by show of hands this is less focused on security I I think the crowd here is like very security conscious and like it works in security but if show of hands like who's actually developing on defy okay though so I have a crowd that's good um in addition to that I have a last point today um specifically geared towards the security community and specifically about turn and and how we went down the the first point is don't hide if if you're building a D5 protocol please please please don't hide and what I mean
by this is this I'm sure a lot of you um are familiar with flips and flops and and beats and wads and and and what I mean by don't hide in in this first uh in this first part in this first advice is don't obfuscate you know like it like the more you obfuscate the the harder it will be for people like like me like us like all the people that work in security to actually look at your code you know uh I I also think this is timely because like another type of obstacation I like we're all talking about like true fights presentation before and uh and that's also a form of obfuscation you know like if your code
is not readable then it's not auditable and if it's not audible it's less secure the more eyes you have on something the the more secure it'll be you know like simple correlation like linear um also another thing that like we see a lot like people like folders and files and like tiny little files with just like one definition and one little interface and like I you know like I like organized stuff as well but like what that usually means when we open up your project and start auditing is this you know this is the this is the caller mind you this is a tiny tiny section of um one of the projects that we audited this call graph is actually huge it
wouldn't fit any screen this is what it looks like when we get the code and we have to look at it again let me reiterate if the code is you all repeat with me if the code is not readable the code is not auditable and then therefore less secure you know like um we should like but both and like I I feel that this is an effort that we could do as well like on the education side and that's why I changed my presentation at the last time because I really think this is really important but it's also an effort on your side just like think about what's going to happen when we get the code think about like the people that are actually going to protect your protocol how you can make their lives easier you know this brings me to another like pet beef
of mine which is like the diamond standard which contributes a lot to this okay so where we get here it's like so we don't want obfuscation and I get it like people we want to go for it like and we want to innovate and we want to create standards and Frameworks so that people can develop easier and faster but some things are just not needed at all which brings me to my second Point don't backdoor your code please it doesn't it's a disservice to everyone to you to us to what I mean by don't backdoor is like and I'll we don't need to read all of these but this is a conversation from 2020 on GitHub talking about like uh the diamond star and and like how it's meant
to be upgradeable right uh and Leonardo keeps saying that like through him uni swap is great because it's not upgradable or centralized and uh and like the the rebuttal to this is like but the upgrade functionality can be removed in a diamond making a diamond immutable and the answer to that is like but why why is it there in the first place the the upgrade functionality can also be removed by not using it in the first place you know uh we arrive at at this comment of mine where I fully agree with Leonardo and like um if you see there like there's a lot of off-chain mechanisms that you can use to achieve the exact same end result which more often than not turn your protocol into a more secure protocol you
know like and the reason for this is does anybody remember this does anybody remember either like it had many many problems but that oh my God you don't you don't need upgradable anything you just go there and you choose the version of the context that you want to use isn't this upgradeable it works like it's and it's not the contracts are immutable you know that whatever is going to happen your money is in a is in a smart contract system that will not be changed you might you might use it a different one on the front end but like you're sure that it's immutable right therefore more secure if it if it's being deployed for a while if it hasn't been acting there's a higher
chance that it's uh unhackable right the the reason why I say backdoor and like obviously I'm being caustic and I'm renting and this is exactly what the presentation was for but this is a good example like vcx had um was what you know like had permission functions like a lot of enemy stuff private Keys got stolen everybody's you know everybody's in a bad place like there's there's very and I'm I'm meant to be Gothic and I and I will fight you on this but please meet me outside and let's and let's let's have a conversation uh we'll also have a panel today but I'll definitely fight you on this I don't think that half of the times anything related to upgrade abilities needed
in uh the third point which is like don't compromise uh with security the more you do uh the the better it is you know like you do you don't have to think that like this tool is not for your code or that tool is not for your code or they'll because you do formal verification you don't need to knot it that's not the way things work the more you do the better it is you know like I made this a while ago uh and I tweeted it out for specifically for diligence products but this can be generalized for for for all the products out there all the security products they have specific times like they they all work in tandem to make your code more secure some sometimes
they're not made for the for the specific development life cycle timeline that you're in right but it will be it will be for you all these tools everything right from like you should start with the static analysis and then like maybe do a little bit of like formal verification then then have an audit at the end all of these things mix and match right like simple things like the tool that you are in Road your information wrote for example a mutation um um a mutation testing tool to to actually see if your tests are good enough right or like to analyze in like in a simple way how good you are writing tests most of the people that come to us don't use this like it's it's free it's
out there and and like you shouldn't have to pick and choose right another good example is is this is is the fact that like in in maker that was really really good at this like they really use formal verification the right way uh in in in Sartori obviously but but it like there is a place and time for everything you don't need to choose you need to do it all maybe it's not for you right now maybe it's not even for for the the funding stage that you're in but it will be and use everything the the more you use the the more secure things you'll get and it but it's better for everyone uh my extra point is don't plug and what I mean by this is this is exactly coming from from a lot
of um a lot of the the rough rough rough messages that I got uh about the term platform where people were trying to tell me what it should have been and what it should say and what it should be um and mind you what I'm about to say I realize how it's gonna sound um and the disclaimer to that is that I really know that like there's a lot of re-entracy attacks in defy you know like just a bunch of millions like I get it I get it guys but but please stop using this modifier like this is everywhere you don't need to blow your code with like unneeded security measures and this is actually
bringing me to the point of people thinking that turn was this and that and they had vulnerabilities no a vulnerability functionality skink you know like you don't just like gram things that you deem make your code more secure for absolutely with absolutely zero intent you know sometimes you don't need a non-re-entrant function the function can have re-under sometimes re-enter is good you know like you don't need to slap this everywhere neither did we like sometimes and people got like really phased about like the malleabilities thing in turn it was reviewed prior to launch and even though like it led to a little bit of Betty wax if it wasn't a vulnerability you know like uh sometimes sometimes you really don't need a lot of these things
I'll also fight you on this and that is the end of the talk guys uh more than happy to talk to you afterwards come come talk to me find me outside and and at the panel I'm sure we'll discuss some of these things [Applause]