Blockchain – The Beginner’s Guide
“A blockchain is essentially a distributed database of records or public ledger of all transactions or digital events that have been executed and shared among participating parties. Each transaction in the public ledger is verified by consensus of a majority of the participants in the system. And, once entered, information can never be erased. The blockchain contains a certain and verifiable record of every single transaction ever made. Blockchain lays the base for a democratic open and scalable digital economy. ”
This is a very dense definition, so let me try loosen things up. A database is a collection of information organized in such a way that a computer can quickly store, search and select desired pieces of data.
An employer might use a database to store information about his employees, like name, birth date, contact address. In the case of a blockchain, the database is a record of all digital events like financial transactions or smart contracts.
A blockchain is a special database, since it’s distributed. This means that the blockchain is not located on only one system, but rather replicated across a number of systems in almost real time. Usually it exists over a Peer-to-Peer (P2P) network, a network where connected nodes (“peers”) share resources amongst each other without the use of a centralized administrative system (Figure 1). This is also referred to as a decentralized network and is used by “services” like BitTorrent.
In a network, based on the client-server model, the individual clients request services and resources from centralized servers (Figure 2) (Figure 4: Model 1). Seems familiar, right? It should be, because when you want to view a website or watch a video, you and everyone else request these resources from a service provider like Google or Facebook. A lot of the internet’s services are centralized.
Figure 1: Peer-to-Peer network
Figure 2: Client-Server model
Since the blockchain keeps record of digital events, we need to verify those. Imagine this common situation: Alice wants to send Bob 20$. Normally a trusted third-party like PayPal makes sure that Alice is actually Alice and that she has sufficient money to execute the transaction and transfers the money.
But a blockchain is decentralized. It uses cryptographic and digital signature to prove the identity, authenticity and enforce read and write access rights for the database. Besides that, verification has to occur without compromising the privacy of the digital assets and parties involved.
In this example we will use 20$ worth of Bitcoins. Alice (sender) would sign the transaction with her private key to identify Alice as the owner of the money, and send it to Bob’s (receiver) public key. Bob then would verify Alice’s private key with her public key, to make sure that she has sufficient cryptocurrency (BTC).
The transaction, represented online as a ‘block’, is broadcast to every participant in the network. However, the transaction itself is not stored in the block. Only the fingerprint (hash) is stored.
The fingerprint is generated with a hash algorithm: It turns data into a fixed-length hash like “85xj0d”: Modifying the data by one bit, for example turning a 0 to a 1 or the other way around, will change the hash completely. Those in the network will approve the transaction and add the verified block to the blockchain. The money will move now from Alice to Bob.
Figure 3: How a blockchain works (Source: Financial Times)
There are two different blockchain types: public and private. In a public blockchain anyone can write and read without the permission of another authority (Figure 4: Model 2). In a “private” blockchain the participants are known and trusted: for example, a company group (Figure 4: Model 3). Many mechanisms like the following wouldn’t be needed – or are replaced with legal contracts.
Figure 4: Centralized vs Public Blockchain vs Private Blockchain (Source: Financial Times)
There are specific mechanisms that make manipulation and tampering with the blockchain next to impossible and very easy to detect when someone tries to. These mechanism would be Proof-of-Work (Bitcoin), Proof-of-Stake (Peercoin) and Delegate Proof-of-Stake (Shift), just to name a few.
After having a brief look at blockchain in general, let’s look at a blockchain on a computer:
A blockchain itself is just a file. Described as above, it is most closely comparable with a database. As the name blockchain says, it is made out of blocks chained together. You can imagine a block as a page in a book. A page contains the text (Story) and information about the page, for example a title or the page number.
A block is similar: The content of the blocks are details about the digital events, while the ‘header’ contains information about the block itself, for example a reference to the previous block and the hash of the data contained (fingerprint).
The hash has an important role for ordering the blocks and securing the blockchain. While a book orders the pages by building on the page whose number is one less (Page 5 builds on page 4), the blockchain orders the blocks by referencing the fingerprint (hash) of the previous block.
If an attacker changes a block in the blockchain, he would inevitable change the hash. This would mean that the whole blockchain needs to be regenerated again, since they are all connected to each other.
Figure 5: A peek inside a blockchain block (Source: A Gentle Introduction to Blockchain)
As mentioned earlier, a Blockchain is an over Peer-to-Peer network distributed database. However, there can be a few problems: How do you ensure that the system can’t be (easily) corrupted by bad peers? If each peer is updating at different speeds and have therefor have slightly different states, how do you determine the “true” state of the data? And what if multiple miners create different blocks at roughly the same time? Which block will count as the legit one that should count?
These are the problems of Blockchain and will be explained here.