pub trait MerkleTreeScheme: Sized {
type Element: Element;
type Index: Index;
type NodeValue: NodeValue;
type MembershipProof: MerkleProof<Self::NodeValue>;
type BatchMembershipProof: Clone;
type Commitment: NodeValue;
const ARITY: usize;
// Required methods
fn height(&self) -> usize;
fn capacity(&self) -> BigUint;
fn num_leaves(&self) -> u64;
fn commitment(&self) -> Self::Commitment;
fn lookup(
&self,
pos: impl Borrow<Self::Index>,
) -> LookupResult<&Self::Element, Self::MembershipProof, ()>;
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>;
fn iter(
&self,
) -> MerkleTreeIter<'_, Self::Element, Self::Index, Self::NodeValue>;
}
Expand description
Basic functionalities for a merkle tree implementation. Abstracted as an accumulator for fixed-length array. Supports generating membership proof at a given position and verify a membership proof.
Required Associated Constants§
Required Associated Types§
Sourcetype MembershipProof: MerkleProof<Self::NodeValue>
type MembershipProof: MerkleProof<Self::NodeValue>
Merkle proof
Sourcetype BatchMembershipProof: Clone
type BatchMembershipProof: Clone
Batch proof
Sourcetype Commitment: NodeValue
type Commitment: NodeValue
Merkle tree commitment
Required Methods§
Sourcefn num_leaves(&self) -> u64
fn num_leaves(&self) -> u64
Return the current number of leaves
Sourcefn commitment(&self) -> Self::Commitment
fn commitment(&self) -> Self::Commitment
Return a merkle commitment
Sourcefn lookup(
&self,
pos: impl Borrow<Self::Index>,
) -> LookupResult<&Self::Element, Self::MembershipProof, ()>
fn lookup( &self, pos: impl Borrow<Self::Index>, ) -> LookupResult<&Self::Element, Self::MembershipProof, ()>
Returns the leaf value given a position
pos
- zero-based index of the leaf in the treereturns
- Leaf value at the position along with a proof. LookupResult::EmptyLeaf if the leaf position is empty or invalid, LookupResult::NotInMemory if the leaf position has been forgotten.
Sourcefn verify(
commitment: impl Borrow<Self::Commitment>,
pos: impl Borrow<Self::Index>,
element: impl Borrow<Self::Element>,
proof: impl Borrow<Self::MembershipProof>,
) -> Result<Result<(), ()>, MerkleTreeError>
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
commitment
- a merkle tree commitmentpos
- zero-based index of the leaf in the treeelement
- the leaf valueproof
- a membership proof forelement
at givenpos
returns
- Ok(true) if the proof is accepted, Ok(false) if not. Err() if the proof is not well structured, E.g. not for this merkle tree.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.