How to manually verify the merkle root of a Bitcoin block (command line)

Jordan Baczuk
Coinmonks

--

Let’s do it again! (see How to manually verify block hash) for a similar article

Source: Investopedia

Merkle Trees

“A hash tree is a tree [usually binary tree] of hashes in which the leaves are hashes of data blocks in, for instance, a file or set of files.” [1] Why not just hash all of the data at once you say? Because it is not as efficient. In applications like Bitcoin when this is done fairly frequently (for tx validation, etc.) this gets costly.

Join people in 22 countries around the world in my course on Become a Bitcoin + Blockchain Programmer.

Calculation

Lets assume that Ha and Hb have already been calculated from the data Ta and Tb and that:

Ha = b1fea52486ce0c62bb442b530a3f0132b826c74e473d1f2c220bfa78111c5082
Hb = f4184fc596403b9d638783cf57adfe4c75c605f6356fbc91338530e9831e9e16

First, we must reverse the bytes (they need to be little endian) because that is how Bitcoin calculates the hashes. You can use this python script, if you like:

#!/usr/bin/env pythonline = raw_input("Input original hex string\n")n = 2
orig_list = [line[i:i+n] for i in range(0, len(line), n)]
reversed_list =…

--

--