Skip to main content

miden_objects/decoded/account/
partial.rs

1pub use proto::account::DecodedPartialStorageMap as PartialStorageMap;
2
3use crate::decoded::VerificationError;
4use crate::{Verify, proto};
5
6#[cfg(test)]
7mod tests;
8
9impl Verify for PartialStorageMap {
10    type Verified = miden_protocol::account::PartialStorageMap;
11    type Error = VerificationError;
12    fn verify(self) -> Result<Self::Verified, Self::Error> {
13        Ok(Self::Verified::try_from_parts(
14            self.smt.verify()?,
15            self.keys.into_iter().map(miden_protocol::account::StorageMapKey::from_raw),
16        )?)
17    }
18}
19
20pub use proto::account::DecodedPartialStorage as PartialStorage;
21
22impl Verify for PartialStorage {
23    type Verified = miden_protocol::account::PartialStorage;
24    type Error = VerificationError;
25    fn verify(self) -> Result<Self::Verified, Self::Error> {
26        let mut roots = alloc::collections::BTreeSet::new();
27        let mut maps = alloc::vec::Vec::new();
28        for map in self.maps {
29            let map = map.verify()?;
30            if !roots.insert(map.root()) {
31                return Err(PartialStorageError::DuplicateRoot(map.root()).into());
32            }
33            maps.push(map);
34        }
35        Ok(Self::Verified::new(self.header.verify()?, maps)?)
36    }
37}
38
39#[derive(Debug, thiserror::Error)]
40pub enum PartialStorageError {
41    #[error("duplicate partial storage map root {0}")]
42    DuplicateRoot(miden_protocol::Word),
43}
44
45pub use proto::account::DecodedPartialVault as PartialVault;
46
47impl Verify for PartialVault {
48    type Verified = miden_protocol::asset::PartialVault;
49    type Error = VerificationError;
50    fn verify(self) -> Result<Self::Verified, Self::Error> {
51        let ids = self
52            .asset_ids
53            .into_iter()
54            .map(miden_protocol::asset::AssetId::try_from)
55            .collect::<Result<alloc::vec::Vec<_>, _>>()?;
56        Ok(Self::Verified::try_from_parts(self.smt.verify()?, ids)?)
57    }
58}
59
60pub use proto::account::DecodedPartialAccount as PartialAccount;
61
62impl Verify for PartialAccount {
63    type Verified = miden_protocol::account::PartialAccount;
64    type Error = VerificationError;
65    fn verify(self) -> Result<Self::Verified, Self::Error> {
66        Ok(Self::Verified::new(
67            self.account_id.verify()?,
68            self.nonce,
69            self.code.verify()?,
70            self.storage.verify()?,
71            self.vault.verify()?,
72            self.seed,
73        )?)
74    }
75}