Struct winter_crypto::BatchMerkleProof
source · [−]pub struct BatchMerkleProof<H: Hasher> { /* private fields */ }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.
Implementations
sourceimpl<H: Hasher> BatchMerkleProof<H>
impl<H: Hasher> BatchMerkleProof<H>
sourcepub fn from_paths(
paths: &[Vec<H::Digest>],
indexes: &[usize]
) -> BatchMerkleProof<H>
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.,
pathsis 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.
sourcepub fn get_root(&self, indexes: &[usize]) -> Result<H::Digest, MerkleTreeError>
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.,
indexesis an empty slice). - Number of provided indexes is greater than 255.
- Any of the specified
indexesis 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.
sourcepub fn serialize_nodes(&self) -> Vec<u8>
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.
sourcepub fn deserialize<R: ByteReader>(
node_bytes: &mut R,
leaves: Vec<H::Digest>,
depth: u8
) -> Result<Self, DeserializationError>
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.,
leavesis an empty slice). - Number of provided leaves is greater than 255.
- Tree
depthwas set to zero. node_bytescould not be deserialized into a valid set of internal nodes.
Trait Implementations
sourceimpl<H: Clone + Hasher> Clone for BatchMerkleProof<H> where
H::Digest: Clone,
H::Digest: Clone,
impl<H: Clone + Hasher> Clone for BatchMerkleProof<H> where
H::Digest: Clone,
H::Digest: Clone,
sourcefn clone(&self) -> BatchMerkleProof<H>
fn clone(&self) -> BatchMerkleProof<H>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl<H: Debug + Hasher> Debug for BatchMerkleProof<H> where
H::Digest: Debug,
H::Digest: Debug,
impl<H: Debug + Hasher> Debug for BatchMerkleProof<H> where
H::Digest: Debug,
H::Digest: Debug,
sourceimpl<H: PartialEq + Hasher> PartialEq<BatchMerkleProof<H>> for BatchMerkleProof<H> where
H::Digest: PartialEq,
H::Digest: PartialEq,
impl<H: PartialEq + Hasher> PartialEq<BatchMerkleProof<H>> for BatchMerkleProof<H> where
H::Digest: PartialEq,
H::Digest: PartialEq,
sourcefn eq(&self, other: &BatchMerkleProof<H>) -> bool
fn eq(&self, other: &BatchMerkleProof<H>) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourcefn ne(&self, other: &BatchMerkleProof<H>) -> bool
fn ne(&self, other: &BatchMerkleProof<H>) -> bool
This method tests for !=.
impl<H: Eq + Hasher> Eq for BatchMerkleProof<H> where
H::Digest: Eq,
H::Digest: Eq,
impl<H: Hasher> StructuralEq for BatchMerkleProof<H>
impl<H: Hasher> StructuralPartialEq for BatchMerkleProof<H>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more