Making Sense of Bitcoin Protocol
Is Bitcoin just a fad? Does it have real value? Is it going to replace fiat currency? — people get into these speculations too early without first understanding how does Bitcoin protocol actually work? This thread is an attempt to explain Bitcoin protocol in the simplest manner.
You want to send some money to your friend B. In real world, you can do that by any p2p money transfer method, but all these would involve a central authority, ie Banks. Banks authenticate the identity, check the balances and record the transaction. Banks create trust in the system.
Now, what if we remove Banks from the equation? We would need some other mechanism to create trust and consensus in the system. That is what Bitcoin protocol achieves. Since there is no central authority, everyone keeps a copy of ledger. Bitcoin protocol ensures that everyone has same copy of ledger and there is no scope to game the system.
Imagine You, your friend — B, and couple of other people. You want to transfer money to B. You will broadcast the message confirming you are sending money to B. Everyone connected to Bitcoin network will receive this message. They will check if you have the balance to send the money, transaction is authorised by sender and it has necessary details like sender, receiver public key.
Once this is done, each node will note down the transaction. Grouping of these transactions is called a block. Block needs to be mined so that it becomes part of a chain. Hence, the name Blockchain.
For mining, Bitcoin protocol uses cryptographic hash function called SHA-256. Any input given to this hash function, it will give a 256 bit output that looks random. This output is unique to a particular input. You cannot reverse engineer the hash function to figure out input from the output. The output of this function is also called — Hash.
The puzzle that Miners have to solve will look like this — “The Hash of Block, Hash of earlier Block and x are fed into hash function, now what would be the x so that output hash will have 10 zeros in the beginning?”
Since hash function can not be reverse engineered, the miners use brute computational power to figure out what would be x. Hence, more the computational power you own, higher will be the chance of you getting lucky.
Person who gets the answer to this puzzle, mines the block on the chain. Others in network will verify if the answer is correct, and move on to mining the next block. The consensus mechanism is also called — Proof of Work. So, the transaction of you sending money to B got recorded in Blockchain.
Bitcoin protocol will maintain average mining time to be 10 min. Accordingly, the difficulty level will keep increasing as more network attracts more computational power. The number of zero required at the beginning will increase, it gets more difficult to solve this puzzle.
The chain which is the longest is considered valid chain as it has gotten more computational power from miners, effectively more support. So, if two blocks get mined, and it creates two chains, then one which turns out to be longest will be considered.
Btw, why would miners spend the computational power this way? Miner will get credited certain newly minted Bitcoin for successfully mining the block. This reward also increases money supply. This reward keeps getting reduced to half every 4 years. This reward will cease to exist one day, but still, miners can get transaction fees from sender, hence there will always be incentive to maintain the blockchain.
This way blocks keep getting added to the chain, and chain keeps becoming longer and longer. Everyone has record of all the blocks added to the chain. Hence, transactions once recorded this way into blockchain become irreversible.
What if someone owns more than 50% of computational power? This is called — 51% attack. If someone has that much computational power, they can theoretically create the chain they want, hence effectively game the system.
It is really rare to get that much computational power as there are lots of nodes working in Bitcoin network. As the chain gets longer and longer, it takes a lot of time to rework the chain, and while doing that also honest nodes will keep creating the honest chain.
Let’s assume a scenario — someone approaches 51% computational power, it will create lots of doubt for people about the security of Bitcoin protocol, the prices of Bitcoin will drop drastically, hence the person who wants to commit fraud will be left with nothing.
This makes Bitcoin the first decentralized cryptocurrency.