Raoul Schaffranek - Using a solidity debugger to explore time and space

ETH Bucharest 2024 · March 2024 · 19:06

Raoul Schaffranek, a formal verification engineer at Runtime Verification, presents a Solidity debugger designed to lower the barrier to formal methods. He frames the EVM as a state machine, explains why long exploit transaction sequences are hard to anticipate, and shows how symbolic execution collapses the space of possible next states. The talk covers the browser-based demo, the Debug Adapter Protocol and IDE support, and ends with audience questions.

Speakers

Topics

From ETH Bucharest 2024, hosted by ETH Bucharest.

Transcript

now uh the last presentation before lunch is uh going to be held by R shafranek I hope I pronounce your name correctly from runtime verification and he's going to be talking about using a solidity debugger to explore time and space let's welcome him with [Applause] Applause hi everybody um my name my name is R shafranek I'm a former verification engineer at runtime verification and it's my pleasure today to um present you the newest addition to our formal methods tool Suite so at RV we get the feedback a lot that formal methods sounds really useful in theory

but it's not really um it's too complicated basically and so we took this feedback seriously and we invented this new tool that is meant to lower the entry barrier two formal methods and basically enable every developer and every security researcher to apply formal methods to their smart contracts um so I can do a lot on this stage to convince you of how cool our new tool is um but I actually want to encourage you to go to our public website we just released a public demo version you don't need to install anything on your computer it one RS completely in a browser so just go to this website it loads a visual studio

code instance and you can start debugging web e with our news tool um so but let's provide a little bit of background Theory so you might have heard that solidity or the evm is a state machine but what does it mean so basically we have states that are composed out of the accounts storage accounts code the balances and then we have transactions which are the transitions of these um of this transition system so let's lay out the uh transaction history of a theum on

a timeline like in 2015 the Genesis block was mined so this is the initial state of our transition system and then we sequenced like a billion of transactions and now we are here at this point ethereum isn't a is in some state but we also know that in the past there have been some buggy States and then have been exploited so as a security company our goal is to make these exploits and vulnerabilities less common and protect ourselves against them but what we have a problem that is well if you look at the past then ethereum's transaction his

history is just a straight line but if you we are thinking in the future then there's like so many things that could happen next we cannot predict what will be the next transaction to ethereum it could be anything really it could be someone making a swap on Unis swap it could be someone staking on lier it could be someone bridging a token to optimism um and then even after the next transaction like if we could solve just this single problem like the problem would repeat itself and we would have a billion more possibilities and so we are branching out in an infinite space of possible states in the future and this is a real problem like

we notice that smart contracts exploits gets more difficult like I don't know who remembers the kyber swb exploit from last year this was not a one transaction exploit but it was an exploit that um involved like long transaction sequences so how can we Safeguard our smart contracts against these long um transaction sequences how can we reason about our code confidentially that this cannot happen and symbolics approach is first of all to collapse the state space of the next possible successor States so um at the top of the slide we have some

possible concrete transactions it could be a transfer from Ellis transferring 10 tokens to Bob or Ellis transferring 20 tokens to Bob Ella is transferring 30 tokens to herself and all these transaction would end up in a different successor state so what we do in symbolic is we collapse these like there are an infinite many choices that you can make here and what we do with symbolic is we collapse all these possible concrete transactions into abstract transactions so in yellow on the bottom of the slide you see an abstract transaction that starts from an abstract State we see that the balances are just some

variables X and Y and then we are making a transfer from and the the receiver and the sender of the address uh of the transfer they are also just variables so same with the amount and then we end up in only two possible successor States like one where the from and the two address are different and one where the from and the two address are the same so we collapsed the entire State space uh into a single abstract transaction but now we still have this problem um that we have possible multiple transaction or we have uh vulnerabilities that only show in

transaction sequences so how do we solve this problem and uh the cool thing is we don't need to do introduce anything else like the approach that we showed before like all these abstract States they also make it possible for us to reason about transaction sequences and the way it works is like you see when you have a transaction a concrete transaction uh that is starting from some State we abstract it in our abstract transaction and start from an abstract state that is more General than the first one so we execute our abstract transaction and we endend up in a in another abstract State now the cool thing is that you can see that this final or this abstract

successor state is also subsumed in our initial state so that basically means uh that we can reason about transaction sequences inductively like that's complicated mathematical term but it basically means this transaction this abstract transaction ction does not care about what has come before it does not care about the history so in summary we collapsed the problem of finding a bug in like an infinite amount of states and possibly very long transaction sequences to the

problem of finding a bug in a single abstract transaction so this is this also goes by the name symbolic execution um what else so when we debug a transaction it's not enough just to look at the pressor state and at the successor state right we want to get insight into the transaction we want to see where are things going sideways so what we do is we break down a transaction into a finer gran ity view basically we can do this on two levels on first like every transaction is composed out of a solidity Trace so we

can break down a transaction into a sequence of solidity statements that have been executed so then our states are not anymore the uh the accounts with all the balances and the storage but our states become the solidity variables and we can't take this one level further we can go even one level deeper and go to the evm level so every solidity statement can be decomposed into a sequence of evm instructions so on this level our states become the uh ethereum memory the stack the program counter the storage and our transitions in this on this deepest level become bite code instructions so how does it look like in

our debugger that was enough Theory so this is a an ethereum state or an evm state that you see on the left like this abstract state that I showed you it has a program counter a stack and a memory and in our debugger um you can see it with the in the variables view so you can see that there's you can see what is the value of the program counter at this at the P State you can see what's the value on this what are the values on the stack what's the memory and you also notice that not all these values are concrete like there are some parameters here um for examp example the call data here well there's a function selector that is fully concrete but what follows after is like a symbolic expression uh

that tells us well whatever comes after whatever the parameters of our functions are in this case we are debugging the transfer from function we make no assumptions about the source and the destination of the transform from and no assumption about the value so we are actually executing it symbolically and to build a little bit more on this metaphor about time and space so there was I think for me like the personal best Innovation that happened to debuggers over the last 10 years was the invention of time travel debugging um so time travel debugging allows you to step backwards through

your code execute a code backwards that is very handy like usually you wanted to run AC you wanted to an accept and you want to see okay how did I get here and then you just start executing backwards to trace down like the uh the conditions that led you to this state and we took this idea and took it one step further further so because we are able to reason about like alternative timelines whatever comes next depending on the inputs we cannot just jump back and forth in our code but we also can jump into alternative timelines um simple example like you have an if statement

and you want you are debugging the then the then Branch but you want to see what's going on in the El branch and you can just select this Branch from this nice little uh graph visualization that you see on the right hand side on on this slide so symbolic our debugger is in its very very early stages we literally released the public demo just a a few days ago um but we have very ambitious plans for this debugger so we are we know we are aware that like solidity is in general they it's missing a good debugger like just a classical

traditional debugger it's not existent in ethereum there are some common line debuggers but common line debuggers are not everybody's cup of tea so um we want to build out symbolic into this nice little symbolic execution debugger but we also want to emphasize on like concrete execution so what we have right now is we have this open Alpha version that you can check out we have like all the things that you can expect from a classical debugger like you can set break points you can step over the code you can inspect uh you can inspect the states the call Stacks um you can even like there's a built in disassembler so you can even like disassemble your smart contract and

see the bite codes and step over the bite codes one step at a time that is very useful for like gas optimizers for example what's coming next is and with next I mean within the next month so in April you can expect our open source release uh so runtime verification is very committed to developing open- Source formal methods tooling because we think that is the only way to scale formal methods and make it accessible for everybody so expect our open source release soon we are also working on a Foundry integration that would allow you to step through Foundry tests uh we kind of have that working already but just in

the symbolic case we are now working like on a more seamless integration with The Foundry team to basically build out this concrete debugger um and what's still missing in our debugger is like well you can inspect the call data you can inspect the stack the memory but at the moment you cannot we cannot decode variables like that's unfortunate but this will come soon so we will start building out support for decoding solidity storage variables um and this nice visual graph that you saw on the last slide this one that's also not part of the public demo yet but that will be released

soon um and then after AOL we have like several stretch goals that we want to reach first of all we want to make the developer experience even more Smooth by decoding every and all possible solidity variables not only uh solidity storage variables and we are working with the ethereum foundation on this e deback format protocol so etherum Foundation is building this East debug format protocol that is basically enabling us uh is giving us all the information from the compiler that we need to make this uh translation back from evm data structures to solidity data structures and

then well we have a debugger working in a web browser which is really really cool uh and we are thinking of building it out into like a main net transaction debugger where you just go to Ether scan you copy some transaction hash paste it into the debugger and and then you can actually replay the transaction of the mainnet inside your debugger all in a browser okay um some Shameless advertisement uh on my side so we are currently hosting or co-hosting a secur race like for those you are not familiar with these secum

Races they are basically just small quizzes they take you 16 minutes to to fill them out and the top 32 participants will be invited to a workshop at onetime verification um this Workshop will not only showcase symbolic and teach you how to use it but it will also contain other tools on our like formal methods tool suite for example control which is like our uh symbolic testing framework think Foundry but instead of uh choosing random inputs we use IC execution and escx which is a automatic conformance checker for um esc20 tokens ESC 4626 ESC 271

tokens uh this Workshop will also have some some prices uh I think the top price will be I think $2,500 and every like the top three participants will uh also get an invitation to or get an interview at V to um apply for a formal verification position to and and that's very important for me that's my last point we are building this debugger and we are building it for the community as I said it will be open source but we really need your feedback like we are building with the community for the community so please try it

out if there's something that you're missing like a feature let us know we we can make it happen um but only if we know so um stay in touch with us like reach out we are on Twitter we are on Discord we are on telegram whatever Channel you prefer somebody will always be uh will always respond to your feedback um yeah that's it thank you very much are there any questions thank you for uh for a talk it's amazing um I'm really waiting for the bugger and the question is is it tightly coupled with the visual studio code visual yeah visual code or it is

like accessible witha debug access protocol or something like this yeah that's a very good question so our initial release focuses on Visual Studio code but it is built around this open uh this uh open standard which is called the deback adapter protocol um so you can actually connect it like if you're an emx die hard for example you can connect connected to emex IDE you can connect it maybe weix can add support if they want to um we are talking with several other like online platforms providing code analysis tools online and they want to make an integration happen so uh to answer your question concisely it's not tightly coupled to visual

studio code it's all built on um uh on Open Standards but for us at onetime verification we focus on the uh on the visual studio code integration the most at the moment because we know from like the solidity developer surveys that solid that vs code is currently the most used IDE among solidity developers thanks do do we have any more questions no okay then yeah have a nice lunch everybody and just catch me outside if you want to if you have more questions and want to talk thank you thank you Raul for

Related talks