What is bitcoin?
Bitcoin is a free-to-use open-source program. It creates a network of computers running this program whose primary function is to enable people to make electronic payments. Open source program means anyone can read the code, run it on their own, connect to other nodes (other users running Bitcoin program on their devices) in the network, send and receive online payments.
Bitcoin’s objective was to create an electronic payment system without relying on any trusted financial institutions. It moves the trust from financial institutions to numbers by using cryptography.
Bitcoin consists of:
Bitcoin Protocol - A decentralized peer-to-peer network
Blockchain - A public transaction ledger
Consensus - A set of rules for independent transaction validation and currency issuance
Proof of Work algorithm - A mechanism for reaching global decentralized consensus on the valid blockchain
All of these are explained further in this article but first, let’s take a look at the history of Bitcoin.
History of Bitcoin
In the 1980s cryptographers around the world started exploring the concept of digital coins i.e. taking a physical coin and converting it into a digital coin. The biggest problem that they had to address was:
Authenticity - Physical coins and cash have sophisticated papers with special patterns to verify that they are not counterfeit. What kind of patterns should be on digital money?
Double Spending - The same coin shouldn’t be reused again just by making a copy of the coin. This is not possible in physical coins.
No one should be able to claim someone else’s money as theirs.
On November 1, 2008, a mysterious person using the pseudonym of Satoshi Nakamoto posted a research paper (Bitcoin: A Peer-to-Peer Electronic Cash System) to an obscure cryptography publication describing his design for a new digital currency that he called bitcoin.
When Nakamoto's paper came out in 2008, trust in the ability of governments and banks to manage the economy and the money supply was at its absolute low. The US government was throwing dollars, the Federal Reserve was introducing “quantitative easing,” essentially printing money in order to stimulate the economy. The fact that bitcoin's public ledger seems to protect against fraud, but the predetermined release of the digital currency kept the bitcoin money supply growing at a predictable rate attracted a lot of attention in the cryptographer's community.
Also, Bitcoin was the first practical solution to a problem in distributed computing, known as the Byzantine Generals Problem. The B.G.P. poses the question of how to establish trust between otherwise unrelated parties over an untrusted network like the Internet.
Who is Satoshi Nakamoto is the biggest mystery to date? Was he a person or a group of people using a pseudonym? These questions are still unanswered, multiple people have tried to fake themselves as Satoshi or are somewhat similar to him as explained in this video.
Since then, bitcoin has gained a lot of traction. Multiple VC firms like A16Z, investors like Chris Dixon, Balaji Subramaniam have invested a lot of their money at a very early stage. Countries like El Salvador have even declared bitcoin as a legal tender, and are hoarding it in their treasury. Bitcoin is now famously called digital gold due to its deflationary nature.
Now let’s understand more about how it works.
How does Bitcoin work?
Bitcoin introduced the concept of the decentralized immutable ledger that uses cryptography and blockchain and functions without the need for any central authority. Let us explore some of the primers that are essential for understanding how Bitcoin works
Hashing
Hashing is a process to encrypt information using mathematical and computer science algorithms. A human can be uniquely identified through their fingerprints, similarly, any information can be uniquely identified using a long string of alphanumeric characters called the hash.
Properties of a good hashing function:
Deterministic - Every time you pass the same input, you get the same output.
Hiding - The hash function should successfully hide the input such that it should be impossible to determine the input to the has function in case someone is in possession of the output
Collision Resistant - Getting two inputs that give the same outputs when passed through the hashing function should be hard.
Puzzle Friendliness - Changing input by little should change the output completely. It shouldn’t be possible to predict the change in output for every change in input through finding out patterns.
Bitcoin uses SHA256 - Secure Hashing Algorithm to hash the transaction information. This hash function was developed by the US National Security Agency in 2001. It produces a hash of a fixed length of 256 bits. If you used using SHA-256 to create the hash of an entire library or that of a single letter, the output would be of the same size (256 bits)
Digital Signatures
Cryptographers found a special keypair called Private Key and Public Key.
Think of Public Key as your email address which you can share with anyone to receive emails and think of Private Key as your password to your email account. You can read the emails only after you verify that you know the correct password i.e. you have the corresponding private key.
Public Key and Private Key always comes in pair which are used to sign transactions in bitcoin. Property of this keypair is that using a public key, digital signature produced by a private key, and the corresponding message you can verify if the signature on that message is actually signed by the person holding the private key.
Bitcoin Architecture
In our current financial system, a bank i.e. the central authority maintains a ledger. Every transaction from A to B is first passed to the bank which verifies if the transaction is valid and on successful transfer writes that down into their ledger. Bank has the power to deny, rollback, modify any transaction.
Bitcoin introduced a decentralized ledger in which every node of the network keeps a copy of the ledger. Multiple copies of the same ledger are maintained by multiple nodes.
Node - It is a computer connected to the network that has a copy of the ledger and runs a bitcoin program on it to validate transactions.
The Bitcoin ledger is called Blockchain. Blockchain is made up of two words: block and chain which means blocks are chained together in a series such that changing one of the blocks will break the chain. More details about blocks and how they are chained in further sections.
Bitcoin Transaction
Each bitcoin transaction essentially contains 5 things:
Sender’s Public Key - Public key of the person sending the bitcoin
Receiver’s Public Key - Public key of the person whom you’re sending the bitcoin
Amount - Amount of bitcoin to be transferred in the transaction
Mining Fee - Amount of fees you’re paying to the miner for putting the transaction into the ledger
Signature - Digital Signature generated using the above four information and the sender’s private key
Each transaction is broadcasted to the bitcoin network which is then verified by multiple nodes in the network.
Verification of a transaction involves:
All necessary information is available in the proper format.
The sender has enough balance in the account to send the amount.
Verification of digital signature by passing the transaction data, sender’s public key, and digital signature to signature verification function.
If the transaction verification fails, the transaction is declined and deleted from all the nodes. But if the transaction is successful, it is then moved to mempool where other pending transactions are waiting to be added to the ledger.
Bitcoin Mining
Ledger is sacrosanct in both centralized and decentralized financial architectures. Any mistake or fraudulent transaction, once written on the ledger can be costly and painful for the system. It can even lead to the collapse of the whole financial system.
Satoshi proposed that writing to the ledger should require a lot of work. By work, he means computational work. This consensus behind the Bitcoin mechanism making the ledger secure is called Proof of work.
Proof of Work - It is cryptographic proof in which the miner proves to the validators (other miners in the network) that a certain amount of computation has been used to write the transaction on the ledger.
Let’s understand some key terms involved in bitcoin mining:
Mining - The process of using computer hardware to do mathematical calculations for the Bitcoin network in order to confirm transactions and write them to the ledger
Miner - Any Bitcoin network node that is trying to add transactions to the ledger
Block - Transactions on the Bitcoin ledger are written in blocks i.e. multiple transactions (~2000) are clubbed into one block to write on the ledger. Since a lot of work is required to write transactions on a ledger, it’s not feasible to write single transactions and thus write as a block of transactions.
Mining Puzzle - To prove to the other networks, miners are trying to solve a puzzle that involves building a block with certain characteristics. Once a perfect block with all the requirements is built, the puzzle is solved and the block of the transaction gets written to the ledger. Though it is very hard for the miner to solve this puzzle, the nature of the solution is such that the solution’s validity can be easily verified by anyone.
Candidate Block
Each miner selects some transactions from the mempool based on the size limit of the block (1MB). Around 2000 transactions are clubbed together in a block. Most of the miners pick the transaction with high mining fees in their candidate block.
Each block contains 8 things:
Block Header - Hash that represents the content of the block. This hash is produced by inputting all the contents of the block into the SHA-256 hash function.
Block Height - Since the bitcoin ledger is based on blockchain, the height represents the position of the block in the chain. The first block also called Genesis block was mined by Satoshi and has a block height of 0. The next block had a block height of 1 and so on.
Previous Block Hash - Hash of the previous block in the blockchain. Previous hash is used to link the blocks. If any of the blocks in the blockchain is tampered with, all the later blocks’ hashes would change as they are dependent on the previous block hash.
Transaction Hash - Hash of all the transactions that are selected in the block. This hash is also known as Merkle Root Hash (Merkle tree is a data structure in which these transaction’s data is stored)
Timestamp - Exact date and time at which miner claims to have successfully created the block.
Difficulty - This parameter decides how hard it is to mine the block or solve the mining puzzle. Bitcoin adjusts the mining difficulty of verifying blocks every 2016 block. The difficulty is automatically adjusted to keep block verification times at around ten minutes.
Nonce - This is called the solution to the mining puzzle. More details explained later.
Transactions - List of all the transactions that are selected in the block by the miner.
Mining Puzzle
Mining Puzzle is a cryptographic puzzle that requires the miner to find a hash of the block header with a certain number of leading 0’s. Difficult decides how many leading 0’s are required in the header hash.
The more the difficulty parameter, the lesser is the chance of getting hash with the corresponding number of leading 0’s, more difficult the puzzle becomes.
If we look at the candidate block, all the things i.e. block height, previous block hash, transaction hash, difficulty are fixed. Since we know from the property of hashing function, changing the input slightly changes the output completely.
There is no way to change the inputs of the candidate block, so a random parameter called nonce is introduced into the block. To find the perfect block header hash, the nonce is iterated starting from 0 till you satisfy the condition of leading 0’s.
Why would miners do such expensive computation?
Miners have two incentives to compete with other miners and do the expensive computation.
Mining Fees - On successfully writing a block on the ledger, miners get to take the mining fees attached with every transaction.
Block Reward - On every new block written to the ledger, a fixed amount of new bitcoins are generated which are given as a reward to the miner. The amount of bitcoin that will be generated with the mining of each block is already fixed in the code. Total 21 million bitcoins will come into existence till 2140 and the mining reward gets halved after every 21000 blocks (~ 4 Years) are mined. This also gives a deflationary nature to Bitcoin.
If miners solve the puzzle and can prove to the network that they have generated the block header faster than any other node in the network, their block of transactions is written onto the ledger.
Forking and Ledger Reorganization
Since a lot of miners are trying to solve the mining puzzle, it could be possible that two of them come up with a solution at the same time. They broadcast their block at the same time, this might lead to a case where some other miners receive block from one miner earlier than the other miner due to network lag.
In such a case, miners create a fork i.e. they keep trying to place both the blocks at the same height in the blockchain. The other nodes which have to validate these blocks can receive either of these blocks first. On basis of the block they receive first, they start mining the next block. They keep on adding further blocks to their version of the chain until they are sent another chain by the network that is longer than the one that they are working on. Once, the longest chain is established, the smaller chain is discarded and its transactions are then sent back to mempool where they wait again to be included in the blockchain.
Reason for selecting longest chain - According to Proof of Work consensus, more blocks in a chain means more work has been done behind making that chain. That block will have the most public support or more than 50% of nodes will have the blocks that are part of the longest chain in their ledger.
Double Spending and 51% attack
As mentioned earlier, Bitcoin was the first solution to the double-spending problem. Let’s understand how it is solved in more detail.
Since the production of bitcoin is fixed using the code, new bitcoins can’t be created. Every bitcoin that is ever produced is registered into the ledger. If you spend the bitcoins you own and that transaction is registered into a ledger then you can’t fake to the network that you still have those bitcoins. The only way you can spend those bitcoins again is if you can bring a copy of the ledger where that transaction has not been registered and 51% of the nodes in the network accept that copy of the ledger to be legitimate.
If someone in the world gets access to 51% of the hash power available in the world, then they can start creating their own copy of the ledger where they can modify the original blockchain in such a way that they will not write their transactions into their copy of the ledger and once their copy of ledger becomes longer than the main chain they can broadcast it to all the other miners of the network. Since their chain will be the longest miners will have to accept that chain. This way they will be able to tamper with the blockchain and will be able to get those spent bitcoins back into their account.
The chances of 51% attack are next to impossible for reasons:
It is highly improbable that one malicious party will be able to get 51% of the hashing power of the world. Lots of big corporations and retail miners have set up huge mining rigs.
Bitcoin is valuable till people trust this network. If something like a double-spending or 51% attack ever happens, the trust in the network will collapse and thus the value of bitcoin will collapse. It is not financially feasible to run such high-energy computations to break the trust in the Bitcoin network. Because once the trust is collapsed, you’ll have the bitcoin in your account but the actual value of those bitcoins will become zero.
Problems with Bitcoin
Some of the problems with Bitcoin are:
Since Bitcoin is based on Proof of Work consensus all the miners are competing with each other to mine a block. The miner who mined the block is rewarded with the block reward and also gets to keep the mining fees whereas all the other miners who were also competing don’t get anything for their calculations. Due to this, a lot of computational power, and hence electricity, is wasted in doing redundant calculations. Due to high power requirements, a lot of carbon is produced that has a severe impact on the environment.
Finding the solution for the puzzle requires a lot of computation power which requires a lot of energy. Big organizations are setting up mining farms dedicating specialized computers for mining also called ASICs (Application Specific Integrated Circuit). This has reached such a stage that it is no longer profitable for miners not using this special hardware (ASICs) to compete in the mining game. This is a dent in the ideology that the network’s decisive powers should not be concentrated with certain large parties like the mining farms.
Block time of Bitcoin is currently 10 minutes. That means, for transactions to be written on the ledger will take a minimum of 10 minutes. This can take even more time depending on the network congestion or volume of transactions at the moment. More the transactions, miners will choose transactions with higher mining fees. For prioritizing the transaction people will have to give higher mining fees. Those transactions with lower mining fees might have to wait for hours in mempool to be selected by miners in their block.
Many projects have sprung up since Bitcoin that aim to solve these problems and add new capabilities.
Bitcoin is far from a perfect system and has a long way to go before it can even stake to replace the current financial systems. However, it still made a remarkable contribution towards opening up the domain of digital currency based on blockchains. We would, the ensuing articles, explore some of the wonderful domains that have evolved from crypto’s evolution.
Also, If you are interested in writing with us. Do hit us up!