top of page
Programming

So how do blockchains and cryptocurrencies actually work!  — Exploring Web3

Updated: Oct 13, 2022


What is a blockchain?

A blockchain is a system of recording transactions in a way that is not controlled by any single entity or organization, thereby reducing the chances of the data being tampered with. Since it is a decentralized network, it is almost impossible for any single person or organization to change the information the nodes contain. All the cryptocurrencies like Bitcoin, Ethereum, etc. use blockchain technology to operate.


To use these cryptocurrencies it is not necessary to know the underlying way these transactions work but it is very interesting to know how these transactions actually take place and what safeguards are present in the protocol which makes this decentralized system of blockchains so reliable and available.

I will start with an analogy to show how blockchains work.


The Analogy

Suppose there are a group of friends and they frequently exchange money with each other. They decide to maintain the transactions in a common ledger rather than actually exchanging cash.

A ledger is a book in which account transactions are recorded.

Whenever someone records a transaction and adds an entry to the ledger, they sign it with their signature. This signature can be created digitally using the SHA256 algorithm.

The SHA256 consists of public key — secret key pair. The secret key pair is only known to the person creating the signature. While the public key is shared with everyone to verify that the signature was created using the secret key present with that person. This makes the signature authentic. Without the secret key, the signature cannot be created.

For every new entry added to the ledger, everyone else verifies that the signature corresponding to the transaction is valid using the public key. This ensures that only valid transactions are recorded in the ledger. Each signature is a hash of the transaction and its unique id. This makes sure that no one else can just digitally reuse the signature of a previous transaction.


Theoretically, with this ledger system, there would be no need for actual currencies. The amount of money a person has can be found using the ledger (history of transactions). Isn’t it interesting! This is exactly what a cryptocurrency is — a history of transactions.

In the above analogy, I have used a common ledger. But this would make the system centralized since there is only one server where the is ledger maintained. To make it decentralized, I will let everyone have their own copy of the ledger.


Whenever a transaction is made, the people broadcast the information out for everyone to record the entry into their private ledgers.


Any Problems with this system?

Yes of course, when any transaction is made, how can everyone be sure and believe that the transaction was actually made. Also, how can anyone be sure that everyone is also recording the same transaction and in the same order? This is the problem addressed in the original bitcoin paper by Satoshi Nakamoto- (an unknown person who developed the bitcoin protocol.)


The Solution — Proof of Work

Record any block that has the proof of work with it. The proof of work, in this case, is the work in which the most amount of computational work has been put. The idea here is that if there is any fraudulent broadcasted message, it will require an infeasible amount of computational work to fool the system. Let me elaborate –

Each block will have a list of transactions and a hash. Suppose a person says that he has found a number that makes the hash of the whole block start with 30 zeroes. It is a computationally rigorous task and it can be said that the block associated with this proof of work might be authentic.


Blockchains

Now that we have a distributed ledger system, we want a way for everyone to agree on what the correct ledger is and what is the order of this transaction. The core idea is to trust the block which has the most work put into it. The transactions on the ledger are divided into blocks along with the proof of work. The proof of work is the number when added to the block makes its hash start with a certain number of 0s.

A transaction is valid if it is signed by the sender. A block is valid if it has proof of work. To make sure that the order is correct, a block contains the hash of the block proceeding it.