Denver Lift-Off 08: Contract Verification | Rocket Pool DAO Event 03 March 2024
Denver Lift-Off 2024 · March 2024 · 26:09
Ramana presents Verifereum, a project to formally verify the implementation correctness of applications running on the EVM. The talk explains what machine checked theorems provide, why proofs target deployed bytecode, and how a property such as a Rocket Pool minipool balance never leaking could be stated. It compares this approach with other verification tools and invites protocols to help define specifications, followed by a Q&A.
Topics
From Denver Lift-Off 2024, hosted by Rocket Pool.
Transcript
uh thank you wack thanks for the introduction it's been a really nice uh morning so far uh morning and afternoon um despite my slides being extremely orange this uh this project and this talk is is probably the least rocket pool related um of the ones on the agenda but I thought I mean since I'm part of the community I wanted to share what I'm doing and I think there's some people here who might be interested in in learning about it um right so I'm going to get right into it so the title of the talk is the name of the project which is ver etherium um and that means formal verification of the implementation of implementation correctness for applications that run on ethereum um or the ethereum virtual
machine so it's kind of a portmanto of the two words verification and ethereum um so I wanted to just go through like this this is quite a mouthful or there's like many Concepts in in this description of what I'm doing so I wanted to go through and say what I mean by each of those um as wax said I I don't have that much material to talk about um I'm more interested in getting questions and like going through it in a more Q&A style so when we get I've got like five slides when we get through the slides we can just go straight into Q&A um okay but let's start with formal verification so formal verification means mathematical theorems uh where the theorems are checked by a machine so we have a a piece of software called a theorem prover which does the checking
and it's doing the checking right down to the lowest like axioms of logic um and we can do that we can automate that using computers so that's why it's a feasible thing to do at all although it's still like quite a big deal and quite slow um but it gives you an extremely high assurance that the thing that you have proved is actually true um and yeah it's way more than you get from any other process so what we're doing formal verification what are we doing formal verification of here formal verification of the implementation of um ethereum applications so what I mean by the implementation is the bite code like the actual code that ends up on chain as the code for a smart contract um and so that'll be like the code for all of the
smart contracts that make up a a protocol or a Dap so in the case of Rocket pool with like a huge Suite of like more than 30 smart contracts um and all of those are compiled and deployed on chain and then there's the bite code sitting on the sitting on chain and that's that's the actual implementation like that's the thing that the ethereum clients are running whenever you do a transaction that interacts with these smart contracts um so we're going to go straight to that source and say like this is the source of truth of what's actually running so that's the thing we're going to verify um okay next terminology here is correctness what do I mean by correctness uh so here I mean we're going to prove a theorem that is is a true fact about any execution of this code whether that's correct from the
perspective of the user or like the perspective of what the protocol wanted there might be a little bit of a gap there because that's more of a subjective thing but the thing we can do is objectively prove mathematical properties about execution uh so in particular that it that it conforms to any desirable properties that we have the patients and expertise to specify precisely in logic uh and of course I would be very happy to work with any protocol and like try to figure out like what should your specification of correctness mean what kinds of properties um might be useful to prove about this project um all right application what I mean by application I think I've talked about this a bit already it's like a a Dap or a protocol or like any Suite of smart smart contracts that are
implementing something this could range from um very small simple single contracts like the wrapped ether contract for example it's just a token contract it's very simple to understand or rocket split which is a project that I've worked on this is a a contract that's designed to be a withdrawal address for um a rocket pool mini mini pool uh and yeah it's just like a single contract it's supposed to do one job um but it could range all the way up to a much larger protocol like rocket pool itself like all of the rocker pool smart contracts um or another big protocol like um you know Unis swap or what's another good like onchain example I mean there there's a ton of onchain things um where they use Lots of lots of smart
contracts sometimes they'll use offchain things as well and then it starts getting a bit harder to um integrate but basically what you would have to do is take what we've got here of our ethereum and also model out enough of the stuff that's happening offchain um in order to to have a complete verification story for that protocol in the case of Rocket pool we already have a little bit of that in that rocket pool depends a lot on the state of the beacon chain it's not just evm um but since the evm is like starting to get the beacon State rout and stuff in that we'll have to model some of the beacon chain anyway um and yes the last thing is the evm so the evm is currently that's the virtual machine it's a very nice virtual machine um that is the execution
environment for applications that run on ethereum uh it's also used on other change so many ethereum layer 2s will also be using the evm or some version of the evm so hopefully this work could be extended to verify protocols on other chains as well but initially I'm going to focus specifically on just um ethereum L1 evm um and it's a yeah it's a nice place to be because that is not a it's not like a a machine that like a typical desktop like x86 um Intel CPU or something which is a lot more complicated to reason about the evm is very small very simple um instruction set uh so it it's kind of a sweet spot because there's a lot of
value in the protocols that people are using like there's a lot of tvl there's a lot lot of money at stake if you have a bug in your protocol but also the thing that you have to verify is very well specified it's very small um yeah so that's nice can how do I move the thing oh there we go all right so now let's go this is a big slide but it's just an example and it's not even a real it's not even a real conjecture it's just to give you a flavor of what I'm talking about when I say I'm doing verification of things and I'll be going through this um in a lot of detail so don't need don't feel like you need to follow what's going on initially um but so yeah the goal the abstract goal of the project is to be able to
prove any functional property of evm by code in a partially specified context so what I mean by that is uh a functional property is just like something that's spec well specified enough that I can write it down in mathematics or in logic uh evm bite code we talked about that before so like we're going to be proving properties of the execution of evm bite code meaning we're proving properties of what happens when a transac action happens on ethereum and this partially specified context thing what I mean by that is we want we want a theorem that kind of we can prove once and for all and then it applies in many different contexts like we want to say this holds kind of when whenever these assumptions hold and you
can vary all kinds of other stuff like other people can be doing other transactions the state of the whole um like the whole ethereum state might have changed in all these different ways but as long as we never made any assumptions about that state this theorem still holds so you kind of get a lasting fact um about whatever you're trying to prove so for example if we wanted to do for Rocket pool mini pools a nice property we might want to prove about those is that the balance of the mini poool can never be drained somewhere else like you can't have an attacker come up with some clever transaction and say well I figured out a way to kind of coax the mini pool into sending all of its ether to me um so that's an example of a nice property we might want to be true of a
rocket of of Rocket pools mini pools so um here's I just I haven't proved this like I'm not at that stage yet I just wrote down what I thought it might look like um so there might be typos in this like when I when it's done with a real theor improver of course there will be it'll be it be solid um but like just to go through this example uh we look at the thing at the last three lines that's the conclusion of the theorem and then the stuff above the arrow is the assumptions of the theorem so you kind of explicitly list all the assumptions you're making about the state of the machine and then you state like what do you want that what you want to be true so let's focus on the conclusion first uh the conclusion here I'm saying that if we take the mini pool which is going
to be a smart contract and look at its balance in the state of the machine so I'm calling the state of the machine this variable M that's the machine State and every contract every address in ethereum has a balance at all times um and so we kind of got two machine States here we've got the M which is the state before the transaction happens and we've got the M prime or the M with a little Dash next to it that's the state of the machine after the transaction executes um so the first line here is talking about the change in balance of the mini pool so it's saying if the balance of the mini pool before subtracted from the balance of the mini pool after um so this is this what would happen if the um mini pool's balance like eth balance
goes down so somehow ether e came out of the mini pool we want that always to be less than or equal to the amount of ether that went into either the rocket eth contract like the token contract that's going to Rocket e holders or to the withdrawal address of the node operator who's associated with that mini pool so this is the conclusion of this theorem is kind of saying whenever the mini pool balance goes down it must be compensated by at least an increase in the balance of either r eth or um the withdrawal address and that that kind of implies that The Ether can't have gone anywhere else like you can't you can't leak funds out of the mini pool um so ideally I would want to be able to prove some property like that we could get into more fine grain properties and say
like actually here's what the split should be like this this much should go to re this much should go to the withdrawal address but even a property like a generic property like this is nice to have because you know like okay there's no way I can craft a transaction that would break this and then what's above the arrow that's all the assumptions that I think that you would have to make in order to prove something like this so we're not going to make a assumptions about the entire state of the chain because that would both be a lot to deal with and also not very applicable because the state of the chain is changing every you know every 12 seconds it's the new state so we make kind of the minimum assumptions that we would need to make in order for this property to hold uh so what I've what
what I was thinking I haven't proved this yet but what I was thinking it would probably come down to is that um we've got the actual bite code of the rocket storage contract and the mini poool base and the de the mini poool delegate are all there in the machine at the addresses that we expect um and if you were to look up the node address and then look up its withdrawal address that comes out with the current withdrawal address for that mini pool so that's that's where we get the withdrawal address from um and then the last bit is oh yeah and we also look up like the rocket token re e address to get the current reth address I mean that one never changes but we just want to say we're making an assumption that the arth contract is implemented at that place uh
and and then the last line of the assumptions is this execute TX which is which will be a relation like that's the thing that I need to Define in logic to say what does it mean to execute a transaction um and I'm saying you if you execute this transaction TX it actually finishes it doesn't revert it comes out with a result and the new state of the machine is M Prime uh and I didn't make any other assumptions about TX TX is this variable that represents the transaction so up the top I've got all of my universally Quantified variables and I don't make any assumptions about them apart from the ones that are listed and since nothing is listed for TX except for the fact that it executes this kind of encompasses all transactions that anyone could do so it
could be from any sender it could be with any data it could be with any value doesn't matter so that's why that's how you can get a theorem like this to um cover like a lot of possible scenarios and and still give you the property that you want right so the rest of the slides are like a lot less details it's uh just an overview of where we're up to um So the plan is to to be able to prove theorems like that the plan is to build a formal model of the evm in logic and I'm using high order logic to do this in particularly using the theover the hologic theover sometimes called hall four uh it's a nice environment for building mathematical theorems like this
it's got a lot of um background libraries like it's got you know libraries for mathematics just generic mathematics so lets you define data types and bytes and bits and uh there's a little bit of like cryptography stuff that I that is not in the libraries that I'm working on right now that I have to add uh but a lot of the stuff that I would need is in there for reasoning about programs in particular um but yeah so that's like the the bulk of the work is build a formal model of the evm um the second step after that after we've got like a pretty good evm I would say is to um add a layer of what's called separation logic which is just it's just like a conventional way of um organizing your reasoning when you're dealing with partially specified
contexts so you want to kind of prove something and say here are the assumptions I'm making about it and the whole the rest of the world can be anything at all um separation logic is a way of organizing that style of reasoning um and I have some prior work that's been used for program verification for machine code like not evm code but like machine code that runs on CPUs uh that I that I'm using as inspiration for how to do this thing uh and the last step which I think is pretty um pretty interesting is what's called decompilation into logic so this is a way so previously I said like we're just going to verify the bite code which is the actual implementation that lives on chain but most developers don't ever
care about bite code like we don't want to look at it as too low level uh we don't want to reason about it that's looking like the individual op codes of a contract most people want to be thinking at least in terms of a high L language like solidity or Viper um there's the Huff language which is like kind of in between it's a bit closer to the bite code and then there's just like the actual bite code it's way down at the low level um this decompilation into logic idea is a way of Bridging the Gap between the really low-level bite code and something higher level like solidity or even even higher level than solidity something just like looking at pure maths um decomp decompilation is into logic is a way of taking some bite code and automatically inferring some functions that are equal like some high
LEL functions or like solidity code you could say um which are equivalently which which have the same semantics as the bite code that you started with u so you can kind of take the bite code that came out of the compile this this means like we don't have to trust the solidity compiler at all we don't have to trust any compilers we start with the actual source of Truth The Bite code we run our decompilation into logic thing and that produces a theorem that says this function this high level function has the same semantics as that by code and then you can reason about that high level function and all of your reasoning will um transfer down to the bite code because it's backed by the theorem um so that's that's one piece of automation that I think would be very helpful for for doing this a bit more
scalably um all right so where are we now uh I've been working on this on the side I would say for the last few months I haven't really touched it in the last half a month um but I was working on it more intensely around December um I have defined the ethereum virtual machine in Horder Logic for the most part uh like I I wrote down what I think it should look like I put all the op codes in I may be missing like three or four op codes um and I'm missing most of the pre-compiled which are these um they're also part of the evm but like they're not they're not OP codes themselves they're just like contracts that are assumed to exist like for example for running sha 3 or doing like an elliptic curve signature verification or something like that um so I've
defined most of that in hologic already it's on GitHub it's there for people to look at if they want to um I haven't tested whether it actually is correct like we this is the kind of the core of the project we need to know that our model of the evm is the same one that the ethereum clients actually Implement um otherwise we're proving against something that's not real uh so the next thing that I want to do is um take the test Suites that the clients actually use to test that the clients are correct and try to run them all against my model in l loic just to give some um assurance that we've we're modeling the same thing like we've got an evm that's the actual evm um and yeah so that would be the next next thing is to figure out how to
get the ethereum client tests and run them on the logical model and then add add the extra pieces that's necessary like we'll have to do the pre-compiled we might have to do a few more op codes maybe a few other features um by the time denune comes in we'll have to do like whatever is needed for the blobs whatever's needed for the beacon route when that comes online uh and then yeah and then it's just following the plan like figure out the separation logic figure out the decompilation and try it out on a few contracts like probably start small do do the rap e through contract for example um I want to personally build like a smart contract wallet to use for myself so I don't have to use everyone uses like um nosis safes I think they're good but they're also like overly complex for my taste I'd like to build
my own wallet and store for my cold storage and but I wouldn't want to put any significant funds in there without formally verifying it um so that's one one thing I'm planning on doing uh and then kind of the future directions for the project is what can you do if we have something like this and I think there are two big obvious directions for what to do with it one is to go after bug bounties so there are millions and millions of dollars available for example on immuni for people to try to break projects find bugs in them if you find any critical bugs so there's no guarantee that there are any critical bugs but if there are one way to find them kind of systematically is to go to the project try to verify it try to check that some you know all the
properties that you think should hold if this protocol do hold and in the process of trying to prove those theorems if they're not true you will find out why they're not true the the process of doing the theor improving kind of tells you where the problem is uh so that could be like a way of systematically claiming bug bounties where possible uh and the other thing that we could offer is an alternative or a complement to auditing services so if you have a new implementation that you want to know uh is correct you can pay Auditors to look at it very closely uh you could also pay someone using ver aerium um to not just look at it closely but like prove some theorems about it uh and then you'd get very strong assurance that what you're
doing um is not going to have any bugs all right so this my my last slide is that this is kind of just me at the moment I have some friends in in the hall four the improving Community who are also like contributing little bits but uh it's mostly me driving it I would love people to come join um collaborators very welcome the whole model is going to be completely free software um and since this this is like a combination of two very deep technical topics one of them being formal verification in high logic and the other one being the ethereum virtual machine and like low-level um smart contract execution uh I don't expect anyone to know how to do these things no experience is required
uh just a lot of enthusiasm and willingness to learn and contribute would be very welcome for people to join on this project uh the code is currently hosted at my GitHub here thanks thank you so much R we've got a question here that we're going to get started with and then if anyone else has any questions please put your hand up so I can see you yeah this looks great thanks thanks for sharing um as someone who is not familiar uh with formal verification of contracts but familiar with solidity testing testing techniques things like uh you know fuzzing invariant testing is this like basically just a more complete
way to to verify functionality in variance yeah you can you can definitely think of it that way so this is more complete more thorough a lot more labor intensive actually too for for that reason U but it's kind of like yeah it's a once you get a theorem out then it's kind of covers everything like it's exhaustive you haven't missed anything and um and it holds forever of course if you upgrade your code you then it's no longer valid but you can prove the try to prove the same theorem for this for the upgraded code um uh so the so like compared to fuzzing we are instead doing like Universal quantification like we're covering all of the Poss it's kind of maybe closer to
symbolic model checking or something like that like you're covering all of the possibilities At Once by using a universally Quantified variable um but compared to testing it's quite it's similar in a way in that you in the tests you kind of specify what you want to be true and then you try it for like a few values whereas here you would specify what you want to be true and then you would prove it for all values there's another question right here so just one moment uh yeah for a non-technical users once it's deployed is there anything about verium itself uh that requires
trust yeah good question so ver aerium itself will um will be written a primarily it will be written as um theorem uh theories for the hall fourth year improver and those can be independently um checked and looked at uh so the thing that the main thing that you're trusting is the theorem prover and the logic that it sits behind and this theorem has a particularly strong um trust story for like why you should trust it uh which is well there's kind of two components to it one is that it can um emit independently checkable proofs which you can you know you can write your own theor approver or use use
another theor appr to check the proofs uh and the other one is just the way that it's designed so it's designed in What's called the uh like lcf family of theor provs I forget what that's stands for but um basically how it works is that it uses strong type checking um to ensure that every every theorem value that gets computed by the theorem prover has a has the type theorem and that type can only be produced by a very small number of functions in What's called the kernel of the theorem prover and each of those functions is an inference rule in logic it's like one of the low-level inference Ru rules of logic um so no matter what you in your theorem proving activity as a human user
at the Top If you get one of these theorem values out you know that somehow it's gone through that Kel and every single step has been checked as again as being a valid inference rule um so yeah it's a I've done work in the past also on um on verifying the theorem prover uh so you kind of get like who who trusts the verifiers kind of um questions but yeah this is I would say way higher in terms of um Assurance than you would get from most other projects we've just got one last question and then we're going to move on I'm uh wondering if you're aware of any smart contract auditing teams that are already using like an approach like this to verify um you know smart contracts and if not why not is there a
Gap in the industry that this type of approach could fill yeah that's a good question as well so I haven't looked too hard into it but I am aware of some companies or some groups that are doing like formal verification is um well liked in the crypto Community more than it is in other areas of Industry which I think is a good sign but yeah there's there's a compony called runtime verification which does something like auditing and theor improving and they use the K theor improver framework um and I think yeah there's also like I know there are people who have for example verified rap ether um but using their own framework um so two things I would say about it so one is
that I think the the approaches that people tend to use are not as high trust as the sorry not as trustworthy as the one that I'm intending to do so they kind of use a less trustworthy the improver um or they use something that like requires more assumptions and the trade-off that they're going for there is that they want it to be more automatic and faster and easier to get the thing done whereas my way is like very expensive in terms of like amount of Labor that you would need to put in to get it get it to work I would be interested in automating as well but I kind of want to do it right from the start uh and that's that kind of answers your second question as well it's just like why is there this Gap like why why aren't people doing this already uh I
think it's it's just the cost um and so their ethereum could be kind of a public good in that in the sense that once you build the model that's like a lot of shared cost across verification projects in the future uh so if we all come together to like build this model and kind of maintain it and keep it up to date with the ethereum um execution specs um that that would alleviate some of the cost of doing this in the future thank you thank you so much Rana that was wonderful guys can we all give Ramana a round of applause please
Related talks
- All about Smart Contract & DApp Auditing
- PQ Ethereum Q&A
- Control Flow Graph Reconstruction from EVM bytecode
- From High-Level DeFi Properties to Concrete Security Bugs
- From Production Rust to Lean 4 Proofs: A Verification Pipeline
- MakerDAO Smart Contract Safety: When Billions are at Stake
- Formal Verification of the Incremental Merkle Tree Algorithm in Dafny (Eth 2 Deposit Contract)
- Formal verification and CBC Casper
- 🛠 Finding Bugs With Formal Verification: Hands-on Workshop - Yura Sherman
