pub struct Proof<D: Digest> {
pub size: u64,
pub digests: Vec<D>,
}
Expand description
Contains the information necessary for proving the inclusion of an element, or some range of elements, in the MMR from its root digest.
The digests
vector contains:
1: the digests of each peak corresponding to a mountain containing no elements from the element range being proven in decreasing order of height, followed by:
2: the nodes in the remaining mountains necessary for reconstructing their peak digests from the elements within the range, ordered by the position of their parent.
Fields§
§size: u64
The total number of nodes in the MMR.
digests: Vec<D>
The digests necessary for proving the inclusion of an element, or range of elements, in the MMR.
Implementations§
Source§impl<D: Digest> Proof<D>
impl<D: Digest> Proof<D>
Sourcepub fn verify_element_inclusion<I, H>(
&self,
hasher: &mut H,
element: &[u8],
element_pos: u64,
root: &D,
) -> bool
pub fn verify_element_inclusion<I, H>( &self, hasher: &mut H, element: &[u8], element_pos: u64, root: &D, ) -> bool
Return true if proof
proves that element
appears at position element_pos
within the
MMR with root digest root
.
Sourcepub fn verify_range_inclusion<I, H, E>(
&self,
hasher: &mut H,
elements: &[E],
start_element_pos: u64,
root: &D,
) -> bool
pub fn verify_range_inclusion<I, H, E>( &self, hasher: &mut H, elements: &[E], start_element_pos: u64, root: &D, ) -> bool
Return true if proof
proves that the elements
appear consecutively starting at position
start_element_pos
within the MMR with root digest root
.
Sourcepub fn verify_range_inclusion_and_extract_digests<I, H, E>(
&self,
hasher: &mut H,
elements: &[E],
start_element_pos: u64,
root: &D,
) -> Result<Vec<(u64, D)>, Error>
pub fn verify_range_inclusion_and_extract_digests<I, H, E>( &self, hasher: &mut H, elements: &[E], start_element_pos: u64, root: &D, ) -> Result<Vec<(u64, D)>, Error>
Reconstructs the root digest of the MMR from the digests in the proof and the provided range of elements, returning the (position,digest) of every node whose digest was required by the process (including those from the proof itself). Returns a Error::InvalidProof if the input data is invalid and Error::RootMismatch if the root does not match the computed root.
Sourcepub fn nodes_to_pin(start_pos: u64) -> impl Iterator<Item = u64>
pub fn nodes_to_pin(start_pos: u64) -> impl Iterator<Item = u64>
Return the list of pruned (pos < start_pos
) node positions that are still required for
proving any retained node.
This set consists of every pruned node that is either (1) a peak, or (2) has no descendent in the retained section, but its immediate parent does. (A node meeting condition (2) can be shown to always be the left-child of its parent.)
This set of nodes does not change with the MMR’s size, only the pruning boundary. For a given pruning boundary that happens to be a valid MMR size, one can prove that this set is exactly the set of peaks for an MMR whose size equals the pruning boundary. If the pruning boundary is not a valid MMR size, then the set corresponds to the peaks of the largest MMR whose size is less than the pruning boundary.
Sourcepub fn nodes_required_for_range_proof(
size: u64,
start_element_pos: u64,
end_element_pos: u64,
) -> Vec<u64>
pub fn nodes_required_for_range_proof( size: u64, start_element_pos: u64, end_element_pos: u64, ) -> Vec<u64>
Return the list of node positions required by the range proof for the specified range of elements, inclusive of both endpoints.
Sourcepub async fn range_proof<S: Storage<D>>(
mmr: &S,
start_element_pos: u64,
end_element_pos: u64,
) -> Result<Proof<D>, Error>
pub async fn range_proof<S: Storage<D>>( mmr: &S, start_element_pos: u64, end_element_pos: u64, ) -> Result<Proof<D>, Error>
Return an inclusion proof for the specified range of elements, inclusive of both endpoints. Returns ElementPruned error if some element needed to generate the proof has been pruned.
Sourcepub async fn historical_range_proof<S: Storage<D>>(
mmr: &S,
size: u64,
start_element_pos: u64,
end_element_pos: u64,
) -> Result<Proof<D>, Error>
pub async fn historical_range_proof<S: Storage<D>>( mmr: &S, size: u64, start_element_pos: u64, end_element_pos: u64, ) -> Result<Proof<D>, Error>
Analogous to range_proof but for a previous database state.
Specifically, the state when the MMR had size
elements.
Sourcepub async fn multi_proof<S: Storage<D>>(
mmr: &S,
positions: &[u64],
) -> Result<Proof<D>, Error>
pub async fn multi_proof<S: Storage<D>>( mmr: &S, positions: &[u64], ) -> Result<Proof<D>, Error>
Return an inclusion proof for the specified positions. This is analogous to range_proof but supports non-contiguous positions.
The order of positions does not affect the output (sorted internally).
Sourcepub fn verify_multi_inclusion<I, H, E>(
&self,
hasher: &mut H,
elements: &[(E, u64)],
root: &D,
) -> bool
pub fn verify_multi_inclusion<I, H, E>( &self, hasher: &mut H, elements: &[(E, u64)], root: &D, ) -> bool
Return true if proof
proves that the elements at the specified positions are included in the MMR
with the root digest root
.
The order of the elements does not affect the output.
Sourcepub fn extract_pinned_nodes(
&self,
start_element_pos: u64,
end_element_pos: u64,
) -> Result<Vec<D>, Error>
pub fn extract_pinned_nodes( &self, start_element_pos: u64, end_element_pos: u64, ) -> Result<Vec<D>, Error>
Extract the hashes of all nodes that should be pinned at the given pruning boundary from a proof that proves a range starting at that boundary.
§Arguments
start_element_pos
- Start of the proven range (must equal pruning_boundary)end_element_pos
- End of the proven range
§Returns
A Vec of digest values for all nodes in nodes_to_pin(pruning_boundary)
,
in the same order as returned by nodes_to_pin
(decreasing height order)
Trait Implementations§
Source§impl<D: Digest> EncodeSize for Proof<D>
impl<D: Digest> EncodeSize for Proof<D>
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
impl<D: Eq + Digest> Eq for Proof<D>
Auto Trait Implementations§
impl<D> Freeze for Proof<D>
impl<D> RefUnwindSafe for Proof<D>where
D: RefUnwindSafe,
impl<D> Send for Proof<D>
impl<D> Sync for Proof<D>
impl<D> Unpin for Proof<D>where
D: Unpin,
impl<D> UnwindSafe for Proof<D>where
D: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Encode for Twhere
T: Write + EncodeSize,
impl<T> Encode for Twhere
T: Write + EncodeSize,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more