Struct MerkleTree

Source
pub struct MerkleTree<E, H, I, const ARITY: usize, T>
where E: Element, H: DigestAlgorithm<E, I, T>, I: Index, T: NodeValue,
{ /* private fields */ }
Expand description

A standard append only Merkle tree implementation

Implementations§

Source§

impl<E, H, I, const ARITY: usize, T> MerkleTree<E, H, I, ARITY, T>
where E: Element, H: DigestAlgorithm<E, I, T>, I: Index, T: NodeValue,

Source

pub fn new(height: usize) -> Self

Initialize an empty Merkle tree.

Source§

impl<E, H, const ARITY: usize, T> MerkleTree<E, H, u64, ARITY, T>
where E: Element, H: DigestAlgorithm<E, u64, T>, T: NodeValue,

Source

pub fn from_elems( height: Option<usize>, elems: impl IntoIterator<Item = impl Borrow<E>>, ) -> Result<Self, MerkleTreeError>

Construct a new Merkle tree with given height from a data slice

  • height - height of the Merkle tree, if None, it will calculate the minimum height that could hold all elements.
  • elems - an iterator to all elements
  • returns - A constructed Merkle tree, or Err() if errors

Trait Implementations§

Source§

impl<E, H, const ARITY: usize, T> AppendableMerkleTreeScheme for MerkleTree<E, H, u64, ARITY, T>
where E: Element, H: DigestAlgorithm<E, u64, T>, T: NodeValue,

Source§

fn push( &mut self, elem: impl Borrow<Self::Element>, ) -> Result<(), MerkleTreeError>

Insert a new value at the leftmost available slot Read more
Source§

fn extend( &mut self, elems: impl IntoIterator<Item = impl Borrow<Self::Element>>, ) -> Result<(), MerkleTreeError>

Insert a list of new values at the leftmost available slots Read more
Source§

impl<E, H, I, const ARITY: usize, T> Clone for MerkleTree<E, H, I, ARITY, T>
where E: Element + Clone, H: DigestAlgorithm<E, I, T> + Clone, I: Index + Clone, T: NodeValue + Clone,

Source§

fn clone(&self) -> MerkleTree<E, H, I, ARITY, T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E, H, I, const ARITY: usize, T> Debug for MerkleTree<E, H, I, ARITY, T>
where E: Element + Debug, H: DigestAlgorithm<E, I, T> + Debug, I: Index + Debug, T: NodeValue + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, E, H, I, const ARITY: usize, T> Deserialize<'de> for MerkleTree<E, H, I, ARITY, T>
where E: Element + CanonicalSerialize + CanonicalDeserialize, H: DigestAlgorithm<E, I, T>, I: Index + CanonicalSerialize + CanonicalDeserialize, T: NodeValue,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<E, H, I, const ARITY: usize, T> ForgetableMerkleTreeScheme for MerkleTree<E, H, I, ARITY, T>
where E: Element, H: DigestAlgorithm<E, I, T>, I: Index + ToTraversalPath<ARITY>, T: NodeValue,

Source§

fn from_commitment( com: impl Borrow<Self::Commitment>, height: usize, num_leaves: u64, ) -> Self

Rebuild a merkle tree from a commitment. Return a tree which is entirely forgotten.
Source§

fn forget( &mut self, pos: impl Borrow<Self::Index>, ) -> LookupResult<Self::Element, Self::MembershipProof, ()>

Trim the leaf at position i from memory, if present. Should not trim if position i is the last inserted leaf position. Return is identical to result if get_leaf(pos) were called before this call.
Source§

fn remember( &mut self, pos: impl Borrow<Self::Index>, element: impl Borrow<Self::Element>, proof: impl Borrow<Self::MembershipProof>, ) -> Result<(), MerkleTreeError>

“Re-insert” a leaf into the tree using its proof. Returns Ok(()) if insertion is successful, or Err(err) if the proof disagrees with the merkle tree
Source§

impl<E, H, I, const ARITY: usize, T> Hash for MerkleTree<E, H, I, ARITY, T>
where E: Element + Hash, H: DigestAlgorithm<E, I, T> + Hash, I: Index + Hash, T: NodeValue + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, E, H, I, const ARITY: usize, T> IntoIterator for &'a MerkleTree<E, H, I, ARITY, T>
where E: Element, H: DigestAlgorithm<E, I, T>, I: Index + ToTraversalPath<ARITY>, T: NodeValue,

Source§

type Item = (&'a I, &'a E)

The type of the elements being iterated over.
Source§

type IntoIter = MerkleTreeIter<'a, E, I, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E, H, I, const ARITY: usize, T> IntoIterator for MerkleTree<E, H, I, ARITY, T>
where E: Element, H: DigestAlgorithm<E, I, T>, I: Index + ToTraversalPath<ARITY>, T: NodeValue,

Source§

type Item = (I, E)

The type of the elements being iterated over.
Source§

type IntoIter = MerkleTreeIntoIter<E, I, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<E, H, I, const ARITY: usize, T> MerkleTreeScheme for MerkleTree<E, H, I, ARITY, T>
where E: Element, H: DigestAlgorithm<E, I, T>, I: Index + ToTraversalPath<ARITY>, T: NodeValue,

Source§

const ARITY: usize = ARITY

Tree ARITY
Source§

type Element = E

Merkle tree element type
Source§

type Index = I

Index type for this merkle tree
Source§

type NodeValue = T

Internal and root node value
Source§

type MembershipProof = MerkleTreeProof<T>

Merkle proof
Source§

type BatchMembershipProof = ()

Batch proof
Source§

type Commitment = T

Merkle tree commitment
Source§

fn height(&self) -> usize

Return the height of this merkle tree
Source§

fn capacity(&self) -> BigUint

Return the maximum allowed number leaves
Source§

fn num_leaves(&self) -> u64

Return the current number of leaves
Source§

fn commitment(&self) -> Self::Commitment

Return a merkle commitment
Source§

fn lookup( &self, pos: impl Borrow<Self::Index>, ) -> LookupResult<&Self::Element, Self::MembershipProof, ()>

Returns the leaf value given a position Read more
Source§

fn verify( commitment: impl Borrow<Self::Commitment>, pos: impl Borrow<Self::Index>, element: impl Borrow<Self::Element>, proof: impl Borrow<Self::MembershipProof>, ) -> Result<Result<(), ()>, MerkleTreeError>

Verify an element is a leaf of a Merkle tree given the proof Read more
Source§

fn iter(&self) -> MerkleTreeIter<'_, E, I, T>

Return an iterator that iterates through all element that are not forgotten
Source§

impl<E, H, I, const ARITY: usize, T> PartialEq for MerkleTree<E, H, I, ARITY, T>

Source§

fn eq(&self, other: &MerkleTree<E, H, I, ARITY, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<E, H, I, const ARITY: usize, T> Serialize for MerkleTree<E, H, I, ARITY, T>
where E: Element + CanonicalSerialize + CanonicalDeserialize, H: DigestAlgorithm<E, I, T>, I: Index + CanonicalSerialize + CanonicalDeserialize, T: NodeValue,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<E, H, I, const ARITY: usize, T> Eq for MerkleTree<E, H, I, ARITY, T>
where E: Element + Eq, H: DigestAlgorithm<E, I, T> + Eq, I: Index + Eq, T: NodeValue + Eq,

Source§

impl<E, H, I, const ARITY: usize, T> StructuralPartialEq for MerkleTree<E, H, I, ARITY, T>
where E: Element, H: DigestAlgorithm<E, I, T>, I: Index, T: NodeValue,

Auto Trait Implementations§

§

impl<E, H, I, const ARITY: usize, T> Freeze for MerkleTree<E, H, I, ARITY, T>

§

impl<E, H, I, const ARITY: usize, T> RefUnwindSafe for MerkleTree<E, H, I, ARITY, T>

§

impl<E, H, I, const ARITY: usize, T> Send for MerkleTree<E, H, I, ARITY, T>
where H: Send, I: Sync + Send, E: Sync + Send, T: Send,

§

impl<E, H, I, const ARITY: usize, T> Sync for MerkleTree<E, H, I, ARITY, T>
where H: Sync, I: Sync + Send, E: Sync + Send, T: Send,

§

impl<E, H, I, const ARITY: usize, T> Unpin for MerkleTree<E, H, I, ARITY, T>
where H: Unpin,

§

impl<E, H, I, const ARITY: usize, T> UnwindSafe for MerkleTree<E, H, I, ARITY, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Element for T
where T: Clone + Eq + PartialEq + Hash,