Skip to main content

merkle-zeppelin

CI/CD pre-commit

PyPI Version PyPI - Status PyPI - Downloads

Python Versions License

A Merkle Tree library aligned with OpenZeppelin's implementation standards.

What's the purpose of Merkle Tree

By storing just one value, the server can confirm whether a specific value belongs to a previously constructed tree.
The server needs to store only the root hash of the tree.
Requests must include the value to be verified along with a list of hashes specific to that value—known as proofs.
This algorithm is particularly valuable when saving storage space is more important than computational power.

How the Tree is Constructed

The animation demonstrates the algorithm constructing a tree for proof verification or calculation. The letters at the bottom represent a list of items stored in the program's memory.

Constructing the tree

Note that dividing the number of each node in the final tree by 2 (without remainder) identifies its parent node. The None placeholder ensures the first element is indexed at 1, not 0, maintaining this parent-child relationship.

Each element, represented by one or more letters, is a hashed value. For instance, given a, ..., e, we have A = hash(a), ..., E = hash(e), where AB = hash(A + B) = hash(hash(a) + hash(b)), and so on.

This library allows selection of the hash function, with keccak256 set as the default to match the OpenZeppelin implementation.

Collecting Proofs

Consider the example below:

Collecting proofs

To collect proofs for a specific value, locate the leaf containing the hash of that value. Collect the sibling's value, move up to the parent node, and repeat until you reach the root.

The proofs are the sibling values collected on this path.

Note

  • To find a sibling's node number, use current_node_number ^ 1.
  • To find a parent's node number, use current_node_number // 2.

Verifying Proofs

To verify proofs, you only need the root value. For example:

value = b
proofs = [A, E, CD]
  1. Hash the value b to get B.
  2. Combine B with the first proof and hash result: hash(A + B) = AB.
  3. Combine AB with the second proof and hash result: hash(AB + E) = ABE.
  4. Combine ABE with the third proof and hash result: hash(ABE + CD) = ABECD, which is the calculated root.
  5. If the calculated root matches the stored root value, it confirms that the value b is part of the tree.

Metadata

Release files for merkle-zeppelin 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for merkle-zeppelin 1.0.0
File Size Uploaded
merkle_zeppelin-1.0.0.tar.gz 1.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for merkle-zeppelin 1.0.0
File Interpreter ABI Platform
merkle_zeppelin-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.7 MB

Release files / merkle_zeppelin-1.0.0.tar.gz

Download URL merkle_zeppelin-1.0.0.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
313a2c6a37a25a36e6e6f5d3b3998c03662110b7cb53c489b660a8862966c114
BLAKE2b-256 checksum
How to use checksums
cf91795dcbfe9a282286f727c36dbc0339da0299f689d0597f6525fd0191fdce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.3

Release files / merkle_zeppelin-1.0.0-py3-none-any.whl

Download URL merkle_zeppelin-1.0.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d36a827c0b3af74c85200a9de1f7742f5856aabbe305d937126c72a5e2e140a8
BLAKE2b-256 checksum
How to use checksums
5aa926b2e63fc501eda2dbbc942b22388b991f03627a0aab4634e477e9d62d80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page