A Guide to ZK Coprocessors for Scalability

If you’re operating an on-chain application, a ZK Coprocessor is a key tool for allowing you to scale your on-chain logic while keeping gas costs low. In this post, we review what a coprocessor is, why it matters, and how you can use the Bonsai ZK coprocessor architecture to scale your application.

Computational Limitations of On-chain Applications

Having your application execute entirely on the EVM comes with drawbacks. Tasks requiring heavy computation or large stores of data require gas fees so high that using your application can quickly become cost prohibitive. This means certain features are not realistically possible on the EVM, limiting the potential of your applications.

The trick is to move computation off-chain, drastically reducing gas fees and making your application more attractive to users. Traditionally, this would require trusting the computation executed on a centralized server, sacrificing the verifiable ecosystem of Ethereum in the name of cost savings. Fortunately, ZK proofs provide a way to securely verify these off-chain results while maintaining core values of decentralization, and at a fraction of on-chain costs.

Entering the Chat: Bonsai ZK Coprocessor

The Bonsai ZK Coprocessor Architecture extends the capabilities of on-chain applications with programmable & verifiable off-chain computation. Instead of spinning up your own ZK infrastructure, you can upload the program and request that Bonsai generate proofs on demand.

The Bonsai ZK Coprocessor Architecture is powered by connecting our zkVM and Bonsai with Ethereum using our ETH Relay. This enables us to extend the functionality of Ethereum smart contracts by allowing applications to port logic into Rust and execute the logic off-chain on Bonsai.

One important callout is that Bonsai isn’t restricted to Ethereum. Any blockchain that possesses an execution and consensus layer can harness the Bonsai coprocessor to shift execution or computation off-chain.

A few examples include:

  • Optimistic Layer 2, such as Optimism and Arbitrum
  • ZK Layer 2, like Starkware and ZKSync
  • EVM Layer 1, including Avalanche and Polygon
  • Non-EVM Layer 1, encompassing Solana and Aptos
  • Cosmos interchains

What is a Coprocessor?

A coprocessor serves as a companion to a processor, allowing for off-loading computation in a resource-constrained system. For example, running an AI model like ChatGPT on your cell phone would be unfeasible. Your phone is slow, has limited storage, you’re paying to download the massive model, and your battery life is limited. However, when you ask ChatGPT a question, it’s sent to a dedicated server where it can run cheaply and efficiently then send back an answer. In this way, ChatGPT’s servers are acting as an AI co-processor for your cell phone’s limited resources.

On the other hand, the EVM serves as a versatile platform capable of executing various operations. Analogous to a personal device, the EVM can handle diverse tasks but might not always be the most efficient for high-volume operations. And zkVM, much like a cloud computer or mainframe, is designed for general-purpose tasks but excels in speed and cost-effectiveness.

Bonsai ZK Coprocessor’s Architecture

  1. Call Bonsai, specifying which program and inputs to execute. You can call Bonsai in one of two ways:
    - Call Bonsai from Ethereum: call the BonsaiRelay contract from your smart contract.
    - Call Bonsai from off-chain: call Bonsai using the REST API.
  2. Bonsai executes your program off-chain on the zkVM with the inputs you provided.
  3. Bonsai sends a proof of the executed program back to BonsaiRelay.
  4. The proof is checked by an on-chain verifier.
  5. Your contract receives the verified result.

Bonsai massively reduces gas fees and expands the capabilities of on-chain applications — slicing through price barriers for your users while providing developers with wider opportunities. This architecture allows you to move the expensive parts of you application, even the entire logic, out of your Solidity smart contracts and into a Rust program that executes off-chain.

Use cases for ZK coprocessors

Many applications, such as on-chain gaming or central limit order books, need off-chain computation to be economical. However, any application logic requiring more than 250K gas can potentially reduce costs with ZK coprocessors.

DAOs are a perfect example of collective on-chain activity involving many actors and multiple smart contracts and leading to heavy computation. ZK Coprocessors for DAO governance ensure off-chain compute for cheaper gas, and verification of on-chain data among parties. With the Bonsai DAO Governor, DAO members were able to lower their gas fees by more than 50% (from $6-9, to just $2-3 per vote during July 23rd) by moving compute off-chain. We’ll release more on how we built the Bonsai Governor soon!

Another notable use-case includes Web2 to Web3 verification. For example, Bonfire Wallet allows users to create a burner wallet using WebAuthn, while Bonsai ZK Coprocessor handles off-chain compute.


Build with Bonsai

To use Bonsai as a coprocessor for Ethereum, all you need to do is:

  • Write a zkVM application that handles your app logic
  • Write a Solidity contract that asks Bonsai to run your zkVM app and what to do with the results

Then, follow the instructions in the deployment guide.

Bonsai can help whether you're looking to take heavy computations off-chain or need to generate proofs for your trustless, verifiable software. For any questions, reach out to our team on Discord!