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