- 1 Understanding what a blockchain is, is not that difficult. Since this concept is becoming common in everyday use, we want to introduce how it works and its innovations gently.
Understanding what a blockchain is, is not that difficult. Since this concept is becoming common in everyday use, we want to introduce how it works and its innovations gently.
Imagine the following situation. Alice wants to send $1000 to Bob. Traditionally Alice will make use of its bank. Using banks has advantages: Alice and Bob need to meet somewhere to transfer the money without the bank. It can also be dangerous to carry $1000 in the streets to make the payment. But, at the same time, using the bank has some disadvantages:
- The bank acts as an intermediary. Understandably, the bank will charge a fee for its services. When this bank services many people, it becomes the center of the financial stage. The bank is a centralized entity; all payments go through its infrastructure.
- Alice has to trust the bank. She has to be confident that the bank annotates the transaction correctly. It has to record a debit in Alice’s account and a credit in Bob’s account. The annotation must be stored securely with some mechanism (computer storage, physical books, etc.)
- Neither Alice nor Bob has any control over the process. Only the bank knows everything about the transaction: Issuer, receiver, timing, accounting, etc. They both depend on those banks and how they do things to complete that transaction. They are subject to its conditions (and its commissions, of course).
The Blockchain solution
With these problems, the blockchain eliminates intermediaries and decentralizes all management. The control of the process belongs to the users, not the banks. Alice and Bob become part of a massive network with millions of users, each a participant and manager of global accounting.
A blockchain is a gigantic ledger in which the records (the blocks) are linked and encrypted to protect the transaction’s security and privacy. It is a distributed and secure database (thanks to encryption) that can be applied to all kinds of transactions that do not necessarily have to be financial. Think about intellectual property or real estate. You don’t trust anyone individually, but you trust all of them as a group.
The blockchain is a unique ledger, agreed upon and distributed in several network nodes. When dealing with cryptocurrencies, we can consider it the ledger where each transaction is recorded.
Building a Block
The ledger (the blockchain) consists of a collection of linked blocks. But what is a block? A block consists of a bunch of data (records). These records can be financial transactions: issuer, receiver, and the amount transferred.
Schematically, a block from a basic (simplified blockchain) consists of the following:
- Block ID. It is a number that identifies a single block. The number grows in sequence as we build more blocks.
- Data. It is the block’s payload; It can be a transaction or any arbitrary data.
- A Hash. A Hash is an identifier that depends exclusively on the data. Mathematically a hash is a function performed over the data that results in a unique number derived from the data. If the data changes, the hash changes as well. In our case, the information to be hashed is not only the transaction data. It must also include the previous block hash, the nonce, and the ID.
- The hash of the previous block. The block’s hash can be zero if we build the first block.
- The Nonce. It is a number that makes the hashing operation much more difficult.
The computation of the hash using the nonce is not an easy task. It is a computationally expensive process. When our computer finally computes the block’s hash, we say that the block is signed. This operation is what people call mining. Mining is signing (hashing) blocks, and this process falls under a consensus scheme called Proof of Work (more on part two of this post.). Once we have our first block, we distribute it to all the participants in the blockchain. All the participants will have an exact copy of our block and check that the hash is correct. The block is added to the blockchain if everybody (+50% of the nodes) agrees on the result.
Adding a new Block
Suppose we have new data to add to the Blockchain because Carol wants to send $500 to Dan, so we have to build a second block. The process is as follows:
- Calculate the block ID: Since this is our second block, it will have ID number 2
- Hash the block’s data. Note that inside our hashed data is the hash of the previous block.
What happens if someone alters the data in the first block? Imagine that someone wants to modify the transaction and puts $10 instead of $1000. In this case, the hash of the first block changes, and the second block loses the first block’s link. Remember that the second block stores the hash of the first block. If you alter the second block, the rest of the nodes will detect that you changed the block, which is rejected. All the blocks behind the altered block will break as well:
We have seen that blockchain is a consensual registry. All the participating nodes store the same information. If some attackers wanted to modify the block’s data, they should change the entire chain in at least 51% of the nodes. In our example, the miners achieve the consensus by hashing blocks. The blockchain that uses Bitcoin uses a similar approach to the one described here. But hashing data is costly. A computer has to make many computations (consuming energy); this is why this type of consensus algorithm is called “Proof of Work or PoW.” The most common alternative to the PoW algorithm is called Proof of Stake (PoS). We’ll talk about consensus algorithms in a later post.
This is the first part post to understand blockchain basics. As we have seen, each block has a specific and immovable place within the blockchain since each block contains information about the previous block’s hash. Once we have a valid block, it is broadcast to all the available nodes, which compute the hashing. The complete chain is stored in each node of the network. All the participants keep a full copy of the blockchain.