Latest Updates from Tech world

Monday 1 January 2018

What is the puzzle solved by bitcoin miners to earn new coins?

What Puzzle is solved by miners?What is Bitcoin cryptographic hash function?How bitcoin mining is done?What is SHA-256?

bitcoin cryptographic puzzle and sha 256
Everybody tells that bitcoin miners solve some complex mathematical cryptographic puzzle to earn new bitcoins. But only few explains what is that puzzle and how it works. Actually it not a complex puzzle.Miners do some guess work to find the solution. To understand this puzzle , first thing to understand is ‘what is cryptographic hash function?’

What is Cryptographic Hash Function?

Cryptographic hash function is basically a mathematic function where you take an input or a message put it into the hash function, output appears to a random series of characters. Hash is different from encryption. In encryption encrypted data can be decrypted. Hash is a one way function – it cannot be decrypted back.. So cryptographic hash is preferred for secure transmission of passwords and data validation. Even if some one intercept hashed data, it will be meaning less to them since original data cannot be recovered. It is also useful for checking data loss while transmission. Data can be validated with it’s hash to ensure that correct and full data is received at end point.

 bitcoin cryptographic hash function sha256

Characterisits of a cryptographic hash function are:

1.It must be computationally easy to produce o/p from i/p
2.It has to be computationally infeasible. That means it is not easy to find the input for a given output.
3.It has to be deterministic. It means for a the same input , output should be the same all the time.
4.if you change a message slightly, the output hash will be entirely different
5.It has to be infeasible for you to find two messages  produce same hash.

SHA-256 cryptographic Hash in bitcoin mining process

Hash function used in bitcoin is SHA-256(Secure Hash Algorithm). SHA-256 is one of the successor hash functions to SHA-1, and is one of the strongest hash functions available.
We have discussed about block chain in previous article. In a block there will be block header.Block header contains:
3.Hash of the previous block
4.Merkele root
5.Difficulty target
Version is the nothing but bitcoin’s  current software version. Timestamp is the approximate time at which block is generated.

Previous block hash is the Hash of the header of the previous block added to the block chain.

Merkle root is basically all the transactions in the block hashed together. It can be viewed as a signature for all the transactions in the block.

Difficulty target is to set difficulty level of the cryptographic puzzle, so that it takes 10 min for all bitcoin miners all together to solve the puzzle. It is a 64 bit hash looks like 000000000ad4bcf645…..
When bitcoin mining software try to find out the next block, it will take a block header and hash on them. If generated hash is less than or equal to difficulty target we have found next bitcoin block. It is extra ordinary to get a hash less than difficulty target. So, basically bitcoin mining software has to try billions or trillions of times to find a value less than target function.

But we know that Hash function is deterministic. If we perform hash on the same block header o/p is going to be the same all the time.That is where the role of ‘nounce’ comes.

Example:Here are few messages and their SHA-256 Hash.
hello hai

hello hai1

hello hai2

hello hai3

hello hai4

hello hai5
Hello hai10

(You yourselves can try this at xorbin SHA 256 calculator)

Look at above example. It took 10 attempt to find a hash of ‘hello hai’ with one ‘0’ in the beginning. In bitcoin environment target hash is a extremely small hexadecimal number starts with 14 zeros. It may look likes 00000000000000adb5674fd67e……..Then you can image how many attempt will be required to find a number starting with 14 zeros and also less than that number.As the times goes on ,difficulty level will increased by appending more number of zeroes in the beginning side. Nounce in this example is 1 to 10.

The bitcoin mining software performs hash on the header if hash is not less than the target , it will increment the ‘nounce’ by 1, and performs hashing again. Actually hashing is done on concatenated value of  header and nounce.  If it still not valid, again nounce will get incremented by 1. As we have seen when input is modified slightly , output hash is entirely different. This process continues till it finds a hash that is valid and that will become next block in the chain. It will takes trillions of tries to find a valid hash. So , success of mining depends on computing power of the mining system. Higher  the computing power ,higher the chance of win.

No comments:
Write comments

Join Our Newsletter