miden_objects/block/
nullifier_witness.rs

1use crate::{
2    crypto::merkle::SmtProof,
3    utils::serde::{ByteReader, ByteWriter, Deserializable, DeserializationError, Serializable},
4};
5
6// NULLIFIER WITNESS
7// ================================================================================================
8
9/// A proof that a certain nullifier is in the nullifier tree with the contained state.
10#[derive(Debug, Clone)]
11pub struct NullifierWitness {
12    proof: SmtProof,
13}
14
15impl NullifierWitness {
16    /// Creates a new [`NullifierWitness`] from the given proof.
17    pub fn new(proof: SmtProof) -> Self {
18        Self { proof }
19    }
20
21    /// Returns a reference to the underlying [`SmtProof`].
22    pub fn proof(&self) -> &SmtProof {
23        &self.proof
24    }
25
26    /// Consumes the witness and returns the underlying [`SmtProof`].
27    pub fn into_proof(self) -> SmtProof {
28        self.proof
29    }
30}
31
32impl Serializable for NullifierWitness {
33    fn write_into<W: ByteWriter>(&self, target: &mut W) {
34        target.write(&self.proof);
35    }
36}
37
38impl Deserializable for NullifierWitness {
39    fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
40        let proof = source.read()?;
41        Ok(Self::new(proof))
42    }
43}