Skip to content


Subversion checkout URL

You can clone with
Download ZIP
An authenticated data structure based on a red-black tree.
Python C++ Haskell
branch: master

Tree dot fixed. First LLRB implementation. Header index cached in a p…


Signed-off-by: Andrew Miller <>
latest commit ded13a7c9b
@amiller authored

Red-Black Merkle Tree

This is a reference implementation of a Self-Balancing Merkle Search Tree (i.e., an Authenticated Data Structure [0]). This can be used to efficiently represent the essential state necessary to validate Bitcoin [1] transactions: the set of available unspent transaction outputs (UTXOs).

Authenticated Data Structures are used in protocols between three parties: 1) the trusted Source, which creates data and publishes a digest; 2) the untrusted Server, which maintains a copy of the data and responds to queries; and 3) the Client, which verifies the Server's responses against the known digest. In this implementation, the data structure requires O(N) storage and each operation takes O(log N) time. These operations can also be verified in worst-case O(log N) time using a Verification Object (a path through a Merkle tree). A verifying Client is only required to maintain O(1) state (specifically, the Merkle tree root hash).

  • RedBlack is a general purpose Red-Black binary search tree [3] that can easily be augmented with a 'digest' function. Typically, the digest should include a secure hash function, forming a dynamic Merkle tree [4].

  • a specialization of RedBlack by definining a digest/serialization protocol appropriate for Bitcoin UTXOs.

  • a script that iterates through the Bitcoin blockchain, from the genesis block to the head, incrementally updating the RedBlack as it goes (requires Gavin Andresen's python bitcointools.

  • treedot: produces graphviz illustrations of the tree (requires graphviz (dot))

  • test_redblack: unit tests for RedBlack


[0] Authenticated Data Structures. Roberto Tamassia. 2003

Something went wrong with that request. Please try again.