Skip to main content

drive/verify/document_count/verify_aggregate_count_proof/
mod.rs

1mod v0;
2
3use crate::error::drive::DriveError;
4use crate::error::Error;
5use crate::query::DriveDocumentCountQuery;
6use crate::verify::RootHash;
7use dpp::version::PlatformVersion;
8
9impl DriveDocumentCountQuery<'_> {
10    /// Verifies an `AggregateCountOnRange` proof and returns
11    /// `(root_hash, count)`.
12    ///
13    /// Counterpart to the prover-side
14    /// [`execute_aggregate_count_with_proof`](Self::execute_aggregate_count_with_proof):
15    /// rebuilds the same `PathQuery` via
16    /// [`aggregate_count_path_query`](Self::aggregate_count_path_query)
17    /// and calls `GroveDb::verify_aggregate_count_query`. The
18    /// caller is responsible for combining the returned `root_hash`
19    /// with the surrounding tenderdash signature — see
20    /// `rs-drive-proof-verifier`'s `verify_aggregate_count_proof`
21    /// wrapper for the canonical composition.
22    ///
23    /// # Arguments
24    /// * `proof` — raw grovedb proof bytes.
25    /// * `platform_version` — selects the method version.
26    pub fn verify_aggregate_count_proof(
27        &self,
28        proof: &[u8],
29        platform_version: &PlatformVersion,
30    ) -> Result<(RootHash, u64), Error> {
31        match platform_version
32            .drive
33            .methods
34            .verify
35            .document_count
36            .verify_aggregate_count_proof
37        {
38            0 => self.verify_aggregate_count_proof_v0(proof, platform_version),
39            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
40                method: "DriveDocumentCountQuery::verify_aggregate_count_proof".to_string(),
41                known_versions: vec![0],
42                received: version,
43            })),
44        }
45    }
46}