Struct risc0_zkvm::Receipt
source · pub struct Receipt {
pub inner: InnerReceipt,
pub journal: Journal,
}
Expand description
A receipt attesting to the execution of a Session.
A Receipt is a zero-knowledge proof of computation. It attests that the Receipt::journal was produced by executing a [crate::Session] based on a specified memory image. This image is not included in the receipt; the verifier must provide an ImageID, a cryptographic hash corresponding to the expected image.
A prover can provide a Receipt to an untrusting party to convince them that the results contained within the Receipt (in the Receipt::journal) came from running specific code. Conversely, a verifier 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.
Example
To create a Receipt attesting to the faithful execution of your code, run
one of the prove
functions from a crate::Prover.
use risc0_zkvm::{default_prover, ExecutorEnv};
use risc0_zkvm_methods::FIB_ELF;
let env = ExecutorEnv::builder().write_slice(&[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>
.
Fields§
§inner: InnerReceipt
The polymorphic InnerReceipt.
journal: Journal
The public commitment written by the guest.
This data is cryptographically authenticated in Receipt::verify.
Implementations§
source§impl Receipt
impl Receipt
sourcepub fn new(inner: InnerReceipt, journal: Vec<u8>) -> Self
pub fn new(inner: InnerReceipt, journal: Vec<u8>) -> Self
Construct a new Receipt
sourcepub fn verify(
&self,
image_id: impl Into<Digest>
) -> Result<(), VerificationError>
pub fn verify( &self, image_id: impl Into<Digest> ) -> Result<(), VerificationError>
Verify the integrity of this receipt.
Uses the ZKP system to cryptographically verify that each constituent
Segment has a valid receipt, and validates that these SegmentReceipts
stitch together correctly, and that the initial memory image matches the
given image_id
parameter.
sourcepub fn verify_with_context(
&self,
ctx: &VerifierContext,
image_id: impl Into<Digest>
) -> Result<(), VerificationError>
pub fn verify_with_context( &self, ctx: &VerifierContext, image_id: impl Into<Digest> ) -> Result<(), VerificationError>
Verify the integrity of this receipt.
Uses the ZKP system to cryptographically verify that each constituent
Segment has a valid receipt, and validates that these SegmentReceipts
stitch together correctly, and that the initial memory image matches the
given image_id
parameter.
sourcepub fn get_metadata(&self) -> Result<ReceiptMetadata, VerificationError>
pub fn get_metadata(&self) -> Result<ReceiptMetadata, VerificationError>
Extract the ReceiptMetadata from this receipt for an excution session.