drive/verify/composite_document/verify_composite_documents_proof/mod.rs
1mod v0;
2
3use crate::error::drive::DriveError;
4use crate::error::Error;
5use crate::query::{CompositeDocumentsResult, DriveDocumentQuery};
6use crate::verify::RootHash;
7use dpp::version::PlatformVersion;
8
9impl DriveDocumentQuery<'_> {
10 /// Verifies a composite query's single merged proof — this query as
11 /// the page plus its [`sub_queries`](DriveDocumentQuery::sub_queries)
12 /// — and returns `(root_hash, result)`.
13 ///
14 /// The verifier trusts nothing about the derivation, and needs
15 /// nothing beyond the proof itself: a BOOTSTRAP subset pass runs the
16 /// page query (and every sub-query that feeds a later binding) alone
17 /// against the merged proof to extract candidate values; every
18 /// sub-query is derived from those exactly as the prover derived it
19 /// from its materialization, the merged query is rebuilt, and the
20 /// AUTHORITATIVE full pass verifies the whole composition — grovedb
21 /// enforces every component's per-instance limit and range
22 /// completeness. The proven results are then routed back to their
23 /// components: an entry no derivation asked for is an invalid proof,
24 /// so is a by-id join missing a referenced document (a
25 /// `permanentDocument` reference cannot dangle), and so is any
26 /// divergence between the values the proven page derives and the
27 /// candidates the query was built from. A proof covering only the
28 /// page (an old node serving the plain query) fails the full pass
29 /// whenever a sub-query derived anything.
30 ///
31 /// One proof means one root by construction; the caller combines the
32 /// returned root hash with the surrounding tenderdash signature — see
33 /// `rs-drive-proof-verifier` for the canonical composition.
34 pub fn verify_composite_documents_proof(
35 &self,
36 proof: &[u8],
37 platform_version: &PlatformVersion,
38 ) -> Result<(RootHash, CompositeDocumentsResult), Error> {
39 match platform_version
40 .drive
41 .methods
42 .verify
43 .composite_document
44 .verify_composite_documents_proof
45 {
46 0 => self.verify_composite_documents_proof_v0(proof, platform_version),
47 version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
48 method: "DriveDocumentQuery::verify_composite_documents_proof".to_string(),
49 known_versions: vec![0],
50 received: version,
51 })),
52 }
53 }
54}