Pages

Monday, March 29, 2021

How does a Cryptocurrency transaction work?

DISCLAIMER: This is not a written-from-the-scratch know-it-all original article. I have collated this information from different sources on the internet in one place for my own reference. So don't cry "plagiarism" because this is an up-front admission.

A transaction in the cryptocurrency space involves the transfer of certain units of the currency from one "address" on the network to another (an address is an identifier just like an account number in a bank record).

This requires a "Wallet".

A wallet is typically a software such as an app on a phone that allows the users to manage its address, "public and private keys".

Private and public keys are strings of letters and numbers used to protect messages cryptographically. An address is the transformed shorter function of the public key.

While the account address is public, only a private key can 'unlock' the address to make the transaction.

A public key coupled with a private key helps to keep a user's holdings secure in the digital ecosystem. As the term "public" suggests, a public key is a unique personal address that is shared in the blockchain network and everyone can see it, while a private key works as a password that you must keep just to yourself.

It is impossible to regenerate the private key from a public key or address, so if an owner loses their private key, any bitcoin or altcoins located at this public address will be inaccessible. However, if the owner loses the public key, it is possible to recreate it with private key.

A bitcoin public key is made up of an extremely long string of numbers, so it is compressed and shortened to form the public address - which is like a bank account number. When two people enter into an agreement in which one sends the other bitcoins or other cryptocurrencies, they reveal their public addresses. The public address is a hashed version of the public key and users can make as many public addresses as they want in order to receive bitcoins.

"Hashed Version"? What Does this Mean?

In simple terms, hashing means taking an input string of any length and giving out an output of a fixed length. In the context of cryptocurrencies like bitcoin, the transactions are taken as input and run through a standard hashing algorithm (SHA) which gives an output of fixed length. 

For example, in case of SHA-256, no matter how big or small your input is, the output will always have a fixed 256 bits length. This becomes critical when you are dealing with a huge amount of data and transactions. So basically, instead of remembering the input data which could be huge, you can just remember the hash and keep track.  

Double Spending Flaw 

Double Spending is a potential flaw in a digital cash scheme in which the same digital token can be spent more than once. Unlike physical cash, a digital token consists of a digital file that can be duplicated or falsified. Without the presence of a third party facilitator, a currency system based on a decentralized ledger is susceptible to aforementioned double-spending attacks.

This brings us to the Byzantine Generals Problem.

Byzantine Generals Problem

This problem was proposed in 1982 by researchers from the SRI International Research Institute.

It goes as follows: there are a number of Byzantine generals besieging a city. The can only communicate via sending messengers to each other. The generals must agree on a common plan of action: whether to attack the city or retreat. However, some of the generals are traitorous and actively working against the forming of a consensus; their number and identities are unknown.

The question posed by the problem is what decision-making algorithm the generals should use to devise a common plan - regardless of the traitors' interference - and whether such an algorithm exists at all.










This problem is highly relevant for cryptocurrencies as they are, in essence, distributed computer systems: they are composed of transaction processing nodes that are 

a) operated by independent people or organizations that compete to process transactions

b) are seperated geographically

c) are independent of each other and any central authority 

d) can only communicate remotely. 

They are the "generals" that need to reach a consensus about which transactions have taken place and when.

The Nakamoto Consensus

The core innovation that Bitcoin brought in this space was through its consensus mechanism, known as Nakamoto Consensus.  

Created by Satoshi Nakamoto in 2008, the Nakamoto consensus answers the Byzantine Generals' Problem and says that it is indeed possible to form a consensus in a computer network of independent, distributed nodes. 

It is a set of rules that verifies the authenticity of a blockchain network, using a combination of the proof of work consensus algorithm on a Byzantine Fault Tolerance (BFT) peer to peer network.

Now what is a blockchain network, proof of work consensus algorithm and Byzantine Fault Tolerance? Let us take them up one by one.

Blockchain Network

Since the decentralized ledger is composed of blocks of cryptocurrency transactions, it is essential for the network to identify the validity of these transactions, and thus the validity of existing chain of transactions in the absence of a trusted third party. 

In order to permanently publish transactions as valid on the bitcoin ledger, the transactions need to be verified together as a group of transactions known as blocks. Once the transactions are verified, they are added on the existing chain of transaction blocks, or Blockchain.

Proof of Work

However, a computationally challenging (and now, resource intensive) cryptographic puzzle needs to be solved to validate the transactions. The puzzle is designed in such a way that the solution of the puzzle should partially have the same characters as the hashed output of transactions. This points to the validity of the transaction in the system while maintaining the psuedonymity of the details. The puzzle is randomized in nature, in order to spread evenly the possibility of finding the solution.

This entire concept is called proof of work, and is the basis of enhancement of multiple blockchains across different cryptocurrencies. If a block is found to have invalid transactions, it is rejected by the participants. These participants, striving to find a solution to the puzzle, are known as Miners, and get a transaction fee and a unit of the cryptocurrency, that they are able to generate after solving the puzzle. The mining computation process is a little bit like a lottery: it's not possible to tell who will find the solution, meaning that miners have to be willing to honestly invest time and money in their participation to validate the next block.

This creates an environment where the honest nodes survive and malicious nodes are discouraged. It also prevents the possibility of double spending, since the time-stamped blocks on the blockchain makes it immutable - the longest chain is the valid chain, since it is supported by the majority of the miners' computing power.

Byzantine Fault Tolerance (BFT)

It refers to the property of a distributed computer system that allows it to overcome the Byzantine Generals Problem and consistently form consensus regardless of the fact that some nodes disagree with the rest, either accidently or on purpose. This can be achieved via technical solutions like Bitcoin's Proof of Work algorithm (mentioned above) but only if more than two-thirds of nodes remain loyal to the system. 

Limitations of BFT

The Byzantine Fault tolerance can be called a precursor to the Nakamoto Consensus, and it had its limitations. for one, in just a BFT system, the voting system for consensus requires a rotating election of leaders. If a leader acted maliciously, as leaders are known to do, then they could be removed from the network by a vote from the other nodes. In the case of Bitcoin (and for the idea of a digital currency in general) this individual removal of leaders through a voting process would pose a huge challenge when it came to scaling.

Conclusion

Satoshi Nakamoto's addition to using BFT on a P2P network was to add the idea of a proof of work consensus mechanism, where nodes had to mine to create a fully decentralized network. Another aspect of Nakamoto Consensus comes from him putting a hard cap on the amount of Bitcoin - there will only ever be a total of 21 million of the cryptocurrency in circulation. This creates artificial scarcity, which again adds to the incentives for miners to participate in the network.

No comments:

Post a Comment