The question
Rather than learning Rust through another collection of disconnected exercises, I wanted to implement something directly related to my professional domain: blockchain engineering.
A Merkle tree seemed like a natural starting point. It is conceptually straightforward, cryptographically significant and sufficiently interesting from a data structure perspective to explore some of Rust's defining characteristics.
My objective was not to build a production-ready cryptographic library, but to understand both the language and the structure through implementation.
What is a Merkle tree?
A Merkle tree, named after cryptographer Ralph Merkle, is a hierarchical data structure in which leaf nodes contain cryptographic hashes of data, whilst internal nodes contain hashes derived from their children.

The resulting root, known as the Merkle root, acts as a cryptographic commitment to the underlying data.
Changing even a single piece of data changes its corresponding hash and, consequently, the hashes along the path towards the root.
What makes this structure particularly interesting is that proving the inclusion of an element does not require revealing or processing the entire dataset. Instead, a Merkle proof provides the sibling hashes necessary to reconstruct and verify the root.
In a balanced binary Merkle tree, this reduces the size of an inclusion proof to O(log n).
This property is fundamental to blockchain infrastructure. Bitcoin, for instance, uses Merkle trees to commit to the transactions contained within a block. Ethereum employs related cryptographic tree structures, notably the Merkle Patricia trie, for commitments to state, transactions and receipts.
Although their implementations differ, the underlying principle remains remarkably elegant: verifying the integrity or inclusion of information without requiring possession of all the information itself.
What I learnt
Coming from Go, one of the most interesting aspects of Rust is how differently the two languages approach simplicity.
Go deliberately restricts the language to reduce the cognitive overhead of writing and maintaining software. Rust, on the other hand, introduces a considerably richer set of concepts to provide stronger guarantees about the behaviour of a program.
Neither approach is inherently superior. They simply address complexity at different levels.
Implementing a Merkle tree helped me understand that ownership and borrowing are not merely syntactical peculiarities imposed by an unnecessarily demanding compiler. They are mechanisms through which the programmer describes the relationships between data, memory and responsibility.
A hash does not necessarily need to own the data from which it was derived. A function does not necessarily need to consume its arguments to produce a result. A tree does not necessarily need to allocate every node independently.
Rust encourages the programmer to make these distinctions consciously.
There is something profoundly elegant about a language that forces you to understand what your program is doing, rather than merely describing what you want it to accomplish.
The experiment also reinforced my appreciation for the Merkle tree itself. From a handful of relatively simple operations emerges a structure capable of providing cryptographic commitments and efficient inclusion proofs over potentially enormous datasets.
This is precisely the sort of elegance that fascinates me in software engineering: sophisticated properties emerging from relatively simple, well-defined rules.
What comes next
There are several directions in which I would like to extend this experiment:
- Complete and validate Merkle proof generation and verification.
- Explore different strategies for handling an odd number of leaves.
- Compare recursive and contiguous representations.
- Benchmark construction time and memory consumption.
- Investigate sparse Merkle trees and Merkle Patricia tries.
- Compare the implementation with established blockchain protocols.
- Explore parallel construction using Rust's concurrency model.
Ultimately, this experiment is not exclusively about Merkle trees, nor is it exclusively about Rust.
It is about understanding the fundamental structures upon which the systems I work with every day are built.
There is a considerable difference between knowing that a blockchain uses cryptographic trees and understanding the engineering decisions that make those trees possible.
I would rather understand the latter.