Cracking ZK Coprocessors: Scaling Onchain Computation
September 26, 2024
Guest post by nairolf.
Complex concepts in simple words—that’s how we best describe the goals of the “Cracking Series," a four part series diving into Lagrange's core technology. In our previous piece, we explored proofs, examining their impact on humanity and their revolutionary role in blockchains. We delved into the concept while maintaining a simple and easy-to-understand language. If you missed it, we strongly recommend reading it first. In this second piece, we venture into Lagrange and crack the ZK Coprocessor.
These days, data is more than just the new gold—it’s like a magic tool helping us make smarter choices and making our lives easier in ways we never thought possible. Take delivery companies, for example, who always seem to know the quickest way to your door. They’re not just guessing—they’re using data from traffic, weather, and even local events to get your package to you faster while saving fuel and cutting down on pollution. And airlines? They’re like data detectives, using all sorts of information from sensors and the environment to keep planes running smoothly, so you can get where you’re going safely and on time.
While companies like Amazon might be famous for knowing exactly what you want to buy next, the real magic of big data goes way beyond shopping. From medical breakthroughs to making daily life more convenient, data is quietly working behind the scenes to make our world a better place. So, next time you’re amazed by how quickly your delivery arrives or how your health app knows exactly what you need, remember—it’s all thanks to the incredible power of data.
Now, let’s take a peek at Web3, where things start to get a bit trickier. Sure, blockchain data is super transparent and there’s plenty of it, but here’s the catch: actually accessing and using that data can be a real pain. It’s not just about the time—it can get seriously expensive too. Imagine you wanted to figure out the average price of ETH on a decentralized exchange like Uniswap V3 over the last 10,000 blocks. Sounds simple enough, right? Well, not in Web3. Fetching this data can take several seconds and cost between 20,000 to 50,000 gas per block. With gas prices around 20 gwei and assuming a conservative estimate of 20,000 gas per block, the total cost could range from $500 to $2,000 for just one computation. Yes, for a single computation. This makes some cool ideas practically impossible due to the high expense and extended time required.
This is probably why we don’t see as many data-heavy apps in Web3, and why some features just haven’t made it off the drawing board. Think about a lending protocol that wants to create a loyalty program to keep users around and fend off those jumping ship for better deals. It’s a great idea! But when you try to actually build it fully onchain, you hit a brick wall—analyzing all that transaction history would be crazy expensive.
These challenges create significant barriers for building data-rich applications. The Lagrange ZK Coprocessor offers a key part of the solution to solving these challenges.
Defining “Coprocessor”
Before exploring the concept of a ZK coprocessor, let’s first break it down by understanding what a coprocessor is.
Imagine you're planning a large party and acting as the main host (the main processor). You’re responsible for everything—greeting guests, managing snacks and drinks, djing, and ensuring the event runs smoothly with a fun, enjoyable atmosphere. It’s a lot to handle, and you’re starting to feel a bit overwhelmed.
Now, picture a friend who’s an exceptional DJ (the coprocessor). This DJ specializes in creating the perfect party atmosphere with great music and beats. You delegate the music duties to your friend, allowing you to focus on other tasks, like serving guests and making sure the cake is cut on time.
In this scenario, you’re the main processor managing the overall party, while the DJ (the coprocessor) handles a specialized task. This arrangement allows both you and your friend to focus on what you do best, making the party a success and ensuring everyone has a great time!
Similarly, a coprocessor is a specialized piece of hardware that works alongside the main processor to handle specific tasks more efficiently. While the main processor manages general computing functions, the coprocessor is designed to take on specialized jobs, such as performing complex computations, to enhance overall performance and improve efficiency.
Defining Lagrange’s “ZK Coprocessor”
Now that the coprocessor is no longer a mystery, let’s explain Lagrange’s ZK Coprocessor.
Remember how hard and expensive it is to query and perform computations over onchain data? Now, what if we entrust this task to a coprocessor that handles it offchain, super efficiently and cheaply? Well, that’s the idea behind Lagrange’s ZK Coprocessor.
In practice, the query is moved offchain, divided into many small tasks, executed, zk-proven, and then verified back in the contract. In simpler terms, instead of directly querying the blockchain and paying hefty fees, the request is made to an offchain computer that will fetch the data. A proof that this data is correct will be created, and the data will be sent back onchain. This way, querying onchain data becomes much less expensive, and numerous use cases are now made possible.
Your next logical question might be something like: “Why on earth do we need ZK proofs for that?” And you’re absolutely right. Lagrange uses a coprocessor to handle heavy computations off the blockchain that would otherwise be too expensive and slow to compute onchain. Since these computations are performed offchain, you might question their correctness and whether they were executed properly. That’s where the ZK part becomes crucial: Lagrange uses zero-knowledge proofs to guarantee the validity of the computations. ZK proofs ensure that the computations are correct.
What makes Lagrange's ZK Coprocessor so special? Well, imagine having a superpower that lets you break down massive tasks into tiny, manageable pieces and then send them off to a team of decentralized 'helpers' (ZK Prover Network) who can scale up or down as needed. That’s what hyper-parallel computations do—splitting up the work so it gets done faster and more efficiently. We’re talking about scalable dataset indexing and proving that’s practically limitless. While others might struggle with a few hundred storage slots, Lagrange's ZK Coprocessor can query millions, making sure no information is left behind. And the cherry on top? Lagrange’s 'updatable' proving system. Instead of redoing everything from scratch each time, the system can just update the parts that have changed. It’s like having a really clever assistant who keeps track of what’s new without starting over every time!
Let’s take an example to gauge the Lagrange ZK Coprocessor. Suppose you want to know which addresses held a Pudgy Penguin NFT during the last 100 Ethereum blocks. While this query might seem extremely simple and straightforward, computing it onchain would take dozens of minutes and cost a significant amount of money. With the Lagrange ZK Coprocessor, it would only take 2 minutes to query the 8,888 Pudgy Penguins over the last 100 blocks, generate the proof, and submit it onchain. Yes, just 2 minutes for a fraction of what it would cost to compute everything onchain.
TL;DR—Lagrange's ZK Coprocessor
In conclusion, the Lagrange ZK Coprocessor is like having that exceptional DJ at your party, but instead of spinning tunes, it’s handling the heavy lifting of data computations offchain and verifying them onchain. Just as the DJ takes over the music so you can focus on other important aspects of your event, the ZK Coprocessor handles complex onchain computations, allowing developers to concentrate on creating innovative and data-rich applications.
By offloading these tasks to a specialized coprocessor and using zero-knowledge proofs to ensure data accuracy, the ZK Coprocessor makes it possible to tackle data-heavy challenges with ease. This means that what once seemed impossible—like querying the average price of ETH on a decentralized exchange like Uniswap V3 over the last 10,000 blocks or building loyalty programs—can now be achieved efficiently and affordably.
So, just as a great DJ can turn a good party into an unforgettable experience, the Lagrange ZK Coprocessor transforms the way we interact with and use blockchain data, unlocking new possibilities and making advanced, data-rich applications a reality.
This piece focused on cracking what the Lagrange ZK Coprocessor is. In our next article, we will delve deeper into how the ZK Prover Network enables efficient proving of computations performed by the coprocessor and explain the process in detail. Complex concepts, simplified: that’s the essence of the “Cracking Lagrange” series.