Skip to main content

drive/verify/shielded/verify_shielded_anchors/
mod.rs

1mod v0;
2
3use crate::drive::shielded::paths::token_shielded_pool_anchors_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 valid shielded anchors.
12    pub fn verify_shielded_anchors(
13        proof: &[u8],
14        verify_subset_of_proof: bool,
15        platform_version: &PlatformVersion,
16    ) -> Result<(RootHash, Vec<[u8; 32]>), Error> {
17        match platform_version
18            .drive
19            .methods
20            .verify
21            .shielded
22            .verify_shielded_anchors
23        {
24            0 => Self::verify_shielded_anchors_v0(proof, verify_subset_of_proof, platform_version),
25            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
26                method: "verify_shielded_anchors".to_string(),
27                known_versions: vec![0],
28                received: version,
29            })),
30        }
31    }
32}
33
34impl Drive {
35    /// Verifies a proof of a TOKEN shielded pool's recorded anchors. Same versioning as
36    /// [`Drive::verify_shielded_anchors`].
37    pub fn verify_token_shielded_pool_anchors(
38        proof: &[u8],
39        token_id: [u8; 32],
40        verify_subset_of_proof: bool,
41        platform_version: &PlatformVersion,
42    ) -> Result<(RootHash, Vec<[u8; 32]>), Error> {
43        match platform_version
44            .drive
45            .methods
46            .verify
47            .shielded
48            .verify_shielded_anchors
49        {
50            0 => Self::verify_pool_anchors_v0(
51                proof,
52                token_shielded_pool_anchors_path_vec(token_id),
53                verify_subset_of_proof,
54                platform_version,
55            ),
56            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
57                method: "verify_token_shielded_pool_anchors".to_string(),
58                known_versions: vec![0],
59                received: version,
60            })),
61        }
62    }
63}
64
65#[cfg(test)]
66mod tests {
67    use super::*;
68    use dpp::version::PlatformVersion;
69
70    #[test]
71    fn test_verify_shielded_anchors_unknown_version_mismatch() {
72        let mut platform_version = PlatformVersion::latest().clone();
73        platform_version
74            .drive
75            .methods
76            .verify
77            .shielded
78            .verify_shielded_anchors = 255;
79
80        let result = Drive::verify_shielded_anchors(&[], false, &platform_version);
81
82        assert!(
83            matches!(
84                result,
85                Err(Error::Drive(DriveError::UnknownVersionMismatch { .. }))
86            ),
87            "expected UnknownVersionMismatch, got {:?}",
88            result,
89        );
90    }
91}