Blockchain Stuff
Published in

Blockchain Stuff

Blockchain Demystified: What is Blockchain? How it Works?

What is Block chain?

A blockchain is a public ledger with an important promise: Everybody can verify the ledger autonomously. There is no need for a central entity. You can easily discover on your own whether someone tampered with your copy of the ledger.

How does Blockchain work?

Let’s understand few things… before we proceed…

Each “line” is a bitcoin transaction: sending wallet ID, amount sent, receiving wallet ID, etc.

Each “page” of the ledger is a block.

The ID of each block (equivalent, if you like, to the page number) is generated to include the ID of the previous block, so the blocks can be considered to be ‘chained’together.

The ledger (blockchain) contains a record of every single bitcoin transaction that has ever taken place. If you have the patience — and software — you can trace every transaction for a specific wallet.

Miners are people or organizations with powerful specialized computers who compete with each other to create the newest block by assembling new, unverified transactions (around 450 of them at the moment), verifying them as described above, generating hash values for each transaction, then generating a series of hash values of each pair of transaction hashes in a pyramid manner until they end up with just one hash. This is called the Merkle root. It is the hash of the hashes of the hashes of the hashes of …….. of the hashes of the transactions. Change one lousy bit in just one transaction and that alters that transaction’s hash, which alters the hash of two hashes, and so on up the pyramid, so that the Merkle root also changes.

The miner then concatenates the Merkle root with the ID of the last blockand with a random number (the ‘nonce’) and generates a hash from that. But the hash has to meet certain conditions such as starting with twenty zeros. It almost certainly doesn’t, since the chances of that happening are 2 to the power 20 which is a million to one against, so the miner increments the nonce by one and generates a new hash. Once again it probably doesn’t meet the condition, so he increments the nonce again and generates a new hash again. This is sort of like buying lottery tickets, with roughly the same chance of winning. He keeps doing this — often several million times — until his hash meets the specified condition. When this happens he does the network version of shouting “Bingo!”, at which point all the other miners who have been frantically doing the same thing say “rats!”, stop what they are doing, pout, check his math, and if it checks out OK they accept his version as the official latest page of the ledger. The hash that met the specified conditions is the ID of the new block.

As his reward he gets to create 25 bitcoins out of thin air and pay them to himself, which is why he is called a Miner and not a Block Assembler or a Transaction Checker. It also explains how new bitcoins come into existence. Every couple of years the amount a winning miner wins is cut by half, so, in time, the reward will be so small that no more bitcoins will be generated. At that point there will be about 21 million in circulation. (And what, you ask, will be the incentive when that happens for miners to keep doing what they do? Good question, but a different question from the one you asked.)

Here’s the clever part. (Actually there are a lot of clever parts in the bitcoin protocol, but here’s a particularly clever part). If anybody tries to go back into an old transaction and change it, that change, no matter how small, will invalidate that transaction’s hash. So, to make sure nobody notices, the evil attacker — that’s what people who try to fiddle bitcoins are called — would have to calculate a new hash for that transaction, which would affect the hash of that hash, which would go all the way up the pyramid and change the Merkle root, which would change the block’s ID (the ID includes the Merkle root, remember), which would change the next block’s ID, which would change the ID of the block after that, and so on and so on through the chain. So the only way this could be done would be if the attacker had enough horsepower to force a completely new chain into existence which would likely be beyond even the capability of the NSA, and anyway the nice people in the NSA would never dream of fiddling around with the bitcoin blockchain because they are too busy reading this answer.

Every two days the whole system pauses for a moment and figures out how many new blocks have been created in the last 48 hours. From that, it calculates how long each block took, on average, to create. If the answer isn’t “10 minutes”, then the condition that the block’s ID hash must meet is made either harder (start with 22 zeros, say) or easier (start with 18 zeros) such that over the next 48 hours a new block will be created, on average, every ten minutes.

If two miners both shout “Bingo!” at the exact same time, the blockchain splits into two branches as it has two apparently valid new blocks side by side. Some miners then start adding to one branch and other miners add to the other branch. Very soon — usually after just one or two split blocks — one of the chains gets longer than the other. When this happens, all the miners working on the shorter chain say phooey and begin working instead on the longer chain. Any blocks on the shorter chain are deleted and any miners who created those blocks and thought they were going to earn 25 free bitcoins are SOL. The chain now reverts back to one chain.

The maximum number of parallel blocks there have ever been in a split blockchain is six, and that happened only once, the odds against it being several kazillion to one. So if you do a bitcoin transaction, you can be reasonably assured that it is valid after ten minutes, because it will by then have been validated and incorporated into a new block, and you can be doggone certain it is valid after an hour because even if the block it is in gets retroactively deleted on account of being part of the losing side of a split blockchain, the chain will have fixed itself after six new blocks at the most, and six times ten minutes is an hour. So if you are selling your Corvette for bitcoins, you should plan on spending an hour chatting with the purchaser before you let him drive away in case he is a very bad person and has found a way to (temporarily) send himself the same bitcoins he sent you for the car. After an hour you can breathe easy.

#Blockchain #Bitcoin #FutureTech



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store