1 stable release
3.0.0 | Mar 12, 2021 |
---|
#31 in #membership
Used in pallet-mixer
73KB
1.5K
SLoC
Merkle Pallet
The Merkle pallet provides functionality for making and managing the Merkle trees.
Overview
The Merkle pallet provides functions for:
- Creating Merkle trees.
- Adding the manager and setting whether the manager is required.
- Adding leaf data to the Merkle tree.
- Adding nullifiers to the storage.
- Managing start/stop flags.
- Caching Merkle tree states.
- Verifying regular and zero-knowledge membership proofs
Terminology
-
Membership proof in zero-knowledge: Proving that leaf is inside the tree without revealing which leaf you are proving over.
-
Proof of creation in zero-knowledge: Each leaf is made with an arithmetic circuit which includes hashing several values. Proving to know all these values are called proof of creation.
-
Nullifier: Nullifier is a part of this leaf circuit and is revealed when proving membership in zero-knowledge. The nullifier's role is to prevent double-spending.
Implementations
The Merkle pallet provides implementations for the following traits:
Group
Functions for creating and managing the group.
Interface
Dispatchable functions
create_group
- Create Merkle tree and their respective manager account.set_manager_required
- Set whether manager is required to add members and nullifiers.set_manager
- Set manager account id. Can only be called by the root or the current manager.set_stopped
- Sets stopped storage flag. This flag by itself doesn't do anything. It's up to higher-level pallets to make appropriate use of it. Can only be called by the root or the manager;add_members
Adds an array of leaves to the tree. Can only be called by the manager if the manager is required.verify
- Verifies the membership proof.
Usage
The following examples show how to use the Merkle pallet in your custom pallet.
use pallet_merkle::traits::Group;
pub trait Config: frame_system::Config + pallet_merkle::Config {
type Group: Group<Self::AccountId, Self::BlockNumber, Self::GroupId>;
}
Dependencies
~14–24MB
~339K SLoC