Skip to main content

miden_objects/decoded/transaction/
notes.rs

1pub use proto::transaction::DecodedInputNoteCommitment as InputNoteCommitment;
2
3use crate::decoded::VerificationError;
4use crate::{BuildUnchecked, Verify, proto};
5
6#[cfg(test)]
7mod tests;
8
9/// Builds the decoded commitment without checking that its nullifier belongs to its note header.
10/// A present header is verified, but the caller must establish nullifier/header consistency and
11/// authenticate the note's inclusion separately. An absent header is not evidence of inclusion.
12impl BuildUnchecked for InputNoteCommitment {
13    type Output = miden_protocol::transaction::InputNoteCommitment;
14    type Error = VerificationError;
15    fn build_unchecked(self) -> Result<Self::Output, Self::Error> {
16        Ok(Self::Output::from_parts_unchecked(
17            miden_protocol::note::Nullifier::from_raw(self.nullifier),
18            self.header.verify()?,
19        ))
20    }
21}
22
23pub use proto::transaction::DecodedPrivateOutputNote as PrivateOutputNote;
24
25impl Verify for PrivateOutputNote {
26    type Verified = miden_protocol::transaction::PrivateOutputNote;
27    type Error = VerificationError;
28    fn verify(self) -> Result<Self::Verified, Self::Error> {
29        Ok(Self::Verified::new(self.header.verify()?, self.attachments.verify()?)?)
30    }
31}
32
33pub use proto::transaction::DecodedPublicOutputNote as PublicOutputNote;
34
35impl Verify for PublicOutputNote {
36    type Verified = miden_protocol::transaction::PublicOutputNote;
37    type Error = VerificationError;
38    fn verify(self) -> Result<Self::Verified, Self::Error> {
39        Ok(Self::Verified::new(self.note.verify()?)?)
40    }
41}
42
43pub use proto::transaction::DecodedOutputNote as OutputNote;
44
45impl Verify for OutputNote {
46    type Verified = miden_protocol::transaction::OutputNote;
47    type Error = VerificationError;
48    fn verify(self) -> Result<Self::Verified, Self::Error> {
49        use proto::transaction::output_note::DecodedNote;
50        match self.note {
51            DecodedNote::Public(note) => Ok(Self::Verified::Public(note.verify()?)),
52            DecodedNote::Private(note) => Ok(Self::Verified::Private(note.verify()?)),
53        }
54    }
55}
56
57pub use proto::transaction::DecodedAuthenticatedInputNote as AuthenticatedInputNote;
58
59/// Checks proof/note identity, not inclusion against a trusted block root.
60impl Verify for AuthenticatedInputNote {
61    type Verified = miden_protocol::transaction::InputNote;
62    type Error = VerificationError;
63    fn verify(self) -> Result<Self::Verified, Self::Error> {
64        let note = self.note.verify()?;
65        let (proof_id, proof) = self.proof.verify()?;
66        if proof_id != note.id() {
67            return Err(InputNoteError::IdMismatch {
68                transmitted: proof_id,
69                decoded: note.id(),
70            }
71            .into());
72        }
73        Ok(Self::Verified::authenticated(note, proof))
74    }
75}
76
77#[derive(Debug, thiserror::Error)]
78pub enum InputNoteError {
79    #[error("note ID mismatch: transmitted {transmitted}, decoded {decoded}")]
80    IdMismatch {
81        transmitted: miden_protocol::note::NoteId,
82        decoded: miden_protocol::note::NoteId,
83    },
84}
85
86pub use proto::transaction::DecodedInputNote as InputNote;
87
88impl Verify for InputNote {
89    type Verified = miden_protocol::transaction::InputNote;
90    type Error = VerificationError;
91    fn verify(self) -> Result<Self::Verified, Self::Error> {
92        use proto::transaction::input_note::DecodedNote;
93        match self.note {
94            DecodedNote::Authenticated(note) => note.verify(),
95            DecodedNote::Unauthenticated(note) => {
96                Ok(Self::Verified::unauthenticated(note.verify()?))
97            },
98        }
99    }
100}
101
102pub use proto::transaction::DecodedInputNotes as InputNotes;
103
104impl Verify for InputNotes {
105    type Verified = miden_protocol::transaction::InputNotes<miden_protocol::transaction::InputNote>;
106    type Error = VerificationError;
107    fn verify(self) -> Result<Self::Verified, Self::Error> {
108        let notes = self.notes.verify()?;
109        Ok(Self::Verified::new(notes)?)
110    }
111}
112
113pub use proto::transaction::DecodedRawOutputNote as RawOutputNote;
114
115impl Verify for RawOutputNote {
116    type Verified = miden_protocol::transaction::RawOutputNote;
117    type Error = VerificationError;
118    fn verify(self) -> Result<Self::Verified, Self::Error> {
119        use proto::transaction::raw_output_note::DecodedNote;
120        match self.note {
121            DecodedNote::Full(note) => Ok(Self::Verified::Full(note.verify()?)),
122            DecodedNote::Partial(note) => Ok(Self::Verified::Partial(note.verify()?)),
123        }
124    }
125}
126
127pub use proto::transaction::DecodedRawOutputNotes as RawOutputNotes;
128
129impl Verify for RawOutputNotes {
130    type Verified = miden_protocol::transaction::RawOutputNotes;
131    type Error = VerificationError;
132    fn verify(self) -> Result<Self::Verified, Self::Error> {
133        Ok(Self::Verified::new(self.notes.verify()?)?)
134    }
135}