drive/verify/shielded/verify_nullifiers_trunk_query/
mod.rs

1//! Module for verifying nullifiers trunk chunk queries.
2
3mod v0;
4
5use crate::drive::Drive;
6use crate::error::drive::DriveError;
7use crate::error::Error;
8use crate::verify::RootHash;
9use grovedb::GroveTrunkQueryResult;
10use platform_version::version::PlatformVersion;
11
12impl Drive {
13    /// Verifies a trunk chunk proof for the nullifiers tree of a shielded pool.
14    ///
15    /// # Arguments
16    /// - `proof`: A byte slice containing the serialized trunk chunk proof.
17    /// - `pool_type`: The shielded pool type (0 = credit, 1 = main token, 2 = individual token).
18    /// - `pool_identifier`: Optional 32-byte identifier for individual token pools.
19    /// - `platform_version`: A reference to the platform version.
20    ///
21    /// # Returns
22    /// - `Ok((RootHash, GroveTrunkQueryResult))`: The root hash and verified trunk result.
23    /// - `Err(Error)`: If verification fails.
24    pub fn verify_nullifiers_trunk_query(
25        proof: &[u8],
26        pool_type: u32,
27        pool_identifier: Option<&[u8]>,
28        platform_version: &PlatformVersion,
29    ) -> Result<(RootHash, GroveTrunkQueryResult), Error> {
30        match platform_version
31            .drive
32            .methods
33            .verify
34            .shielded
35            .verify_nullifiers_trunk_query
36        {
37            0 => Self::verify_nullifiers_trunk_query_v0(
38                proof,
39                pool_type,
40                pool_identifier,
41                platform_version,
42            ),
43            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
44                method: "verify_nullifiers_trunk_query".to_string(),
45                known_versions: vec![0],
46                received: version,
47            })),
48        }
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55    use platform_version::version::PlatformVersion;
56
57    #[test]
58    fn test_verify_nullifiers_trunk_query_unknown_version_mismatch() {
59        let mut platform_version = PlatformVersion::latest().clone();
60        platform_version
61            .drive
62            .methods
63            .verify
64            .shielded
65            .verify_nullifiers_trunk_query = 255;
66
67        let result = Drive::verify_nullifiers_trunk_query(&[], 0, None, &platform_version);
68
69        assert!(
70            matches!(
71                result,
72                Err(Error::Drive(DriveError::UnknownVersionMismatch { .. }))
73            ),
74            "expected UnknownVersionMismatch, got {:?}",
75            result,
76        );
77    }
78}