Crate pallet_merkle[][src]

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>;
}

Re-exports

pub use traits::Group;
pub use pallet::*;

Modules

pallet

Implementation of Merkle pallet

traits

All the traits exposed to be used in other custom pallets

utils

Utility functions and data type definitions

weights

Autogenerated weights for pallet_merkle

Structs

GroupTree

Essential data about the tree

Manager

Data about the manager of the GroupTree

Functions

default_hasher

Default hasher instance used to construct the tree