Skip to main content

miden_core/deferred/
claim.rs

1use super::DeferredRoot;
2use crate::{
3    Word,
4    serde::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
5};
6
7/// The exact deferred-state claim proved by a precompile VM proof.
8///
9/// The root is the PVM STARK public input. The commitment identifies the claim in proof-request
10/// keys and downstream statements. For this claim type, the protocol defines that commitment to
11/// be the root itself.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13#[cfg_attr(
14    all(feature = "arbitrary", test),
15    miden_test_serialization_macros::serialization_test
16)]
17pub struct DeferredClaim(DeferredRoot);
18
19impl DeferredClaim {
20    /// Creates a claim for `deferred_root`.
21    pub const fn new(deferred_root: DeferredRoot) -> Self {
22        Self(deferred_root)
23    }
24
25    /// Returns the deferred root used as the PVM STARK public input.
26    pub const fn root(self) -> DeferredRoot {
27        self.0
28    }
29
30    /// Returns the identifier used to bind and address proofs of this claim.
31    ///
32    /// For this claim type, the protocol defines the commitment as the root itself, so this
33    /// returns the same word as [`Self::root`].
34    pub const fn commitment(self) -> Word {
35        self.0
36    }
37}
38
39#[cfg(any(test, feature = "arbitrary"))]
40mod deferred_claim_arbitrary {
41    use proptest::prelude::*;
42
43    use super::{DeferredClaim, DeferredRoot};
44
45    impl Arbitrary for DeferredClaim {
46        type Parameters = ();
47        type Strategy = BoxedStrategy<Self>;
48
49        fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
50            // DeferredRoot is a Digest alias; any digest is a valid claim root.
51            any::<DeferredRoot>().prop_map(Self::new).boxed()
52        }
53    }
54}
55
56impl Serializable for DeferredClaim {
57    fn write_into<W: ByteWriter>(&self, target: &mut W) {
58        self.0.write_into(target);
59    }
60}
61
62impl Deserializable for DeferredClaim {
63    fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
64        Ok(Self::new(DeferredRoot::read_from(source)?))
65    }
66
67    fn min_serialized_size() -> usize {
68        DeferredRoot::min_serialized_size()
69    }
70}