pub struct BatchMerkleProof<H: Hasher> {
pub nodes: Vec<Vec<H::Digest>>,
pub depth: u8,
}Expand description
Multiple Merkle proofs 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 proofs. The algorithm is for aggregation is a variation of Octopus.
Fields§
§nodes: Vec<Vec<H::Digest>>Hashes of Merkle Tree proof values above the leaf layer
depth: u8Depth of the leaves
Implementations§
Source§impl<H: Hasher> BatchMerkleProof<H>
impl<H: Hasher> BatchMerkleProof<H>
Sourcepub fn from_single_proofs(
proofs: &[(<H as Hasher>::Digest, Vec<<H as Hasher>::Digest>)],
indexes: &[usize],
) -> BatchMerkleProof<H>
pub fn from_single_proofs( proofs: &[(<H as Hasher>::Digest, Vec<<H as Hasher>::Digest>)], indexes: &[usize], ) -> BatchMerkleProof<H>
Constructs a batch Merkle proof from collection of single Merkle proofs.
§Panics
Panics if:
- No proofs have been provided (i.e.,
proofsis an empty slice). - Number of proofs is not equal to the number of indexes.
- Not all proofs have the same length.
Sourcepub fn get_root(
&self,
indexes: &[usize],
leaves: &[H::Digest],
) -> Result<H::Digest, MerkleTreeError>
pub fn get_root( &self, indexes: &[usize], leaves: &[H::Digest], ) -> Result<H::Digest, MerkleTreeError>
Computes a node to which all Merkle proofs aggregated in this proof resolve.
§Errors
Returns an error if:
- No indexes were provided (i.e.,
indexesis an empty slice). - 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 into_openings(
self,
leaves: &[H::Digest],
indexes: &[usize],
) -> Result<Vec<(<H as Hasher>::Digest, Vec<<H as Hasher>::Digest>)>, MerkleTreeError>
pub fn into_openings( self, leaves: &[H::Digest], indexes: &[usize], ) -> Result<Vec<(<H as Hasher>::Digest, Vec<<H as Hasher>::Digest>)>, MerkleTreeError>
Computes the uncompressed individual Merkle proofs which aggregate to this batch proof.
§Errors
Returns an error if:
- No indexes were provided (i.e.,
indexesis an empty slice). - Number of provided indexes does not match the number of leaf nodes in the proof.
Trait Implementations§
Source§impl<H: Clone + Hasher> Clone for BatchMerkleProof<H>
impl<H: Clone + Hasher> Clone for BatchMerkleProof<H>
Source§fn clone(&self) -> BatchMerkleProof<H>
fn clone(&self) -> BatchMerkleProof<H>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<H: Hasher> Deserializable for BatchMerkleProof<H>
impl<H: Hasher> Deserializable for BatchMerkleProof<H>
Source§fn read_from<R: ByteReader>(
source: &mut R,
) -> Result<Self, DeserializationError>
fn read_from<R: ByteReader>( source: &mut R, ) -> Result<Self, DeserializationError>
Parses internal nodes from the provided source, and constructs a batch Merkle proof
from these nodes.
§Errors
Returns an error if:
sourcecould not be deserialized into a valid set of internal nodes.
Source§fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
fn read_from_bytes(bytes: &[u8]) -> Result<Self, DeserializationError>
Source§impl<H: Hasher> Serializable for BatchMerkleProof<H>
impl<H: Hasher> Serializable for BatchMerkleProof<H>
Source§fn write_into<W: ByteWriter>(&self, target: &mut W)
fn write_into<W: ByteWriter>(&self, target: &mut W)
Writes all internal proof nodes into the provided target.