Skip to main content

drive/verify/shielded/verify_shielded_notes_count/
mod.rs

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