Skip to main content

drive/verify/document_sum/verify_aggregate_sum_proof/
mod.rs

1mod v0;
2
3use crate::error::drive::DriveError;
4use crate::error::Error;
5use crate::query::drive_document_sum_query::DriveDocumentSumQuery;
6use crate::verify::RootHash;
7use dpp::version::PlatformVersion;
8
9impl DriveDocumentSumQuery<'_> {
10    /// Verifies a grovedb `AggregateSumOnRange` proof (grovedb PR
11    /// #670) and returns `(root_hash, i64 sum)`. Counterpart to the
12    /// prover-side
13    /// [`Self::execute_aggregate_sum_with_proof`].
14    /// Calls `GroveDb::verify_aggregate_sum_query`.
15    ///
16    /// Tree-type restriction: the chosen index must declare
17    /// `rangeSummable: true` so the terminator's value tree is at
18    /// least a `ProvableSumTree`; the grovedb merk gate rejects
19    /// lighter sum-bearing variants on the aggregate primitive.
20    /// Same path-query byte-equality contract as every other paired
21    /// prover/verifier in this surface — both sides share
22    /// [`Self::aggregate_sum_path_query`].
23    pub fn verify_aggregate_sum_proof(
24        &self,
25        proof: &[u8],
26        platform_version: &PlatformVersion,
27    ) -> Result<(RootHash, i64), Error> {
28        match platform_version
29            .drive
30            .methods
31            .verify
32            .document_sum
33            .verify_aggregate_sum_proof
34        {
35            0 => self.verify_aggregate_sum_proof_v0(proof, platform_version),
36            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
37                method: "DriveDocumentSumQuery::verify_aggregate_sum_proof".to_string(),
38                known_versions: vec![0],
39                received: version,
40            })),
41        }
42    }
43}