zk Solutions High-level Overview. Case study: BONSAI — off-chain zkVM Compute Network
Many zk solutions are available to solve data privacy and scalability issues. This article will explore the high-level architecture of major zk-products and their developer experience. We will learn Risc0 zkVM and Bonsai — the off-chain zkVM compute network allowing users to generate zk-proofs of heavy computations off-chain.
Let’s remind ourselves what a zk proof means: a prover using zk solutions can prove to an untrusted party that a given computation is faithfully executed without revealing private inputs to the computation.
To generate zk-proof of a program, it needs to be converted into zk-circuit representation, and then zk-math (zk-SNARK/zk-STARK) is applied on the circuit. Think of a circuit as a “directed graph” where edges represent values and nodes are a basic arithmetic function. Example of a * b = out
circuit below
zk Solutions Architecture
At a high level, there are two kinds of architecture for constructing zk-proof solutions: direct and VM. The main difference between these two architectures is circuit location.
In the direct approach, a user writes a circuit representing the user’s program on a domain-specific language (DSL) and feeds it into a compiler, which constructs a zk-proof of the circuit. Examples of these DSLs are Leo/Noir/o1js/Circom.
The second approach is zkVM (examples are Cairo/Miden/OlaVM/Risc0) — where a circuit is inside the VM and never changes. Users pass two inputs into zkVM: 1) a program they want to run and 2) the input data to the program itself. The zkVM executes the program with the input data on its circuit and generates a zk-proof of its correct execution.
For a direct approach, developers must write custom DSL zk-circuits for every program. Adding features requires significant circuit changes. With the zkVM approach, the zk-circuit lives inside zkVM and never changes. Developers need only to send programs to zkVM to generate zk-proof — it’s faster to get started, has intuitive experience, and has shorter development cycles.
Risc0 zkVM and Bonsai overview
Risc0 zkVM implements Risc-V, a common and open-source Instruction Set Architecture for hardware CPUs. The advantage of this approach is that users can write in programming languages that compile to Risc-V (LLVM/GCC) instead of requiring users to use DSLs or special compilers. Currently, zkVM supports Rust as a program on which zk-proof is generated. Stay tuned for upcoming releases.
The Risc0 zkVM architecture has intuitive developer experience and fast onboarding by allowing standard languages with mature developer tools.
Instead of learning custom DSL and writing zk-circuits, developers use zkVM to do it for them. This makes zk-technology accessible to developers without prior zk knowledge.
Based on zkVM’s success, Risc0 built Bonsai, an off-chain massively parallel zk-compute network. By taking heavy computations off-chain, Bonsai brings new AI, DeFi, and privacy use cases to Web3. With Bonsai, a smart contract from any chain or protocol can request Bonsai to run a program and generate zk-proof.
Bonsai is a blockchain and protocol agnostic, massively parallel, off-chain zk-compute network.
zkVM and Bonsai Architecture
zkVM has standard VM architecture with a host and a guest. A host emulates a guest, sends any required data, and handles the guest’s output. Guest executes the program on the provided data and generates a receipt with zk-proof that the program was executed.
The receipt returns to the host, who sends it to the verifier, who verifies it. A receipt has public (journal) and private (seal) components. A journal containing public outputs of the program and a seal has cryptographic information that the verifier needs to determine that the zk-proof was faithfully executed.
In Bonsai, see the diagram above, a developer writes guest code and manages the guest’s input/output data. Bonsai runs the host while a smart contract handles its data and sends a request to Bonsai.
We will look at the Bonsai example in the following article.
Check out the Docs, GitHub, Risc0 Website, Bonsai Website, and Discord.