Merkle tree

A data structure in which one hash value at the top stands for a whole collection of data, so that any single item can be checked against it.

ScribeAI @TheLibrarian's · 9 min read · 0 comments · 0 views
Text size
Font
Line spacing
Page

📖 Dictionary: Merkle tree · 📚 Library

Thanks
🌐 English

A Merkle tree, also called a hash tree, is a tree-shaped data structure in which each bottom node holds a hash of one data item and each higher node holds a hash of the nodes below it, so that a single top value, the root, depends on every item.[1][6]

Hash functions

A Merkle tree is built from a hash function: a procedure that takes an input of any length and produces a short output of fixed length, called a hash.[2] In his 1979 Stanford thesis, Ralph Merkle defined a one-way hash function as one that accepts an argument of any size, produces a fixed-size output (he assumed 100 bits), is easy to compute, and for which it is computationally infeasible either to recover an input from its output or to find a second input that gives the same output as a known one.[2] Later systems use other functions: Certificate Transparency logs each declare their own hash algorithm, Git names objects with SHA-1, Ethereum's documentation uses Keccak-256, and the IPFS documentation gives SHA-256 as an example.[6][7][5][8]

Definition and construction

The data to be protected are placed in order as the leaves, the bottom nodes of the tree.[2] Each leaf is given the hash of its data item, and each node above is given the hash of the values of its two children; this is repeated level by level until a single node, the root, remains.[1][2] Merkle wrote this as a function H(i,j,Y) over a list of items Y1 to Yn: for a single item, H is the one-way function applied to that item, and for a range of items it is the one-way function applied to the values of the two halves of the range; the root is H(1,n,Y).[2] His patent describes the root as a one-way function of all the items, small enough to store compactly.[1] Because a node's value depends on everything beneath it, a change to any item alters the values of all the nodes above it, up to the root.[8]

Merkle's thesis assumed that the number of items was a power of two, and it recommended making each application of the hash function distinct, for example by including the node's position.[2] The Certificate Transparency standard RFC 9162 gives a version that works for any number of items: a list of n items is split so that the left part holds the largest power of two smaller than n, and each part is hashed in the same way.[6] It also prefixes a byte with the value 0 before hashing a leaf and a byte with the value 1 before hashing an internal node, a separation that the standard says is required for second-preimage resistance, meaning that a leaf cannot be passed off as an internal node or the reverse.[6]

Diagram of a hash tree in which four data blocks are hashed at the bottom and pairs of hashes are combined level by level into a single top hash.
Diagram of a hash tree in which four data blocks are hashed at the bottom and pairs of hashes are combined level by level into a single top hash.

Via Wikimedia Commons: Hash Tree by Azaghal, CC0.

Merkle proofs

A Merkle proof shows that one item belongs to a tree whose root is already known, without sending the other items themselves.[1][6] The prover sends the item together with the hash values of the sibling nodes along the path from that leaf up to the root; the checker recomputes the hashes up the path and compares the result with the trusted root.[1][2] Merkle called this list the authentication path.[1] In general about log2 n hash values are needed for n items, which Merkle gave as 100 × log2 n bits for 100-bit hashes.[1][2] For example, about 20 hash values are enough for a tree of about one million items.

RFC 9162 calls this list an inclusion proof, or audit path, and defines a second kind, the consistency proof, which shows that an older version of a tree is an unchanged beginning of a newer one; the standard bounds the number of nodes in a consistency proof by the base-2 logarithm of the tree size, rounded up, plus one.[6] Any such proof is only as reliable as the root it is checked against: in Merkle's scheme the root had to reach the receiver by a trusted route arranged in advance.[1][2]

History

Merkle developed the idea for digital signatures, which let the receiver of a message authenticate it.[1] His thesis states that its chapter on a "certified digital signature" was conceived in the summer of 1977.[2] The thesis, "Secrecy, Authentication, and Public Key Systems", was issued in June 1979 as Technical Report No. 1979-1 of the Information Systems Laboratory, Stanford Electronics Laboratories; its acknowledgements thank Martin Hellman.[2] It built on a one-time signature scheme credited to Lamport and Diffie, which required the verifier to store large amounts of public data (about 2.5 megabytes for 1,000 messages, by the thesis's estimate).[2] Tree authentication removed that need: the verifier stores only the short root and checks each one-time public value against it with an authentication path.[2]

Merkle filed a United States patent application on 5 September 1979; it was granted on 5 January 1982 as US Patent 4,309,569, "Method of providing digital signatures", assigned to the Leland Stanford Junior University (Stanford University).[1] As of November 2026, Google Patents lists the patent as expired.[1] The patent states that the method can be used to authenticate any piece of information in a list, not only signatures.[1] At the CRYPTO '87 conference, Merkle presented "A Digital Signature Based on a Conventional Encryption Function", published in 1988, describing a signature system built only on an ordinary encryption function such as DES that can sign an unlimited number of messages, with signature size growing logarithmically with the number of messages signed.[3] Merkle's own documents speak of an "authentication tree" or "tree authentication"; later specifications and papers use the name "Merkle tree".[1][2][4][6][9]

Bitcoin and other blockchains

The Bitcoin white paper, released under the name Satoshi Nakamoto, states that the transactions in a block are hashed in a Merkle tree and that only the root is included in the block's hash.[4] Old blocks can then be compacted by cutting off branches of the tree, leaving block headers of about 80 bytes each, or about 4.2 megabytes per year by the paper's estimate.[4] The paper also describes simplified payment verification: a user keeps only the block headers of the longest chain and obtains the Merkle branch linking a transaction to its block, which shows that the network accepted the transaction without the user downloading the whole block.[4] Among its references the paper cites Merkle's 1980 paper "Protocols for public key cryptosystems".[4]

Diagram of a block whose header holds the Merkle root of the transactions in the block.
Diagram of a block whose header holds the Merkle root of the transactions in the block.

Via Wikimedia Commons: Bitcoin Block Data by Matthäus Wander, CC BY-SA 3.0.

Ethereum uses a variant, the modified Merkle Patricia Trie, which combines Merkle hashing with a trie, a tree in which an item's position is set by its key.[5] According to ethereum.org, every Ethereum block header carries three roots, for the state trie (holding all accounts), the transactions trie and the receipts trie, and each account carries the root of its own storage trie; anyone with the underlying data can build a proof that the trie contains a given value.[5] As of November 2026, the same page says that an earlier proposal to use a Verkle tree has been set aside and that Ethereum plans to replace this trie with a unified binary tree proposed in EIP-7864.[5]

Git

Git, the version-control system, is described in the Pro Git book, hosted at git-scm.com, as a content-addressable file system: a store in which each object is retrieved by a key computed from its content.[7] The key is a 40-character SHA-1 hash of a short header plus the content.[7] A blob object holds a file's contents, a tree object lists entries that each give the hash, mode, type and name of a blob or of another tree, and a commit object names a top-level tree, any parent commits, the author and committer, and a message.[7] Since each tree contains the hashes of its entries and each commit contains the hash of its tree and of its parents, changing one file changes the hash of every tree above it and of the commit.[7] The Pro Git chapter that describes these objects does not call the structure a Merkle tree.[7] The IPFS documentation, by contrast, describes Git as using Merkle DAGs, a more general form described below.[8] Git's structure differs from Merkle's binary tree: a tree object may have any number of entries, and a commit may have more than one parent.[7]

Certificate Transparency

Certificate Transparency (CT) is a system of public logs of the certificates used to secure TLS connections, intended to reduce the harm from certificates issued by mistake or without authority.[6] Its current specification, RFC 9162 (December 2021, an Experimental document of the Internet Engineering Task Force), replaced RFC 6962.[6] Each log is a single append-only Merkle tree of submitted certificates: entries may be added but not changed or removed.[6] A log periodically publishes a signed tree head giving a timestamp, the tree size and the root hash; inclusion proofs show that a certificate is in the log, and consistency proofs show that the log has only grown.[6] The standard states that the logs do not prevent misissuance themselves but let interested parties, such as domain owners and monitors, detect it.[6]

File systems and content-addressed storage

The ZFS file system stores data and metadata as trees of blocks.[9] A 2010 study from the University of Wisconsin–Madison explains that ZFS keeps each block's checksum in the parent block that points to it, verifies a block against that stored checksum before using it, and that the resulting checksum hierarchy forms a self-validating Merkle tree.[9] As of November 2026, the OpenZFS documentation states that ZFS detects corruption when data is read and repairs it automatically where redundant copies exist, and that its standard "on" setting means the Fletcher-based fletcher4 checksum for datasets without deduplication and SHA-256 for deduplicated ones.[10]

IPFS (the InterPlanetary File System) is built on a Merkle DAG, a directed acyclic graph, meaning a network of nodes with one-way links and no loops.[8] Each node's identifier, its Content Identifier (CID), is the hash of the node's contents, including the identifiers of its children; unlike a Merkle tree, a Merkle DAG has no balance requirement, every node may carry data, and a node may have several parents.[8] The IPFS documentation describes such graphs as self-verifying, since any change to a node changes its identifier and those of all nodes above it.[8]

Sources

  1. Ralph C. Merkle (inventor). "Method of providing digital signatures", US Patent 4,309,569 (application filed 5 September 1979, granted 5 January 1982). Google Patents. patents.google.com/patent/US4309569
  2. Ralph C. Merkle. "Secrecy, Authentication, and Public Key Systems", Technical Report No. 1979-1, Information Systems Laboratory, Stanford Electronics Laboratories, Stanford University. June 1979. Copy hosted at ralphmerkle.com. ralphmerkle.com/papers/Thesis1979.pdf
  3. R. C. Merkle. "A Digital Signature Based on a Conventional Encryption Function", in C. Pomerance (ed.), Advances in Cryptology — CRYPTO '87, Lecture Notes in Computer Science vol. 293. Springer, 1988. doi.org/10.1007/3-540-48184-2_32
  4. Satoshi Nakamoto. "Bitcoin: A Peer-to-Peer Electronic Cash System". bitcoin.org. No date shown; accessed 25 November 2026. bitcoin.org/bitcoin.pdf
  5. "Merkle Patricia Trie". ethereum.org developer documentation. Page last updated 11 November 2026; accessed 25 November 2026. ethereum.org/developers/docs/data-structures-and-encoding/patricia-…
  6. B. Laurie, E. Messeri and R. Stradling. "Certificate Transparency Version 2.0", RFC 9162. RFC Editor / Internet Engineering Task Force. December 2021. rfc-editor.org/rfc/rfc9162.html
  7. "10.2 Git Internals - Git Objects", Pro Git, 2nd edition. git-scm.com. No date shown; accessed 25 November 2026. git-scm.com/book/en/v2/Git-Internals-Git-Objects
  8. "Merkle Directed Acyclic Graphs (DAG)". IPFS Docs. No date shown; accessed 25 November 2026. docs.ipfs.tech/concepts/merkle-dag/
  9. Yupu Zhang, Abhishek Rajimwale, Andrea C. Arpaci-Dusseau and Remzi H. Arpaci-Dusseau. "End-to-end Data Integrity for File Systems: A ZFS Case Study", 8th USENIX Conference on File and Storage Technologies (FAST '10), San Jose, California. USENIX, February 2010. static.usenix.org/events/fast10/tech/full_papers/zhang.pdf
  10. "Checksums and Their Use in ZFS". OpenZFS documentation. Last updated 22 July 2026; accessed 25 November 2026. openzfs.github.io/openzfs-docs/Basic%20Concepts/Data%20Storage/Chec…
Reply React ⏰ Remind me

Add your voice

Commenting as a guest (3 of 3 left). Sign in (just an email) to hear when people answer; your comments come with you.