Skip to main content

drive/verify/document_sum/verify_distinct_sum_proof/
mod.rs

1mod v0;
2
3use crate::error::drive::DriveError;
4use crate::error::Error;
5use crate::query::drive_document_sum_query::{DriveDocumentSumQuery, SumEntry};
6use crate::verify::RootHash;
7use dpp::version::PlatformVersion;
8
9impl DriveDocumentSumQuery<'_> {
10    /// Verifies a regular grovedb range proof against a
11    /// `rangeSummable: true` index's terminator `SumTree`s and
12    /// returns the per-`(in_key, terminator_key)` sums. Sum analog
13    /// of count's `verify_distinct_count_proof`.
14    ///
15    /// Used by the prove path's
16    /// [`DocumentSumMode::RangeDistinctProof`] (GroupByRange /
17    /// GroupByCompound + range + prove). Rebuilds the same
18    /// `PathQuery` the prover used via
19    /// [`Self::distinct_sum_path_query`] (including `limit` and
20    /// `left_to_right` — both are encoded into the path query
21    /// bytes) and walks the verified
22    /// `(path, key, Option<Element>)` triples to extract
23    /// `sum_value_or_default()` from each terminator SumTree.
24    ///
25    /// Cross-fork aggregation is intentionally NOT done here —
26    /// callers reduce by `key` client-side if they want a flat
27    /// histogram. See [`SumEntry`]'s sibling
28    /// [`crate::query::SplitCountEntry`] for the no-merge
29    /// rationale (identical contract on the sum side).
30    pub fn verify_distinct_sum_proof(
31        &self,
32        proof: &[u8],
33        limit: u16,
34        left_to_right: bool,
35        platform_version: &PlatformVersion,
36    ) -> Result<(RootHash, Vec<SumEntry>), Error> {
37        match platform_version
38            .drive
39            .methods
40            .verify
41            .document_sum
42            .verify_distinct_sum_proof
43        {
44            0 => self.verify_distinct_sum_proof_v0(proof, limit, left_to_right, platform_version),
45            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
46                method: "DriveDocumentSumQuery::verify_distinct_sum_proof".to_string(),
47                known_versions: vec![0],
48                received: version,
49            })),
50        }
51    }
52}