pub struct BatchMerkleProof<H: Hasher> {
    pub leaves: Vec<H::Digest>,
    pub nodes: Vec<Vec<H::Digest>>,
    pub depth: u8,
}
Expand description

Multiple Merkle paths aggregated into a single proof.

The aggregation is done in a way which removes all duplicate internal nodes, and thus, it is possible to achieve non-negligible compression as compared to naively concatenating individual Merkle paths. The algorithm is for aggregation is a variation of Octopus.

Currently, at most 255 paths can be aggregated into a single proof. This limitation is imposed primarily for serialization purposes.

Fields§

§leaves: Vec<H::Digest>

The leaves being proven

§nodes: Vec<Vec<H::Digest>>

Hashes of Merkle Tree proof values above the leaf layer

§depth: u8

Depth of the leaves

Implementations§

source§

impl<H: Hasher> BatchMerkleProof<H>

source

pub fn from_paths( paths: &[Vec<H::Digest>], indexes: &[usize] ) -> BatchMerkleProof<H>

Constructs a batch Merkle proof from individual Merkle authentication paths.

§Panics

Panics if:

  • No paths have been provided (i.e., paths is an empty slice).
  • More than 255 paths have been provided.
  • Number of paths is not equal to the number of indexes.
  • Not all paths have the same length.
source

pub fn get_root(&self, indexes: &[usize]) -> Result<H::Digest, MerkleTreeError>

Computes a node to which all Merkle paths aggregated in this proof resolve.

§Errors

Returns an error if:

  • No indexes were provided (i.e., indexes is an empty slice).
  • Number of provided indexes is greater than 255.
  • Any of the specified indexes is greater than or equal to the number of leaves in the tree for which this batch proof was generated.
  • List of indexes contains duplicates.
  • The proof does not resolve to a single root.
source

pub fn into_paths( self, indexes: &[usize] ) -> Result<Vec<Vec<H::Digest>>, MerkleTreeError>

Computes the uncompressed Merkle paths which aggregate to this proof.

§Errors

Returns an error if:

  • No indexes were provided (i.e., indexes is an empty slice).
  • Number of provided indexes is greater than 255.
  • Number of provided indexes does not match the number of leaf nodes in the proof.
source

pub fn serialize_nodes(&self) -> Vec<u8>

Converts all internal proof nodes into a vector of bytes.

§Panics

Panics if:

  • The proof contains more than 255 Merkle paths.
  • The Merkle paths consist of more than 255 nodes.
source

pub fn deserialize<R: ByteReader>( node_bytes: &mut R, leaves: Vec<H::Digest>, depth: u8 ) -> Result<Self, DeserializationError>

Parses internal nodes from the provided node_bytes, and constructs a batch Merkle proof from these nodes, provided leaves, and provided tree depth.

§Errors

Returns an error if:

  • No leaves were provided (i.e., leaves is an empty slice).
  • Number of provided leaves is greater than 255.
  • Tree depth was set to zero.
  • node_bytes could not be deserialized into a valid set of internal nodes.

Trait Implementations§

source§

impl<H: Clone + Hasher> Clone for BatchMerkleProof<H>
where H::Digest: Clone,

source§

fn clone(&self) -> BatchMerkleProof<H>

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<H: Debug + Hasher> Debug for BatchMerkleProof<H>
where H::Digest: Debug,

source§

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

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

impl<H: PartialEq + Hasher> PartialEq for BatchMerkleProof<H>
where H::Digest: PartialEq,

source§

fn eq(&self, other: &BatchMerkleProof<H>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<H: Eq + Hasher> Eq for BatchMerkleProof<H>
where H::Digest: Eq,

source§

impl<H: Hasher> StructuralPartialEq for BatchMerkleProof<H>

Auto Trait Implementations§

§

impl<H> Freeze for BatchMerkleProof<H>

§

impl<H> RefUnwindSafe for BatchMerkleProof<H>
where <H as Hasher>::Digest: RefUnwindSafe,

§

impl<H> Send for BatchMerkleProof<H>

§

impl<H> Sync for BatchMerkleProof<H>

§

impl<H> Unpin for BatchMerkleProof<H>
where <H as Hasher>::Digest: Unpin,

§

impl<H> UnwindSafe for BatchMerkleProof<H>
where <H as Hasher>::Digest: UnwindSafe,

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> 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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>,

§

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.