Close this search box.

An introduction to blockchain – hashes, pointers & blocks

Right now, Cloud infrastructure and big data are two of the most in demand technology areas. I think that blockchain will be next. Let’s look at how blockchain works & some potential use-cases.

Before we get into what blockchain is exactly, we need to understand a few terms. First, a hash. A hash function converts string of any length into a string of bits of a fixed length. It’s an identifier for the data. For example, if we hash the string ‘something to say’, the hashed value is: b'{\xfcp^\xb7<jE\xc7O\xda\xdbWm\xe2\xcc\xed\xe8X\xa6\xf6\x93\xcb\x87\xbc\xda\xb3\x9f6\xcbK%’

The interesting thing is, if we change the string very slightly to ‘something to says’ (adding an S to the end), the hash is entirely different. Making the smallest change to the input, results in a completely different output. We refer tot his as being non-malleable. b’\tI\xd2\xbc\xe5\xfa\xd5\xd2%3\xec0tR\x02\xcd\x90O\xe6\x83\x8f[\xfb\x85\x89\xf6j\x8b\x1c\x82&\xa8′

Hashes are also collision resistant. While is it possible that two completely different messages would hash to the same value, this is very rare. We can hash in Python as below. Note that SHA256 creates a 256 bit hash of the data. SHA512 would be a 512 bit hash.

from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.exceptions import *
digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
digest.update(b'something to say')

Now, we need to understand what a pointer is. A pointer is simply a variable which stores the address of a given datapoint / file. A hash pointer stores the address of the variable but also the hash of the entire data stored at that address.

Finally, we have a linked list. This is a data structure where each node has a pointer to the previous or next node. We traverse through the list by moving from one node to the previous, to the previous and so on.

These are the core components of a Blockchain. In the below diagram, we have a 3 block chain (which is a linked list). Each block contains a hash of the previous blocks data (the first block will simply have 000000 as there is no previous block); the hash of its own data and has a pointer back to the previous block. The blocks are cryptographically linked together, as each block contains the fingerprint (or hash) of the previous block.

To confirm, each block contains:

  • Its data
  • The hash of the previous block data
  • A hash of its data The current hash is calculated as the hash of the data on the current block in addition to the hash of the previous block. This means that every node in the chain has a copy of the blockchain, rather than a centralised source, which can lead to data tampering.

This is a brilliant solution. It’s tamper proof. If we change the data in block A, the hash will be completely different as we demostrated above. This means, if block A were to change, the hash pointer of block B would be invalid. If we tried to then fix the issue with block B, we would invalidate block C. The more blocks in the chain, the more secure it is – it’s harder for a ‘hacker’ to change every block in the chain.

If we chose to remove a block, the same issue would be present. By removing block A the hash pointer would still be invalidated.

To add a transaction to a blockchain is made by concensus. The majority of nodes in the chain must agree that the transaction is valid. The important thing to note is, once a block has been accepted into the chain, it will never change – the contents of that block & its hash are set in stone.

Blockchain security is further enhanced through the use of a P2P (Peer to Peer) network. A copy of the blockchain exists on each computer in the network. When a transaction is added to the chain, it’s instantly copied to each of the other nodes.

If an attacker changes the data on a chain (as in the bottom image), they will change it on one of the devices on the P2P network. However, given that the majority of computers on network have a different copy of the blockchain; they will identify a problem and they will automatically update the node that the hacker had altered. This makes blockchain extremely difficult to hack. The hacker would have to change all blocks, on all computers on network simultaneously to succeed.

We now know that blockchain is an immuatable, auditable, secure ledger, let’s think about some use-cases. Ultimately, Blockchain’s ability to keep data in an incorruptable manner, makes is super secure.

  • Secure sharing of sensitive medial data – every new treatment added as a new block to the chain; every prescription etc.. Better coordination of care between healthcare providers, pharmacies etc..
  • A loyalty reward programme in stores: eliminating card-based loyalty programmes
  • A new way to vote digitally, without the risk of tampering
  • Home purchasing: title transfers; legal documentation; searches etc.. this could cut out the intermediaries (solicitors, banks, lawyers) in a home purchase, as the chain is a verfied, tamper proof audit trail of the property.
  • Wills stored on the blockchain network

Let’s look specifically at a home purchasing example: When you buy a house you get a deed which states you own the property and you get this registered with the government to show you own the land. The government may have a database which stores this information.

It is possible that someone could change the owner details, so you don’t own it anymore, this could be accidentally or on purpose. Consider, if the database server had an issue & was restored to an earlier state; your data may not be restored & no record would exist of you owning the land.

If this was blockchain, a new block would be added to the chain when you purchased the property. You would then have new blocks added for your council tax, refuse contracts etc… If someone tried to tamper with the records in Block A, it would invalidate blocks B, C and D. This makes it very difficult for someone to tamper with the data.

In the next article, we will start to look at building our own blockchain.

Share the Post:

Related Posts