Prashant Ram

@prashantramnyc

Blockchain Demystified: Looking Under the hood of the Blockchain

A definitive guide to understanding what makes Blockchain tick!

What is BlockChain?
Blockchain technology” is a technique by which the principles of distributed computing and hashing algorithms are applied to create a (decentralized) distributed ledger(record keeping).

BlockChain technology and principles ensures prevention(or detection) of any malicious tampering or alteration of the ledger record (without the need for an external trusted middle-party).

How does BlockChain work?
Block chain employs the use of (a) hash algorithms (eg. SHA-256), (b) chaining of hashed blocks, and (c) peer-to-peer distributed database for a robust and secure record keeping mechanism, making malicious alteration of records infeasible (i.e. highly expensive computationally).

Even though Blockchain has gain notoriety in the late 2010s, the underlying principles and technology of Blockchain have been around since the 1990s.

The principles of BlockChain were originally described in 1991 as a means to prevent backdating of digital documents and prevent tampering with digital assets. It went largely unused, until 2009 when Satoshi Nakamoto used the technique as the underlying principle to create the cryptocurrency, Bitcoin.

What problems does BlockChain solve?
Block chain principles (i.e. The ability to maintain trusted records/ledgers that are impervious to alteration), can be applied to any Use Case that requires “Trust Management” and “Trusted Record Keeping” (without the need for an external 3rd party or middle-man).

Blockchain makes trusted ledger and record keeping,

  • Transparent
  • Democratic
  • Decentralized
  • Secure

There are multiple real-world scenarios that require this trusted record keeping and trust management. Eg. wallet transaction, land records, financial transactions, election voting, car odometer reading etc. The principles of Blockchain (i.e. trusted record keeping) can be applied to several of these real-world Use Cases.

A BlockChain is a “chain of Blocks” secured using BlockChain principles. The Blocks may contain any digital assets, i.e. informational assets (eg. transaction records, ledgers, voting results, medical records etc.), or other digital assets (eg. computer programs etc.).

more on this here…

The Building Blocks of BlockChain

Hashing

In order to understand BlockChain we must first understand Hashing Algorithms.

A Hash function is a mathematical function which takes an input and produces an output. i.e. Y= H(X) , where X is the input, H() is the hash function, and Y is the output.

Hash functions have the following special properties,

  • Hash functions are one-way: 
    Given an input, the hash function can generate a “hashed” output very quickly. However it is infeasible to reverse engineer the input from the output, i.e. given an output (i.e. hashed string), it is infeasible to determine the input that generated that output.
The Hashing algorithm generates a “hash” of the input text

If we know X, using the H(), we can generate Y in a matter of milliseconds.

However if we are given Y, and asked to determine what X produced Y, this is not directly computable (and will typically require a brute force approach i.e. manually checking different X’s, passing it through H() and verifying if it produces the given Y).

  • Hash for a given input is always the same: 
    For the given input, the hash function will ALWAYS produce the same output. However, If the input in altered even slightly, the “hashed” output is completely different.
Adding a “1” in the input text, dramatically alters the hash ouput
  • The Hash output is always a fixed length: 
    The output is always a fixed length, irrespective of the size of the input string.
Hashed Output is always FIXED length

The mathematical functions that generate Hashes are well defined.

Some of the widely used hashing algorithms are MD5, SHA1 and SHA256.

Hash functions (along with Salts and Peppers) have been in common use on the internet since the late 1990s in secure password management.
Instead of securing the user password in clear text in the database, systems usually store only the “hash” of the passwords. When a user creates a password, the system uses the Hash Algorithm to generate the “hash’” of the password and stores the hash in the password table in the database. Subsequently, when the user attempts to login, the password the user enters is hashed and the hash is checked vs. the hash stored in the password table. If the “hash”’s match, then the user is allowed to login.
This way even if the system database is hacked and the passwords table is compromised, it will be impossible for the hacker to reverse engineer the clear text passwords.
more on Hash, Salt and Peppers here..

Resources:
SHA256 Hash Generator: https://passwordsgenerator.net/sha256-hash-generator/

BlockChain technology and Hashing Algorithms

BlockChain technology employs Hashing Algorithms as the building blocks to create secure Blocks of data.

In a overly simplified explination, it does this by asking the following question

Given a hashed output with some criteria, can you determine what input will generate that output? i.e. What input string, when passed through a hashing function (eg. SHA256), will generate an output string that ends in …..abc276

Given the nature of hashing algorithms (i.e. hashing algorithms are one-way), we know that to answer this question is difficult, and will possibly require brute force approach, which would translate to a great deal of computing power. After trying several million different combinations of inputs, finally one input string may generate an output string like ed892349837abd2349abc276, which will finally match the criteria.

The computation of the input string that generated this output requires a great deal of computational power, and is called “mining”.
The “?” in the above diagram which is computed during the mining process is called the Proof-of-Work or PoW

The Block and the BlockChain

Now that we understand how hashing algorithms are used in BlockChain technology, let’s take a step back now and understand what is a “Block” and the “BlockChain”.

In simplistic terms, a Block in a BlockChain consists of three main components.

  • Data, this could be any digital asset eg. transactional records, medical records etc. that we want to preserve, and prevent any unintended tampering/alterations. The type of data (digital asset) stored in the block is determined by the type of BlockChain i.e. BitCoin Blockchain stores transactional records. Other Blockchains might store voting records etc. )
  • “Hash” of the Current Block, a unique fingerprint of the block, generated using a Hashing Algorithm, eg. SHA256. If using the Hash algorithm generates a different hash than the one recorded on the block, then we know that that Block has been altered (and should be discarded).
  • “Hash” of the Previous Block, (The Hash of the previous block + the data of the current Block (+ the Proof-of-Work(PoW)) is used to generate the Hash of the current Block. i.e.
    Hash of current Block = Hash( Hash of Previous Block + Data in Current Block + PoW). This is how the Blocks become “linked” in a BlockChain. Note: The first Block of the Block chain is called in the “Genesis Block”.

Every Block in the BlockChain is “sealed” with a hash signature. This hash signature is generated by passing three components to any predefined hashing algorithm.

  1. Data in the Current Block
  2. Proof-of-Work (obtained through the “mining” process)
  3. Hash of the previous Block

To verify the integrity of the Block, any user can simply check the “sealing” hash signature on the Block and compare it with the “hash” generated by passing the above three components through the hashing algorithm.

BlockChain and Distributed Ledgers

Now let us examine how the BlockChain principles above are applied to generate distributed ledgers, using distributed databases.

  • Let’s assume that there are 5 Users in the BlockChain group. Each of the Users will maintain a distributed database copy of the BlockChain.
  • Now when any User makes an entry into the Block, that entry is recorded in the databases for all the 5 users.
  • In case of a BitCoin type BlockChain the data entries in the Block are financial transactions. Thus, if User1 sends $30 to User3, a record of the transaction is added to the Block, and this is recorded by all 5 Users.
  • Over the course of time different Users may send or receive money from other Users in the group, and each of these transactions will be recorded within a Block.
  • At some point the Block will reach its size limit and it will be time to “seal” the Block. This is done by generating a “hash”’ for the block using the 3 components defined previously i.e. the data within the Block, the hash of a previous Block, and the Proof-of-Work.
  • The process that computes the Proof-of-Work is called mining. Mining can be independently performed by any and all Users in the BlockChain group. The first User to compute the Proof-of-Work “wins” and broadcasts this PoW to the other Users in the group.
  • The other Users in the group can now use this PoW and independently verify it by passing it (along with the Block Data and Previous Block Hash), to the hashing algorithm, and comparing it with the Block Hash. If the Block is verified the Block is “sealed” and the individual Users “add” the Block to their copy of the BlockChain.
  • Now a new Block is created to record the next transaction and the process continues.

Since BlockChain by design makes it computationally infeasible for a hackers to modify or alter the BlockChain, the longest chain in the BlockChain (to which the BlockChain group has contributed to) is typically considered the honest chain (and the source of truth).

In Conclusion

The BlockChain technology is a technique that is built on the building blocks of hashing algorithms, chaining using previous block hash, and distributed databases. All these principles are combined together and reinforce each other to allow for BlockChain technology to create a distributed repository of secure, un-alterable, record keeping.

This robust, secure, and distributed record keeping that is (computationally) impervious to alteration and tampering is the core appeal of BlockChain technology.

BlockChain Vulnerabilities

While the BlockChain technology is robust and secure it does inherently have the following vulnerabilities.

  • The 51% attack
    BlockChains are vulnerable to the 51% attack due to the nature of the distributed database network. Since BlockChains rely on a distributed databases and the hash signing of a Block is determined through the democratized process of group consensus, in theory if >51% of the group decides to maliciously tamper with the BlockChains, the security of the Blocks in the Blockchain can be compromised.
    However, the general assumption is that the pool of users using the Blockchain is large and diversified the chances of the 51% attack are low.

Found this post useful? Hit the 👏 button below to show how much you liked it :)

Follow me on Medium for the latest updates and posts!

Resources:

  • How does BlockChain Work?
  • What Is Hashing? Under The Hood Of Blockchain
    https://blockgeeks.com/guides/what-is-hashing/
  • Following is a great introduction to implementing BlockChain in JS. 
    It drives home the fundamental concepts of BlockChain using implementation in JavaScript.

More by Prashant Ram

Topics of interest

More Related Stories