Module risc0_zkvm::receipt

source ·
Expand description

Manages the output and cryptographic data for a proven computation.

Receipts are zero-knowledge proofs of computation. They attest that specific code was executed to generate the information contained in the receipt. The prover can provide a receipt to an untrusting party to convince them that the results contained within the receipt came from running specific code. Conversely, a verify can inspect a receipt to confirm that its results must have been generated from the expected code, even when this code was run by an untrusted source.

There are two types of receipt, a Receipt proving the execution of a crate::Session, and a SegmentReceipt proving the execution of a crate::Segment.

Because crate::Sessions are user-determined, whereas crate::Segments are automatically generated, typical use cases will handle Receipts directly and SegmentReceipts only indirectly as part of the Receipts that contain them (for instance, by calling Receipt::verify, which will itself call InnerReceipt::verify for the interior InnerReceipt).

Usage

To create a Receipt, use crate::Session::prove:

use risc0_zkvm::{default_prover, ExecutorEnv};
use risc0_zkvm_methods::FIB_ELF;

let env = ExecutorEnv::builder().add_input(&[20]).build().unwrap();
let receipt = default_prover().prove_elf(env, FIB_ELF).unwrap();

To confirm that a Receipt was honestly generated, use Receipt::verify and supply the ImageID of the code that should have been executed as a parameter. (See risc0_build for more information about how ImageIDs are generated.)

use risc0_zkvm::Receipt;


receipt.verify(FIB_ID).unwrap();

The public outputs of the Receipt are contained in the Receipt::journal. We provide serialization tools in the zkVM serde module, which can be used to read data from the journal as the same type it was written to the journal. If you prefer, you can also directly access the Receipt::journal as a Vec<u8>.

Structs

  • A receipt attesting to the execution of a Session.
  • Data associated with a receipt which is used for both input and output of global state.
  • A receipt attesting to the execution of a Segment.
  • A wrapper around Vec<SegmentReceipt>.
  • Context available to the verification process.

Enums

Functions

  • Compute and return the ImageID of the given (merkle_root, pc) pair.