Blockchain, cryptography and cryptocurrencies maybe the terms which you might have heard and may seem to be daunting at first to anyone.
Without putting much emphasis on the word to word definitions of these things, let’s get started straightaway. You’ll get to know about the real meaning of a lot of things along the way.
Suppose you have three friends — Alan, Bill and Steve. All four of you do transactions frequently. But since you live in different cities, it is not possible to pay in cash immediately. So we come up with an idea of creating and maintaining a LEDGER.
All the transactions performed will be added to the ledger.
A transaction will have the payee name, reciever’s name and the amount of money to be paid.
Now suppose you people meet once in a month. The person who has to pay more than he recieves, puts the difference into the pot. The person who has to recieve can take the required amount from the pot. This way we can easily solve the problem of not being able to pay immediately.
This ledger would be in one place and available for everyone to see, that is, it would be centralized and public.
Taking the above example — Alan has to pay $50, Bill pays $100. So there would be $150 in the pot to take.
You get $50 while you have to pay $25 so you will pick up $50-$25 = $25 from the pot. Steve will pick up $125.
Therefore, you all settled the balance easily using the ledger system.
Anyone can add a line to the ledger.
This means that Bill might add a line to the ledger like Steve owes Bill $300 without even Steve approving of it.
You might think that there should be a way so that Steve can approve or disapprove a transaction made on his name. And yes you’re right.
We can think of using digital signatures to authorize every transaction made.
You can’t sign on a digital ledger just like you do on papers. Therefore you might think of using a unique pattern of binary digits which would represent your signature.
Your signature on paper with a pen is a bit difficult to exactly copy. But the above signature that we used is nothing but a simple pattern of numbers which can be easily copied.
Bill, being a clever person, initiates a transaction of recieving 100$ from Steve.
Steve approves it with a digital signature. However, now Bill can copy the signature of Steve as many times as he wants and generate fake transactions.
LOOPHOLE: Anyone can copy the pattern of binary numbers to create as many fake transactions as required.
Alan comes up with an idea for implementing a public key encryption system for digital signatures. I would like to discuss the Public Key Encryption sytem in very brief. A lot of complicated maths is involved in actually implementing this but that isn’t a concern.
Public Key Encryption System
Each one of you will have a private key as well as a public key.
As the names suggest, your public key will be available for all to see while the private key has to be kept a secret.
These private and public keys would be used to uniquely generate a digital signature and also verify that. Let’s see how,
Your secret key is required along with the message to generate your digital signature.
The Signature function will take two inputs for now — The Transaction Message and Your Secret Key. It will spit out a 256 bit long digital signature to be attached with the transaction.
A Verification function will take three inputs, the message, signature and your public key and tell if the signature is valid or not.
Now that the digital signature requires the private key of a person and the message, one cannot simply multiple transactions as digital signatures would be different for each message.
But there’s still a loophole left to be covered.
Suppose Steve approves the transaction of $100 to be payed to Bill. Bill can copy the same message as many times as he like because the message and the payer keys are the same.
The solution to this problem is to attach a unique ID with every message and make it as an input to the Signature as well as the Verify funciton.
Protocol created until now:
- Anyone can add lines to the ledger
- Settle up with real money each month.
- Only Signed Transactions would be considered valid.
A huge problem of trust issue is solved with the public key cryptography signatures and indexing of transactions.
What if a person promises to pay more money than he actually has and goes on adding transactions and doesn’t actually show up when real money is to be exchanged.
Give everyone a fixed amount of money
Let’s suppose that 200 bucks are distributed to everyone at the start. So now we just have to check that no one spends more than that.
The situation of someone spending more than he has can be caught easily if a running balance is maintained for each person.
Like in this situation the last transaction made by Bill is invalid because he has already spent 200 bucks and didn’t recieve anything. So as his balance has become 0$, he can’t send more than that.
Did you notice the fact that since a virtual kind of currency has been distributed to everyone, we do not require actual money to perform transactions now. We have set up our own virtual currency which people can use to perform transactions. Let’s call our new currency Ledger Dollars.
Anyone of you can exchange your Ledger Dollars with some other person in exchange of real currencies like USD, GBP, etc. for any amount. The exchange rate will be decided by the market itself but that is a topic for a different article of how the BTC-USD and other rates are decided.
Starting from a simple ledger, you have now reached a stage where you’ve created your own virtual currency. To make it sound fancier, you can call it a cryptocurrency.
I had mentioned two words: Cryptocurrency and Decentralised. We have taken care of what a cryptocurrency is, now we should look at the second aspect called Decentralisation.
Our ledger is still kept in one centralised location. You have to trust the authority who is maintaining the ledger and there’s also a chance of the database getting corrupt and all transactions become null and void.
Trust on the authorities, big organisations and companies can backfire if the company loses your data in a big blunder, or someone managing the database is paid to modify some data. These things are not uncommon and have been happening in various sectors since a long time. Decentralisation however appears to be the correct answer for this.
The basic philosophy of decentralisation is to let everyone connected in the network keep his/her own copy of the ledger instead of mainting one central ledger. Whenever a new transaction is made, it should be broadcasted to everyone’s ledger so that everyone is updated.
A new problem arises with this setup, how can you believe that the transaction that your system recieved is the same as everyone else has recieved. Not only this, but we also have to keep the track of everyone’s current balance.
The solution to this problem is the very fundamental basic of how a decentralised ledger system will work.
Trust the ledger with the most amount of Computational Work put into it.
To actually understand what Computational Work is, let’s understand a little bit about Hash Functions.
A Hash Function is a mathematical function which returns a very random digest or a number. Hash function applied on the same message will generate the same output. There is no way to get the original message by somehow decrypting the digest.
Even a small change in the message changes the digest drastically.
One such example of a hash function used widely is the SHA256 function which returns a 256 bit number.
A 256 bit pattern can represent 2²⁵⁶ different possible messages. To give you an idea of how difficult it is to extract the original message : Breaking a symmetric 256-bit key by brute force requires 2¹²⁸ times more computational power than a 128-bit key. Fifty supercomputers that could check a billion billion (1018) AES keys per second (if such a device could ever be made) would, in theory, require about 3×10⁵¹ years to exhaust the 256-bit key space.
But how does this SHA256 help you solve the problem of computational work required?
Remember that we have already taken care of verifying all the transactions, now the problem is that we have to make sure everyone keeps the updated and correct version of the ledger.
To make the transactions secure and make them immutable we’ll start by bundling up a few transactions into a block.
Each block to be added to everyone’s ledger should contain a proof of work or computational work attached with it.
PROOF OF WORK
To consider a block valid, a number must be added at the end of the block. Suppose, the hash of the function along with the appended number must start with 40 zeroes for a block to be considered valid and broadcasted to everyone.
As discussed earlier, it is very difficult to guess the number with which this pattern can be achieved. This requires the system to try billions of numbers so that the hash of the block starts with 40 zeroes. This number will be the proof of work which will be intrinsically tied to the block and this will make it secure and permanent.
You’ll later understand the importance of achieving a specific pattern of hash digest for a block to be considered valid.
Now since the transactions in a block are in a specific order, the blocks also must be in an order. This is achieved by arranging them in a chain like structure. One block should also contain the hash of the previous block with it. The hash for this block will also depend upon the hash of previous block and this the whole chain behind it.
If we try to change the order of the blocks or even a bit of a transaction of block, a domino effect forces every hash and blocks to change which is impossible. You’ll have to do all the work again for each block to find numbers for finding specific patterns. The electricity and computational power is astronomical.
Therefore, now that we have created blocks which are arranged in a chain like structure and are decentralised structure. We have finally created our DECENTRALISED BLOCKCHAIN.
If you remember, I mentioned that the system has to try billions of numbers.
Actually this is done by people called Blockchain Miners. Blockchain miners listen to the transactions, bundle them up and try to find the specific pattern. A lot of their monetary and time resources are wasted upon trying to find the all important number. In return of their work, they get incentives/block reward transactions for each block they successfully mine.
Thousands of blockchain miners are out there with their powerful GPUs and machines playing a kind of a lottery.
The lottery is : The one who guesses the number for a block first gets the reward for it.
A transaction for paying cryptocurrency to the miner is automatically appended with the block. No one actually pays that money. Thus, new bitcoin currency is generated with each block mined. This block would be broadcasted to all the people on the blockchain network.
WHAT IF YOU HEAR TWO DIFFERENT BROADCASTS?
You should always trust the chain with more amount of computational work attached with it. If they are same, wait for some more broadcasts and then go with the longer chain.
To see if this system is secure, we’ll see what happens when one tries to create fraudulent transactions and how the dependency on computational work actually solves the problem.
CREATING FRAUDULENT BLOCKS
Let’s suppose Alan broadcasts fake blocks to your ledger. He’ll have to mine the blocks containing fraudulent transactions quickly than other miners. This is very difficult but let’s suppose it’s possible.
To keep that fraudulent transaction in place, Alan will have to keep mining quicker than others so that you always trust Alan’s broadcasts. Going by statistics, Alan will have to own more than 50% of World’s computing resources so that one transaction stays.
Therefore, creating frauds and fake transactions is almost impossible and this makes blockchain network the safest method of keeping records.
The records which are decentralised, immutable and cannot be destroyed.
The Main Ideas that we have discussed upon are:
These few ideas are the underlying basics of the blockchain network and are used by almost all the cryptocurrencies and blockchain systems.
APPLICATIONS OF BLOCKCHAIN
Bitcoin, Etherum are just a few examples of the use of blockchain network. I discussed with you how to create a virtual currency exchange network but the blockchain fundamentals are not only limited to financial applications.
Blockchains can be used to create voting applications, Unique Indentification systems, Land Record Systems, Health Record Database.
You can see blockchain as more of a modern version of a database which is decentralised and immutable and requires no middlemen and organisations.
It is a natural continuation of the mankind’s efforts to remove the dependency on trust on other people for doing basic things like trade.
I hope this article helped you to understand the underlying groundwork of the blockchain systems coming up.
I’ll be writing more articles on blockchain and cryptography. Follow me > Aayush Joglekar.
Give as many claps as you like, they’re free. ❤ I would love to hear responses from your side. Share this article if you found it useful. ❤