Usar Merkle trees para datos verification
Merkle trees hash datos en un tree estructura, enabling efficient verification de individual elements sin downloading el entire dataset.
- 1
A Merkle tree hashes data blocks at the leaves, then pairs and hashes up to a single root. To verify a block, you need the block and its Merkle proof (sibling hashes along the path to the root). Verification is O(log n) instead of O(n) — you don't need all data, just the proof. Used in Bitcoin, Git, ZFS, and certificate transparency logs.
- 2 Calculadora de hash →
Hash each data block to create leaf nodes. Use SHA-256 (Bitcoin) or SHA-3. Pair leaves and hash their concatenation to create parent nodes. Repeat until one node remains — the Merkle root. The root commits to all data: any change in a leaf changes the root.
- 3 Hash SHA-3 / Keccak →
Use SHA-3-256 for Merkle tree hashing. SHA-3 is resistant to length extension attacks (unlike SHA-2), making it safer for Merkle trees where hash concatenation is used. Alternatively, use SHA-256 with a domain separator (e.g., hash(0x00 || left || right) for internal nodes, hash(0x01 || data) for leaves).
Preguntas frecuentes
- What is a Merkle proof?
- A Merkle proof for a leaf consists of the sibling hashes along the path from the leaf to the root. For a tree with n leaves, the proof has log2(n) hashes. To verify: hash the leaf, combine with the proof hashes in the correct order, and check if the result equals the root. This proves the leaf is in the tree without downloading all data.
- Where are Merkle trees used?
- Bitcoin (transaction verification in blocks), Git (content-addressable storage), ZFS (data integrity), Apache Cassandra (anti-entropy repair), Certificate Transparency (log verification), and IPFS (content addressing). Any system that needs efficient verification of large datasets benefits from Merkle trees.