BlockX Labs

@blockxlabs

Trees & Hash: An in-depth look at the Bitcoin Halvening

By: Jesse Abramowitz
Blockchain Developer

Recently, a co-worker came across an article on the bitcoin halvening. Which is actually happening super soon…like in just over 480 days. She was saying she was having some trouble finding articles with technical explanations of this and after explaining it, it seemed like it was a good article to write.

Let’s get ahead of the curve and I will do my best to explain what is happening technically, but also ELI5. First we need to understand some basics about the blockchain.

Hash

Hashes are used throughout the computing world. There are many different uses of a hash and ways to calculate them but let’s keep it basic.

Hashing is how you can take a string and convert it into a fixed output assortment of numbers and letters. Some hallmarks of a hash are:

  • They are one way functions — you can turn the string to a hash but not the hash to the corresponding string
  • The same string will always produce the same hash
  • If you change the string slightly you change the hash significantly

Hashes are used a lot in bitcoin but for the sake of this article, they are used to represent transactions as strings of numbers that are easy for computers to store and look up. This will come in handy later in the article.

Why take my word for it? let’s make some hashes instead! If you are on a Mac or Linux open up your terminal and type:

echo ‘hello world’ | md5 

As we see here, we take a string ‘hello world’ and turn it into an md5 hash. Everytime we run it, it will give us the same hash. If I change it a little by removing a space, it will produce a significantly different output.

Merkle Trees

What do we have now? We have a bunch of transactions in a block all represented as hashes. The blockchain itself is meant to be open, honest, and auditable. It is a “Trust but always verify mentality” which is supposed to be immutable.

Hash functions can help us with immutability. If a person were to take a transaction and change it, we can very easily and programatically see this by using hash functions. One small change leads to a significantly different outcome.

However, if we want to audit the whole blockchain it can take a long time to go through each and every hash and manually checking each one. This is similar to organizing books in a library with the dewey decimal system. In this case, we also organize all these hashes and through merkle trees.

Each block has a bunch of transactions and all of those transactions are hashed. These hashes form the base layer of a pyramid. The hashes are then math-ed again and hashed and so on and so forth all the way up to the top of the pyramid which we call the root hash.

This root hash is then hashed again with the hash of the previous block.

Just for ease of reference, let me find a picture that best describes Merkle Trees:

Thank you to our Marketing & Operations Officer, Laura for the lovely accurate picture of me.

This next picture will probably be more helpful:

Thus, if I ever want to verify any information on the blockchain all I need to do is check the block hashes against other people’s block hashes or my own. If they are the same, I can be certain that none of the information has been tampered with.

Proof Of Work

Now we have gone through all of this we get to a point of game theory. Someone needs to calculate all this and decide what is true or false.

To do this, it involves everyone competing to solve a math problem that it hard to solve but easy to calculate. Guess what this has to do with?

Hashes!

It kinda goes like this:

Bitcoin Protocol: Hey puny mortal get me a block hash that with some math done to it we get a number with x amount of 0s in the result.

Miners: Sure, this seems like a great use of my time

Random Miner: Got it!

Everyone else: Let’s check to make sure this is right

Rewards

Lastly, the person who completes this math, receives a reward. Originally, it was 50 BTC but it halves around every four years. Currently it is down to 12.5 BTC and it is set to halve again in just a little over a year.

Takeaways

The question is: does this have any real world effects? It should make sense that the blockhash adds security to the Bitcoin network.

Think about it: if I want to change or fake a transaction, I would need to change a block in the blockchain, that would change its blockhash. Since all blockhashes are linked by the previous hash, you would have to change every block after that. All of this math would need to be resolved at a higher level of difficulty and surpass the chain in length that is currently accepted as the Bitcoin chain.

This is called a 51% attack.

By definition, you would need at least 51% of the hash power of the bitcoin network to do it since you would need to go back rewrite and then surpass all the current blocks. Which you can’t do with less computing power than half the network.

Soooooooooooooooooooooooooooooo ya.

51% attacks are definitely possible. In fact, this recently happened to Ethereum Classic. It is important to understand that ETC was a significantly lower hash rate that Bitcoin (by, like, a lot):

42 million trillion hashes per second to ETC’s 8 trillion hashes per second, to be exact.

Bitcoin is not really in danger of a 51% attack. It is hard and expensive to mine bitcoin now and eventually that reward will halve again. If a price increase does not accompany this halving then we could see the bitcoin hash rate drop.

This will also mean that the reward for attacking the bitcoin network will also drop. Much like this following quote: “If you are trying to protect $500 in a safe make sure the safe costs $501 to break into”(source unknown).

The world will come to an end Bitcoin will be hackable!!!!!!

Not really. But this is definitely something fun to talk and think about. Hopefully, you have a better understanding of the halvening after reading this!

Are you excited about the Bitcoin Halvening? What do you think of Satoshi’s mechanism to decrease inflation? Let us know in the comments!

Jesse Abramowitz is a Blockchain Developer at BlockX Labs. He has worked on multiple DApps, projects, and Blockchain Networks. Currently, he is also a lab assistant at a local college and is always looking to help, teach and build on the blockchain.

You can reach him at: jesse@blockxlabs.com

More by BlockX Labs

Topics of interest

More Related Stories