The Bitcoin Blockchain Explained6 min read
Many are familiar with the term Blockchain, the underlying technology that powers Bitcoin, but many people struggle to understand how the technology works. To understand the Bitcoin blockchain we need to understand:
- What is a blockchain
- SHA 256 Hash Function
- Immutable Ledger
- Distributed P2P network
- Mining & Cryptographic puzzle
- Consensus (PoW)
What is a Blockchain?
A blockchain is a data structure where information is stored in blocks and cryptographically chained together. New data are stored in blocks chronologically and chained onto the previous block. Tampering with any block will cause the digital fingerprints/hash to no longer match up with the chain’s chronology and become invalid. In Bitcoin’s case, the blockchain is decentralized and distributed where no single group or authority has control over it. In the Bitcoin blockchain, data can only be inserted and viewed; no data is ever edited or deleted. Unlike traditional databases like SQL, we can not overwrite any of the stored data in a block, as modifying the data will change the hash and disrupt the cryptographic chain. To make updates, the data is appended or added as a new transaction.
What is Sha 256 Hash Function?
The SHA 256 hash is a digital fingerprint used in the Bitcoin protocol. The SHA 256 algorithm is a one-way algorithm that is used to scramble data in a deterministic manner where the hash algorithm will produce the same result for the same input. It allows fast computation where a tiny change in the input will cause a catastrophic change in the hash.
The hash function works one way and has non reversible operation.
Data > Sha 256 > Hash value
Showing how tiny changes creates catastrophic changes in hash
^Sha 256 hash for “This is opennode”.
Adding a small change (in this case a period) causes a catastrophic change in the hash result.
Every block in the blockchain contains a hash or digital signature but also for the previous one. This is how the blocks are chained together and this ensures that no one can intrude in the system or alter the data that is stored into the block. Manipulating a block would disrupt the chain as the hash value will no longer correspond to the chain. This makes it almost impossible to tamper with any transaction on the Bitcoin blockchain as tampering with a block will make the rest of the chain of blocks invalid and disrupt the chain connection. This is important to Bitcoin as no data can be missing
Distributed Peer to Peer Network
A distributed P2P network consists of a group of computers (nodes) where every node stores and shares the system’s data. In Bitcoin, the blockchain is distributed across all the nodes peer to peer. When a new block is added, the information is communicated throughout the network until all the nodes have that block added. The nodes constantly check on average every 10 minutes to see if their blockchains match up. If a malicious attack took place in a node’s blockchain, the peers would see this problem that their blockchain no longer matches with the malicious blockchain. The majority of the nodes will notice that the malicious blockchain is in the minority. Thus, the malicious blockchain will automatically be replaced by the majority blockchain, which is the consensus.
Mining & Cryptographic puzzle
Mining is how new bitcoins are added, and transactions are validated in the Bitcoin network. Miners compete to validate transactions and add new blocks by solving a cryptographic puzzle. Every block in a blockchain contains a nonce (number used only once). This is the only piece in the block that can be changed. The nonce allows miners to vary it and iterate through it to create a hash. The blockchain algorithm will set a target for miners to find a certain hash under a certain range called the target. Any hash that is above this set target will be rejected, and the hash will not be used to create a new block. However, if a miner found a hash inside the algorithm’s arbitrary target, then the hash can be used to produce a new block. Adding a new block miners are rewarded with the new bitcoins called the coinbase transaction, which is also how new bitcoins are injected into the system.
The consensus protocol is used to make sure that there is a single source of truth. Proof of work is the consensus algorithm used by bitcoin. Let’s say that two miners mine a block almost simultaneously. Now, this would create a conflict in the chain. As these conflicting blocks are added and distributed to the network, there will be competing chains. This is where the Bitcoins consensus protocol would come into play. In this case, the longest chain wins, and whichever chain has the most number of blocks will win and will eventually replace the blocks in the entire network.
The Bitcoin blockchain is a distributed ledger that is open to anyone. Each block contains data, a hash of the current block, a hash of the previous block, and nonce. The hash of the current block and the hash of the previous block is used to create a chain which makes it very secure. Additionally, the bitcoin blockchain is distributed in a peer-to-peer network where anyone can participate voluntarily. When a node joins the network, they get a full copy of the blockchain and is distributed to everyone. The network of nodes also creates a consensus protocol and reaches an agreement. Finally, to verify and validate new blocks in the blockchain, miners have to compete and solve a difficult cryptographic puzzle where they guess the hash of a new block that is under a target set by the Bitcoin algorithm. After the miner finds a hash under the target, nodes will independently validate each block and ensure that the block is valid before it propagates it to its peers. If accepted by all the nodes, the transaction is added to the blockchain by the miner. In return for the miner’s contribution, they receive the ‘block reward’ and the fees as compensation. These elements altogether make Bitcoin the most secure and decentralized money ever created.