Back in 2009, the year Bitcoin was invented, seven transactions per second speed might sound all right, since Bitcoin was only circulated within a small group of cryptographic geeks and nobody thought to use it for everyday purchases. However, the hard-coded limits of the Bitcoin protocol has become a hurdle to its wider applicability. Bitcoin transaction takes 10 minutes, sometimes much longer to get the first confirmation; even worse, it usually requires six confirmations for a transaction to be considered permanent. The long wait time not only leads to a longer queue; in some cases, it could be catastrophic. A 10 minutes delay could make you miss your flight, or liquidation of your trading account. Why we can spend money instantly using our credit cards, but Bitcoin still sits at this unbearably slow speed eight years after since its birth? To understand this, we must look into the mechanism of Bitcoin.
The Bitcoin network, along with its clones, is maintained by computer nodes called miners. So, what exactly do the miners do? Let us look into the canonical Bitcoin data structure. A Bitcoin block contains two parts: a block header and a block content. This might reminds you the HTML tags <head> and <body>. Similarly, the Bitcoin block header contains no transaction data, but only a Merkle root and meta data. If we look into the original Bitcoin client source code, we can find that Bitcoin uses ThreadBitcoinMiner to handle mining. What it does are:
1. Get the target difficulty
2. Create a new coinbase transaction
3. Collect transactions from memory into the block
4. Call ProcessBlock method to validate and save the block
The ProcessBlock checks the validity of the block header and individual transaction data in turn. The proof-of-work is done in step one, which we will explain later. It has nothing to do with the transaction verification process. The definitions of CheckBlock and CheckTransaction can be found in classes CBlock and CTransaction, respectively. CheckBlock does a simple calculation to verify whether the hash is equal to the data from which it is derived. CheckTransaction is straight forward, as it checks whether the input transactions have enough unspent balance to cover the output transactions and verifies the signature of the sender. Each node in the network, whether it is mining or not, must verify the block data before accepting it to the blockchain stored on the node.
The mining process consists of proof-of-work and collecting transactions into block. We are not going to give a lesson on cryptography here. Simply put, the proof-of-work process is a mathematic puzzle to find an answer called hash. This hash must satisfy at least three features:
1. There are large enough candidates in the hash collection
2. The result of the hash must be unpredictable and cannot be reversed
3. It is easy to verify the hash
For example, the SHA-256 hash of 100000000 is e59bbea6227c578f97fc467bc62dc340-7d4885693d74e6e970f6cab44158fef4, while the hash for 100000001 e0d3b72f72183185-c11356d4f280ceceb336622fbab3b4f4fbe6af73ca4dbcbc. A small change in the original data results in another completely different result. This ensures that no one could find a specific hash without brute forcing it. The SHA-256 algorithm is widely adopted by Bitcoin. In Bitcoin network, a miner must find a certain hash before other miners do to secure his reward, which is a small amount of Bitcoins. Nowadays, specifically designed hardware is required to mine Bitcoins. The lower the target difficulty, the more computing power is required to find the hash. Bitcoin network adjusts the target difficulty so that the average time to find the hash stays at 10 minutes. Since every block is chained to its predecessor, with the exception of the genesis block, to change a past block one must redo proof-of-work of all blocks chained after it, which is impractical in current landscape.
The sole purpose of proof-of-work is to make it extremely to rewrite the history of the blockchain. Therefore, the mining interval must be significantly greater than the network latencies and transaction processing time. No matter how many transactions a block can put into, a Bitcoin transaction must always take at least 10 minute to be processed. A modern desktop computer can verify 8,000 – 10,000 Bitcoin transactions in just one second. It appears ridiculous that still sits only a fraction of this rate. However, why can’t Bitcoin just increase its current block size of 1mb, or shorten its mining interval? We will explain this in our next article.