Blockchain and Bitcoins 101 – Part 4
Continued from – Blockchain and Bitcoins 101 – Part 3
Now that we know the concept of blockchain let us understand the bitcoin math. But why was understanding of blockchain important for this?
It was essential because blockchain works on verification. Verification of transactions by peers, since there is no central authority. The main purpose of mining is to ensure that all the peers have a consistent view of the Bitcoin data.
Miners are those peers who want to participate in verification so they can win rewards.
The Bitcoin Math
Bitcoin mining requires computers to perform complex math problems. We will have an overview of the bitcoin math as the computation in depth is not required for anyone who only wish to understand bitcoin without getting into the technical nitty gritty. If you are good in cryptography and really interested in bitcoin mining, then you may read detailed descriptions in the links provided below.
Remember the term cryptocurrency? On a technical level the math problem is nothing but a task that involves cryptography, with a hash function. So, let us understand hashing.
A hash function will take an input of variable length, and produce an output of a fixed length.
Variable length input 1 – 12345678910 (these are 11 digits)
Fixed length output (for input 1) – 01038438 (these are 8 digits)
Variable length input 2 – 12345 (these are 5 digits)
Fixed length output (for input 2) – 83291340 (these are 8 digits)
Note that the length of both the outputs is same, though the inputs were of different length.
The same input value will always generate the same output.
But remember that hashing is irreversible. For e.g. when you input 12345678910 for hashing, you will get, suppose, 01038438 as an output but when you reverse the procedure and you input 01038438, you may not get 12345678910 as an output. In fact, even if you change one letter/digit in the input the output will be different.
This behavior of hashing makes it very difficult to predict what input gives an output.
Good read on hashing – http://searchsqlserver.techtarget.com/definition/hashing
Miners are presented with a similar challenge. Once the blocks are completely mined, they are sent to the network.
There is a target value, a challenge, and an output. The output is the hash value towards which miners will work.
Target value – Network Intelligence
Hash of the target – 123456789101112131415 (suppose)
Challenge – change the target value in such a way that the hash value for the changed target will begin with “0s” (zeros).
To come to a specific input that will give a specific output requires a lot of combinations and attempts. One needs to try out different numbers in combination with the target to get a specific output.
|Combinations with the target||Output hash value|
|Target + number 1||493932027hd8613md302iein|
|Target + number 2||Asakenwe029973232i4nxnixl|
|Target + number 3||0nwe02732i4238dhdsmw93m|
|Target + number 4||00ken32mw93mdhds we0299|
|Target + number 5||000ncixe39ns0w0efeiladncow|
“Target + number 5” is the winning combination here. Number 5 will be referred to as a nonce. In cryptography, a nonce is an arbitrary number that may only be used once.
Now this is just an example, in actual mining the target value will be some information (like transaction ID) from bitcoin transaction record which has come to the ledger, and needs to be modified (hash with zero in the front) to fit in the existing blockchain.
Let us see the structure of a transaction block. It has various fields some of which are as follows.
Note – there are many other fields in a block. More information can be found here.
The previous block hash i.e. hash value of a previous transactions block is mentioned here because the sequence of transactions is in a chain format. Every block is linked to each other by the way of hashes. Blocks are ordered by reference to previous block hashes and are not in a sequence number (like any book with page numbers). Hence the term “chain”.
Once you find an input that gives the value you want, nonce, it’s easy for anyone to verify the hash in the network using the proof of work of miners. The winning nonce will help in addition of the current block in the chain.
To find a hash every ten minutes, the Bitcoin hash rate needs to be insanely large. Bitcoin Mining Uses $15 Million’s Worth of Electricity Every Day.
The math behind bitcoins – https://www.cryptocoinsnews.com/explaining-the-math-behind-bitcoin/
Next in series – Blockchain and Bitcoins 101 – Part 5