Skip to main content

drive/verify/document_count/verify_distinct_count_proof/
mod.rs

1mod v0;
2
3use crate::error::drive::DriveError;
4use crate::error::Error;
5use crate::query::{DriveDocumentCountQuery, SplitCountEntry};
6use crate::verify::RootHash;
7use dpp::version::PlatformVersion;
8
9impl DriveDocumentCountQuery<'_> {
10    /// Verifies a regular grovedb range proof against a
11    /// `ProvableCountTree` and returns `(root_hash, entries)`. Each
12    /// entry's `count` is bound to the merk root via
13    /// `node_hash_with_count(kv_hash, l_hash, r_hash, count)`, so
14    /// once this returns `Ok` every count is cryptographically
15    /// committed to the same `root_hash` the caller can pass to a
16    /// tenderdash signature check.
17    ///
18    /// Counterpart to the prover-side
19    /// [`execute_distinct_count_with_proof`](Self::execute_distinct_count_with_proof):
20    /// rebuilds the same `PathQuery` via
21    /// [`distinct_count_path_query`](Self::distinct_count_path_query)
22    /// and calls `GroveDb::verify_query`. Caller is responsible for
23    /// combining the returned `root_hash` with the surrounding
24    /// tenderdash signature — see `rs-drive-proof-verifier`'s
25    /// `verify_distinct_count_proof` wrapper for the canonical
26    /// composition.
27    ///
28    /// Entries are emitted unmerged: for compound (`In`-on-prefix)
29    /// queries each entry retains its `in_key` (the In value for
30    /// that fork) alongside the terminator `key`. See
31    /// [`SplitCountEntry`]'s doc for the no-merge rationale.
32    ///
33    /// # Arguments
34    /// * `proof` — raw grovedb proof bytes.
35    /// * `limit` — the same limit the prover applied (also used to
36    ///   reconstruct the matching path query).
37    /// * `left_to_right` — same iteration direction the prover used.
38    /// * `platform_version` — selects the method version.
39    pub fn verify_distinct_count_proof(
40        &self,
41        proof: &[u8],
42        limit: u16,
43        left_to_right: bool,
44        platform_version: &PlatformVersion,
45    ) -> Result<(RootHash, Vec<SplitCountEntry>), Error> {
46        match platform_version
47            .drive
48            .methods
49            .verify
50            .document_count
51            .verify_distinct_count_proof
52        {
53            0 => self.verify_distinct_count_proof_v0(proof, limit, left_to_right, platform_version),
54            version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
55                method: "DriveDocumentCountQuery::verify_distinct_count_proof".to_string(),
56                known_versions: vec![0],
57                received: version,
58            })),
59        }
60    }
61}