Merkle Tree Generator Online | Build & Verify Proofs (SHA-256/Keccak)
Hash Functions How It Works
This tool builds Merkle trees from a list of leaf data and generates cryptographic proofs entirely in your browser. It supports SHA-256/SHA-512 (Web Crypto API) and Keccak-256 (@noble/hashes, loaded as a lazy chunk). Choose between duplicate or promote odd-leaf rules, raw or sorted-pair concatenation (OpenZeppelin compatible), then click any leaf to get its authentication path or paste a proof to verify membership.
Algorithm Comparison
| Algorithm | Output Size | Used by | Best for |
|---|---|---|---|
| SHA-256 | 256-bit (32 bytes) | Bitcoin, TLS, general-purpose | Standard Merkle trees, blockchain |
| SHA-512 | 512-bit (64 bytes) | High-security systems | Larger digest, collision resistance |
| Keccak-256 | 256-bit (32 bytes) | Ethereum, Solidity | EVM compatibility, smart contracts |
Code Examples
Build and verify a Merkle tree with @noble/hashes:
// Browser — SHA-256 Merkle tree
import { sha256 } from '@noble/hashes/sha256';
// Hash leaves
const leaves = ['a', 'b', 'c', 'd'].map(
x => sha256(new TextEncoder().encode(x))
);
// Build tree (duplicate odd-leaf rule)
let level = leaves;
while (level.length > 1) {
const next = [];
for (let i = 0; i < level.length; i += 2) {
const left = level[i];
const right = level[i + 1] || level[i]; // duplicate
next.push(sha256(new Uint8Array([...left, ...right])));
}
level = next;
}
const root = level[0];
console.log('Merkle root:', Array.from(root).map(b => b.toString(16).padStart(2, '0')).join('')); # Python — SHA-256 Merkle tree
import hashlib
def merkle_root(leaves):
if not leaves:
return None
level = [hashlib.sha256(l.encode()).digest() for l in leaves]
while len(level) > 1:
next_level = []
for i in range(0, len(level), 2):
left = level[i]
right = level[i + 1] if i + 1 < len(level) else level[i]
next_level.append(hashlib.sha256(left + right).digest())
level = next_level
return level[0].hex()
print(merkle_root(['a', 'b', 'c', 'd'])) Security Notes
- Merkle proofs are logarithmic — for N leaves, proof size is O(log N), making them efficient for large datasets.
- Root is tamper-evident — changing any single leaf produces a completely different root.
- Match conventions exactly — hash function, leaf encoding, odd-leaf rule, and concatenation mode must all match between tree builder and verifier.
- Sorted-pair simplifies verification — OpenZeppelin mode eliminates left/right position tracking in smart contracts.
Related Tools
Need to generate a plain hash? Try the SHA Hash Generator. For HMAC generation with a secret key, see the HMAC Generator. You can also verify digital signatures with the Digital Signature & Verify tool.
Frequently Asked Questions
What is the difference between duplicate and promote odd-leaf rules?
When a tree level has an odd number of nodes, the last node is unpaired. "Duplicate" (Bitcoin convention) hashes the odd node with itself. "Promote" carries the odd node to the next level unchanged. Both produce valid trees but different roots — match the convention of the system you are verifying against.
What is sorted-pair (OpenZeppelin) concatenation?
In standard (raw) mode, left and right child hashes are concatenated in order before re-hashing. In sorted-pair mode (used by OpenZeppelin's MerkleProof library), the two hashes are compared byte-by-byte and the smaller one goes first. This eliminates the need to encode left/right position in proofs, simplifying smart contract verification.
Which hash algorithms are supported?
SHA-256 (Bitcoin standard), SHA-512, and Keccak-256 (Ethereum's original hash, distinct from NIST SHA3-256). All three produce 256-bit or 512-bit digests. Keccak-256 is used by Ethereum for Merkle-Patricia tries and Solidity's abi.encodePacked.
Why doesn't my root match another tool's root?
Merkle roots are only comparable when all conventions match: same hash function, same leaf encoding (UTF-8 vs hex), same odd-leaf rule (duplicate vs promote), and same concatenation mode (raw vs sorted). A mismatch in any one produces a completely different root.
How do I verify a leaf belongs to the tree?
Switch to Verify mode, paste the expected Merkle root, the leaf data, and the proof JSON (array of sibling hashes). The tool recomputes the root by hashing the leaf with each proof step, then compares it to your expected root. If they match, the leaf is provably part of the tree.
Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.
More in Hash
SHA Hash Generator
Generate SHA-256 or SHA-512 hashes from text or files online. Real-time computation, batch upload with CSV export, Hex/Base64 output.
Hash Compare
Compute and compare SHA-1, SHA-256, SHA-384, and SHA-512 hashes side by side online. Hex/Base64 output for checksum verification.
HMAC Generator
Generate HMAC (Hash-based Message Authentication Code) online with SHA-256/384/512. UTF-8/Hex/Base64 input and output, real-time computation.
Bcrypt Hash Generator
Generate and verify bcrypt password hashes online. Adjustable cost factor (4-20), real bcryptjs implementation, Node.js compatible.