Reckle Trees: Primitives for zk-Coprocessor
ETHCC 7 · 11 Jul 2024 · 21:57
Shravan Srinivasan, an applied cryptography researcher at Lagrange Labs, presents Reckle trees, a way to build Merkle batch proofs with recursive SNARKs that can be updated in logarithmic time when data changes and generated in parallel. He explains how the same structure supports verifiable map-reduce computation over dynamic data, including translating a Keccak-based digest to Poseidon, and how it underpins Lagrange's ZK coprocessor for SQL-style queries over historical blockchain data. He reports speedups of up to 270x from parallelism and 10x to 15x faster updates.
Speakers
Topics
From ETHCC 7, hosted by Ethereum France.
Transcript
Looks like I'm good to go. Hi, I'm Shravan Srinivasan. I work as an applied cryptography researcher at Lagrange Labs. At Lagrange Labs, we work on how do we scale map reduced style computation over historical blockchain data. Think about, think of it more like ZK SQL and so on. Today I'm excited to talk about Recultrees. Breckl trees is a way to do verifiable map reduced computation over dynamic data. And this is a joint work with some of my amazing uh colleagues from Lagrange Labs. So all of us here know and love our Merkle trees, but let me begin with the basics.
So Merkle tree is a way to sorry about the Slack. Merkle tree is a way to uh commit to an audit sequence of values. Say you have values from A0 to A15. Uh the way you go about building a Merkle tree is you take an adjacent pair of values, push it through a hash function, and you keep on recursively doing this all the way to the top. You are just when you're just left with one hash value. The top, the root is called as the root of the Merkle tree or the digest of the Merkle tree. Um they are synonymously used uh with each other.
Um in addition to just computing short commitments, Merkle trees also help us prove membership of an element inside of inside this vector. Say uh if you want to prove the prove the membership of value A phi in this vector, all you have to do is to give out these green values, which is A4, C L R, C R, C L L, and so on. So anyone can verify if this Merkle proof is valid by recomputing the hash path from A5 to the root, by uh just using the sibling values, you can end up uh reconstructing the root of the Merkle tree. If you know for a fact that the root of the Merkle tree is what you expect, then you know that uh the membership proof is indeed correct.
Merkle trees are amazing. One of the cool properties of Merkle trees are you can uh update your membership proofs uh pretty easily. Say uh in this vector, uh A12 changes from A12 to delta, A12 plus delta. All you have to do is to recompute the path, uh the hash path of A12 to the root, and you have to figure out where it intersects with your membership proof. In this case, all I have to just worry about updating C R from C R prime, and that's the only portion of my membership proof that gets changed. And once I have that from the update of A12, uh I have the most up-to-date membership proof.
So the focus of this talk is about batch proofs. Um I know that um from batch proofs to map reduce is quite a bit of jump, but uh I'll I'll tell you more about how we go about doing this. So uh a batch proof is going to be a single proof that uh opens k arbitrary elements simultaneously. Uh we need a key efficiency requirement. The obvious trivial solution is to give out k individual proofs. Uh however, um the one of the key requirements of having a batch proof is you need to have this proof much smaller than giving out this trivial solution. Um there are current multiple ways by which you can do this.
Currently, however, uh one of the key drawbacks of the existing approaches are you cannot update these batch proofs whenever there is an underlying element in the vector that changes or even the batch changes. So this is going to be the primary focus of my talk. How do you go about updating batch proofs and how how about extending this to generalizing this to map reduce computations? So aggregation is a very related notion to batch proofs. All you do is when you're given K individual proofs, you combine them into one batch proof, and that's the uh that that's that procedure is called as aggregation. Um there are countless applications in which you can use batch proofs in the context of blockchains and outside blockchains and so on.
So that brings me to the problem statement. Um the question which we want to ask is can we build a succinct Merkle batch proofs that are efficiently updatable? Um obviously, like this is not the first time one wants to do something like this. What are the drawbacks of the existing approaches? First, let me actually begin with uh a cool thing about existing approaches, you have really small batch proof. Um unfortunately, um the drawbacks are you have to recompute this batch proof from scratch in the existing um techniques. And uh the batch size is also static, meaning whenever uh batch size, a batch size changes, you have to recompute everything from scratch, or uh you need to run some sort of a uh setup to make sure that you have parameters to uh parameters to do uh batching for a larger uh batch size.
And yeah, if you go around using SNARC-based approaches to do your batch proofs, then uh you also have high memory requirements when you have a really large uh batch size. So the primary contributions of this work are first, uh we show how to do batch proofs in Merkle trees using the recursive snacks, and uh we maintain some of the cool properties which uh Merkle tree Merkle trees have. First one is we can update the proofs just like the way I showed you how to update a membership proof. You can update our batch proof in logarithmic time. And uh yeah, our approach is uh naturally parallelizable, and the complexities around uh log in uh parallel complexity.
And um the key the key uh um feature which we have in this line of work is uh we enable uh uh map reduce we enable map reduce style computation which can be verified uh uh even on dynamic data. So the the prop, so what would be the statement that would look like? Say uh verify the number of items in this Merkle tree that are greater than five. You might have such queries uh um and you can compute a correct proof of computation uh in the map reduce style. Uh and where do we use this is the the ZK co-processor work which we are doing at Lagrange, and um this is the key technology that enables us to accomplish that.
Um in this talk, uh we call the recruit plus trees as the one that generalizes the batch proofs into verifiable map reduced computation. And uh in the paper, we show uh how to do uh two uh two key two cool applications. One is aggregate B less keys, and other is the what we call as dynamic digest translation. So this is slightly technical, but uh I'll I'll move on pretty quickly and I'll walk you through with more of figures. But uh we essentially break down a Merkle tree into a bunch of subtrees. And let's say that I want to prove that there are certain elements inside the batch.
All I have to do is uh in this approach is in addition to keeping track of the hashes of the the Merkle uh uh nodes, I also keep track of at each node if in if there are any elements of the batch that are there. So uh that's what I call as SV in this thing, uh in this slide, uh a claimed subset of Merkle leaves, which in this subtree rooted at this node, if there are any values in that. And at each node, uh I just go about computing a recursive SNARK proof which says that SV is the subset of some Merkle tree whose Merkle root digest is C V. I know that this is a lot, but this will become very apparent in the next slide.
So I'm trying to, in this slide, I'm trying to prove that A2, A4, A5, and A15 are in a batch. So first, what would I do go about is uh I would compute something called as a node subset. That's highlighted in the blue values. So if you take a specific node, if it's going to be empty if there are no values of the batch is in that subtree, else it would contain all the values that are in that batch. So I can keep on building this uh node subsets uh all the way to the top uh top of the tree. So in this particular example, you can see that on the left subtree uh where I have CL, uh A2, A4, and A5 are in this subtree, hence I have that in my node subset.
And on the right one, you can just see that I just have A15 because that is the only value in the batch that is inside this subset. So I just have these two values. And at the root, I always have all the elements that are inside this batch of values. So how does this go about uh uh in our approach? First is uh you would verify if uh there's consistency checks between uh each level of the Merkle nodes. So uh uh essentially we compute a snark statement that says that the Merkle hash value in this particular node is indeed correct. And the node subset is actually the union between the left and the right uh subtree.
And we recursively do this all the way to the bottom to show that uh all the values that are there below um these nodes are indeed uh have a valid uh consistency checks. So it's so the verification would go about something like this. In CLL, I check if whatever it's left and right subchild are correct, and I keep on doing this to all the values that are there between the batch to the root. At the leaf level, it's a slight special case. What I would do is I would check if the claimed value that is supposed to be in the batch is in fact in the node subset.
So that's uh that's the uh base case of this approach, and it checks if it's the values are there. Um yeah, so um instead of using batch subset, we use set commitments. So because the batch subset which I'm showing you do depend on the size of the batch. In inside the snarks, you don't want to do something like that. So we use um um other approaches to do it. So uh so to compute a batch proof, I would compute uh snark proofs all the way from the bottom to the top, where uh these are recursive snark proofs, which says that uh underlying um tree has consistent uh hash values and consistent batch values in it. So uh the batch proof of this thing is I just have to pick the proof from the top of the tree, and and that that acts as a batch proof for the uh all the values that are inside this batch.
Um so just like Merkle trees, they are pretty easy to update. Say that our A5 value gets updated from uh A5 to A5 plus delta. All I have to do is just to recompute the snark proofs that are there between the path of A5 to the root, and uh and this way I can compute the most up-to-date batch proof. So you can see that um only the values that are in red changes and everything else remains the same, so you don't incur overhead in changing other things whenever there is only a small portion of the tree changes. A natural optimization, which you can do is you can rather than doing one leaf at a time, you can look at multiple uh leaves at a time.
And this is a standard technique in computer science. This is called as bucketing. So you can bucket these values, uh, you can break this vector into subvectors into contiguous paths and keep them as in a separate bucket, and you can pretty much do what I showed you in the previous slide. However, you would do this for buckets. In this case, you would save on some recursion uh overhead as well. So obviously uh you can generalize this approach from uh binary trees to uh any generic trees. So uh Merkle Patricia tries are uh have 16 children and so on. So uh this approach can be simply generalized to even do a technique like that.
So in this example, I have a A1, A3, A4, and A8 are in the batch, and all I have to do is to keep some keep track of the node subsets and the Merkle hash values, and this way you can recompute all the way to the top and uh attach a attach a um SNART proof along with it. So uh I've been talking about that this approach is nationally parallelizable. So uh to see this in a little bit of action, all I have to do is to just take uh the workload a layer at a time. So what I mean by that is like uh you just take um the tasks one, two, three, you can run these three tasks in parallel because none of the results of uh results or the input depends on one another.
So you can do this in parallel. Once you have the results of these um tasks, you can deploy tasks uh at the next level of the tree. So in this case, it's going to be task four, task five, and task task six. And once you have those results, you can uh you can continue to do all the way to the top. So this way you can distribute the overhead of computing the snart proof at the top. So yeah, that brings me to how do we do map reduced computation. So if you recall, let's take in this example we have a vector of eight values from A0 to A7. This is this is how we compute the Merkle digest.
So if you recall from my batch proof slides, batch proof was just checking if the hash Merkle hashes were right. And in addition to that, it was just checking if the node subset values which I said were of the batch are indeed correct. Rather than just doing that, you can swap the computation to a map reduce style work, where uh at the leaf level you could have a map computation which takes on the leaf values and transforms into a specific value of your choice. And in the subsequent uh and any further levels subsequently, you can take these inputs and perform a reduce operation uh along with it.
So you would all you have to do is to embed your generic map computation at the leaf level, which I showed in the past, and you would have to embed the reduce uh operations at the levels uh which are not at the leaf of the tree, and you can do this all the way to the top, where you take the results of the previous two um levels and keep on reducing all the way to the top. And you can have a SNART proof of computation, which says that uh I indeed performed the reduce operations uh correctly as well. Um yeah, uh one of the cool applications which um this uh this map reduced style uh work enables is say that you have a vector of n values.
Say like let's say on L1 it's hashed uh using the uh using catchak uh with a different RT. You want to have a snart friendly data uh uh snart friendly version of this hash structure. Um you might use this uh snart friendly data structure in rollups and so on. So in that case, you would want to have instead of catchak, you want to use uh a Poseidon hash hash functions. So all you have to do is to recompute this proof, uh recompute this tree in the new hash function, but uh instead of doing it trivially, you can use um the recruit plus trees approach, where uh I want to prove something along the lines of the digest C1 and C2 computed using hash functions H1 and H2 respectively, correspond to the same set of values. So, what's the benefit of doing something like this?
Um you can you can update your proofs, uh you can update the proof that uh this is the um this is the digest if you use catchak, and let's say that's gonna be C1, and C2 is going to be the digest when you use Persadan, and you can keep updating these proofs without recomputing from scratch uh every time. So, to see this in a little bit more pictorially, again we have the hash, uh we have the Merkle tree built based on C1. And in the map function, I'm going to have an identity operator. So that's why it's going to be still A0, A1, A2, and so on. Uh in the reduced thing in the reduce uh operator is going to be I'm going to use a different hash function h2 and take on the previous results and keep recursing all the way to the top while computing a snart proof at each node in the tree that attests to the fact that everything below that subtree was done correctly.
And you can keep doing this all the way to the top, and you just have a single proof pi. So yeah, the updates become easier. So let's say that when A7 becomes A7 Prime, you just have to update all the snart proofs that are in this path on this path from leaf to the root. Yeah, so that's how we would go about doing a verifiable map reduced style computation using Recul Plus trees. So in the paper, you can take a look at the paper where we talk more about, we give more applications of this. But one cool application which I'm personally uh we are excited about at LeGrange is uh this enables um uh ZK co-processor technology that we have been working uh on it.
So the first thing is uh the the key uh work which this is trying to solve is uh how do you query historical uh blockchain data in a scale style uh approach? And uh ReculTree's approach is a fundamental building block that helps you uh do this even when uh underlying data keeps changing. And the parallelism from ReculTree's style approach can be inherited in uh in uh in our uh core processor technology as well. So um to see this in a little bit more action, let's say that you have a table. My first job is to transform this into uh some sort of uh data structure that is amenability querying.
So uh I would just keep on building this uh Merkle tree style approach. Uh uh, in addition to just keeping the Merkle hash values, uh we also need to keep some sort of a set commitment. That's what I call as uh our diagnostic digest uh on this on this slide. And whenever uh let's say I have a SQL query that needs to run on this table or many tables at a time, all I have to do is to break down this SQL query into a bunch of well-known SQL operators and map each SQL operator into a map reduced style computation, which I kind of showed like a few slides ago. And you generate a proof for each proof of correctness of each operator being performed.
And you can you can combine these proofs into a single proof and show that uh indeed this entire uh entire computation was done uh correctly. So um uh looks like I might uh have a little bit more time. So um one of the cool things which uh we did in this paper is like we evaluated uh our approach and uh uh the parallelism can be up to 270 times faster than the single threaded implementation. Our proof sizes uh 112 kibytes, but you can compress this using uh uh you can compress this using uh GROT 16 or something to make it smaller if you're interested. And yeah, uh our aggregation is uh roughly uh uh 1.6 times to 2.1 times faster than uh baseline approaches.
And uh in fact, our verification can be as high as 50 uh 1,500 times uh up to 1500 times better than the baseline approach, which we considered. And um and updates are really fast. Uh it can be up to 10x to uh 15x uh faster than the baseline approaches. So uh we extend uh uh this analysis to the um the Recul Plus trees approach where we verify the map reduced stuff, and even in those uh uh applications, we expect our true word to be uh 200x faster and updates to be 12x faster than the baseline. Um similarly in a different application, which I didn't go uh in detail today, but uh it it's um even in those applications you can have six X faster uh performance.
So yeah, with that uh I'll stop and take questions. I I think I have a minute or so, but yeah. Um thanks a lot for your um presentation. And I I wonder uh what um uh data struct uh I mean at what database operations um uh your record trees uh uh supporting? I'm I'm sorry, could I uh I mean that's uh uh which uh operations are supported by your uh record trees.
Which works? Uh which uh database operations. Oh uh so uh we are we have a test net uh that is out that that's uh that performs a specific query. Uh in the upcoming days, we wish uh we plan to sub uh support more uh SQL operators uh in the uh upcoming days. You can you can uh follow us on like Ranch Dev uh to uh see see the updates, yeah. Oh okay, I will follow you. And uh and and after that I may uh explore more to your uh data structured uh design. And um by the way, uh could you please share the slides to me?
Yeah, sure. Uh I I hope to have the slides uh on our website soon, but yeah, we oh okay, great. Yeah, thank you. Thank you. Any more questions? Uh hey, um, if you were to simply describe Lagrange, what would be yeah, your description? So uh my simple description would be like we enable you to query historical blockchain data with blazingly fast speed and uh with uh with verifiability. Yeah.
That's it. Thank you. Give me a wee, give me a wee, give me a
Related talks
- Intro to SNARKs 1: What are SNARKs?
- zkSummit: A new optimized elliptic curve for one layer proof composition - Youssef El Housni (EY)
- How Shafi Goldwasser Co-Invented Zero-Knowledge Proofs
- Zero knowledge протоколы и решаемые ими задачи • Сергей Прилуцкий
- Современные системы доказательств: STARKs, SHARKs и другие • Александр Власов
- Эволюция рекурсивных снарков
- We Built the Wrong Internet
- Zcash
- Beyond the Johnson Bound: A Path to Smaller Post-Quantum SNARKs