pub struct MerkleCap<F, Digest> { /* private fields */ }Expand description
The Merkle cap of height h of a Merkle tree is the h-th layer (from the root) of the tree.
It can be used in place of the root to verify Merkle paths, which are h elements shorter.
A cap of height 0 contains a single element (the root), while a cap of height h contains
2^h elements. The Digest type is the full digest (e.g. [W; DIGEST_ELEMS]).
The root count is always a power of two.
A cap is one full layer of a binary tree, so a layer at depth h holds 2^h digests.
The height is recovered as log_2 of the root count, which exists only for a power of two.
Every path that builds a cap enforces this, including the one that reads it off the wire.
Implementations§
Source§impl<F, Digest> MerkleCap<F, Digest>
impl<F, Digest> MerkleCap<F, Digest>
Sourcepub fn new(cap: Vec<Digest>) -> Self
pub fn new(cap: Vec<Digest>) -> Self
Wrap one full layer of digests as a cap.
§Panics
Panics when the number of digests is not a power of two.
Sourcepub const fn height(&self) -> usize
pub const fn height(&self) -> usize
Returns the height of the cap (log2 of the number of elements). A cap with 1 element has height 0, a cap with 2 elements has height 1, etc.
Sourcepub fn into_roots(self) -> Vec<Digest>
pub fn into_roots(self) -> Vec<Digest>
Flattens the cap into a single vector of digest words.
Trait Implementations§
Source§impl<'de, F, Digest: Deserialize<'de>> Deserialize<'de> for MerkleCap<F, Digest>
impl<'de, F, Digest: Deserialize<'de>> Deserialize<'de> for MerkleCap<F, Digest>
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
§Errors
Returns an error when the root count is not a power of two.
Such a count has no base-two logarithm, so the cap would have no height.
Untrusted bytes are the only route by which such a cap could reach a verifier.
impl<F: Eq, Digest: Eq> Eq for MerkleCap<F, Digest>
Source§impl<F, Digest> IntoIterator for MerkleCap<F, Digest>
impl<F, Digest> IntoIterator for MerkleCap<F, Digest>
impl<F: PartialEq, Digest: PartialEq> StructuralPartialEq for MerkleCap<F, Digest>
Auto Trait Implementations§
impl<F, Digest> Freeze for MerkleCap<F, Digest>
impl<F, Digest> RefUnwindSafe for MerkleCap<F, Digest>
impl<F, Digest> Send for MerkleCap<F, Digest>
impl<F, Digest> Sync for MerkleCap<F, Digest>
impl<F, Digest> Unpin for MerkleCap<F, Digest>
impl<F, Digest> UnsafeUnpin for MerkleCap<F, Digest>
impl<F, Digest> UnwindSafe for MerkleCap<F, Digest>
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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