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 max_encode_size(siblings: usize) -> usize
pub fn max_encode_size(siblings: usize) -> usize
Returns an upper bound on the encoded size of a proof with at most siblings sibling
digests.
Sourcepub fn verify_element_inclusion<H: Hasher<Digest = D>>(
&self,
leaf: &D,
position: u32,
root: &D,
) -> Result<(), Error>
pub fn verify_element_inclusion<H: Hasher<Digest = D>>( &self, leaf: &D, position: u32, root: &D, ) -> Result<(), Error>
Verifies that a given leaf at position is included in a Binary Merkle Tree
with root.
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,
elements: &[(D, u32)],
root: &D,
) -> Result<(), Error>
pub fn verify_multi_inclusion<H: Hasher<Digest = D>>( &self, 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.
Positions must be strictly ascending and in range. The error names the first position in input order that is out of range, repeats the previous one, or precedes it.
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,
position: u32,
leaves: &[D],
root: &D,
) -> Result<(), Error>
pub fn verify_range_inclusion<H: Hasher<Digest = D>>( &self, 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§fn encode_inline_size(&self) -> usize
fn encode_inline_size(&self) -> usize
BufsMut::push
during Write::write_bufs. Used to size the fixed working buffer for
inline writes, so it must not be less than the bytes written inline.
Override alongside Write::write_bufs for types where large
byte fields go via push, or the working buffer will over-allocate.impl<D: Eq + Digest> Eq for Proof<D>
Source§impl<D: Digest> Read for Proof<D>
impl<D: Digest> Read for Proof<D>
impl<D: PartialEq + Digest> StructuralPartialEq for Proof<D>
Source§impl<D: Digest> Write for Proof<D>
impl<D: Digest> Write for Proof<D>
Source§fn write_bufs(&self, buf: &mut impl BufsMut)
fn write_bufs(&self, buf: &mut impl BufsMut)
BufsMut, allowing existing byte chunks to be
appended via BufsMut::push instead of written inline. Must encode
to the same format as Write::write. Defaults to Write::write.Auto Trait Implementations§
impl<D> Freeze for Proof<D>
impl<D> RefUnwindSafe for Proof<D>where
Vec<D>: RefUnwindSafe,
impl<D> Send for Proof<D>
impl<D> Sync for Proof<D>
impl<D> Unpin for Proof<D>
impl<D> UnsafeUnpin for Proof<D>where
Vec<D>: UnsafeUnpin,
impl<D> UnwindSafe for Proof<D>where
Vec<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> Codec for T
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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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> ⓘ
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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