pub struct Proof<F: Family, D: Digest> {
pub leaves: Location<F>,
pub digests: Vec<D>,
}Expand description
Contains the information necessary for proving the inclusion of an element, or some range of elements, in a Merkle-family data structure from its root digest.
The digests vector uses a fold-based layout:
-
If there are peaks entirely before the proven range (fold prefix), the first digest is a single accumulator produced by folding those peaks:
fold(fold(..., peak0), peak1). If there are no such peaks, this entry is absent. -
The digests of peaks entirely after the proven range, in peak iteration order.
-
The sibling digests needed to reconstruct each range-peak digest from the proven elements, in depth-first (forward consumption) order for each range peak.
Fields§
§leaves: Location<F>The total number of leaves in the data structure. For MMR proofs, this is the number of leaves in the MMR, though other authenticated data structures may override the meaning of this field. For example, the authenticated crate::AuthenticatedBitMap stores the number of bits in the bitmap within this field.
digests: Vec<D>The digests necessary for proving inclusion.
Implementations§
Source§impl<F: Family, D: Digest> Proof<F, D>
impl<F: Family, D: Digest> Proof<F, D>
Sourcepub fn verify_element_inclusion<H>(
&self,
hasher: &H,
element: &[u8],
loc: Location<F>,
root: &D,
) -> boolwhere
H: Hasher<F, Digest = D>,
pub fn verify_element_inclusion<H>(
&self,
hasher: &H,
element: &[u8],
loc: Location<F>,
root: &D,
) -> boolwhere
H: Hasher<F, Digest = D>,
Return true if this proof proves that element appears at location loc within the
structure with root digest root.
Sourcepub fn verify_range_inclusion<H, E>(
&self,
hasher: &H,
elements: &[E],
start_loc: Location<F>,
root: &D,
) -> bool
pub fn verify_range_inclusion<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, root: &D, ) -> bool
Return true if this proof proves that the elements appear consecutively starting at
start_loc within the structure with root digest root.
Sourcepub fn verify_multi_inclusion<H, E>(
&self,
hasher: &H,
elements: &[(E, Location<F>)],
root: &D,
) -> bool
pub fn verify_multi_inclusion<H, E>( &self, hasher: &H, elements: &[(E, Location<F>)], root: &D, ) -> bool
Return true if this proof proves that the elements at the specified locations are included
in the structure with root digest root. A malformed proof will return false.
The order of the elements does not affect the output.
Sourcepub fn reconstruct_root<H, E>(
&self,
hasher: &H,
elements: &[E],
start_loc: Location<F>,
) -> Result<D, ReconstructionError>
pub fn reconstruct_root<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, ) -> Result<D, ReconstructionError>
Reconstruct the root digest from this proof and the given consecutive elements,
or return a ReconstructionError if the input data is invalid.
Sourcepub fn verify_range_inclusion_and_extract_digests<H, E>(
&self,
hasher: &H,
elements: &[E],
start_loc: Location<F>,
root: &D,
) -> Result<Vec<(Position<F>, D)>, Error<F>>
pub fn verify_range_inclusion_and_extract_digests<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, root: &D, ) -> Result<Vec<(Position<F>, D)>, Error<F>>
Reconstructs the root digest 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 Error::InvalidProof if the input data is invalid and Error::RootMismatch if the root does not match the computed root.
Sourcepub fn verify_proof_and_pinned_nodes<H, E>(
&self,
hasher: &H,
elements: &[E],
start_loc: Location<F>,
pinned_nodes: &[D],
root: &D,
) -> bool
pub fn verify_proof_and_pinned_nodes<H, E>( &self, hasher: &H, elements: &[E], start_loc: Location<F>, pinned_nodes: &[D], root: &D, ) -> bool
Verify that both the proof and the pinned nodes are valid with respect to root.
The pinned_nodes are the peak digests of the sub-structure at start_loc, in the order
returned by Family::nodes_to_pin. Each pinned node is either:
- A peak that precedes the proven range (fold-prefix peak). These are verified by refolding them and comparing against the proof’s fold-prefix accumulator.
- A sibling node within a range peak’s reconstruction. These are verified against the digests extracted during proof verification.
Returns true only if the proof reconstructs to root and every pinned node digest is
accounted for. When start_loc is 0, pinned_nodes must be empty.
Trait Implementations§
Source§impl<F: Family, D: Digest> EncodeSize for Proof<F, D>
impl<F: Family, D: Digest> EncodeSize for Proof<F, D>
Source§fn encode_size(&self) -> usize
fn encode_size(&self) -> usize
Source§fn encode_inline_size(&self) -> usize
fn encode_inline_size(&self) -> usize
BufsMut::push
during Write::write_bufs. Used to size the working buffer for inline
writes. Override alongside Write::write_bufs for types where large
Bytes fields go via push; failing to do so will over-allocate.Source§impl<F: Family, D: Digest> Write for Proof<F, D>
impl<F: Family, D: Digest> Write for Proof<F, D>
Source§fn write_bufs(&self, buf: &mut impl BufsMut)
fn write_bufs(&self, buf: &mut impl BufsMut)
BufsMut, allowing existing Bytes chunks to be
appended via BufsMut::push instead of written inline. Must encode
to the same format as Write::write. Defaults to Write::write.impl<F: Eq + Family, D: Eq + Digest> Eq for Proof<F, D>
Auto Trait Implementations§
impl<F, D> Freeze for Proof<F, D>
impl<F, D> RefUnwindSafe for Proof<F, D>where
F: RefUnwindSafe,
D: RefUnwindSafe,
impl<F, D> Send for Proof<F, D>
impl<F, D> Sync for Proof<F, D>
impl<F, D> Unpin for Proof<F, D>
impl<F, D> UnsafeUnpin for Proof<F, D>
impl<F, D> UnwindSafe for Proof<F, D>where
F: UnwindSafe,
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<T> EncodeExt for Twhere
T: EncodeSize + Write,
impl<T> EncodeExt for Twhere
T: EncodeSize + Write,
Source§fn encode_with_pool_mut(&self, pool: &BufferPool) -> IoBufMut
fn encode_with_pool_mut(&self, pool: &BufferPool) -> IoBufMut
Source§fn encode_with_pool(&self, pool: &BufferPool) -> IoBufs
fn encode_with_pool(&self, pool: &BufferPool) -> IoBufs
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