Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/spacemeshos/merkle-tree

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/spacemeshos/merkle-tree

  • v0.2.6
  • Source
  • Go
  • Socket score

Version published
Created
Source

merkle-tree

Efficient on-the-fly Merkle Tree implementation. This implementation allows generating minimal partial trees that proven membership of several leaves at once, without repeating nodes in the proof or including nodes that can be calculated.

Usage

TODO: add info

How it Works

Tree Construction

This library constructs a tree sequentially, in-memory, using O(log(n)) memory (n being the number of tree leaves).

Leaves are added to the tree one-by-one using the Tree.AddLeaf() method.

The following animation illustrates the way a tree is constructed:

legend Tree construction

For each node added we do the following (the leaf layer is 0):

  • Check if there's a pending node at the current layer in pending_left_siblings.
    • If there isn't - add the currently processing node to the current layer in the list.
    • If there is - use it along with the currently processing node to calculate the parent node and add it to the tree (then clear it from the list).

When there is a power-of-two number of leaves and this process is repeated for all leaves and internal nodes encountered, the end result in the pending_left_siblings list is that all entries are empty, except the last, which represents the root of the tree.

Since we process leaves sequentially from left to right, each left sibling (odd-indexed leaf) will end up being added to pending_left_siblings until its right sibling arrives. At this time both siblings are available and their parent can be calculated. We then go up a layer and repeat the process.

Proof Construction

TODO: add info

FAQs

Package last updated on 07 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc