Bitcoin and Blockchain

Bitcoin and Blockchain

Addresses

Bitcoin implements the concept of Public/Private keys to secure your wallet. This idea is no different to a typical Username/Password combination, except here both keys are a variable length secret number that appears entirely random. Bitcoin Public Addresses are 512-bit strings, 25-34 characters in length that represent your wallet identifier. This wallet is secured by your 256-bit or 512-bit Private Key. Each Private-key is mathematically related to the Bitcoins in your wallet, and is the only possible key to validate the SSL signature of the transaction that transferred the Bitcoin to your Public Address in the first place, thus proving you are the legitimate owner of that Bitcoin sum. Here is an example of a Bitcoin Public Address, and it's QR Barcode:

qr code

177Rw9N2PoepGwWumjgFn38W3N8LAddku5

A random 20 digit key such as this is assigned as your Public Address, the indentifier for your wallet. Another is assigned as your Private Address, or rather the key to this wallet. When you make a transaction, this message is hashed against your private key, creating a unique digital signature tied to your Private Key, without ever leaking or compromising your Private Key.

The Hashing Algorithm

SHA-256 is the hashing algorithm used in the Bitcoin Protocol. Developed in 2001, SHA-256 is a part of the SHA-2 Secure-Hash Algorithm series, sucessor to the SHA-1 and SHA-0 series before it. SHA-256 generates a 256-bit randomised output from a 32-bit input using a complex 68-step mathmatical loop. The same input will produce the same output EVERY TIME, but changing the input even slightly will produce a vastly different output.

"SHA256 Hash Test 1" = 884a2dbf29536b4a90605d32ac4cdd2834c0b39e5455e8b7afdf63d43fd21c33

"SHA256 Hash Test 2" = ec6a5de5230b31d795edaf01453c93ecf797c0ef4c96547ce8851c264609358c

Note that such a small change to the input results in a completely different resultant hash.

As each digest can only be verified by the original message, this algorithm creates a mathematically perfect method of validation, and has been used by many to authenticate online activity such as forum posting, or software downloads for many years. Being a 256-bit random value, it would take a 2017-level computer 7 years to guess the correct input and reverse the hash, but a miniscule fraction of a second to gnerate a hash if the input is known and compare the outputs to ensure they are identical. This is where the Public Address comes into play, being used to validate the digital signature of a transaction. Bitcoin is completely built around SHA in every aspect of the technology to create a decentralized computing network that operates built on a foundation of Mathematics, Consensus and Validation, with no need for Trust. Whilst more modern Cryptocurrencies have chosen to adopt more advanced hashing algorithms such as SHA-3 and Scrypt, the purpose and implementation is near identical to that of Bitcoin.

Validation and Mining

Digital scarcity has been the overwhelming hurdle for every digital currency before Bitcoin. Validating the authenticity of a digital element seemed impossible without reverting to a centralised accounting server, a single point of failure. The Bitcoin Network uses cryptography to secure each and every coin in existance. Every transaction is hashed against eachother to create new digests, and these digests are then hashed again until there is only a single digest that represents every unconfirmed transaction being captured in the current block. This digest is final, and each coin in each transaction can be traced back to it's origin with the blockchain. Once this value has been calculated, the miner must perform a proof of work to secure the block. This involves generating a random PoW value, and running this with the resultant digest through SHA256 once more with the goal of creating a resultant FINAL digest with X leading 0's. X is the mining difficulty, and increasing this will increase the time taken to compute. X is currently set to 40. The chance that the first digit is 0 is 50%, the odds that the first two digits are both 0 is 25% (50% x 50%). The chance of the first 40 digits being 0 is so small that on average it requires around 1 TRILLION computational cycles.

Eventually, a miner on the network will find a successful hash pair, and this marks the beginning of a new block. The miner will broadcast this new block to the whole network immediately, and all miners will then abandon their failed guesses because the race has been won. The winning miner is incentivized by being rewarded with several bitcoin (bitcoin reward halves every 210,000 blocks until the year 2040 when all in circulation). They will begin processing and verifying the new block, validating every single transaction and updating their record of the blockchain by building it one block at a time.

If a miner leaves the network, they simply don't receive the newest block. The blockchain is secured by game-theory and the concept of consensus. All miners agree that the longest blockchain is the valid blockchain, and so each miner must have a fully up to date blockchain record before it can participate in mining and validating transactions. Without a fully up to date blockchain, validating transaction are impossible, as every block is encoded by the previous block.

Game-Theory and Consensus

Now Game-Theory is a study of strategic decision-making that focuses on chance versus reward, and can be applied to any game in existance. Without going too in-depth, the Theory outlines how at any point in a game, the player will measure the chance of success and the potential reward for that success. Let us breach this section with a simple example;

John and Jim have committed a crime. They are promised a reduced-sentence if they confess to the crime, but threatened with an increased-sentence if they are discovered to have been lying. As the reward factor is important, let us exaggerate this example by stating that the reward for confession is a single year in prison, but the punishment for lying is life in prison. Without knowing what the other will say, the element of chance comes into play. John now has a 100% chance of getting a reduced sentence by pleading guilty to the crime. If John and Jim both lie then they are both free, but if only John lies and Jim confesses, then John is punished with life in prison while Jim is rewarded. If no bribery is involved, both parties will make the decision best for them and confess when the a large punishment is pitted against a small reward. The chance of success relative to the reward is weighted against the alternatives in any scenario.

In a Bitcoin-focused example, a miner has just expended a large cost of energy resources to win the mining race. The miner is now tasked with validating all transactions to build the newest block. If they validate a false transaction and another miner disputes this validation, they risk losing their mining reward. If they validate it correctly they get the standard mining reward governed by the Network. If this is a single fraudulent miner, the validation will be disputed by any other miner, and so they face a 100% chance of losing their reward. It would be silly to lie.

Now we can bring bribery into play. Our fraudulent mining friend has other friends willing to lie for them. They have been bribed with a reward, and face no consequence of punishment as they were never elegible for the mining reward in the first place. But the next block requires guessing the next correct hash pair in order to validate the next block. The chance of any one miner finding this is equal to their ratio of their Hashing Power to that of the rest of the Bitcoin Network. At the time of writing, the total Hash Power of the Network is 12 million Tera-Hashes per-second. The most expensive, powerful ASIC's on the market can acheive around 15TH/s, or rather 0.00000125% of the total Network Hash Power. With 15TH/s, this percentage is the miner's chance of validating the next block. Now the chance of validating 2 blocks in a row becomes extremely unlikely. 3 blocks near-impossible, and so-on. With each new block, more and more electrical mining resources are being risked, as all rewards will be lost if a transaction this Blockchain is found to be invalid.

But here's the trick. In the Bitcoin Protocol...a transaction is not considered successful unless it has been in the last SIX validated blocks.

Here we can see the genius of Bitcoin's decentralized nature. A fraudulent attack on the Network would require vast amounts of Hash-Power and an incomprehendable amount of luck, with a high-level of financial risk on the line. Game-Theory protects every transaction on the Blockchain to ensure only legitimate transactions can be validated.

Now Bitcoin has encountered anomolies in the past; in 2014 the group mining pool AntPool mined 6 new blocks in a row, creating a lot of panic in the Network. At the time, such a large amount of processing power was concentrated to a single virtual miner that by this anomoly occured by sheer chance. The pool voluntary shut down to allow the Network to converge, and reduced their hash rate immediately. Such teething problems were mathematically improbable but possible at the time, but with the recent growth of the Bitcoin Network's Hash Power, a modern day consensus attack would require far more power than any single mining pool can accomplish, and the more decentralized the Network becomes, the greater the inbuilt security against such attacks becomes.

John and Jim may choose to risk a greater punishment by lying, but as the number of other parties involved increases, the odds of them all deciding to corroborate the lie grows ever smaller. This is how Bitcoin secures a valid copy of the Ledger.

Related Article