Struct winter_crypto::BatchMerkleProof
source · 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
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.,
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.
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.,
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.
sourcepub fn into_paths(
self,
indexes: &[usize]
) -> Result<Vec<Vec<H::Digest>>, MerkleTreeError>
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.
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.,
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
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>
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more