pub struct Proof<D: Digest> {
pub leaf_count: u32,
pub siblings: Vec<D>,
}Expand description
A Merkle proof for multiple non-contiguous leaves in a Binary Merkle Tree.
This proof type is more space-efficient than generating individual proofs for each leaf because sibling nodes that are shared between multiple paths are deduplicated.
The proof contains the leaf count and sibling digests required for verification. The leaf count is incorporated into the root hash during finalization, so modifying it will cause verification to fail (preventing malleability attacks).
Fields§
§leaf_count: u32The number of leaves in the tree.
This value is incorporated into the root hash during finalization, so modifying it will cause verification to fail (prevents malleability).
siblings: Vec<D>The deduplicated sibling digests required to verify all elements, ordered by their position in the tree (level-major, then index within level).
Implementations§
Source§impl<D: Digest> Proof<D>
impl<D: Digest> Proof<D>
Sourcepub fn verify_element_inclusion<H: Hasher<Digest = D>>(
&self,
hasher: &mut H,
leaf: &D,
position: u32,
root: &D,
) -> Result<(), Error>
pub fn verify_element_inclusion<H: Hasher<Digest = D>>( &self, hasher: &mut H, leaf: &D, position: u32, root: &D, ) -> Result<(), Error>
Verifies that a given leaf at position is included in a Binary Merkle Tree
with root using the provided hasher.
The proof consists of sibling hashes stored from the leaf up to the root. At each level, if the current node is a left child (even index), the sibling is combined to the right; if it is a right child (odd index), the sibling is combined to the left.
The leaf_count stored in the proof is incorporated into the finalized root
computation, so any modification to it will cause verification to fail.
Sourcepub fn verify_multi_inclusion<H: Hasher<Digest = D>>(
&self,
hasher: &mut H,
elements: &[(D, u32)],
root: &D,
) -> Result<(), Error>
pub fn verify_multi_inclusion<H: Hasher<Digest = D>>( &self, hasher: &mut H, elements: &[(D, u32)], root: &D, ) -> Result<(), Error>
Verifies that the given elements at their respective positions are included
in a Binary Merkle Tree with root.
Elements can be provided in any order; positions are sorted internally. Duplicate positions will cause verification to fail.
The leaf_count stored in the proof is incorporated into the finalized root
computation, so any modification to it will cause verification to fail.
Sourcepub fn verify_range_inclusion<H: Hasher<Digest = D>>(
&self,
hasher: &mut H,
position: u32,
leaves: &[D],
root: &D,
) -> Result<(), Error>
pub fn verify_range_inclusion<H: Hasher<Digest = D>>( &self, hasher: &mut H, position: u32, leaves: &[D], root: &D, ) -> Result<(), Error>
Verifies that a contiguous range of leaves starting at position are included
in a Binary Merkle Tree with root.
This is a convenience method for verifying range proofs. The leaves must be
in order starting from position.
The leaf_count stored in the proof is incorporated into the finalized root
computation, so any modification to it will cause verification to fail.
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
Source§impl<D: Digest> Read for Proof<D>
impl<D: Digest> Read for Proof<D>
impl<D: Eq + Digest> Eq for Proof<D>
impl<D: Digest> StructuralPartialEq 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