Minting and Collecting Writing on Mirror with Graeme Boy
ETH Seoul 2022 · 22 Sept 2022 · 26:37
Norswap, who works on research and development at Optimism, explains how the Optimism rollup is kept secure. After a short primer on optimistic rollups, sequencers and verifiers, the talk shows why fault proofs are needed and why re-running whole blocks on Ethereum would cost too much. It then walks through the Cannon challenge game: bisecting an execution trace to isolate a single disputed step, compiling a minimal version of Go Ethereum to MIPS, executing that one step on chain, and using Merkle proofs and a pre-image oracle for memory and transaction data. It closes with the roadmap toward challenging layer 2 blocks on layer 1 after the Bedrock release.
Speakers
Topics
From ETH Seoul 2022, hosted by KryptoSeoul.
Transcript
better like this yeah all right hello everybody i'm north swap i do research and development at optimism and what i want to talk to you about today is how we secure the optimism blockchain so optimism is a layer 2 roll-up so first of all if you're not familiar with rap i'm going to give you the real short version of how an optimistic roll-up works so the issue with ethereum is that it doesn't scale it doesn't scale for a very good reason it's that they want to stay decentralized and so sort of the line in the sand that was drawn is that everybody should be able
to validate their own blockchain at home using only a laptop and you know maybe some extra equipment but it should stay relatively affordable and free and that's pretty good but we still have a problem that people want to transact and there's not enough uh transaction space available so roll ups our way to fix this and the way it works is that you have your uh l1 blockchain so that those are the little computers you see there and if you are a l1 user you're rich so you have a top hat and a mustache and you can translate directory on ethereum if not your l2 user can can transact with one or multiple entities known as the sequencer
and sequencers are big entities and there will be much less of them than l1 nodes so what the sequencer do is that they process the l2 transactions just like they were normal transactions then they send the data of the transaction to l1 only transaction these transactions are not executed on that one they're only executed on r2 they also send to the l1 blockchain the result of executing a transaction so that's a stage route that commits to the whole state of the layer 2 blockchain then you have these other actors called verifiers and what the verifiers do is that they
download the l2 transactions that have been posted to ethereum they re-execute them and then they check if the results that they get is the same as the result that the sequencer got if they get the same result it means everything is fine and the sequencer did a good job if the result is different it means that there was a bug in the sequencer or sequencer attempted to do some malicious action to steal funds or something like that so if they detect such a case where they disagree with the result of the sequencer what it can do is something called a fold proof so this is a process in which on ethereum they're going to challenge the results and this
presentation is really about explaining how this fault-proof process works you know how how can we be secure right so there is one compared to ethereum it's almost as secure there's only one security assumption that is added and the security assumption is that there's at least one verifier that exists that is honest you only need the one and then you're fine okay so the next step is explaining these fault proofs so as i recap optimistic roll-ups are secure if the term is secure and we rely on this single verifier default proof is played through
something called a challenge game and it's played between two actors a verifier and the sequencer we also sometimes call them a challenger and defender but for simplicity you can think of the verifier that detected the problem and the sequencer that posted the result in the first place that is being challenged so the guarantee is that as long as ethereum itself is secure then this process will work and then the challenger will always be able to challenge the sequencer successfully as assuming he is indeed right and the sequencer misbehaved and so if you given this property it means that using
the main bridge of optimism you will never be able to transfer stolen funds back to ethereum so this is the same thing but in a graphical way for those of you that are more graphical so you have l1 ethereum the verifier reads the bachelor so these are groups of transactions of l2 transactions e executes them and creates these output routes he also downloads the output route from l1 then he compares those if they're the same everything's peachy but if they're different
then it does this challenge game this fault proof on r1 so now we run into a problem so we have determined that executing the transaction leads to different results for sequencer and challenger how do we decide who's right and who's wrong you know if you were to take a naive approach what you want to do is re-execute all the transactions on ethereum the problem with that is that it's extremely expensive so the very simplest approach you can take is to rerun the block um on ethereum so in an evm interpreter that is itself running
on the evm there are huge overheads in doing so and it's not possible because you're executing a whole block worth of gas within a transaction that is itself limited in gas and because you have overheads a multiplier in the time of execution it's just not possible so another solution would be to say well um blocks on layer two they are actually um evm right like turns out we on the optimism we use the evm and so the the code that we're executing is the same that is being run on r1 so what if we could just execute that code directly
that's a good idea but there is a problem the problem is that there's a lot of up codes and operations that depend on the context of the blockchain and so a very simple example that is the blocked number up code so when you run block number on l2 you will get the l2 block number but on r1 you will get the l1 block number and so there is a way to fix that and is that you need to patch the up code to remove this and put a call to a contract that holds all the context and you run into similar issue if you're trying to read the blockchain memory for instance this is still way too expensive but what if we did this but instead of challenging a whole block we would just
challenge a single transaction so this works and this is what optimism tried to do uh the first time we tried to do fault proofs we tried to do exactly this there are very there are a lot of nasty issues with this it's so expensive and to give you just an example of one nasty issue that happens with this so ethereum has a limit on the size of contracts so the number of up codes that you can put a contract is bounded and the problem is that we need to patch the upcode so we take the l2 contract and we replace some of codes by some calls to special context contracts on r1 and these these patches they are bigger
than the original thing that we replace so the contract size grows when you deploy it on r1 and that means that effectively your r2 contracts are much more limited in size than the l1 contract so this is a very very bad user experience because you try your contract on one it works but on l2 it doesn't work because it becomes too big so this was very nasty so what is the solution it's through something called a challenge game so now we're stopping with the idea of executing the whole block or the whole transaction what we want to do is figure out exactly where we disagree
in a small part of the computation and then we want to execute only that small part on ethereum and so what we will call this as a single step of this agreement so the goal is to find the symbol step of this agreement and what is a step there's different way you could do it but the two most common way are one evm instructions or one assembler instruction in the program that validates a block and executes the transactions i'm going to explain both of these things um so our fault proof and uh challenge game system is called canon it was originally designed by uh george
was was a very famous hacker he was the first one to unlock the iphone and he also hacked one of the playstations and now it's under development by optimism so including me it's not the first system of this kind so carly z does something different arbitrarium also think true bit so this is an idea that has been around it's the idea of verified computation so you do have chain computation and then you verify it on chain however it is the first system of this kind that supports evm equivalence so anything that works on ethereum also works on optimism you can reuse all the
tools hard hat foundry whatever you use to do your development it will work on optimism out of the box so to figure out where we disagree the challenge game performs something that is called others for just for the full proof you do something called a challenge game and what that challenge game is it's a bisection on the execution trace so what is the execution trace when you run a program you run a bunch of instructions one after the other and the execution trace is just the list of all the instructions that you're going to execute so um but what's being executed so
there's two ways to do it you can think of evm execution then your trace is a bunch of evm up codes but validating a block is more than just executing transactions and so if we go this way where all traces if vm up codes we need to do the rest of the block validations in specialized evm contracts that we have to write the other way to do it is to say well the program that we execute is not the vm execution of the transactions it is the validator software so go ethereum or arrogan all those they validate blocks so what if we could take those software and run them and that's our execution
trace and that is what we'll be able to challenge and so that's that's the approach that we're taking and we have this um piece of software called mini geth so it's a subset of geth autoethereum that is patched support our system and compile to mips and the difference between um go ethereum and mini gf is very very small so we just removed a bunch of codes that's very easy and then we made like very small a very small amount of changes so that it supports the system and that's important because it means that whenever go ethereum is updated we can always update mini gf very easily so
how to figure out the step of this agreement over this execution trace the the general principle and i'll give a graphical illustration of this after is that you wanna hash the memory of your program at different points of the exchange execution execution trace and you're going to start at the midpoint so at fifty percent of the execution after half the up codes you take your whole memory you create a hash of it so for those of you that are familiar there's actually a marker root and you send that to the l1 challenge contract the verifier does this the sequencer does this and they compare
the results if the results are the same we go to 75 percent of the exclusion execution trace so that's like half of the remaining span and if it's different it means that we disagree before and so we go to 25 percent right so if you agree of 50 it means the disagreement is after if you agree if you disagree at 50 it means the disagreement is before and we can keep doing this cutting the space of possible disagreement in half each time until we find a single instruction where we agree on the memory before but we disagree in memory after so executing this single step against the memory will
tell us who is right and who is wrong so once we find this step we need to execute on the blockchain and so we compile mini gif to the mips instruction set and we use maps because it's a very simple instruction set so we have a on-chain mips interpreter that is less than 400 lines of solidity and we use that to execute the instruction but this instruction will need to access uh the mini geth memory right and the mini gif memory is not on layer one it also needs to access the transaction batches and those are
those are on layer one but they need to be accessed so accessing memory is relatively easy because we already have a hash of the memory we have a miracle root of the memory and this micro route lets us prove any possible piece of memory against it right so america root is a a tree structure made of many hashes and the property of it is that you can say well this byte is this value and you can submit a proof of that that you can verify on chain and a single maps instructions is not going to touch a lot of memories memory spots maybe you know two or three at
most and so you only need to provide three of these proofs which are relatively small to be able to execute the instruction so to access the batches and i should have said these transaction batches they are posted to ethereum but they are not stored in the evm memory because that would be too expensive instead they are opposed that as call data so they live with the transaction within the transactions and to access them with something called pre-major recall and this is what i will explain next this was already like a lot of content so i want to pause to see if there's like any questions or you know there's no stupid questions so
don't be afraid uh i know i look very intimidating but i'm very nice i swear everybody all right if you're already too shy you can come find me afterwards and ask your questions so all right this is a illustration of the challenge game graphically so these boxes on the top and the bottom these are the extru the execution trays of the challenger and the defender so every single box is one assembly instruction so you start at the middle you are going to take a hash of your
memory you submit it to ethereum and you compare in this scenario we're going to say it's the same so the disagreement is after the midpoint so you got 75 again you take a hash of the memory you compare it in this scenario it's different again you cut it in half 62.5 you keep doing this until you find a single instruction that you disagree on all right so the the next thing we need to talk about is the pre-measure recall and this is the way the previous work is a way in which you can access any data on the ethereum blockchain ever
and you can prove that this data existed there so how does it work so the interface of the premier account is simply a function that given a hash return a pre-image of the hash so the primitive dash is the thing that needed to be hashed to produce the hash and so assuming that you implement this in a contract because yeah so it's very important to say that if you're using a cryptographic hash it's normally impossible to do this you cannot take a hash and find the pre-image because there are many possible pre-images and also it's compute computationally infeasible but if you give the preimage in advance
to the to say to a contract then you can query these pre-images that you've stored say hey here's the hash give me the pre-image why is this useful for us is useful because in ethereum you get a lot of hashes that commit to important information so you have an upcode that gives you block hashes and a block hash is a hash of block header which contains useful information each block header contains the hash of the previous block header so that's also something that you can use and so using those you can already see that if we have the premature oracle we can walk the whole blockchain backwards by starting with the hash we get the header then we can
walk we have the hash of the previous header so we can walk there then we have the dash of the previous header so you can just traverse the whole chain using only the simple interface so they already see that it's quite powerful and the other thing you can do is you can prove any state in any block so any state that the uterine blockchain had over all the blocks or any transaction that was ever included and that's because every block header has a miracle route for all the transactions in that block and numerical route for the whole state of the blockchain in that block so you go to the block you want and then
you find the marker route for the state at that time or for transactions at that time and you can go down there and prove via the premature call any state and and this works because a marker try is a tree of hashes and there will be the next slide will will show this graphically so it'll be a bit more understandable uh okay access and yeah on that that's that's what i just said okay so this is the graphical slide so these two trees at the bottom these are marker tries and the way a miracle try works so this
is a binary marker try so each node has two children and basically each node can be represented by the hash of its children so if you start from the bottom with pure data right you can see that you have a piece of data l1 so maybe this is a transaction and the node h00 just the hash of of the data l1 but then to create the the node 0 you hash the two children 0 0 and 0 1 and these two are only hashes right and then to create the top hash you hash zero and ash one together
and so you can see it's a tree of hashes all the way down so to take an example of working this so say i'm interested in getting a transaction or transaction batch that lives in block 41. say i'm at you know block 42 i use the blocker shop code to get the latest block hash then each green arrow here is a use of the pre-image oracle so i have the bloghashop code i use the preview recall to get the block header then from the block header i get the hash of the previous block and i use the permission article to get the you know previous block headers the block 4d1
in block 41 i get the transaction marker root and use the pre-measure recall to [Music] get in the tree and get the children and then for each children i each time use the premature a call to get the child until i can get the transactions that i'm interested in and this is exactly what we use to read those transaction batches that contain all the l2 transactions so concretely in miniget which is or you know re-implementation of the well not or modification of go ethereum that validates block
we use this to [Music] um re-implement the the database right so normally if you have a go ethereum node it has a database of the whole state of the blockchain of the you know the blockchain you're validating and it turns out you can use the premature record to implement that and we actually have three implementations of the premature recall and this is where it gets a little bit tricky it's implemented on chain and this is used for the single step execution and on chain we simply submit the pre-images and store the hash to pre-image mapping very simple it is
we also have one implementation of this in that we compile to mips and this one is necessary so we need to run mini geth in mips off chain because we need to hash the memory for the challenge game otherwise we need to run maps of chain but we need to get these hashes so we can do the actual challenge game and these users pre-fetched hash prefetch hashes so the premium record was similarly like we already know the hashes in advance and so we just read from a hash to pre-image mapping
and then but then we also need to run mini gaf in you know normal instruction set whatever runs on your laptop or server and for those we need to get the pre-images and we use the json-rpc methods that you know online nodes expose in particular we use a get block by hash and we use this thing called ethget proof which we use uh very creatively there are some challenges there but basically gifts get proof gives you a miracle proof or of any piece of state in ethereum all right so a small summary
optimistic graphs are secure as long as there are one less family editor the radiator if he disagrees with the sequencer can initiate a fault proof using canon that's a fault-proof system so the validator and sequencer they play a challenge game and they find a single status agreement in the execution of the validator which is compiled to maps so this is called the challenge game and finally this single step is executed on chain and we can access the memory of the validator through some microproof and the batches of transactions that are being you know executed can be read using the primage oracle
and yeah that's that's how it works oh yeah the final slide very important where are we with this so this is actually not fully implemented yet this is the design design is fixed we know how to do it but george gave us a prototype which allowed us to challenge l1 blocks on r1 this is useless because by definition l1 blocks are correct right but it's a proof concept that shows that this can work and so what we're almost done with is changing l2 blocks on l2 so the simple transposition of this concept but it shows that whatever changes we made to the original go ethereum that we're using on optimism uh still doesn't break the system
and then the real thing that we want to do is challenge l2 blocks on l1 right that's the whole point and for doing this we need to add something called l2 chain derivation to mini-gf and that's the part where we take these transactions that have been posted on r1 so the l2 transaction on r1 and we create blocks from them and that's a logic we already have written and we can import it fairly easily because everything in this stack is in the go language so we can use the go module into our node directly to do that and so this will be probably probably our next focus after we release
bedrock which is the next version of optimism there you go if you have any questions again feel free to ask them now or find me later
