Skip to main content

drive/verify/document_count/verify_aggregate_count_proof/
mod.rs

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