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

source

pub fn new(inner: InnerReceipt, journal: Vec<u8>) -> Self

Construct a new Receipt

source

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.

source

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.

source

pub fn get_metadata(&self) -> Result<ReceiptMetadata, VerificationError>

Extract the ReceiptMetadata from this receipt for an excution session.

Trait Implementations§

source§

impl Debug for Receipt

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Receipt

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl PartialEq for Receipt

source§

fn eq(&self, other: &Receipt) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Receipt

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for Receipt

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,