Introduction to blockchain, Part II – A deeper dive 

Sep 13, 2022 | by By Romain Cauchois

Today, most people have crossed paths with blockchain in some form, or have, at the very least, heard of the term. Fewer can say that they have a clear understanding of what it is. And a much smaller portion has a deep understanding of how blockchain works. Our Introduction to Blockchain covered the basic concepts and functionality of the technology. In this article, we’ll delve deeper into blockchain.   


So, what’s under the blockchain hood?  How is the chain of blocks assembled?  


For the sake of this example, we will use the most well-known blockchain application — the bitcoin cryptocurrency. One of the most common terms associated with bitcoin is “mining.” The bitcoin blockchain is, to a certain extent, like a digital mine. And unlike coal or gold mining, which includes helmets, pickaxes, shovels, mineshaft elevators, etc., bitcoin miners use computing power to build the blockchain and maintain its integrity and security. Lots of it.  

The miners are the humans who run the mining machines and constitute the nodes of the network. They are responsible for building the blockchain and maintaining its integrity and security. Using computers, they collect and add transactions to the blocks, which they then add to the ledger, all while allowing it to work as a peer-to-peer decentralized tamper-proof network.  


There have been four types of bitcoin mining. The first is CPU mining. Although no longer viable for miners, this option was widespread during the early days of bitcoin. A single computer’s Central Processing Unit (CPU) would do the job.  


When CPU miners started to realize that their units were too slow, they started using their graphics card, or Graphics Processing Unit, instead. Enter GPU mining, a very efficient option for bitcoin mining that could be assembled in racks of numerous graphics cards. This required more power for running and cooling.   


The third mining configuration is FPGA which stands for Field Programmable Field Arrays. It offered better performance than graphics cards, especially for fiddling with bits, thanks to its all-card-transistors usability.  


Today, FPGA has been largely eclipsed by ASIC (application-specific integrated circuits), a constantly maturing specialized hardware, more complex and more expensive, specifically designed for mining. This is now the dominant bitcoin mining solution and is only found in professional mining centers.  


Now, let’s look at how a miner adds a block to the chain. A miner node is one of the four types of decentralized nodes that exist in the bitcoin network. A miner node, unlike other types of nodes, has a copy of the entire up-to-date bitcoin blockchain stored and works to solve a very complex computational puzzle.  


The miner starts by collecting and verifying multiple transactions made between users across the network. They then assemble them into a candidate block in what is called the memory pool. The first step of block mining consists of adding an extra transaction to the list of transactions in the memory pool, known as the coinbase transaction — granting the miner their mining reward in bitcoin, and creating new coins — and hashing each transaction. The hashes obtained are then organized into pairs, which are, in turn, hashed again, and so on up until one single root hash is produced. This “tree” of hashes is referred to as the Merkle Tree.  


Next, the root hash, along with the previous block’s hash and a variable value called a “nonce,” is placed in the block’s header, which is then passed through a hash function called SHA-256. The miners keep hashing the header repeatedly with different nonce values until one comes up with a valid output that will serve as the block’s identifier. To be considered valid, the block identifier needs to be less than a certain target value set by the protocol, it must start with a certain number of zeros. This is known as the hashing difficulty, and it varies to ensure that the rate of creation of new blocks remains proportionate to the amount of the network’s hashing power. In essence, the validity of a new block depends on the work performed by the miner, and on the previous block last added to the blockchain. This is what we call Proof of Work (PoW), a consensus algorithm that allows the network to achieve consensus, by the actual mining “work” provided to solve the complex math puzzle.  


When a valid hash is found, the miner broadcasts the block to the other nodes in the network which then check if it is valid. If successfully validated, add a copy of the newly mined block into their copy of the blockchain. It can happen that two miners find and broadcast a valid block at the same time, resulting in two different competing blocks in the network. In this case, the other miners start mining the next blocks based on the one they received first. And the competition continues until the next valid block is mined based on either one of the two competitors, wherein the other one is left out and called orphan block. The miner who found the winning block gets rewarded. The miners who were mining based on the orphan block switch back to the winning block. And this is how the blockchain ledger remains the same for all.