risc0_zkvm/claim/
mod.rs

1// Copyright 2025 RISC Zero, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Claim types and utilities for the zkVM.
16
17use borsh::{BorshDeserialize, BorshSerialize};
18use risc0_binfmt::Digestible;
19use risc0_zkp::core::digest::Digest;
20use serde::{Deserialize, Serialize};
21
22use crate::sha::Sha256;
23
24pub(crate) mod maybe_pruned;
25#[cfg(feature = "prove")]
26pub(crate) mod merge;
27pub(crate) mod receipt;
28pub(crate) mod work;
29
30/// A receipt (e.g. [SuccinctReceipt][crate::SuccinctReceipt]) may have an unknown claim type when
31/// only the digest of the claim is needed, and the full claim value cannot be determined by the
32/// compiler. This allows for a collection of receipts to be created even when the underlying
33/// claims are of heterogeneous types (e.g. `Vec<SuccinctReceipt<Unknown>>`).
34///
35/// Note that this is an uninhabited type, similar to the [never type].
36///
37/// [never type]: https://doc.rust-lang.org/std/primitive.never.html
38#[derive(Clone, Debug, Serialize, Deserialize)]
39#[cfg_attr(test, derive(PartialEq))]
40pub enum Unknown {}
41
42impl Digestible for Unknown {
43    fn digest<S: Sha256>(&self) -> Digest {
44        match *self { /* unreachable  */ }
45    }
46}
47
48impl BorshSerialize for Unknown {
49    fn serialize<W>(&self, _: &mut W) -> core::result::Result<(), borsh::io::Error> {
50        match *self { /* unreachable  */ }
51    }
52}
53
54impl BorshDeserialize for Unknown {
55    fn deserialize_reader<R>(_: &mut R) -> core::result::Result<Self, borsh::io::Error> {
56        Err(borsh::io::Error::new(
57            borsh::io::ErrorKind::InvalidData,
58            "BorshDeserialize attempted to deserialize Unknown; data is malformed",
59        ))
60    }
61}