Talk: What's next in EVM
Secureum Talks · 19:18
A member of the Ipsilon team at the Ethereum Foundation surveys proposed EVM changes and asks security researchers and language designers to pick them apart. The main focus is the EVM Object Format (EOF), which separates code from data, validates contracts at deploy time and makes the format extensible, along with static jumps and code sections that replace dynamic jumps. The talk also touches on an account abstraction proposal for EOAs and an idea for a single checked-arithmetic instruction.
Topics
From Secureum Talks; community: Secureum.
Transcript
[Music] yeah so this talk okay um you know watching like barry's talk and he had like this cheat sheet and everything unfortunately you're not gonna get this from from this talk but rather i'm going to turn it around i'm presenting you you know what is going on in like the protocol layer and what kind of changes we're talking about and i want you guys to pick it apart and tell us why it is bad and unfortunately
of course i said like what is next in evm and when i started looking at all these different proposals for the evm it has been i don't know 20-ish proposals so they're not going to make it into the chain anytime soon but because of that and you limit the time of 20 minutes i had to pick and choose so it's only going to be you know some of them so it's not everything what is on the plate for evm um just briefly about epsilon this is the team working at the ef uh researching evm proposals both external proposals and stuff we propose um there's the website ipswan.xyz you can find every single link including this slides there so you don't you don't need
to bother with anything else now moving on um it was funny actually this weekend was the first time i found this uh design goes with dvm even though i've been looking at the even for quite quite a bit of time so this is the version from 2015 written by vitalik and it's quite interesting because actually all these design goals are kind of accomplished today and i want to highlight the first one simplicity that is the one which it accomplished the most and maybe too much simplicity at this point so if i would have been there i would have added like these two more points um to the design goals the first one extensibility i would wanted to have something extensible so
that it is easy to add features easy to remove features without breaking like everything which is the case today and also i would have asked to have some kind of uh once of validation of code before it gets into the state so that you know we don't have all this like weirdness in the accounts as we do today and i want to motivate like four different issues uh we are kind of annoyed with and so the first one is what i mentioned basically that everything exists in the in the in the state every single byte is accepted all these instructions which do not exist yet they are in the state so whenever as an instruction is introduced it may do something and you know accessing contracts may start doing something else what the authors never intended them to do
so it is like you know one of the the biggest issues we are facing every single instruction introduction is preceded by a lot of analysis and the second one is that you know kind of similar that we also have like the special instruction of push which is the only one which has immediate data and it is a special case because we do not want to jump into this push data we want a really safe control flow and because of this we have this we have this special like jump test instruction uh to detect the the places we can jump into but the jump and jump this instruction is just a single byte so it can definitely occur in like this push data so how do we actually solve this
problem we cannot do this at run time so we have this uh complete analysis before executing every single evm code and we call this jump this analysis so this is the byte i mentioned it's 5b it is annoying the main problem with this process that we do it every single time it is expensive and it's also linearly scaling with you know how big the the code is and in many cases we're actually not executing all that code but we do have to scan everything the next big issue is like data sections so if you look at contracts um one basic example is like unit code you know when you deploy a contract you
have this unit code and that contains the the run time which is going to be in the state and this runtime is kind of like a data we are not trying to execute it during unit code we are just storing it but yet the evm doesn't know the difference so we have to handle it this code and the other one which is actually in pretty much every single contract is this metadata field added by solidity now you guys who are using viper you don't have this but everybody else has this metadata um the problem is really is just too much to analyze and the more important one is this data section can have jump desks so can we jump there we shouldn't and the last big issue we kind of hate
in the team is it's not possible to remove instructions because there's no validation at all and now of course i'm presenting a solution to this it's called the evm object format um it has these three goals we are trying to separate code and data we want to validate all of this and we want this to be extensible there's actually a set of different tips and the first two are accepted for shanghai now what is this accepted for shanghai means first of all it just means that the shanghai hard fork which is after the merge whenever it emerges right so it's after the merge and accept it means that now the core devs should consider you know looking at this it doesn't mean
it's going to go in but at least they are encouraged to look at it and we also want to get like this other one the static jumps it may make into it but it's not accepted yet for like consideration and the last one that's you know pretty far ahead but i'm going to explain all of these so this evm object format actually changes even bytecode quite a bit because right now as you all know it's just a string of instructions and after this we can actually have a header uh we're going to have a header with like a magic version number a list of sections etc and then the sorry the section data and just to visualize this so we have the legacy code on the top
and the uf code below you can notice that there's like an extra how many like 11 bytes so that's the overhead we have with this and and this is what they actually do so the magic is the first two bytes the version number uh a section usually is like three bytes you have the the section kind the size and the size is two bytes uh so there's a code section and we also have a data section at the very end and this terminator signals that we reach the end of the headers and the code this one is just a usual init code it just returns to the runtime code which is the one at the end now we're changing a few
semantical things here we're changing how control flow works so the offsets for the jump and the pc those are relative to only this section this code section they're not you cannot jump outside you cannot do any kind of control flow outside of this code section but we are not changing the the code copying because we still want to be able to to copy the entire you know access everything here so this is the only only symmetrical change to the evm but we also have this validation process which happens at deploy time so when you deploy a contract whether it's through the create transaction or to these opcodes it's going to go through a validation process and both didn't code
like this entire thing and the the runtime code this last bit both of them have to pass validation and if any of them failed and the contract creation fails um and actually we had like a protocol workshop on the first two days of this week and where this was presented it was like a good opportunity to get like more of the the protocol devs to give feedback and initially we had like these four cases which could happen you could have this eof contracts create eof contracts you could create legacy contracts etc um but we decided that e of contracts creating legacy is not a good idea so we only have these three cases now and then we have this magic one right the the main question is okay why do we have the magic and if we have this
deployed on validation what happens with code which is already in the state we want to make sure whatever is in the state is valid in this uf format so deployed in the london upgrade we have deployed the study ip which rejects contracts starting with zero ef and this enabled s2 to select this magic which means that there's no single contract anywhere in mainnet nor any of the the side chains or evm compatible chains which start with an eef zero zero byte so now if you deploy after this is enabled now we if you deploy a contracted ef-00 it has to be valid eof we also have like this validation eip um just like the second one i mentioned and what we are validating is that there
is no there's no op code which is is not a valid op it has to be a defined opcode um we it cannot be a truncated byte code and we also planning to to maybe reject like uh contracts with call code cell district that's etcetera now the interesting one is is the relative jumps you know everything in the evm brightness dynamic jumps which makes analysis quite hard and we're trying to turn this into static jumps and i'm going to give you like a few examples here so this is what jumps look like today you have the jump test which is an instruction itself takes a bite then you push the location and then you jump and all this costs like a thousand gas like every such occurrence is a thousand gas
at deploy time and nine gas two to run now with the static jumps you don't need a jump test because you have that encoded in the relative jump as an immediate data it costs much less to store much less to execute but you cannot use this to actually do all kinds of jumps needed in the evm so they're like two major jumps we're doing in solidity we're doing these static jumps already to to every single location just you know we're mimicking static jumps with dynamic jumps so most of the the jumps are static but then the only case where we return from a function call that is dynamic that cannot be done with a static system so therefore we have this other proposal
to actually break up evm code into code sections so each of the different functions would be different code sections and you can call into them and return from them so there's like a call stack next to it the the really interesting part of this proposal though is that it also validates the expected stack height when joining a function and the expected stack height when leaving it so it also validates uh the stack and the functions cannot actually manipulate the stack outside so it's like pretty cool um how do we are on time oh that's that's plenty yeah so i mean these are the it's like
i like it but right it's quite a big change to the evm and now kind of moving on from from the i guess the eof um era so these four as i mentioned yeah so these four the ones i talked about so the top two the including code validation they're very likely to get in um so that's the one where i would like you to get the most feedback on but i really hope that the static jumps are gonna get in now the the function section which is the the most intrusive but also really interesting one because that is the one enabling the complete removal of dynamic jumps but i think that is probably the most complex and most risky to introduce
so you would be the best audience to get feedback on this eip and now moving on to another eip vf here which is the alt authorization feature have anybody heard about this before not many of you so this is part of the account abstraction direction which means to to make eoas and user accounts much more smart and what this proposal is trying to do is that as an eoa you can authorize a access contract to interact in your name which means to to send calls with your address
and the way this is achieved is by by two instructions we have the first instruction where you pass in an ecdsa signature and you authorize this contract to um to act in your name this is kind of like the permit functionality for erc20 so this contract would store the signature and when whenever it wants to interact in your name it's going to call this instruction which sets a context variable whether the authorization was successful or not and from that point on whether it uses this odd call instruction it's going to make a call with your address this would enable a lot of different use cases and this was proposed a year ago at this this point the reason it failed
because yeah what is the reason do you have any idea okay the reason is it cannot be revoked once you give this authorization it's done and you know whatever happens with the contract if it's hacked your eoa is like fully compromised so with eof there would be an option to actually make this revocable we could use these code sections to have a special code section for validation and this validation means that whenever you use this uh whatever this this old call instruction it would check if the the result address is a contract and if it is a contract then it calls this validate and if that
returns true then it can be authorized and if it returns false then it has been revoked and now you ask okay but it's an eoa we're talking about how the hell can it have code so there's like another proposal too to make that happen which is which i haven't listed because it's too new um there are a few more use cases already for this uf stuff and there's like another i wanted to just mention this address space extension discussion uh which might be interesting to you guys uh currently all the addresses are 20 bytes long the idea is to make them 32 bytes long which is simple enough right but all the contracts are kind of depending and not depending on it depends on the solidity
optimizer some cases it maximizes them truncates them in other cases it doesn't so we cannot just do it we have to have some more complex system in place and and the cof proposal may help with that and there's also like another proposal to have complete control flow validation at deploy time which would mean it would ensure that there wouldn't be any kind of stack underflow overflow a really great idea a lot to be done at this point i mean that was a talk but i do have a few bonus slides if we have time and we don't have questions no questions then okay i'm going to show this so we have been you know with the uft the idea was that we could also change
other missing features like do checked arithmetics you know if i mentioned safe math all of you know what i mean um so we were looking into ways to do that um and it turned out we actually don't need us for it um but we looked at one specific use case which is the maldive uh actually gonna go here did you guys see this before it's a long code one person knows i think every single one of you uses this have you ever made a unit swap transaction yeah this is the coding unit swap it's quite long and uh we would be able to replace this long piece of code with a single
instruction and the the really cool part here is finally figuring out a way how to have a single instruction which can do both checked and unchecked arithmetics and i think we found like a way to do it and this eip5000 if you can convince the eip editors for this number then it's the ib 5000 and just like a really cool way and it may set the the precedence have you do check their headaches for the other instructions and i run out of time and i guess if you have questions see if you have questions otherwise you can add an extra bonus any any questions for alex all right can i request you to please
come and take so if i can just repeat the question what are the gas savings on maldives for uni swap yes at this so the the the opcode itself doesn't do checked arithmetics it helps you do check their arithmetics and this like the the the the the workaround you have to do to do checklist medics so this costs roughly 2530 gas and the current code is like 250 gas so this piece is 250 ish this is 30 and you use this i i don't know entirely how
many times but i would guess like 20 times at least 10 20 times so you scaled it up um but ud swap is used all the time any other questions for alex you may have time for a bonus slide i actually removed the other bonus sides because there were just too many of them but anyway i just really hope to to you know open your mind all these different proposals which are out there because uh what happens is that i don't think
really the protocol devs uh the actual application devs and security people they don't really seem to be language designers like all these four categories they don't seem to be interacting that much and nobody is like giving input you know from these other layers into protocol in protocol we we just look at oh we would like to improve evm in a certain way and it makes sense to us it may not make sense to you it may not make sense to you to language designers um so i wanted just to give you like a little overview you know what is going on and and hope that you guys start interacting uh you know with the protocol people on this all right fantastic thank you alex thank you [Music]
Related talks
- Ethereum Execution Layer Specifications (EELS)
- The Future of EOF: Layer 1, Layer 2, and Beyond! by Danno Ferrin | Devcon SEA
- Diffusion en direct de EthCC Livestream3
- EIP-3074 and the role of the EVM in a L2 world - Ansgar Dietrichs aka @adietrichs at @ETHDubaiConf
- Ethereum 2 Update: Ethereum Engineering Group Meet-up - fixed
- Ethereum in 30 minutes
- Как работает EVM: практическая часть ▫️ Dive into Solidity ▫️ Эльшан Джафаров
- Design Mistakes
- Verkle integration in reth
