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

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 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.

source

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.

source

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.

source

pub fn get_claim(&self) -> Result<ReceiptClaim, VerificationError>

Extract the ReceiptClaim from this receipt.

Trait Implementations§

source§

impl Clone for Receipt

source§

fn clone(&self) -> Receipt

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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 From<Receipt> for Assumption

source§

fn from(receipt: Receipt) -> Self

Create a proven assumption from a Receipt.

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

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

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>,