Skip to main content

drive/verify/document_having/verify_having_range_proof/
mod.rs

1mod v0;
2
3use crate::error::drive::DriveError;
4use crate::error::Error;
5use crate::query::DriveDocumentHavingQuery;
6use crate::verify::RootHash;
7use dpp::version::PlatformVersion;
8
9impl DriveDocumentHavingQuery<'_> {
10    /// Verifies a grovedb indexed-axis range proof and returns
11    /// `(root_hash, entries)`.
12    ///
13    /// Counterpart to the prover-side
14    /// [`execute_range_with_proof`](Self::execute_range_with_proof).
15    /// Both sides derive the proved subtree from
16    /// [`indexed_property_name_tree_path`](Self::indexed_property_name_tree_path)
17    /// and the same bounded axis `PathQuery` from
18    /// [`AxisRangeBounds::i128_bounds`](crate::query::drive_document_having_query::AxisRangeBounds::i128_bounds),
19    /// so the verifier cannot drift from the prover on *which* bound over
20    /// *which* tree it is checking.
21    ///
22    /// The returned entries are in axis order in the walk direction,
23    /// exactly as the unproven
24    /// [`execute_range_no_proof`](Self::execute_range_no_proof) would
25    /// return them. The caller combines `root_hash` with the surrounding
26    /// tenderdash signature — see `rs-drive-proof-verifier` for the
27    /// canonical composition.
28    ///
29    /// # Arguments
30    /// * `proof` — raw grovedb proof bytes.
31    /// * `platform_version` — selects the method version.
32    ///
33    /// # Returns
34    ///
35    /// * `Ok((RootHash, Vec<RankedEntry>))` with the proof's root hash and the groups whose
36    ///   aggregate falls in the bounds, at most `limit` of them, in axis order in the walk
37    ///   direction; empty when no group matches.
38    /// * `Err(Error)` when the method version is unknown, the index path cannot be resolved,
39    ///   the proof does not verify against the rebuilt traversal, or its entries have the
40    ///   wrong axis shape or exceed the limit.
41    pub fn verify_having_range_proof(
42        &self,
43        proof: &[u8],
44        platform_version: &PlatformVersion,
45    ) -> Result<(RootHash, Vec<crate::query::RankedEntry>), Error> {
46        match platform_version
47            .drive
48            .methods
49            .verify
50            .document_ranked
51            .verify_having_range_proof
52        {
53            0 => self.verify_having_range_proof_v0(proof, platform_version),
54            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
55                method: "DriveDocumentHavingQuery::verify_having_range_proof".to_string(),
56                known_versions: vec![0],
57                received: version,
58            })),
59        }
60    }
61}