Buck Perley gives an overview of BHN in this seven minute demo.
Why We Built BHN
Developers told us they wanted to verify Chainpoint proofs without needing to run a full Bitcoin node, or use an API provider such as Blockcypher. We built BHN to make it simple to verify a Chainpoint proof.
Chainpoint proofs are used to verify the integrity and timestamp of any data. Each Chainpoint proof contains a series of operations that commits some data to a Bitcoin block header. With just a Chainpoint proof (~1kb) and an 80 byte block header you can prove the integrity and timestamp of any data. You simply process the operations in the Chainpoint proof to calculate an expected hash value. The proof is valid if the hash matches the Merkle Root in a Bitcoin block header.
BHN provides a lightweight way to check if the Merkle Root in your Chainpoint proof exists in a Bitcoin block, without using a third-party api or running a Bitcoin full node. Before BHN, the lightest alternative would be an SPV (Simplified Payment Verification) node which requires about 170MB of disk space. While this is less than the ~200GB of disk space needed by a Bitcoin Full Node, we wanted to see if we could build something light enough to run in a browser extension or mobile device.
To reach this goal, we focused on two areas:
BHN strips out all data not necessary to validate block headers and Bitcoin’s Proof-of-Work
BHN can ignore blocks earlier than a specific block height
Because the Chainpoint protocol launched in 2015, the oldest block you could need for verification is January 1st, 2015. Earlier blocks don’t need to be downloaded.
BHN with all of the relevant blocks for verifying Chainpoint proofs is approximately 30MB and syncs in an hour. An SPV node takes a couple hours to sync, and requires over 5x more storage. A full node requires over 6,600x more disk space and can take days to sync.
How BHN Works
BHN connects to Bitcoin nodes, syncs headers from a specified block height, verifies Proof-of-Work locally, and exposes an API that lets you get header data. Let’s start by setting up BHN and showing how we’re incorporating it into Chainpoint.
BHN can be installed via npm or downloaded directly from the GitHub repo. It can also be installed as a package and used within a JS project just like a normal bcoin node.
To startup BHN from a custom start height* all you have to do is run the following commands:
$ npm install -g bhn #installs bhn in your global node_modules directory
$ bhn --start-height=337022
You can use the HTTP API to interact with BHN. Most options available on a normal bcoin node can be passed to a BHN node. This can be done with curl, the CLI tool bclient, or in a JS script. For all available methods, see the BHN readme on GitHub and the bcoin API docs.
Chainpoint CLI Integration
We have integrated BHN directly into an upcoming version of the Chainpoint CLI. Using the same CLI tool you use to interact with the Chainpoint network, you can:
start and stop a bhn node
check BHN’s status
get a block header
execute many bitcoin RPC methods
Best of all, the Chainpoint CLI will verify all proofs against BHN, if you have one running. If you don’t run BHN, the CLI will fallback to asking remote Chainpoint nodes.
Built using Bcoin
Bcoin’s modular architecture makes it simple to include only the modules your application needs. This was key to creating a lightweight BHN. Many modules of a Bitcoin Full Node weren’t required. BHN needed a database for persisting the header information, an http/RPC server for communication, a network pool for communicating with peers, and an ephemeral chain for tracking and verifying incoming blocks. BHN didn’t need things like a mempool, wallet, miner, or to persist full block data.
A recent bcoin update added an Indexer interface, which listens for events that indicate a new block has been received and then indexes relevant data. We extended this Indexer interface, to persist a database of only the block header data that we need.
We hope developers find Bitcoin Header Node useful. Try BHN for yourself, review the code, and leave any comments, questions, or requests on GitHub.