What is Bitcoin? how does it work?
Bitcoin is just like any other form of money. But the big difference is it doesn’t have any central authority governing the currency flow. Normal currency usually has respective governments and banks governing the currency flow.
To understand bitcoin first you need to understand the concept of ledger. Ledger is a piece of document that keeps track of a set of transactions. Let’s think there are 4 people sharing money between them. Let’s name them A, B, C and D. They may transfer money between each other multiple times during a certain period of time. But giving money at each time may be difficult. So what they can do is keep a ledger which keeps track of who gave money to whom. Then after a certain time, maybe a month they can look at the ledger and settle how much each other have to pay to whom. Ex.








To understand bitcoin first you need to understand the concept of ledger. Ledger is a piece of document that keeps track of a set of transactions. Let’s think there are 4 people sharing money between them. Let’s name them A, B, C and D. They may transfer money between each other multiple times during a certain period of time. But giving money at each time may be difficult. So what they can do is keep a ledger which keeps track of who gave money to whom. Then after a certain time, maybe a month they can look at the ledger and settle how much each other have to pay to whom. Ex.
In above ledger entries being added. So at the end of the month it can be calculated how each other gets and has to pay. Rather than paying money each time.
Now this is the concept of cryptocurrencies as well. But before converting this into cryptocurrency. We need to solve a few issues in the above model.
First thing is since this ledger is publicly available for A, B, C and D anyone can put any transaction to this. For example A can put B paid me 400 even though B didn’t didn’t pay me any. So to avoid this each transaction should be verified by payers signature. So ledger will look like this,
This is a digital signature in computer systems.
Next issue is what will if B copies above entities. That means copy and paste entry “A pays B 100 signOf(A)” to have multiple entries. Even though A only paid B one time. To avoid this we need to add a transaction id to each entry. Then the digital signature of each entry should also be unique. Using this we can make sure no one can forge transactions.
First let’s talk about these digital signatures. Usually in the real world signature is a unique item for each individual. But digital signatures in cryptocurrencies is different from that it changes from transaction to transaction even for a specific user. So they are more robust than real world signatures. Here we use a hash for the signature. To generate the hash we use hash functions.
Here each user has their own private key and public key pair. This private is used to generate the hash and public key is used to verify the hash. Private key has to be kept to yourself. Public key is shared between users. To generate a hash you need to call a hash function. Also you need to define a hash algorithm. Bitcoin uses the sha256 hashing algorithm. This is a very commonly used hash algorithm in many applications. So to generate the hash transaction message is used as well. It will look something similar to this.
hash = generateSha256Hash(transactionMessage, privateKey)
Hash is basically a bit stream. Here it will contain 256 bits. Once this is generated we can add it at the end of the transaction. Now for anyone to verify the transaction they have to call the verify function.
boolean verified = verify(transactionMessage, hash, publicKey)
This returns true / false value depending on the validity of the hash.
So what is so special about these hash values. Basically they are almost impossible to reverse engineer. Let’s say we have a hash value like hash_1. Using this we cannot get the private key even though we know the transaction message and hash algorithm. So basically this hash is a value which only can be verified using the public key. Any change to transaction message or private key will change the hash_1 value completely. This change is completely random. So the only way to make verify true without knowing the hash signature from a specific user is to guess the hash value until verify == true. That means guess the hash value produced by a specific user using his private key. But the problem is since there are 256 bits there are 1/2^256 possible values for a given hash. Value for this given below.
So this is almost impossible to do. So this makes it so reliable.
Let’s move to cryptocurrencies again. Using this digital signature you can make sure that transactions can’t be forged.
Next issue for us to resolve is how to stop people leaving the system without settling their transaction values. For example B can put some transactions in the ledger but he will leave the system before ledger values are benign settle at the end of the month. To avoid this what we can do is not allow users to spend more than they have. So initially what should be done is give each user some amount of money. Something like this.
So these will be the initial amounts each user has. So each user has to put 1000 into a common bucket at first. Then transactions can proceed. But no user can spend more than they have. Amount they have will change with the transactions happening, but this means they simply can’t leave the system without settling.
So now the system has to make sure that none of the transactions above are contaminated by malicious parties before adding a new transaction entry. To do that when creating the digital signature (hash) use all the transaction entries up to now. So the new hash function will look like this.
hash = generateSha256Hash(listOfTransactionMessagesBefore, privateKey)
So if some malicious party decided to change the transactions above for his preference generated hash will be changed.
But there is another issue here, if we keep the ledger centralized in one location it will lead to a single point of failure. Also some third party need to be there to manage the ledger and it will be prone to malicious attacks. Now let’s see how bitcoin has resolved this issue.
Cryptocurrencies tend to be decentralized systems. This is certainly the case with bitcoin. The ledger that we mentioned above is copied to all the peers in the bitcoin network. All transactions are synchronized to all the peers at some point. Bitcoin maintains a blockchain in order to maintain the list of transactions. This blockchain acts as the distributed ledger.
This blockchain consists of a list of blocks attached one after another. Each block has its own hash. This is a cryptographic hash signature. Now this works as follows.
Add a number at the end of the list of transactions after the last block and generate a hash using that number and selected transactions after the last block and the hash of the last block.
This can be represented as follows.
blockHash = generateSha256BlockSignarate(hashOfPerviousBlock + listOfSelectedTransactionsAfterPreviousBlock + specialNumber)
Once this number is generated it is very easy to verify the special number, all we have to do is use the above combination to make sure the hash value matches. So for verification don’t have to go through the process again. This is called the proof of work in bitcoin. So how difficult is it to generate this special number?
Let’s say generated hash value value must have 30 zeros at the beginning. In this case the probability of a given special number providing a 30 zeros in the beginning of the hash is 1/2^30. So to get this number for the first time you need to be very lucky. But once you get the number verification is very easy as mentioned earlier. So a large amount of computation work is required to generate this special number in the first place. That work can be verified by a verification process which is called the proof of work. This is the consensus in bitcoin.
Now let’s move further. This ledger is distributed. That means the CAP theorem applies. According to CAP therium in a distributed system we can either have two of (Perfect) Consistency and Availability, Availability or Partition tolerance or Partition tolerance and Consistency. From practice we know that in any distributed system partition tolerance is a must. Since networks are unreliable. And in most publicly available distributed systems availability is preferred over consistency. This is the same for the Bitcoin system. So at a given time blockchain for a given peer may differ from a blockchain of another peer. So how to reconcile this. So the solution given in bitcoin is always choose the longest blockchain. Even partitioned systems will come online after sometime. Once they come online they will compare their blockchains with other blockchains and they will take the longests chain. This way even though there is no perfect consistency always, consistency is achieved so at the end everybody agrees with a common set of transactions.
Now let’s discuss the impacts of this. Let’s say you are in a partitioned network (which is more than likely). Your transaction is in the last block where you will receive some amount of bitcoin. Now let’s say you agreed to the transaction immediately. Now when your network gets synchronized with outside networks your blockchain is replaced by the longest chain. That means your accepted transaction is lost. So you will lose the bitcoins you got from the transaction. So the rule of thumb is wait for at least 6 blocks to be added after the transaction before confirming. In bitcoin a new block is added every 10 minutes. This means you have to wait for around 60 minutes to accept a transaction. This will usually guarantee your transaction is not going to be lost. In the case of very large transactions you should wait for longer. Max block size of a bitcoin is 4mb but usually the actual value is around 2mb. This depends on transactions added to that block.
Ok in the above paragraph I mentioned that every 10 minutes a new block is added. How does bitcoin guarantee this?. This is actually down to miners. Miners are the people who are trying to find this next block in the blockchain. So the amount of miners in the system changes from time to time. So for the 10 min period to be maintained, the blockchain system changes the amount of work required to mine the next block (special number). This is done by changing the number of leading zero bits. I took this number as 30 earlier. But in the real system this changes from time to time to make sure a block is generated every 10 minutes. So if you manage to find a new block system it will give you some amount of bitcoins. That means the system will generate new bitcoins and will give that to miners who found that new block. This is bitcoin mining. Amount of bitcoin you get reduces. As per 2020 miners will get 6.25 bitcoins per block. This is called the Block reward. This gets reduced in half every 210000 blocks. That is roughly 4 years. This is a one incentive miners get from mining. Also when you initiate a transaction you can put some amount of coins from your transaction. So a miner will receive that amount if he decides to add your transaction to the block he is trying to find. If that amount is high is it more likely to get added to a block quickly. So chances of your transaction getting verified quickly is higher. In some cases you might have to wait for days to make sure your transaction is verified. This is another way miners will receive the money from the system.
So can someone cheat the system? Well the only way to cheat the system is to steal someone's private key for their bitcoin wallet. These keys are usually stored somewhere. There is always the possibility someone might steal this. If this happens, that person will be able to do transactions on your behalf. Bitcoin transactions are irreversible. So you will be powerless to stop it. But it is the user's responsibility to keep their private key safe. As per the network anyone who has the private key, he is the user. So cheating in the system is pretty much involved with impersonating a user in this way.
So why can’t we create new blocks with some fraudulent transactions and broadcast? Well you can do that no problem. But first you need to find the special number for that block. Now let’s say you included a transaction in your block that A paid B 10 Bitcoins. Let’s say this is a fraudulent transaction. Now even if B received this block he will wait for more blocks to be added to the block chain. Other peers will also generate new blocks. For A to keep his fraudulent transaction he has to keep finding blocks faster than all the other miners in the world. Because otherwise his chain becomes smaller and B eventually accepts the longest block which will discard A’s blocks with fraudulent transactions. So for A to keep this up he must have 51% of computational power of all the bitcoin miners of the world so A can find blocks faster than all the miners in the world. So this is practically impossible. This makes a system that is very robust against frauds.
Bitcoin has something called mempool. Once you post a transaction it goes to this mempool. From there miners will pick transactions which will be added to their blocks. So more the incentive, more chance of the transaction getting added to a block. But usually all the transactions get added to a block after sometime. But in some cases you might have to wait for days until the transaction is verified.
Issues with bitcoin system
Main problem is scalability. Bitcoin has a low transaction per second compared to other services like visa / paypal. (Below values are in TPS)
- Visa: 24,000 transactions
- Ripple: 1,500 transactions (cryptocurrency)
- PayPal: 193 transactions
- Litecoin: 56 transactions (cryptocurrency)
- Dash: 48 transactions (cryptocurrency)
- Ethereum: 20 transactions (cryptocurrency)
- Bitcoin: 7 transactions
Above are some of the TPS (transactions per second) rates for different payment services. As you can see Bitcoin is very low compared to other payment services. This is down to consensus difficulty and block sizes in bitcoin. This makes it relatively long time needed to create a block in bitcoin causing a low TPS. Bitcoincash is a new cryptocurrency introduced to improve the TPS. But we are not going to look into that in this blog.
Another problem in cryptocurrency is relatively larger miner incentives. This is also caused by low TPS, So if you want to make your transaction included in blocks faster you have to provide a larger incentive to miners.
Also since the amount of bitcoin you get from mining reduces as the time goes. So the maximum possible bitcoin in the system will be 21 million bitcoin. Also sometimes users' private keys are lost. In that case those bitcoins are practically unrecoverable. So the actual number may be far less than this.
So why 21 million only? First let’s see how we get this 21 million
6 blocks per hour, 24 hours per day, 365 days per year, 4 years per cycle that means 210,240 blocks let’s round this up to roughly 210,000
So at start block reward was 50 bitcoins,
Sum all the block reward sizes:
50 + 25 + 12.5 + 6.25 + 3.125 + … = 100
Multiply the two:
210,000 * 100 = 21 million.
So the person who created the bitcoin system decided this is the maximum amount possible. Well who actually came up with this? Satoshi Nakamoto is the person credited for creating the bitcoin system. This was presented in a paper called “Bitcoin: A Peer-to-Peer Electronic Cash System” But nobody really knows who the actual person responsible for this system is, even though a person is identified. Some claim Satoshi Nakamoto is a group of people rather than one. Well you can do some investigation on this yourself. But whoever came up with this is a real genius. No question about that.
Comments
Post a Comment