Blockchain Ep01: Demystifying the Chain

Alabhya Mishra
Coinmonks
10 min readNov 15, 2021

--

Being a part of the financial world, I realize that we are at the precipice of a pivotal technology. Some even consider it the Internet v3.0, even though the idea of decentralization has been around since forever. So naturally, I wanted to understand why everyone considers it — The Blockchain Revolution.

As with all my journeys into the unknown, this too started with books, specifically Antony Lewis’s — The Basics of Bitcoins and Blockchain. This book, in a very simple language, lays down the driving need for Blockchain in the financial world — starting from what Money is and why transactions in our current world are so expensive (hint: Centralized Finance is not really very well centralized).

In a series of blog posts, I want to outline my understanding of Blockchains and why I believe it really has a potential to change the world. I write these for two major goals -

  • I believe that writing helps solidify the knowledge
  • I want to hear from people & enthusiasts who really know, so that I can learn better

In this post, I am going to try and build a very primitive ‘chain of blocks’ with protocols similar to (but weaker than) the Blockchain. I start from scratch, from the basics that pretty much all of us have seen before. Hopefully, by the end of it I will have explained what it really means to Chain the Blocks. But let’s start from the beginning, with the very first Aha! I had…

The Aha Moment!

Blockchain is made of 2 things — Blocks and Chain. When I began my journey with Blockchain, for a very long time I focused on the Blocks, to understand them, to appreciate the genius in them. Only very late did I realize the beauty of the Chain. Don’t get me wrong, Blocks are important, very important, without the Chain it just doesn’t work. So understand how the Chain works, and you are 60% there.

That aha! moment was when I realized — I have met something like a Chain before…

Data Structures

We all know what Data is — a piece of information — your latest post, a word, a letter, a pixel, an electric pulse! But we can only make sense of Data when there is a structure to it. Structure enables us to process the Data, add to it, remove from it. Computers need structure to Data too. So our brilliant computer scientists defined different ways to structure Data. And many of them come from real-life examples we all can relate to.

Queues

We have all been in a queue before, at Starbucks maybe, at an airline check-in or if you’re like me — at football stadiums. You always join the queue at the end, you always exit from the front. Cutting into a queue is sacrilege.

Computer Queues work pretty much the same way. You can only remove/process data from the front of queue, you can only add new data at the end. In computer jargon, its also called FIFO — First In First Out.

If I got into the queue before you did, I’d want to exit before you did. Or we fight…

Stacks

Stack a book on top of another, do it for a few books. You’ll notice you always add to the top of the stack. Now remove books, one by one — you’re removing from the top of the stack. So the book that was added most recently, gets to leave first!

Computer Stacks work like that too. Data is added to the top of the stack, and removed from the top too. Last In First Out — LIFO

If I join a queue after you, I want it to convert to stack immediately!

A quick side note
Both Queues and Stacks are sequential — to get to the 5th data (or person, or book) you have to go through the 4 data elements (or people, or books) ahead of it. You can’t jump, it wouldn’t be fair, its not possible. That is very restrictive — imagine if you had to listen to 4 songs before you could get to the 5th. Really imagine — the image below has no relevance at all ;)

90’s kids, where art thou?

Lists

Lists are a little complicated, but also more flexible. You can add data to any point in the list — the start, anywhere in the middle or the end; you can remove/process from any point in the list. Think of your shopping list. You can buy the items in any order, you can also (if it wasn’t inked on a paper) add to list anywhere you want.

To simplify matters, lets agree on the terminology that Lists are made of several elements put together. Elements store Data. In computers, each element has a hidden attribute called the Index. A new element can be inserted at any point in the list, so there has to be a way to tell computer what that point is. That is all Index does, it acts like an address.

Index is an address, Elements store data

Linked Lists

Now lets get adventurous with Lists, lets modify the elements so that it stores 2 pieces of information — the Data of current element and the Index of the next element in sequence. In doing so, we have linked elements of the list together, because every element gives directions to the next element. Linked Lists are like Treasure Hunt (or Scavenger Hunt). Every puzzle solved gives you the clues to the next puzzle and until you solve this new puzzle, you can’t go to the next round.

Food for thought: Does LinkedIn connections have anything to do with Linked Lists?

Because it is getting somewhat complex, let us summarize the technical bits -

  • Each element in a Linked List contains 2 components —Data of current element and the Index (or address) of the next element
An element of Linked List
  • You can enter a new element at any point of a Linked List; you just have to insert this new element such that links are updated in the right manner
Adding element D between elements B & C. Letters represent the Index/Address
  • You can remove an element from any point of a Linked List, as long as you update the links
Removing element B

These features of the Linked List make it a chain (not THE Chain, not yet). Its a chain, in which each element connects to the next, and can be modified as many times as we want, as long as we keep updating the links correctly.

Note: There are a few variations of Linked Lists, but that is not in the scope of discussion here.

Building The Chain

Making the leap from a chain to the Chain requires a few modifications. In the next few steps, we will try to build a very primitive ‘chain of blocks’ using the Linked List concepts as our starting point.

The zeroth modification is that I will now refer to each Element as block (not yet THE Block, capitalization is important folks!) and change the shape a little. I do this for convenience.

A ‘block’

The first modification is very minor. We just flip the direction. Instead of each block storing the address of the next block, they store the address of the previous block.

‘Flipping’ the direction of links. This representation can start getting noisier. So the image below, represents the same idea in a different format.
Same idea as image above, but a tidier representation

Now, game changing second modification! In Linked Lists, we stored the address of just the previous (because we have already flipped direction) block. Here, lets also store the address of every preceding element in the chain in the right order. So the last block contains the address of every block that came before it, and in the order of their appearance. Very subtle, but very powerful!

Storing the entire ‘preceding’ history of links in each block

The third modification is Duplication — lots and lots of duplication. This chain of blocks is saved on many computers on a network. And every time we make any change to the chain, we re-share the updated chain to all these computers. In essence, every computer in the network has an identical replica of the chain.

Chain Verification Protocol

With these modifications, we have moved far from the traditional domain of Data Structures. So, now is a good time to take a pause and reflect on what we have achieved. We have built a primitive ‘chain of blocks’ as promised. This structure has very weak security, anyone can make changes to the chain, as long as they follow the protocols of chain verification.

Every time the chain is modified, the update is received by each computer in the network, because Duplication. This kicks off a verification process at each computer before they accept the updated chain. Every single block is checked to see if they have the right order of preceding blocks’ addresses stored. If all the addresses are correctly ordered in all blocks, computers accept the updated chain and save it. If not, they reject the updated chain and preserve the original version. Because each computer gets to independently verify whether the links are correct, we have introduced Decentralization. There is no One Computer to rule them all!

Now let’s see how we can make changes to this chain.

Adding a new block at the end of the chain

This is quite simple. Even in the real Blockchain, this happens all the time. Adding new blocks is how we add more data to our ‘chain of blocks’ increasing the length. Adding block G to the chain, as seen below, simply means copying all the addresses from the preceding block F and adding an extra line to the address on G.

A new block at the end of the chain

Adding a new block in the middle of the chain

This isn’t as simple. Because if we are not careful, we can fail the chain verification. Adding a new block in the middle requires updating every single block following it in the chain. This is not impossible, its just more work. And as long as we do this extra work, we will pass the chain verification!

Let’s add a new block G, between blocks C & D.

What did we miss?

Once this update is shared with the other computers as a result of Duplication, each computer independently runs the chain verification protocol. Starting with Block F, every address looks good because using the information in the address part, the computer can traverse from block F to block A. Then it tries to do the same, starting with block E. But the verification fails, because according to block E, D points to C. Not true! Because the verification fails at block E, this update is rejected.

An acceptable update would look like this -

A change in every block after the new block is inserted!

Adding a new block at the start of the chain

This pretty much follows from the above. If we add a new block at the start of the chain, we just have to update the address of every block in the chain. I don’t want to take up space with another picture, but I think you get the point by now. The most important thing to take away from this is — The higher up in the chain we add a new block, the more blocks we have to modify, the more work we have to do to keep the chain valid!

In Conclusion…

So far we have built a very primitive chain of blocks, where adding new blocks to the chain is relatively easier than adding a new block in the middle (or anywhere high up). It is not impossible, of course. But it is extra work. If somehow, we can make the work very difficult (or costly), it will become impractical to insert anything in the middle of the chain. And that is the essence of Blockchains — the work required to add this new line of X points to Y on any Block is extremely costly, so much so that its just not worth doing it more than once (for a new block at the end of the chain).

A lot of time, we read something like Blockchain is immutable (which means it cannot be modified). That is not really true. Theoretically, Blockchain is mutable, its just not practical (given current computing infrastructure).

I have purposefully ignored the Data stored in the blocks. And what happens if we want to modify the Data within an existing block? There is no way to prevent that right now. Also, the chain we have created has a very inefficient way of maintaining addresses — if the chain gets very long, the number of address lines will explode and potentially become much larger than the data stored. To store 5 MB of data, you’d need 100 MB of addresses alone, crazy! But I hope you are now able to appreciate the mechanisms of the Chain.

What about the Block you ask? Well, that is the subject of my next post. See you then…

Cliffhanger

The real Blockchain makes both address maintenance simpler as well as data/chain modification practically impossible, by a single swoosh of computer magic. Hashing!

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also Read

--

--

Alabhya Mishra
Coinmonks

Working in finance, data science and analytics. Interested in learning Blockchain