从 The Merge 到 The Surge:Vitalik Buterin 的以太坊 30 分钟精讲 | ETHPanda 译制

Devcon 6 · 11 Oct 2022 · 30:36

Vitalik Buterin explains post-Merge Ethereum, covering transactions, accounts, smart contracts, EVM execution and gas fees. He introduces proof-of-stake validators, fork choice, finality and Merkle proofs, then outlines rollup scaling and future protocol upgrades.

Speakers

Topics

From Devcon 6, hosted by Ethereum Foundation.

Transcript

[music] [music] So this is actually not the first time I've given this talk, right? This is uh the I've given something like this uh about pretty much once every DevCon, I think since uh at least Defcon 1. And the point of this talk has always been to just give a kind of big rapid fire introduction into some of the basics of how Ethereum works, some of the basics of what Ethereum tries to accomplish and you know just try to get it done within um I guess right now it's 1.8 kilos or 150 slots. Um so what is Ethereum right?

Ethereum is a general purpose blockchain. So people have seen uh general purpose uh system platforms before and people have seen blockchains before and I think at this point we can all kind of intuitively understand what the value of both of those categories is. Right? So blockchains can facilitate a large scale consensus. They can protect against censorship. They can enable censorship resistant applications. Blockchains are always available. If you build on a blockchain, then the thing that you build on that blockchain is going to be available.

It's not going to just get pulled under you because um you know some particular company decides it would be 12% more profitable if they just change the API on you without notice. It is uh you know independent of any one particular nation state. It's not dependent on any particular um you know centralized corporation. Avoid dependence on centralized parties. Um it's the uh you know one neutral ground at a time when almost every other grounds that we see is uh you know picking picking sides of some kind or other and uh you know often for very good reasons. But you know blockchains are this kind of base layer between parties that do not trust each other that you know still allows them to

have positive some interactions. Uh blockchains can allow applications that are open that are transparent where people who participate on them are can be sure that the application is going to follow the rules that they signed up for, right? So blockchains are great for you know things that really need stability. Um so there's a good reason why money is the first app. Um but there's other apps as well and you know I'm sure a lot of people behind those apps are going to be talking a lot about them at this conference. General purpose platforms are powerful too, right?

General purpose platforms are interesting because they open the door to independent innovation. So if you have a general purpose platform, then it just makes it much easier to build something on top of it because if he wants to build some specific thing instead of having to like rebuild all the infrastructure yourself, you know, you just add a tiny little piece, right? They can create powerful network effects between different types of applications. Uh so you know you got your unis swap and then you got your like dowo that plugs into the unis swap and then that and then that unis swap itself gets used to trade between um you know USDC tokens and maker tokens and you you can create these kind of complicated chains of seven different applications that all

talk to each other and sometimes they talk to each other in insanely crazy ways within one single transaction that uh you know really fun people from paradigm go and write amazing blog posts about. Um but so uh general purpose platforms lower the barriers to entry. They make it simpler to build. They uh enable a lot of um innovation and uh often general purpose platforms end up being far more useful than even the creators originally imagined. So Ethereum is a general purpose blockchain, right? And so Ethereum tries to be both. So this is like one of the sort of three minute pitches of uh you know what Ethereum could be could could allow you to do. So what what is

Ethereum and how does this work? So the these three pictures are from a slide that I used to describe Ethereum at some of the previous Ethereum in 30 minute sessions, right? So you know you have like single application blockchains which are like pocket calculators. Then you have like multi-lication blockchains that explicitly support a small number of applications. I call them Swiss Army knife blockchains. And then you have you know the smartphone blockchain. It's a, you know, it's general purpose and if you want to do something, you just like download the app, right? So these days, you know, unfortunately, you know, we're in, you know, 2022 and, uh, you know, talking about a general a blockchain being general purpose as

though that's something cool is, um, you know, kind of like a, uh, someone selling a house describing their house by saying, you know, we're we're really modern. We have a refrigerator. Who here has a refrigerator? Wow, lots of people have not raised their hands. I'm impressed. Um, I I guess do people like order out? Do people eat raw food? Like what's the idea here? I don't know. I mean, people have done refrigerator free living successfully for like, you know, 1900 years in the AD era alone. But that's, you know, still impressive. Um, anyway, so like what does the blockchain look like, right? So, one of the uh exciting

things about doing this presentation this year is that like I actually had to change it a lot, right? Like between a lot of the previous sub ones, it's like, okay, you know, it's Ethereum, here's how it works. Okay, it's Ethereum, it's how it works. Okay, it's Ethereum, it's how it works. But in between the last Defcon and this one, the way that the Ethereum blockchain works just like changed very fundamentally, right? and the the rate of change and our ability to actually execute on and implement changes to the Ethereum protocol significant changes that we have wanted to do um almost since the protocols launch and and that we've been talking about for almost a decade but you know finally managed to done has really been

accelerating right so we had EIP1559 in you know 2020 and then the beacon chain launched and now the beacon chain took over and you And uh you know Ethereum is only a proof ofstake system. So you know lots of very big changes and uh you know lots of different things that we have to talk about right. So like remember back in when during the proofof work era we had to talk about how like blocks include uncle blocks right do people remember this? So people remember how like sometimes people would even you know try to be gender neutral call them armor blocks instead of uncle blocks as well. And like you know I get the you know I get the sentiment very honorable sentiment but like come on like armor just sounds like an insult for people who meditate

but okay so these days you know we're proof of stake right and the blockchain looks kind of different from what it did before right so what so let's like talk about what the blockchain looks like without reference to you know the dark old proofof work era that our grandchildren will eventually remember in the same light as how they Remember how houses used to not have refrigerators? So you have blocks, right? And blocks contain transactions. What is a transaction? A transaction is an object sent by a user that contains information about something that they wants to do, right? So if I want if I have like some ETH um E ETH is the

cryptocurrency inside of Ethereum and I want to send you one ETH then that request would be packaged up inside of a transaction. If let's say I [snorts] have an NFT and I want to send you the NFT that um request is packaged up inside of a transaction. If I wants to publish an entirely new application then and create the smart contract for the application and that's something I'll cover later that is also packaged up inside of a transaction. So a transaction is like a a package of data that contains information about stuff that somebody wants to do. These transactions get included in blocks.

Every block is created by by a validator and a block. So blocks are just these packages of transactions and one new block comes every slot. One slot is 12 seconds. Then we have attestations. Atestations confirm blocks, right? So atestations are like these messages signed by other validators that basically solidify the position of a block inside of the AI blockchain, right? So when you a block gets published and then that block within a few seconds it almost immediately gets thousands of attestations supporting it and that kind of solidifies that block's position in the chain such that other blocks that compete with that block that like also try to claim that they're um that you know that are not kind of

children of that block but that are you know siblings and that try to claim that they're the real history those blocks are not not going to be able to get through right so in as Danny mentioned you know in the entire almost month that post merge Ethereum has been running, we've only had like 26 reorgs and that's maybe an overount and even those cases are cases where a block is published too late and it probably did not get many atestations. Right? So lots of attestations in parallel solidify the position of a block in the chain. Block gets published, block gets attested, block gets published, block gets attested, blocks published, block gets attested. Right? people understand um raise your hand if you understand.

Okay. Wow. It's like mo more people understand this that have a refrigerator. This is like a basic. Okay. So, let's talk about what happens inside of a blockchain, right? So, uh there's the blockchain keeps track of um information that we call state. And the the state that the blockchain keeps track of is made up of accounts, right? And there's two types of accounts. Um, basically you can think of them for now as like accounts controlled by people and accounts controlled by robots where the robots also are also only exist inside of the chain, right? So an externally owned account. This this is an account that represents a user, right? So like for example, if you hold ETH today, that ETH is stored inside of

your externally owned account, right? So there exists a record which is like an EOA that is in the blockchain that the blockchain keeps track of and that object contains a record saying you know hey this address contains this amount of ETH. The other kind of account is what we call a contract. A contract is like a computer program that lives on chain. The code of that computer program is on chain. So the chain stores the code of the contract. The chain stores internal storage of the contract. Internal storage is like memory that that contract has the ability to update and contracts are basically how all applications that that are in Ethereum work, right? So an application is generally has an onchain component that

kind of controls the business logic of that application that generally is one or a set of contracts. So what do contracts look like? Um so this is an example of a source code of a simple smart contract. Um this is by the way in a language called Viper. It's a uh a less well-known language. It's the kind of largest alternative to Solidity. So if people aesthetically prefer coding in Python syntax. I mean like I personally think Python is like way aesthetically superior to anything using curly braces, but I know this is a controversial topic and like half of you are going to cancel me. Um but um you know if uh if that's you or if you like some of uh Viper's

kind of other features that like try to kind of take a very pro or from scratch approach to being sort of more restrictive and more secure in various ways you can check it out but this is a simple you know contract for a domain name registry right so basically the same sort of thing that ENS is trying to do right so what do we have here right so we have first like a mapping right domains mapping bytes 32 we're gonna uh and to a domain right um right so the bytes 32 here is like basically you know the address like what the domain is right so the uh you know I'm just kind of being very lazy and very simple not introducing strings or variable lengths or fancy stuff and you

know if you want to like register George then you would just like put 26 zero bytes and you would like stick George at the end and uh you know that would be the key in the mapping And then the value in the mapping is just who is the owner and what is the IP address that the domain uh corresponds to. Right? So then we have two functions. The first function is set owner. Right? So the point of this function is basically if you are the owner then you can transfer ownership to a new owner or if the domain is not yet claimed then you can call this function set it to yourself or set it to some owner and you can become the owner. Right? So you should be able to you know if you have any programming experience just kind of read the code

and understand what's going on right basically you look at what the owner of the the particular domain that you're looking at right now is and if that owner is zero or if that owner is you then you can set the owner to whatever you want right so that's one function and then the other function is well if you are the owner you can set the IP so what's actually going on here right basically we have these functions and it's a piece of code how does this kind of translate to what's happening on a chain. So this is a transaction flow example, right? So basically what we have here is um you know you have a the contract. It's the a kind of bubble on the bottom the 0x 849 C41 down there, right? That is a uh an account. It is a

contract account and that contract account is going to have a piece of code. What is that code? It's a compiled version of this, right? [clears throat] So that lives on chain and then you have that contract and that it also has some storage. Now at the top we have your transaction right. So as we mentioned before transactions are like these packaged objects that represent requests to do something. So in this case um you we're going to make a request to change the basically calls set address right? So we're gonna call it with a particular domain. We're gonna call it with a particular new address. And you're going to make a transaction where the two of the transaction, right, the two address is the account that you're calling,

right? So it's going to be 0x849 C41 down there. The data is going to be the stuff that you call it with. And then the signature is like cryptographic data that proves that it actually is you, the owner of the sender account that actually created the transaction, right? So the signature determines who the sender is. only the sender like only the owner of the actual private key corresponding to the sender can actually create a transaction with that sender. So that transaction gets included in a block. what happens in the EVM, right? So, it starts off with a call from the the account at the top, the CA291D up there, right? The account at the top, which is an externally owned account.

That is the account owned by you, right? Now, what does that account do? So, what are the state changes that happen? So first of all your balance goes down a bit to pay for the transaction fee and then a bit of balance gets transferred to the minor um or now to the block proposer and then it makes another call and that call calls down to the contract that is the application and the data of the call encodes what you want to do and then basically it actually does like a series of storage operations that just are what's happening here right so first you do an S lo a storage load to bas to figure out like what actually is in the domain or in the storage for the particular domain. It returns let's say a zero because nothing has happened

there yet. And then we s store and um in this case you know we're changing the address and it's just going to s at a particular address that that maps to where that domain is stored and it's going to store the new address there. Right? So this is like a very simple example but like this is a bit of a view of you know what happens inside of the EVM when you send a transaction. So gas, this is something in Ethereum that has not changed yet, right? So gas is the uh unit of resource consumption within Ethereum, right? So examples of gas. Um so a transaction costs a base 21,000 gas. Each computational step costs usually between two and 10 gas depending

on how how complicated the operation is. Editing a storage slot costs 5,000 gas or it costs 20,000 gas if the storage slot is not filled yet. And so you're actually expanding the storage. And every bite of data in a transaction costs 16 gas. Or if it's a zero bite, then it only costs four gas. Right? So gas is like this master unit that represents all of the resources that are being consumed during the execution of a transaction. If you send a transaction which gets included in a block, you have to pay a fee that's proportional to how much gas the transaction consumed.

Right? So whatever amount of re total resources and transactions consumed you have to pay an amount proportional to that right it so the fee is basically the what's called the base fee plus priority fee multiplied by the gas you use so the base fee is like a fee that's adjusted by the protocol it adjusts up or down to try to keep the usage at at about the same level and then the priority fee is like an extra amount that you pay to the block proposer to sort of encourage them to add your transaction and in this partic generally people just set a priority fee of one, but you know, if there's a particular time where lots and lots of people are sending huge numbers of transactions and the blocks are congested, you can set a higher priority fee to get in first. And

a maximum of 30,000 gas can be spent inside of each block, right? So, who remembers how much gas it a basic transaction costs? Hint, it's in the previous slide. 21,000. Okay. Um, so 30,000 30 million divided by 21,000. Anyone want to guess about how much that is? One refrigerator. Excellent answer. Yes. So it's okay. Right. So it is, you know, going to be about in about in the 1400 range. Right. So a maximum of 1,400 you know roughly simple transactions can make it into each block and uh you know if the transa but on average it's going to be 700 because like the priority fee adjusts to keep the average usage around

or sorry the the base fee adjusts to keep the usage around 15 million but um you know if the transactions get more complicated then they start consuming more gas and the you know you a block can include fewer of them. So that's what gas is. So this is what a transaction object looks like right? So a transaction as we mentioned is like this big blob of data that represents you know an op a thing that a user wants to do that gets included on chain. Um and you know you can see kind of some of the parameters of what they are. So transaction type um this particular transaction type is 0x02. There's also 01 and like others before it. Um chain ID which chain is this for? Are you even sending a transaction for Ethereum or

for Ethereum Classic or for ETH POW? who here has sent a transaction on ETH power. No hands raised almost. Okay. I a couple of hands raised. Okay. No, no, don't worry. You're not cancelled. Um so, okay. You know, just we want to give people the ability to send a transaction on one chain instead of sending it on on all the other chains. You know, it's not that hard, right? Um nons this is like an anti-re replay value, right? So, every time you send a transaction that gets included, the nons also like has to go up by one each time, right? So, this prevents a transaction that you send from being included more than once.

Pretty simple. Max priority fee, the priority fee that you're paying. Max fee, which is like the maximum base fee that you're willing to pay. Gas limit, the maximum gas the transactions allowed to consume. Um, destination, which address the transaction goes to, the amount, how much how much ETH that you're sending. Um, data is if you're calling a contract, then the then what is the data that gets passed in the call. Access list is like this fancy way to access some accounts in some storage slots kind of earlier and access them a little more cheaply and then the signature is like a cryptographic thing that verifies you know who sent the transaction. Okay. So, high level languages, right? So, uh you know, we mentioned that there's Viper. Um there's

also Solidity, there's also um you know, LL, there's like a long list of kind of various highle languages that you can write contracts in. So, when you write a uh a smart contract, you're generally writing in this high level code. There's a compiler. The compiler converts the high level code to bite code and it also outputs an API. Um AI stands for application binary interface. It's basically the way to encode particular like requests like things that users want to do like users attempts to call particular functions in the contract into a set of bytes right so in this case like if you call you know set owner with a particular um you know with particular address actually this should

be this should be set IP I put an IP and that's a bit of a mistake right then you can use the API and you can convert that into some call data right and the call data is what actually gets into the transaction right So there's this kind of logic that happens that basically converts this sort of highle human readable stuff that people want to do. You know both the human readable code of the contract and kind of human readable instructions like you know I wants to send Bob 25 E because I really like him. You wouldn't put the I really like him part into the contract. You would just like send him a love node offchain or something. Um but you know convert that into a kind of bite request that the EVM understands. Um so proof ofstake consensus right. So the thing that

actually kind of keeps the whole thing safe. So we talked about blocks, we talked about atestations, who gets to produce these blocks and atestations. Anyone can if they deposit 32 ETH and become a validator, right? And if you have less than 32 ETH, then you can join the system through stake pools, right? So there are stake pools, you know, there's rocket pool, there's Lido, there's a bunch of other pools and you and if you have less than 32 ETH, you can kind of become part of a validator using a stake pool as well. So deposit 32 ETH becomes a validator and in each slot 12 seconds one over 32 of all validators attest to the block that was created during that slot. The uh validators get revenue, right? So why

would you stake? Well, you get rewards. You get two kinds of rewards. You get in protocol rewards. So you get automatic rewards for creating blocks, creating attestations, you know, doing all all of the good things. Um and uh you also get priority fees and me from uh transactions right so you know you get revenue in two ways and validators can you know withdraw at any time well this will be enabled in the next hard fork right but validators will be able to withdraw at any time with a delay um and usually that delay will be pretty short but in extreme cases like if everyone's trying to withdraw at the same time then there is going to be a queue and you might have to wait for some amount of time so That's proof of stake consensus, right? Basically, you know, if you have

32 ETH, you can deposit, become a validator, and all of these validators are the ones that participate in this big system of blocks and attestations that keeps the chain progressing and keeps the uh blocks that are being added safe. Um, fork choice, right? So the reason why we need to have like weird fancy stuff in consensus is because what if you have this situation where people publish two blocks and those blocks disagree with each other, right? So in this case you have two blocks and these blocks are um you know they're sister blocks, right? They have the same parent. Um so clearly you can't get like put both of these blocks in at the same time. They might have conflicting transactions. They have some of the same transactions. They even might have some

of the same transactions in different order, right? But blocks are you know what happens if you have like two blocks that create two conflicting histories? You have to choose one of you have to choose one of these histories somehow, right? And the mechanism that does this choosing is called the fork choice, right? Because the blockchain forked and we have to choose one one part of the fork. So the mechanism that does this right now, it's called LMD ghost and it's very simple. It's just addestation counting. Basically, you have block A and you have block B and you just count the number of addestations that support block A or support its children. And then you also count the number of attestations that support block E, block B or supported

indirectly by supporting its children. You see which side has more. In this case, the top side has four, the bottom side has six. The bottom side wins and so you choose block B. Right? So this is one part of the proof of state consensus. There's also this mechanism called Casper FFG finalization, right? Casper FFG finalization is like this extra gadget that lives on top of this attestation game. And it gives us this really extra special property that if more than twothirds of validators are online and honest, then after two epochs, so one epoch is 32 SWATs um and or 6.4 minutes, so after 12.8 minutes, a block gets finalized and that block cannot be reverted, right? So if we take

this example, if you take the block B over here, after one epoch, if more than twothirds of the testers in that epoch support B, then B is justified. And if after another epoch, more than twothirds of a testers still support B, then B gets finalized. Right? Once a block is finalized, it cannot be reverted. But you know, in practice, waiting for the Casper FG finality is like more a thing for highv value use cases. If you are just making a very simple application that's not doing anything super high value then generally one of what we call safe slot is enough for most applications right so if you have one slot we're during that slot the proposer acts correctly and he gets lots of attestations then that's like generally enough to be secure Merkel tree is um

who here knows who's on the picture here um who here thinks it's Ray Curtzswhile who here thinks it's Ray Dalio um who here thinks it's Craig, right? Who here thinks it's Satoshi? Um, interesting. So, a few people think Ralph Merkel is Satoshi. That's fascinating. Okay, I gave away the answer. It's Ralph Merkel, right? So, Ralph Merkel is great because he invented Merkel trees and he also invented the Merkel damard construction for hash functions. which you know actually has has some problems and spong and uh it's you know why people want to switch to sponges lately but it was you know an amazing invention for its time and uh you know he uh recently also

doing some interesting stuff about cryionics but you know Merkel trees are great and doas are also great um raph Merkel and doas are not actually connected the only connection is that I like both of them um but the um so what are merkel trees right a merkel tree is like this data structure that lets to create one small object that commits to a large number of objects where it becomes very easy to prove for any one of those objects that that object is inside of this entire big entire tree. Right? So you have this one object that's called you know a header and it might be committing to like a million different things and for any one of those million things you can make a short proof that shows that that one thing actually is you know in the set of

things that that's been committed to. Why do we care about this? Well, Ethereum blocks are big. The Ethereum state is even bigger, right? The Ethereum state is like 40 GB. So, what if you want to prove something that happened in a block or prove something about your account and you want to prove it to someone that has these block headers that are at the top, but that does not have the entire 40 gig 40 gigabytes or the entire, you know, really huge amount of of uh of data in the Ethereum chain. Well, Merkel proofs come to the rescue, right? Basically, you just provide the value. You provide a couple of like sister hashes going up along the tree and anyone can verify the proof by just kind of continuing to hash up the the values going going up

together and then seeing whether the route they get matches, right? So, really powerful technology, Ethereum actually, you know, uses it everywhere. Um, last fun thing, layer 2 protocols, right? So, most people or increasingly more and more people don't use Ethereum directly. They use what are called layer 2 protocols that inherit security from Ethereum and add higher scalability on top. Right? So rollups, I wrote an article on them. They're really fun. There's a bunch of them. From a user's point of view, living on a modern layer 2 feels like living on Ethereum. You know, applications work the same way, but because these applications don't stick everything on Ethereum directly, fees are many times lower. So layer 2 are great. Layer 2s are how Ethereum is

is scaling. And you know, we encourage everyone to pay attention and learn a lot about layer twos this year. So finally, you know, future directions, the merge done. Yay. Um, okay. Next up, the search increasing scalability, going finally going sustainably below 5 cents a transaction, go getting us to thousands of transactions a second. Next up, The Verge. Replacing Merkel trees with more efficient structures that let Ethereum nodes be much lighter. Ethereum nodes don't have to have huge amounts of data becomes much easier for anyone to run them. Yay.

The Purge, clearing out old data, clearing out technical debt, making Ethereum nodes easier to run, and making the Ethereum protocol simpler. Woohoo. And uh the splurge, grab bag of various useful stuff. Account abstraction. EVM improvements, proposer builder separation, making everything amazing with ZK Snarks. Yay, Ethereum is getting better and I'll have to keep rewriting this presentation for next year. Amazing. Thank you guys. Bye-bye.