We went through the building blocks of blockchain technology in Part 1. There are a few other concepts that are integral to blockchain and Bitcoin. Let’s go through them one by one in this second post on Blockchain Technology and Bitcoin Cryptocurrency.
- Distributed Consensus Protocol
- Double-Spend Attack
- Proof of Work
- Incentive Mechanisms
There is no central repository of information in Bitcoin. The network maintains a shared distributed ledger among its nodes. Even though Bitcoin itself is decentralized, the software updating part (of Bitcoin) is decided by an elite group of developers. When the rules of the network are changed, software update takes place. Such an update should be reflected in all the nodes in the network or else there is a probability of a fork occurring. These forks result in alternate cryptocurrencies or “Altcoins” such as Bitcoin Cash, Bitcoin Gold, and so on.
Distributed Consensus Protocol
Bitcoin, being decentralized, depends on distributed consensus protocol to maintain the blockchain. Whenever a new transaction is created, it is broadcast to the network.
Bitcoin makes use of the distributed consensus protocol to bring consistency in:
- Transactions that are broadcast
- Order in which the transactions happened
For the sake of efficiency, the transactions are grouped into blocks. Thus, it is the order of the blocks that the nodes must reach a consensus on. The consensus state of blockchain is the collection of blocks stored in every node and all the nodes are agreed on the inclusion of those blocks.
A node may have a set of transactions that are not included in the current consensus state of a blockchain. These transactions are called outstanding transactions, and they are placed in the outstanding transaction pool.
The nodes take a transaction from the outstanding transaction pool, validate it, and place it in a block. The validation step involves verifying the sender’s claim to the coin to be transferred. This can be done easily by tracing the flow of the coin using the hash pointers.
The block is then broadcast to the network. Nodes will signal the acceptance of a block by extending the blockchain starting from that block. If they reject that block, they will extend the chain by ignoring that block and starting from whatever was the previous block in the blockchain. The act of a block getting accepted and being succeeded by future blocks is known as confirmation. This is how consensus is reached.
Consensus in Bitcoin works much better than in theory. A major reason for this is the introduction of the incentive system. The nodes are incentivized to act honestly. An honest node will always extend the longest valid branch. The nodes will benefit only if they propose a valid block, which should then be accepted by other honest nodes. In short, honesty pays. (The system runs on the assumption that majority of the nodes are honest; if not, all hell will break loose).
Another reason for its success is the method of selecting a node for proposing the next block. Bitcoin brings in randomness (or as close to randomness as possible) in its selection of nodes. This is achieved by utilizing the Proof of Work concept (more on it later).
A double-spend is an attack where a given set of coins is spent in more than one transaction. Consider this transaction. Alice pays Bob for some service. The transaction contains Alice’s signature, Bob’s public key, and a hash. The hash points to the transaction from which Alice got the coins. It takes no effort to verify the details of the transaction. Alice broadcasts this transaction to the network.
The nodes that receive this transaction will validate it and add it to their blocks.
There might occur a situation wherein Alice uses the same coins in a different transaction. She might broadcast another transaction along with the previous one. In the fraudulent transaction, she could specify the receiver as herself.
The coins in both the transactions will point to the same location. This is a classic example of a double-spending attack. Which of the two transactions will end up in the long-term consensus blockchain will depend on the number of confirmation each of them receives. Eventually one of the transaction will reach the consensus state. The other one will get rejected.
A block gets into the long-term consensus chain.
With time, the number of confirmations on the valid block increases. Higher the number of confirmations, higher the probability of the valid block ending up on the long-term consensus chain.
When a block is added to the long-term consensus chain, the probability of it getting rejected reduces exponentially with each confirmation. Heuristically, it would be best to wait for six confirmations before a block is to be regarded as part of the long-term consensus chain.
Proof of Work
The selection of a random node for proposing the next block plays a crucial role in the stability of the system. Randomness ensures that each node has a healthy possibility of getting the incentive.
The nodes are given a computationally hard hash puzzle and the first one to solve it gets to propose the next block. By solving the puzzle the node has made itself eligible for the incentive. This is known as the proof of work. The hash puzzle involves finding a hash value lesser than the target value decided by the network. To solve the puzzle, one has to find a random number––nonce. This should be hashed with the hash value (Merkle Root) of all the transactions in the block and the previous hash value. The resulting hash value is supposed to be less than the target value. The set of all possible hash values that are lesser than the target value is known as the target space.
The target space will be less than 1% of the overall output space. This adds to the difficulty factor. The process of guessing this number is known as mining. The one who mines the block, or guesses the nonce, gets rewarded. Those nodes that engage in the process of mining are known as miners.
The network adjusts the target value and its difficulty in such a way that a new block is mined every 10 minutes. When more miners join the network and the block creation rate increases, the network readjusts the target value so that the block creation rate decreases and the loop continues.
The rate at which a node finds blocks depends on what other miners are doing. The probability of a miner mining the next block is proportional to the fraction of the global hash power that the node controls. Verifying the result is easy. The miner who mines the block must attach the nonce value in the proposed block. The other nodes only need to verify that the hash value of the block is less than the target value.
The system relies on honest nodes. In order to promote honesty, an incentive mechanism was introduced in Bitcoin.
There are two ways in which honest nodes get rewarded:
- Block reward
- Transaction fee
Whenever a node mines a block and it gets into the long-term consensus blockchain, the node will get the block reward. Because Bitcoin is itself a cryptocurrency, the network uses this currency to reward these nodes.
The node which mines the block can include a special transaction called Coinbase transaction. The recipient of this transaction will be the node itself. The node will get this reward only after the block ends up in the long-term consensus branch.
New coins are created on the Bitcoin network only via these special coin creation transactions. Presently, the block reward is 25 Bitcoins. The reward halves every four years. By the year 2140, the last Bitcoin would have been mined. There is a hard limit on the number of Bitcoins, which is 21 million.
The other incentive mechanism, transaction fee, is likely to gain the upper hand in the future. The transaction creator will offer some coins to the node which first puts its transaction in the long-term consensus blockchain. The miner that mines that block can collect the Transaction fee of all the transactions included in that block. Currently, the major source of income for the miners is the block reward but soon it will change.
Learn what a Bitcoin transaction looks like in Part 3 of the series.