Skip to content

Commit

Permalink
Add seal_size method to receipt types (risc0#2262)
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz authored Aug 23, 2024
1 parent 4ee1105 commit f865f63
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions risc0/circuit/recursion/src/prove/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ pub struct RecursionReceipt {
pub output: Vec<u32>,
}

impl RecursionReceipt {
/// Total number of bytes used by the seal of this receipt.
pub fn seal_size(&self) -> usize {
core::mem::size_of_val(self.seal.as_slice())
}
}

/// Prover for the recursion circuit.
pub struct Prover {
program: Program,
Expand Down
25 changes: 25 additions & 0 deletions risc0/zkvm/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ impl Receipt {
pub fn claim(&self) -> Result<MaybePruned<ReceiptClaim>, VerificationError> {
self.inner.claim()
}

/// Total number of bytes used by the seals of this receipt.
pub fn seal_size(&self) -> usize {
self.inner.seal_size()
}
}

/// A record of the public commitments for a proven zkVM execution.
Expand Down Expand Up @@ -376,6 +381,16 @@ impl InnerReceipt {
Self::Fake(_) => Digest::ZERO,
}
}

/// Total number of bytes used by the seals of this receipt.
pub fn seal_size(&self) -> usize {
match self {
Self::Composite(receipt) => receipt.seal_size(),
Self::Succinct(receipt) => receipt.seal_size(),
Self::Groth16(receipt) => receipt.seal_size(),
Self::Fake(_) => 0,
}
}
}

/// A fake receipt for testing and development.
Expand Down Expand Up @@ -639,6 +654,16 @@ impl InnerAssumptionReceipt {
Self::Fake(_) => Digest::ZERO,
}
}

/// Total number of bytes used by the seals of this receipt.
pub fn seal_size(&self) -> usize {
match self {
Self::Composite(receipt) => receipt.seal_size(),
Self::Succinct(receipt) => receipt.seal_size(),
Self::Groth16(receipt) => receipt.seal_size(),
Self::Fake(_) => 0,
}
}
}

impl From<InnerReceipt> for InnerAssumptionReceipt {
Expand Down
5 changes: 5 additions & 0 deletions risc0/zkvm/src/receipt/groth16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ where
verifier_parameters: self.verifier_parameters,
}
}

/// Number of bytes used by the seal for this receipt.
pub fn seal_size(&self) -> usize {
core::mem::size_of_val(self.seal.as_slice())
}
}

/// Verifier parameters used to verify a [Groth16Receipt].
Expand Down

0 comments on commit f865f63

Please sign in to comment.