Understanding bitcoin and its underlying technology “blockchain” — Part (1/3)

Chirag Bhattad
7 min readAug 26, 2018

Please note that this is a post which will go deep into some concepts like Secure Hash Algorithm, Merkel tree, etc. So if you are not ready to absorb dense computation concepts, then this post is not for you.

I’ve done by best to tone down the math and make sure that the post is readable for a beginner entering into the world of cryptocurrency

Abstract:

Providing a starting point to understand Blockchain technology, the cryptocurrency Bitcoin and how the two are interlinked. Taking a look at the need for the above technology, understanding what are the underlying principles behind the technology, analyzing their strengths and weaknesses along with possible applications.

Introduction:

This blogpost tries to outline the Blockchain technology, the use of the cryptocurrency Bitcoins and the emergence of UPI in India. It is not an in-depth analysis of any of the above three technologies, but it does take a look at the three of the most path-breaking, high-profile destructive inventions of the digital era.

Blockchain technology is, in simple terms, a decentralized digital ledger which stores an aggregation of transactions in blocks. All the blocks are connected via chains, leading to the name Blockchain. The ledger itself is impenetrable, because it is not stored in a singular location. Instead, these blocks are distributed across the world, back-linked using chains, with each block holding the cryptographic signature of the previous block. Once a transaction is recorded in this digital ledger, it cannot be modified unless we can access all the blocks previous to the particular block, which is extremely difficult due to the decentralization.

The Blockchain technology itself, was never published independently. It was first proposed by a person/organization/super-computer, Satoshi Nakamoto in his October 2008 paper, Bitcoin: A Peer-to-Peer Electronic Cash System. The paper proposed a Peer-to-Peer transaction of electronic cash, which would remove the the banking and financial institutes, a.k.a the third party. Blockchain took care of storing the digital signature of each transaction in a secure and accessible way while Bitcoin, a cryptocurrency, was the Electronic cash which Satoshi Nakamoto proposed. Blockchain timestamped the digital transactions by hashing them into an ongoing chain of hash-based Proof Of Work (PoW). This legitimized the security of Blockchain, as the record cannot be changed without redoing this PoW.

Bitcoin is the first ever decentralized cryptocurrency, which means this currency is not dependent on a financial institution or a person. Bitcoin transactions can take place digital and between two person directly, without the need for an intermediary, in other words, bitcoin transactions are peer-to-peer and decentralized. As of 2017, atleast 5 million users are using a cryptocurrency wallet, with bitcoin still holding its charm as the most sought after cryptocurrency. To earn a bitcoin, a person or an organization needs to do a process called mining. The main attraction of bitcoin is that it is not governed and regularized by a central authority and thus it cannot be mis-used or affected by any body or institution.

Blockchain and Bitcoin:

Blockchain, at its heart, is a distributed digital ledger. It was combined with the cryptocurrency Bitcoin when it was first envisioned by Satoshi Nakamoto. Blockchain has been historically confused with being a part of bitcoin, when in fact the blockchain technology is the reason behind the existence of bitcoins and other cryptocurrencies. Apart from digital currencies, blockchains can be used for smart contracts, automated voting systems and maintenance of a decentralized digital records for various sectors.

Blockchain is a decentralized, digital ledger with each transaction registered with a time stamp. The meaning of Decentralization is that the ledger is not stored in one fixed physical location. Instead, it is distributed over its network of nodes, with a small part of the ledger stored in each node. This way, the chances of the data in the ledger getting attacked and destroyed are minuscule, since there is no way to know where the pieces of the ledger are located. The timestamp associated with each transactions are used to order the data.

Bitcoin Hashing:

Hashing is a popular encryption process which is also used to manage and store data structures. The input data is passed through a hash function, which performs a series of calculations which results in the output of a hash value. This hash value is unique to the input data and the original data can only be retrieved using the hash function. Hashing is used for cryptographic security, data verification and encryption.

The Hash algorithm or hash function, is in crux, similar to any other function. It takes an input data of any size and transforms it into a fixed alphanumeric string. This alphanumeric string depends on the type of hash function being used. The hash function is designed to produce a unique output and it is a one-way function. To understand how the has function cannot be used to reverse engineer the original data, use the analogy of thumb and fingerprint. The original human thumb is the input and the thumb fingerprint is the output. The digital fingerprint can never be used to generate an actual human thumb.

FIG. 1. Hashing process explained using a simple flowchart

Secure Hash Algorithm:

Developed by the National Security Agency (NSA) in 2001, the SHA256 is a cryptographic hash algorithm which generates a 256 bit hexadecimal number for any input data. This output is unique and depends on each and every bit of the input data. Changing even a single bit of input data could change the output. This sensitive property is called the Avalanche Effect, similar to the sensitivity of certain semiconductors.

Bitcoins uses the SHA256 algorithm to mine blocks. Using this algorithm, bitcoin miners solve computationally difficult mathematical problems with each solution resulting in the generation of a new block which can be added into the blockchain. But this is not the end of the process. Like the H1B VISA lottery system, the fate of the blocks produced is decided by a lottery system. This lottery system is the Proof of Work for the Bitcoins.

FIG. 2. SHA256 algorithm’s flowchart.

Blocks:

Blocks are tumblers which are filled with an aggregation of digital transaction records, which are timestamped and encrypted. These blocks are hashed and encoded into a Merkel tree. Every block contains a key which points to the previous block. This key is cryptographically hashed and leads to the chaining of the two blocks. The process of chaining helps connect the blockchains into a single network, which makes it easy to reproduce and difficult to hack.

FIG. 3. Visualizing chained blocks in a blockchain.

Merkel Tree:

Merkel Tree or hash tree is a tree where the leaf node contains the hash value of the input data while the internal nodes contain the cryptographic hash values of its children. Thus, the input data, which passes through the SHA256 hash algorithm, resulting in the output of the hash value for the input data. This hash value is stored into the leaf nodes of the tree, with the internal nodes holding the encrypted values of its children.

Merkel trees are used specifically in a peer-to-peer network to verify the data received against the root of the Merkel tree. The following protocol is used to verify data:

  • Peer A sends a hash of the file to the Peer B.
  • Peer B checks the hash against the root of the Merkel tree.
  • If verification is not achieved from the above step, then Peer B requests for the hash of the two subtrees.
  • Peer A sends the hash of the subtrees to Peer B.
  • The above two steps are iteratively repeated till the data blocks that are inconsistent are pin pointed.

Since the Peers are sending over only hash values across the networks, the process goes very quickly. Also, it separates the validation of data from the data itself, thus increasing the security of the whole process. Merkel Trees require only O(log n) time complexity for Data Synchronization and Data Search, making it a faster application than other trees.

FIG. 4. Visualizing a Merkel Tree to understand the content of the internal nodes and leaves.

Note:

The first part of this three part post was aimed at introducing the concept of blockchain and how bitcoin was created leveraging this technology. The first post dived into the concepts of Hashing, understood the Secure Hash Algorithm, learnt what a typical block contains in it and studied a Merkel tree.

The second part of this post will cover forking, the Proof of Work concepts and explain what block time means. I will then talk about the Double Spending problem and explain what the 51% attack is, which you would have heard of in the famous HBO show “Silicon Valley” (SPOILER ALERT!!)

--

--