Skip to main content

drive/verify/shielded/verify_shielded_notes_count/
mod.rs

1mod v0;
2
3use crate::drive::shielded::paths::token_shielded_pool_path_vec;
4use crate::drive::Drive;
5use crate::error::drive::DriveError;
6use crate::error::Error;
7use crate::verify::RootHash;
8use dpp::version::PlatformVersion;
9
10impl Drive {
11    /// Verifies a proof for the shielded notes commitment-tree leaf count.
12    ///
13    /// Returns the verified `(root_hash, Option<total_count>)`. The count
14    /// is the first field of the proved `CommitmentTree` element, whose
15    /// serialized bytes are bound into the Merk value hash — see
16    /// `verify_shielded_notes_count_v0`.
17    pub fn verify_shielded_notes_count(
18        proof: &[u8],
19        verify_subset_of_proof: bool,
20        platform_version: &PlatformVersion,
21    ) -> Result<(RootHash, Option<u64>), Error> {
22        match platform_version
23            .drive
24            .methods
25            .verify
26            .shielded
27            .verify_shielded_notes_count
28        {
29            0 => Self::verify_shielded_notes_count_v0(
30                proof,
31                verify_subset_of_proof,
32                platform_version,
33            ),
34            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
35                method: "verify_shielded_notes_count".to_string(),
36                known_versions: vec![0],
37                received: version,
38            })),
39        }
40    }
41}
42
43impl Drive {
44    /// Verifies a proof of a TOKEN shielded pool's notes count. Same versioning as
45    /// [`Drive::verify_shielded_notes_count`].
46    pub fn verify_token_shielded_pool_notes_count(
47        proof: &[u8],
48        token_id: [u8; 32],
49        verify_subset_of_proof: bool,
50        platform_version: &PlatformVersion,
51    ) -> Result<(RootHash, Option<u64>), Error> {
52        match platform_version
53            .drive
54            .methods
55            .verify
56            .shielded
57            .verify_shielded_notes_count
58        {
59            0 => Self::verify_pool_notes_count_v0(
60                proof,
61                token_shielded_pool_path_vec(token_id),
62                verify_subset_of_proof,
63                platform_version,
64            ),
65            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
66                method: "verify_token_shielded_pool_notes_count".to_string(),
67                known_versions: vec![0],
68                received: version,
69            })),
70        }
71    }
72}
73
74#[cfg(test)]
75mod tests {
76    use super::*;
77    use dpp::version::PlatformVersion;
78
79    #[test]
80    fn test_verify_shielded_notes_count_unknown_version_mismatch() {
81        let mut platform_version = PlatformVersion::latest().clone();
82        platform_version
83            .drive
84            .methods
85            .verify
86            .shielded
87            .verify_shielded_notes_count = 255;
88
89        let result = Drive::verify_shielded_notes_count(&[], false, &platform_version);
90
91        assert!(
92            matches!(
93                result,
94                Err(Error::Drive(DriveError::UnknownVersionMismatch { .. }))
95            ),
96            "expected UnknownVersionMismatch, got {:?}",
97            result,
98        );
99    }
100}