Skip to main content
Version: 0.18

Host Code 101

In a zkVM application, the host is the machine that is running the zkVM. The host is an untrusted agent that sets up the zkVM environment and handles inputs/outputs during execution.

Note: If you're building for Bonsai, you don't need to write host code.

This page serves as an introduction to writing RISC Zero host code, to help you get started building applications for the zkVM.

The Executor & the Prover

In a zkVM application, the host is responsible for constructing and running the Executor and the Prover.

From Guest Code to Receipt

In more detail, the host will:

  1. Construct an execution environment where it will run the Executor for a guest program.
    • This environment is where the host will provide settings and communicate with the guest.
  2. Run the Prover to execute and prove the guest program and generate a receipt.

The receipt can now be passed to a third-party for verification.

A Very Simple Host

The code shown below is the main() function for a very simple host program. Aside from the absence of any I/O during execution, the host performs exactly the actions described above.

use risc0_zkvm::{default_prover, ExecutorEnv};

let env = ExecutorEnv::builder().build().unwrap();
let prover = default_prover();
let receipt = prover.prove_elf(env, METHOD_NAME_ELF).unwrap();

To see more complex examples, check out our examples folder on GitHub.

Verifying Receipts

The functionality for verifying receipts is also included in the risc0-zkvm Rust crate.

The standard workflow is for one party to generate a receipt and pass it to another party for verification, along these lines:

receipt.verify(METHOD_NAME_ID).unwrap();

For more information on passing and verifying receipts, check out our page on Receipts. For practical demos, check out the examples on GitHub.

Happy Building!

Hopefully, this guide and the zkVM Quick Start page will be sufficient for you to build your first zkVM application!

If you run into problems, don't be a stranger! You can file an issue on these docs or the examples, and we're happy to answer questions on Discord.