Trading Articles

How the Blockchain Works

A clear and understandable explanation of the blockchain and what makes it impregnable... almost.

article

Blockchain for Blockheads

Whether Satoshi Nakamoto exists or not could be controversial; however, it is clear that the person/group/entity bearing his name latched onto two principals in the aftermath of the 2008 financial meltdown:

  1. Trust in nationally issued currencies can easily be manipulated and should not be entrusted to humans who are governed by instincts, fear, greed, alliances, and so forth, or the banks that employ them.
  2. Debt and credit are a departure from true capitalism since they introduce the concept of bondage – a social relationship that distorts the objective relationships required to store, communicate and transfer value/wealth.

In response, Bitcoin set itself the task of communicating value using a trustworthy medium. It is upon this precept that all cryptocurrencies are constructed, and it is, therefore, perhaps, worth our while to examine the basics of this first such system – the one from which others grew and upon which they sought to improve.
If until now, currencies were issued and maintained by government agencies and banks in order to communicate value, cryptocurrencies enable that communications directly – without the interference of an external agent. All that needs to be done is to record at all times who possess value and to whom he or she has transferred it. The question of “in return for what” is irrelevant.
Bitcoin, for example, is a system administered by all its users and built upon the wirings of binary-coded computers – it’s that simple, it’s that transparent. That entire infrastructure is called a blockchain and it is – in essence – a ledger that records transactions.

Keeping the Books to Ourselves

A ledger, to anyone too young to have actually seen one, is a book in which one records transactions. A bank ledger will record its clients’ transactions, in each line stating the remaining balance in one’s account.

Now, if that ledger is available to all, one would not need money, since the immediate recording of transactions and balance would waive the need to transfer representations of what has been recorded through the aid of a physical medium (money). Before selling your car, you could simply see if your buyer has sufficient cash to cover the cost of the car, immediately deduct the cost from his ledger page and add it to your own. The concept also cancels the need for banks and their oft-repeated tendency to satisfy their shareholders at the expense of their clients.
In practice, cryptocurrency users do not actually maintain the ledger themselves, since this is a very resource-demanding procedure. Instead, a community of “miners” collect a series of transactions, seek verification from the other miners in the community, and lock them for perpetuity in the online ledger in a series of small blocks, which form a chain of past transactions (in later lessons we will explain precisely how this works).
To participate in this ecosystem, the user/buyer/seller merely needs to download a digital wallet (since the actual “bitcoins” do not really exist) to his/her mobile app or computer. There, he receives his own encoded signature, which is proof of his ownership/identity. Each time a transaction is made, that is the identifier used.
All that is left is to find an exchange where one can buy/sell bitcoins for ready cash or trade them online without actually owning them…

The Ledger – it’s like a database

Bitcoin as an actual round metal disk does not actually exist. Bitcoin users do not have a physical wallet with ₿-stamped coins. What they have is an application that provides them with access to a large database that is constantly growing – one block at a time. Each block contains a series of transactions, the user code of the parties to each transaction, each transaction’s timestamp and a code that identifies and names that specific block.

Whenever a user wishes to perform a transaction (buy a car, for example), his “wallet” delves into the entire chain of transactions that exists and checks whether that user has received sufficient value (value received minus value spent) to buy that new car. One thing that Bitcoin does not permit is credit or debt – one cannot spend more than one owns. What this means is that the ledger does not contain the user’s balance – it is computed from day one anew each time he/she enters a transaction.

Distributed, not Decentralised

If the above takes care of our second requirement above, the first component (trust) is achieved by copying the transaction into several computers. The blockchain is not merely decentralized; it is distributed amongst all its users and a transaction can only be performed after all the participating computers have internalized and verified the transaction (the buyer has sufficient value). Each time a new block of transactions is added to the chain, each participant backchecks it and validates it. This is what makes theft nearly impossible – it’s not sufficient to rob a bank – you have to rob all the banks at precisely the same moment and in precisely the same manner.

A Block: What is it?

A block is a component in a chain of transactions. To understand how the blockchain works, one must try to envision a long train at a 3-part platform backing into a warehouse.

Load it

At any point in time, three blocks/carriages are being processed: the furthermost carriage from the warehouse is uploaded with transactions – each of which has been checked against all the carriages in the train to ensure one is not spending more than one has received.

Name it

As soon as that carriage is full it advances to stage 2, where it is given a codename that is a function of all the data it contains. Meanwhile, the next carriage is loaded.

Verify it

The moment that next carriage is full and the previous carriage named, the train advances to the next position. Here, the first carriage is verified (to ensure that the codename fits the data) and the second carriage undergoes its codenaming process. At the same time, a third carriage gets loaded, and so forth.

Store it

Finally, the first carriage enters the warehouse, the second one is verified, the first one named as a new carriage gets loaded.

The Long Version

Let’s look at the process in more detail:
A 1-megabyte Bitcoin block contains about 500 transactions (up to 2400, depending on their complexity). Each transaction records the codenames of the parties involved, the sum involved and the timestamp. Before a transaction can be recorded in the block, its details are verified: the payer’s back-records are checked to ensure he/she has received enough and not spent too much to be able to afford the required payment.
An additional transaction above these is the identifying code of the miner who closed the block and received remuneration for his/her work. And, another element of the block is the previous block’s 256-bit binary hash – an identifier that is a chain of 256 zeroes and ones whose numerical value would be 79 digits long.

The final element that locks the block is that block’s hash. That block’s unique hash is computed by the miner by operating a 32-bit operator (a nonce) upon the 500 transaction details plus the previous block’s hash. The encryption method used, incidentally, SHA256 encryption is based on a protocol developed by the US’ National Security Administration.
Now comes the complicated part. A miner must find a unique nonce (never used before) that – after being operate upon the rest of the data – results in a hash that fulfills a set of requirements (it must be larger than x, smaller than y, begin after a specific set of zeros, and so forth – the requirement actually changes every 10 minutes).

To find that nonce, the miner has no choice but to begin at 0 and work his/her/its way up until the correct never-before-used nonce is found. This is a largely mechanical activity that requires nothing but a huge amount of computational power. Since the work is rewarded through the minting of new bitcoins, there is a race between miners to find the correct nonce.
Once the nonce is found, the block is locked down and submitted to the network for confirmation. Once the network has confirmed the block, it is added to the chain in all its copies and the block’s hash is passed on to the next block for the next block’s computation.
And so, we have a never-ending chain of blocks, of which three are operational at any time: one accepting new transactions, the next – locked down and the nonce being computed, and the last being confirmed by the network before being added to the chain.

Locked, Loaded, Impenetrable

Clearly, altering the blockchain in order to counterfeit value (trying to fool the system into believing I have more than I have received or spend less than I have) would change at least one parameter in a locked-down block. Since that block’s hash is a function built upon that parameter, it would change the hash and those of all those following it (since the previous block’s hash is part of the data being processed to create a new hash). Moreover, reverse engineering the hash to derive the particulars of the block is an almost impossible feat, since the nonce remains unknown – it too is locked into the block.

Harry Potter Fans – Unite

The race to find the nonce is more important to the Bitcoin system than one would expect. Remembering it is a 32-bit binary chain, the number of permutations is over 2 billion. Because of this and the fact that we cannot know how the rest of the data was ordered (what numbers represent users, sums, datestamps, etc.), it is virtually impossible to reverse engineer the nonce from the hash.
Nonces are applied at a rate of quintillions per second by miners – people sitting by very hard-working computers as users sit at their tables waiting for their restaurant bills to be approved. Moreover, nonces are unique – they can only be used once each in the entire chain. Thus, the longer this process continues, the harder it is to find the nonce that creates a hash that fulfills the requirements.
Now, rare as this is, two miners could find the same nonce at the same time. The result would be a temporary fork – two chains emanating from the same block. The problem is solved by payment for work being withheld from the miners as two identical new blocks are being formed and their nonces being found. The first to be solved determines which of the two chains is the “legitimate” one and who of the two previous miners gets paid. This free-work is priced into the cost for work, and yet that price continues dropping.

The payment for downloading/solving the Genesis block equalled 50 Bitcoins; that number is halved every 210,000 blocks and is currently expected to hold at 6.25 Bitcoins until the end of next year.
Thus, miners can receive an additional payment from users as an incentive to prioritizing their transactions’ inclusion in a block.