drive_proof_verifier/lib.rs
1//! Proof verification library for Dash Drive
2#![warn(missing_docs)]
3#![allow(clippy::result_large_err)]
4
5/// Errors that can occur during proof verification
6pub mod error;
7/// Implementation of proof verification
8mod proof;
9pub mod types;
10mod verify;
11pub use error::Error;
12pub use proof::chained_document::{
13 verify_chained_documents_proof as verify_chained_documents_tenderdash_proof, ChainedDocuments,
14};
15pub use proof::composite_document::{
16 verify_composite_documents_proof as verify_composite_documents_tenderdash_proof,
17 CompositeDocuments,
18};
19// Re-export the per-sub-query result of a composite query at the
20// crate root, paralleling `SplitCountEntry` below, so SDK consumers can
21// name it without depending on rs-drive directly.
22pub use drive::query::SubQueryResult as CompositeSubQueryResult;
23pub use proof::document_count::{
24 verify_aggregate_count_proof, verify_carrier_aggregate_count_proof,
25 verify_distinct_count_proof, verify_point_lookup_count_proof,
26 verify_primary_key_count_tree_proof, DocumentCount,
27};
28/// Verified having-range (`GROUP BY … HAVING <aggregate> <op> <value>
29/// LIMIT n`) result types. `DocumentHavingEntries` carries one entry
30/// per matching group **in axis order**;
31/// [`verify_having_range_proof`] is the tenderdash-composition wrapper
32/// that binds the proof's reconstructed root hash to the signed app
33/// hash and returns the verified entry list — including its
34/// completeness: an in-range group the node omitted fails verification.
35pub use proof::document_having::{verify_having_range_proof, DocumentHavingEntries};
36/// Verified ranked (`GROUP BY … ORDER BY <aggregate> LIMIT n
37/// [OFFSET m]`) result types. `DocumentRankedEntries` carries one entry
38/// per returned group **in ranking order**, plus the `starting_rank`
39/// that pins each entry to an absolute position;
40/// [`verify_ranked_top_k_proof`] is the tenderdash-composition wrapper
41/// that binds the proof's reconstructed root hash to the signed app
42/// hash and returns the whole verified [`drive::query::RankedPage`].
43pub use proof::document_ranked::{verify_ranked_top_k_proof, DocumentRankedEntries};
44pub use proof::document_split_count::DocumentSplitCounts;
45// Re-export `SplitCountEntry` from rs-drive at the proof-verifier
46// crate root so SDK consumers don't have to depend on rs-drive
47// directly just to name the entry type returned by
48// `verify_distinct_count_proof` and `DocumentSplitCounts::from_verified`.
49pub use drive::query::SplitCountEntry;
50// Same treatment for the ranked surface's entry types, plus the
51// fixed-point scale the Avg axis sorts by. `RANKED_AVG_SCALE` is
52// itself a re-export of grovedb's `AVG_FIXED_POINT_SCALE` — it moved
53// from 10^15 to 10^19 late in grovedb's development, so clients must
54// read it from here and never hardcode the literal. Divide an
55// `AvgFixedPoint` value by it (or call `RankedEntryValue::as_f64`) to
56// render an average.
57//
58// The fixed point is the exact integer grovedb ranks on **when it came
59// from a proof**. `DocumentRankedEntries::from_unproved_response`
60// reconstructs it from the wire's `double` (the no-proof path carries
61// an f64 approximation, since a proof-verifying client rebuilds the
62// entry from the proof instead), so on that path the low digits past
63// f64's ~15–16 significant decimals are noise. Anything that needs the
64// committed integer must go through the proof.
65// `RankedPage` rides along because it is what
66// `verify_ranked_top_k_proof` returns: a caller verifying a ranked
67// proof for themselves needs to name the type without depending on
68// rs-drive.
69pub use drive::query::{RankedEntry, RankedEntryValue, RankedPage, RANKED_AVG_SCALE};
70/// Verified average result types. Average-side analog of `DocumentSum`
71/// / `DocumentSplitSums`; carry the `(count, sum)` pair the verifier
72/// recovers from grovedb PR 670's `AggregateCountAndSumOnRange`
73/// primitive. Client computes `avg = sum / count`.
74pub use proof::document_average::{
75 verify_aggregate_count_and_sum_proof, verify_carrier_aggregate_count_and_sum_proof,
76 verify_distinct_count_and_sum_proof, verify_point_lookup_count_and_sum_proof,
77 verify_primary_key_count_sum_tree_proof, DocumentAverage,
78};
79pub use proof::document_split_average::{DocumentSplitAverages, SplitAverageEntry};
80/// Verified sum result types. Sum-side analogs of `DocumentCount` /
81/// `DocumentSplitCounts`; see their respective module docs for the
82/// grovedb PR 670 dependency status.
83pub use proof::document_split_sum::{DocumentSplitSums, SplitSumEntry};
84pub use proof::document_sum::{
85 verify_aggregate_sum_proof, verify_carrier_aggregate_sum_proof, verify_distinct_sum_proof,
86 verify_point_lookup_sum_proof, verify_primary_key_sum_tree_proof, DocumentSum,
87};
88// Re-export the rs-drive `SumEntry` + `AverageEntry` at the
89// proof-verifier crate root, paralleling `SplitCountEntry` above —
90// the per-shape verifier helpers above all return these types.
91pub use drive::query::drive_document_average_query::AverageEntry;
92pub use drive::query::SumEntry;
93pub use proof::{FromProof, Length};
94
95// Re-export context provider types from dash-context-provider
96#[cfg(feature = "mocks")]
97pub use dash_context_provider::MockContextProvider;
98pub use dash_context_provider::{ContextProvider, ContextProviderError, DataContractProvider};
99
100/// From Request
101pub mod from_request;
102/// Implementation of unproved verification
103pub mod unproved;
104
105// Needed for #[derive(PlatformSerialize, PlatformDeserializeTrusted, PlatformDeserializeUntrusted)]
106#[cfg(feature = "mocks")]
107use dpp::serialization;