Unchained Smart Contract Security
DeFi Security Summit 2023 · 15 Jul 2023 · 16:54
Alex Manuskin, a product manager and researcher at StarkWare, describes three pillars of Starknet security: validity proofs, native smart accounts and the Cairo language. He focuses on account abstraction, where signature logic is written in code and can add two-factor authentication, hardware signers such as phones and key rotation. Multicalls let one transaction approve and revoke a token allowance, which improves usability and lowers cost on a rollup, and the talk closes with Cairo's memory and type safety.
Speakers
Topics
From DeFi Security Summit 2023, hosted by DeFi Security Summit.
Transcript
great to be here thank you for the organizers a really really cool event didn't know that there would be so many fireworks for this so I'm Alex I'm a PM and researcher at starkwell and today I'll be talking about building a secure starknet so when we are building a start nuts we are standing on the shoulders of giants it's not that we are so smart that we are thinking about it ourselves the ecosystem has been up for a while there are many Lessons Learned in the in security and the smart contract Security in particular but building a new system there is an opportunity to take some of the known
Concepts and the resting them think about new approaches and that's that's exciting when we are building a new system like this so today I'll be talking about the three pillars of starkness security as I see them validity proofs smart accounts and the Cairo the native language of starknet manual focus on Smart accounts and Cairo so just a brief overview overview starting is a validity roll up on top of ethereum that means that data is posted on L1 as status approve if submitted to the L1 verifier contract and once the verifier
checks the proof then we know that everything is fine and the state is final and the execution was correct so that's validity ropes and I will move to the next topics so a bit about user roles the users of our networks of of the blockchains that we are building so a meet happy guy is a new user to blockchain he just got into the space he watched some videos he wants to to make money and get rich he opens a wallet gets some tokens and starts participating in defy and getting big bags with all with all the right main coins uh one day he's been out on the in the lovely streets of
Paris having fun drinking a bit and coming home and seeing this pop-up that tells him put your seat phrase here or you your money is going to be lost which he digs out of the closet puts in there and the rest is that someone needs to come in save whatever is possible from his money and does anyone has any has this happened to you or do you know anyone who this happened to raise your hand probably everybody okay so his bags got a little smaller but he's still he's still pretty happy and he's going to make it all back in one trade so he approves some music 20 on on uni swap
maybe a while ago maybe he even forgot for forgets about it and then opens up a crypto Twitter with the cold sweat and starts remembering all the stuff that he needed to to approve and and now needs to revoke which probably also you know someone who this happened to so in enter native smart accounts so uh smart accounts or what is also known as the kind of traction is the only way that you can interact with the the start net chain and there are many benefits to that non-subtraction fee abstraction but mainly here I'll talk about a signature
abstractions and multicalls so signature abstractions is basically that we can write any code in Cairo in this case and verification of this code is the way that to make a transaction and because it is a layer two it is much cheaper we can make some interesting use cases here we can make 2fa MFA that is built into the account we can make signatures with a hardware signers also more ubiquitous Hardware wallets like iPhones which is also already live and and available on wallets that are operating on stagnet today like Argentine Bravos and of course you can change the private key key rotation and
other stuff so definitely would have saved the happy guy from a lot of trouble if he would enable 2fa of or some additional signing besides his seed phrase another maybe unpopular or maybe I don't know not I don't see this uh discussed enough is the benefits of the multi-call so yeah this is how an interaction with usually looks like in D5 you approve Samir C20 to use your contract interact with the contract and if you are diligent enough you also remember to revoke it and of course this is value X this is a more expensive so users just will put an infinite approve probably forget about
it and now even if you are diligent apparently there are scammers who are scamming the revokers so this is quite quite fun as well uh unlike the multicoil where everything is done in a single transaction of course it is triple it's better ux you only do one click but the real cool thing about it is because of the way that of the data availability on starting this is also the cheaper way to interact with the network so in the state if data availability model you only post on L1 the changes to the state so if there's has been no change to the to the approve no change to to the state here because it was given
used or revoked at the end of the transaction no state if so cheaper transaction is a safer transaction which is pretty cool um so why why are people still using eoa it's not that smart contracts accounts were invented yesterday they've been around for a while on on ethereum on the in other AVM chains as well uh probably the main reason again there everything here that you you can't do with an eoa but what you can do is open on YouTube and see how do you interact with blockchain and see that you need to open metamask um so you say okay Alex you've been living under a rock
43 37 I think you have has been published and is taking over the world and the problem with 4337 is not the default right it is an application layer specifically in ethereum you start using it you figure out that opening a new account is expensive you default to using the eoa and then you use the same eoa across all the even the AVM chains that you're bridging to right the bridge knows this address you you know this address you know how to use it you just keep using the eoa um so uh 4337 is great and really hope that we as a community adopt it and
start using it more [Music] just we need to think of a way to make it the only way to interact with the blockchain because that's how users will be forced to use it and rethink their their old patterns uh of course with with it being an applicative solution there are some interesting Concepts to think about bundler Mev who is building the bundles who is adding the bundles into the block but that's a talk for another time bottom line it is more accounts makes darknet safer okay so we covered the users now let's talk about the developer woes so happy guy is finished his designing life he's now saying okay I'm
gonna go heads down building the next D5 protocol and get reached by that and He is building a proxy also interesting a great talk before that on proxies building a process so he can upgrade his account later and take some code maybe you can take a look and think what would happen to this code later and this caused a 6 million a dollars lost in audios and the root cause is just because of how solidity Maps storage right there is based on slots and the first storage of
the proxy is also the first storage slot of the implementation so if you are not thinking about it and not considering or leaving space or doing some some fancy stuff to to make sure there is no Collision there you might run into some issues like that another case which is also interesting so there is some some function here that either takes some East or take some erc20 and [Music] uses it later in the code and this again was a hack in in open in this case and the root cause is this in in this example it was because there was
some assumption about the message value that was used a few times while calling the function but I would say that then another one another possible issue that that did not happen here is that there is a special treatment for eth and there is no um guarantee that this F if else is implemented everywhere in the code even if if it did not require some special treatment you would still make sure you need to make sure that there is a an if else for every special token that you are handling so a bit of an introduction to Cairo so Cairo is the the smart contract language of starknet if you
have maybe seen Cairo before it has been a significantly revamped in the past few months and very much inspired by Cairo by rust both in syntax and the approaches to how it handles memory safety and type safety so Cairo is compiled to Sierra a safe intermediate representation there are some great Talks by the guys who are developing it on YouTube that compiles to Cairo assembly and that's what actually runs on on startnet so there are some really great features in Cairo memory and type safety as I mentioned the ownership of of storage and of data during the execution
uh quite importantly a strict compiler right again very much in the in the spirit of rust when you are writing a Cairo code now uh the the compiler will lead you through right it will pop up errors it's not going to be a smooth sailing which is what we want we want our compilers to to give guard rails as much as possible to our developers who are Building Systems that should be handling money um a few examples from before just addressing I guess the the the cases shown in the in the example so it's a stark net Cairo combination first in the
in starknet the storage slots are a result of the hash of the name of the storage there can still be collisions but most likely if you define an admin variable you would still want it to be the admin variable after you do the upgrade right upgrades are still possible and bugs are still possible um but but it makes sense and in Cairo this is how storage definition looks like it's very explicit there are explicit types that are followed by that are followed by the compiler in runtime and in compilation time and all the storage is defined in one place which is really nice for Auditors to to see there are no story slots appearing and the second example here is
is enums which is also a pretty cool tool um again starknet combination for this is that there is no special C token the fee token is also a near C20 so no special treatment needed for for the message value and so it's all on your C20 again just um not being Shackled to this has to work exactly like ethereum and the evm and the enums here are also really cool that even if you have several tokens that you need to handle once you add another variable here to the enum you will have to go over all of the code the compiler will shouted you
that there is a case you are not handling in your in your switch case and you will have to address it everywhere in the code where there is a where the cinema is used so bottom line languages that we use for smart contracts and D5 should be safe which is what we're trying to do a short summary solidity is great it's really fun it's really great to develop and it's also fun to learn all the all the quirks and features of the lady right and it's fun for the developer it's fun for the auditor that needs to find these bugs later and puts uh puts bread on the table and but uh Cairo in this case
takes the opportunity to make a much safer language so this is different this is a new ecosystem it is growing we are of course bug bugs will happen and it will be interesting to come here hopefully maybe next year and discuss edge cases and and cool bugs that were found in Cairo this is where we need a community right this is a great opportunity to join and be the first to develop all these tools and all the good and best practices that are used to in solidity in the starting ecosystem as well so many Builders and tools are
already there and great opportunity for you to join things to follow us and me and a link to the telegram security Community that's that I hope will kick-start from this session thank you [Applause] thanks for great speech and really inspirable way to learn Cairo I am really interesting can check the documentation how to build on Cairo I think many of people as well and now it's time for a few questions I check timing so I can see hand here
hi um you're making an argument that account abstraction makes stocknet more safer for users and developers but AAA is pretty standard in this dating l2s as enshrined you know protocol level as well as L1 Solutions what what's the difference why does it make star net you know most safer than anyone else okay yeah so the argument there is mostly that there is no fallback to the eoa right a lot of uh change the nail ones and twos that are trying to be compatible there are making a new UA an option because it's easier
and easier to onboard more people that are already using it if there are chains that are already implementing it and making it the default and grade if they are implementing a a hardware signing with iPhones great I mean this is the way to go one more question okay if we have no question questions one two three okay thanks so much it was great great great