soil_client/client_api/proof_provider.rs
1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7//! Proof utilities
8use super::{CompactProof, StorageProof};
9use subsoil::runtime::traits::Block as BlockT;
10use subsoil::state_machine::{KeyValueStates, KeyValueStorageLevel};
11use subsoil::storage::ChildInfo;
12
13/// Interface for providing block proving utilities.
14pub trait ProofProvider<Block: BlockT> {
15 /// Reads storage value at a given block + key, returning read proof.
16 fn read_proof(
17 &self,
18 hash: Block::Hash,
19 keys: &mut dyn Iterator<Item = &[u8]>,
20 ) -> crate::blockchain::Result<StorageProof>;
21
22 /// Reads child storage value at a given block + storage_key + key, returning
23 /// read proof.
24 fn read_child_proof(
25 &self,
26 hash: Block::Hash,
27 child_info: &ChildInfo,
28 keys: &mut dyn Iterator<Item = &[u8]>,
29 ) -> crate::blockchain::Result<StorageProof>;
30
31 /// Execute a call to a contract on top of state in a block of given hash
32 /// AND returning execution proof.
33 ///
34 /// No changes are made.
35 fn execution_proof(
36 &self,
37 hash: Block::Hash,
38 method: &str,
39 call_data: &[u8],
40 ) -> crate::blockchain::Result<(Vec<u8>, StorageProof)>;
41
42 /// Given a `Hash` iterate over all storage values starting at `start_keys`.
43 /// Last `start_keys` element contains last accessed key value.
44 /// With multiple `start_keys`, first `start_keys` element is
45 /// the current storage key of of the last accessed child trie.
46 /// at last level the value to start at exclusively.
47 /// Proofs is build until size limit is reached and always include at
48 /// least one key following `start_keys`.
49 /// Returns combined proof and the numbers of collected keys.
50 fn read_proof_collection(
51 &self,
52 hash: Block::Hash,
53 start_keys: &[Vec<u8>],
54 size_limit: usize,
55 ) -> crate::blockchain::Result<(CompactProof, u32)>;
56
57 /// Given a `Hash` iterate over all storage values starting at `start_key`.
58 /// Returns collected keys and values.
59 /// Returns the collected keys values content of the top trie followed by the
60 /// collected keys values of child tries.
61 /// Only child tries with their root part of the collected content or
62 /// related to `start_key` are attached.
63 /// For each collected state a boolean indicates if state reach
64 /// end.
65 fn storage_collection(
66 &self,
67 hash: Block::Hash,
68 start_key: &[Vec<u8>],
69 size_limit: usize,
70 ) -> crate::blockchain::Result<Vec<(KeyValueStorageLevel, bool)>>;
71
72 /// Verify read storage proof for a set of keys.
73 /// Returns collected key-value pairs and the nested state
74 /// depth of current iteration or 0 if completed.
75 fn verify_range_proof(
76 &self,
77 root: Block::Hash,
78 proof: CompactProof,
79 start_keys: &[Vec<u8>],
80 ) -> crate::blockchain::Result<(KeyValueStates, usize)>;
81}