zkEVM #06 - Devconnect AMS'22
Devconnect Amsterdam 2022 · 27 Jun 2022 · 14:55
A research session from the zkEVM gathering at Devconnect Amsterdam 2022 on proving Ethereum state with a Merkle Patricia Trie circuit. The presenter starts from the JSON returned by a get proof call, with its account proof and storage proof made of branch, extension and leaf nodes, and shows how the hashed address becomes nibbles that pick each child position. The talk then covers how the circuit checks a storage modification with two parallel proofs, and its special cases, such as a leaf replaced by a new branch or a key with no value, where placeholder rows are used.
Topics
From Devconnect Amsterdam 2022, hosted by Ethereum Foundation.
Transcript
Okay, sorry for this. Okay, so Mercury Patricia 3, uh MPT. Uh I will just start with uh how with the JSON that is returned by a get proof call. Uh it basically it contains um two proofs. One is account proof and the other one is storage proof. So uh in the account proof there are some RLP streams. Uh each one of them is a branch or extension node, but extension node is just a special case of a branch. Uh so and each of these branches, each uh each of these rows is a branch, and uh which contains 16 children, uh basically hashes of these children.
So there are uh 16 uh substreams, each of uh 42 uh length. And um the so for example the second one uh if you hash the second row uh you get one of the values in in the first row. And uh one of the and it's at the position from one of the uh zero to fifteen, and this position is determined by the account address. So the account address is once it is hashed, it is uh 32 bytes uh long, and then this is uh converted into nibbles.
So each byte is two nibbles from zero to one to fifteen value, and these nibbles determine the positions of the uh elements in in their parent elements. So the but the last one, the last row is account leaf, uh which contains this information here: balance code hash, nonce, and uh the root of a storage tree. Uh and then the situation is is similar in storage proof. We again have some branches like this is uh the root branch in storage tree and it's it's only one in this case uh and this is storage leaf which contains uh key and value uh in this case value is one um the key is what is um so um the in this case for example there are there's only one nibble used uh because there's only one branch and the remaining 63 nibbles are s are stored in in uh in um leaf so the the general idea of the of the circuit is um we we put um uh uh each branch into 16 rows uh and uh then uh each of these 16 uh the the hash of this 16 rows is computed there's no it should be a bit colored but it's it's not the blocks are not clearly seen here but uh so for example um yeah this is one block and the hash of this block uh in 16 rows needs to be at the proper position in the in the parent branch um and this position is given by by by nibbles um so um yeah in um in in the circuit, we we actually have uh two two proofs in parallel.
So uh on the on the left side there is uh proof, a kind of uh of a read operation. So what was um the state before the storage modification, and on the right side there is a uh state of the proof uh for the for the state after the storage operation. So this is a proof of one storage operation uh for uh for for a storage modification at some particular key. Uh and uh this key is uh the same for for both of these two parallel proofs. Uh and the circuit makes sure that uh both proofs are the same in most of the rows, except at the rows um which are given by this nibble.
So there is an additional column called uh modified node. Uh so that means the position of the children in in this branch, and the so these two proofs differ differ at at this rows. Um yeah, and once once uh we arrive to the to the uh uh account leaf, the hash of the account leaf is computed and checked to be uh in in the parent branch, and when we move to the storage tree, um the hash of the root branch needs to be, we check that it's in the account leaf. So that's that's the basic idea.
But uh yeah, if we uh zoom in a bit uh in into the branch block, this is this is uh a block of one branch. It it actually contains uh 19 rows, not 16, because there's an additional uh data. So for example, in break branch init, there are some RLP metabytes, like this 2449. This is this specifies the length of the of the branch. And it's it's sometimes these metabytes are of length three and sometimes of length two.
So there's some some branching needed to uh to correctly check the things. Um the uh the branch is put into 16 rows. So this this the first two, for example, are not empty here, the the third one is empty. It only has this 128 value, which is some specifics of the RLB encoding. And in case when this is not a regular branch, but an extension node, there are two additional rows which I'll cover uh just in a second. So usually uh in when when there is a regular branch, uh this the random linear combination of these bytes is computed, and then a lookup is made uh into Ketchak circuit uh to check whether this RLC corresponds to the RLC of this uh hash.
In this case, at the position uh 15. Um but in uh the extension node case it's a bit different. In this case, uh we need to check that the extension node is kind of uh branch uh where the path is a bit longer to arrive to the branch. So there are some uh additional nibbles, and these nibbles are stored here, and then uh the hash of the this branch is stored here. So there are constraints to check that uh the hash of this branch is stored here, and then uh we compute the RLC, the random linear combination of this extension node, and then this is checked.
The the hash of this needs to be in the in the branch above. Um yeah, but but uh that's not these are not the only constraints that needs to be that need to be checked. Uh this uh parent thing. Uh it also needs to be checked that uh the storage modification happens at the correct uh address and at the correct key. Um so uh what is uh the circuit is computing the uh RLC of the nibbles. Uh and then this RLC of the address, for example, is compared to the uh address, check to be the correct one, but it's uh it makes it a bit difficult because these are nibbles, not bytes, and we are computing random linear combination of bytes.
Uh so sometimes this nibble needs to be computed by uh 16 and and the multiplication factor, and sometimes with uh by it needs to be multiplied by one. Uh and if there would be only regular branches, this would be uh easier because then this uh would be just alternating. So once you need to multiply by 16 and once uh you need to multiply by one but there if there is some extension note in between extension node have some additional nibbles and when it has an odd uh number of nibbles uh this uh alternation is uh broken so there needs to be some additional branching for for the constraints um yeah and when we arrive to the to the leaf then this um so we were computing the the RLC of the nibbles so like uh like this way from the from this branch from the first two branches we get uh this value and then the remaining nibbles are are stored here and uh we continue computing the RLC but it's uh again some branching is needed because these nibbles the remaining nibbles are stored here in um in a compressed format and this format depends uh on how many on whether there are odd or 11 or or or or even number of nibbles um uh yeah this is just shows how the yeah the storage leaf it it takes two rows um for for the C proof for the left proof and and two rows for the right proof uh and yeah one of the things that that need to be checked is uh so some um sometimes this is the the the length of the nibbles is uh it it uh varies.
So uh and because we are computing the RLC of this uh of leaf, we need to make sure that uh after the uh length is uh after the specified length of this stream is uh finished, uh then that there are really zeros uh after this uh position. Um yeah, and then there are quite some uh special cases. So for example, um sometimes uh when an new value is added to the to the tree, uh an existing leaf is uh replaced by a branch.
So for example, in this case, uh we have some some leaf which is uh the uh the RLP is here, and uh it's inside this branch zero. Uh but after a new value is added, uh this leaf is replaced on the right side by a branch. So here another branch appears. Um yeah, and and the circuit just uses some placeholder values at this side, and the constraints then are goes like this. Uh the storage on the right, the the leaf uh on the right side needs to be checked, uh the hash of the leaf needs to be checked to be here at the proper position, and uh then the hash of this branch needs to be at this position where the branch was inserted, uh but on the right side uh the hash of this leaf needs to go uh one level above, uh so it needs to be there in in branch zero.
And there are some further constraints in this cases. So for this some additional branching branching is needed, and uh yeah, that's that's a similar case.
So uh yeah, that would be it.
Related talks
- Keccacheck: solving the Keccak bottleneck in zk SNARKs
- The road less travelled: 4 years of direct arithmetization of the EVM
- ZK in a Nutshell and the Gem of Pectra (Combined Recording)
- Ethereum's Next Revolution: Privacy by Default
- Proving Ethereum in Real Time with OpenVM 2.0
- zkStudyClub: Sean Bowe on “Halo and Accumulation Schemes”
- Is Beam Chain Good For Ethereum? With Justin Drake
- 'Introduction to Zero Knowledge Proofs' - Elena Nadolinski
- STARKs: Verifying Computations Faster than Re-Executing Them - Christian Reitwiessner
