Struct risc0_zkvm::Receipt
source · pub struct Receipt {
pub inner: InnerReceipt,
pub journal: Journal,
}
Expand description
A receipt attesting to the execution of a guest program.
A Receipt is a zero-knowledge proof of computation. It attests that the Receipt::journal was produced by executing a guest program 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(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. You can use Journal::decode to deserialize the journal as typed and structured data, or access the Journal::bytes directly.
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 that this receipt proves a successful execution of the zkVM from
the given image_id
.
Uses the zero-knowledge proof system to verify the seal, and decodes the
proven ReceiptClaim. This method additionally ensures that the
guest exited with a successful status code (e.g. Halted(0)
or
Paused(0)
), the image ID is as expected, and the journal
has not been tampered with.
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 that this receipt proves a successful execution of the zkVM from
the given image_id
.
Uses the zero-knowledge proof system to verify the seal, and decodes the
proven ReceiptClaim. This method additionally ensures that the
guest exited with a successful status code (e.g. Halted(0)
or
Paused(0)
), the image ID is as expected, and the journal
has not been tampered with.
sourcepub fn verify_integrity_with_context(
&self,
ctx: &VerifierContext
) -> Result<(), VerificationError>
pub fn verify_integrity_with_context( &self, ctx: &VerifierContext ) -> Result<(), VerificationError>
Verify the integrity of this receipt, ensuring the claim and jounral are attested to by the seal.
This does not verify the success of the guest execution. In
particular, the guest could have exited with an error (e.g.
ExitCode::Halted(1)
) or faulted state. It also does not check the
image ID, or otherwise constrain what guest was executed. After calling
this method, the caller should check the ReceiptClaim fields
relevant to their application. If you need to verify a successful
guest execution and access the journal, the verify
function is
recommended.
sourcepub fn get_claim(&self) -> Result<ReceiptClaim, VerificationError>
pub fn get_claim(&self) -> Result<ReceiptClaim, VerificationError>
Extract the ReceiptClaim from this receipt.