Bitcoin is the world's first and most popular digital currency that is completely decentralized and not controlled by any particular authority or organization. You may be curious to know why you can’t copy your bitcoins or what prevents you from doing transactions which don’t belong to you. In this article we will plainly be talking about how Bitcoin works and what the technology underlying this digital currency can be used for other than finance. Bitcoin has overcome three record-related challenges, and does not require a decentralized registrar such as a bank.These challenges are as follows:
1-Proof of Bitcoin Ownership
2-Preventing third party intervention by recording past transactions
3-Providing a valid general ledger
1) Proof of ownership
When a transaction takes places within the network, how can we make sure the transaction has been done by the owners of the bitcoins and not a fraudster? The answer to this question lies in the computer cryptography.
Private and public key encryption
In this type of encryption, data encrypted by one key can be decrypted by another key. One of these keys is public but the other one must be kept private. This feature can be used to send a secret message and in the meantime, that message becomes incomprehensible to third parties, so only the recipient is able to decrypt it by the private key.
Bitcoin transaction signatures
Bitcoin wallets are actually a combination of private and public keys. When someone gives you their wallet ID, it's actually the public key. When you transfer coins to another wallet, the Bitcoin software uses your private key to verify that the transaction is going to be done by you and not a fraudster. In this case, when the sender wants to send some bitcoins to the recipient, he uses his private key to sign the transaction and everyone on the network is sure that the transaction is from the sender because his public key can decrypt and verify this transaction. Bitcoin is like a general ledger that contains inputs and shows how much bitcoin has been sent from one person to another, and all of these transactions are digitally verified. It's just like a paper ledger where entries are written and each entry is signed.
2) Intervention in the general ledger
Another challenge facing Bitcoin is the intervention and manipulation of the ledger. Supposing you sent some bitcoin to a friend last month and now you regret it. What could prevent you from deleting or modifying the transaction from the general ledger? The answer to this question is a computational method which is called Hashing. Hash is an algorithm for verifying data. Any message can generate a hash value, but small changes in that message can lead to fundamental changes in the hash value. To gain a better understanding of Hashing, have a look at the two messages and their hash values.
Bitcoin makes use of this computational method. It uses a hash to verify that its general ledger has not been tampered with. A set of transactions is periodically published together as a new record, which is called block. Each block stores the hashes of its previous block transactions. As can be seen from the picture below, there is a three-block ledger.
If I go back and delete transaction 3 from the first block, everyone will notice that it is invalid because the hash in block 2 proves that block 1 has been tempered with. Even if I edit block 2 to make sure that block 1 confirms my forgery, this idea will not work either because the hash value in block 2 is used as input to create block 3 hash validation and block 3 hash reveals that block 2 has been manipulated.
In short, it is impossible to manipulate any part of this general ledger, and for the slightest manipulation, a completely new general ledger must be created. This is why the general ledger is called blockchain; all the blocks are perfectly connected and cannot be separated.
3) How to make sure a blockchain is valid and reliable
Imagine our blockchain has two blocks, two new transactions are done, attached to the general ledger and at the same time three other transactions are attached. Now we have two rival blockchains.
Proof of work
This is solved through a concept called Proof of Work (POW). Computers convert hash values to zeros and ones like this:
Imagine we’ve created an obstacle against adding a block to the general ledger unless the hash confirms that the previous block starts with zero. In this case, there will be a fifty-fifty chance of getting the hash we want to have.
Similarly, if we create an obstacle that requires an initiation with two zeros, we’ll then have a 25% chance.
This increases exponentially. Now supposing we create an obstacle that should start with 32 zeros, our chances will be approximately 1 in 4 billion.
Bitcoin poses such a barrier. However, the hash of the previous block always remains the same. Now the question arises as to how we get the hash that can break through this barrier with a fixed input. The answer is that this is done by adding a random value to each block which is called nonce value. When calculating the hash, the nonce value is combined with the previous block. Before adding a block to the general ledger, computers around the world move through random values and search for nonce values that lead to a hash that starts with a certain number of zeros. Finding such a value is the proof of work (POW)
This is computationally very intense but it can be estimated how long it will take. When it comes to Bitcoin, it is a block that will last an average of 10 minutes. Over time, computers will become more powerful, and so the situation will become more difficult for Bitcoin and more zeros will be needed each time a certain number of blocks is released. Bitcoin difficulty is a measure of how many hashes (statistically) must be generated to find a valid solution to solve the next Bitcoin block and earn the mining reward.
The longest general ledger is the oldest
Since proof of work does not allow new blocks to be issued faster than a certain rate, we know that any general ledger that is longer than another general ledger is older. It is impossible to create a blockchain, unless the computing power we have is greater than the computing power of all bitcoin users together.
In short, when competing general ledgers exist on the Internet, all bitcoin users recognize the one with the most blocks as the oldest, and therefore consider it a valid general ledger.