Hashing and Bitcoin mining explained simple

in #hashing6 years ago

is-bitcoin-mining-destined-for-data-centers.original.jpg

This is a simple article explaining what hashing and bitcoin mining are all about.

What is bitcoin hashing?

Hashing is an important element of the mining process in blockchain like Bitcoin. You can't really talk much about bitcoin mining without understanding what cryptographic hashing is. Cryptography refers to the technology used to achieve secured and private commutation of data. It is a way of sending coded messages that are understandable only by selected authorised parties. Hashing, is a type of cryptographic technique used in blockchain to achieve secured transactions.

A hash is a long number which could be understood as the digital fingerprint of any collection of data. When you take a specific input and hash it. You will get your output as a long number. Hashing makes it possible to identify and also electronically shorten or convert data into a fixed range of numbers. SHA256 is the specific hash function used for Bitcoin mining and it generates a 64-digit hexadecimal number.

An example of SHA256 output below:

3dfb2e6953d41b533736adaadea27ce04c76d244a7bfe210bc045af748275eb4Data stored on each block could be quite substantial. Hashing makes it possible to shorten/convert data into a fixed range of numbers. You could also try the hash function here: https://www.freeformatter.com/sha256-generator.html#ad-output

In the Bitcoin blockchain network, the blocks are linked together through the hash outputs. The hash of the current block is generated through the SHA256 functions using the block number, the previous block hash number, and block data together. In other words, the hash of the current block will contain information/hash of the earlier block.

A slight input distortion on any of the blocks will affect not only the block itself but also the whole blockchain; thus rendering the whole chain of transactions invalid. This dependent connection between successive blocks on the blockchain makes the blockchain highly secure and also tamper-proof.

Bitcoin Mining

Bitcoin mining involves the solving of a cryptographic puzzle.

The Cryptographic puzzle structure consists of many elements we have already mentioned in the previous article. In the context of Bitcoin blockchain network, each block contains not only the elements we mentioned earlier, but also a Nouce.

A Nonce is a 32 bit superciliously chosen set of numbers that can only be used once. It is used in the block to generate the hash value together with other elements the block contains. Since the nonce value is independent of the other elements of the block and is totally under our control, we can vary the hash output by varying the value of the Nonce. The presence of the Nonce component in a block makes it possible for miners to be able to alter the current block’s hash value without having to tamper with the data content of the block. The mining process involves getting to a specific hash output value by changing the value of the Nonce.

SHA256 functions gives a different output whenever new information is added or exiting data altered in any form. Each time a new Nonce is being used, a totally different hash output value will be generated. SHA256 has a total possible hash value of 16⁶⁴. This means 16 possible values are allowed for each hexadecimal digit and 64 of this 16 hexadecimal digit makes up the SHA256 function hash value.

Every two weeks the Bitcoin network will define a minimal target for the hash value. Anything above this target will be rejected. The targeted hash value is the number of leading zeroes in the hash output. The more the number of zeros, the more difficult it is to achieve that value. For every leading zero, the possible number of potential hash to be calculated will be reduced by a factor of 16

If the number of leading zeros is 12, the total number of possible hash value that could meet the requirement out of the 16⁶⁴ becomes (64-12) = 1652

Thus the total number of valid hashes is 1652.

In order to calculate the probability that a hash value picked at random is going to be valid,

1652 / 16⁶⁴ = 16^ (-12)

The target is not being set at random.To calculate the target, a summary of all bitcoin miners’ computational power is taken into consideration. The calculation work is in such a way that the higher the hash rate/computation power, the more difficult the target is. This is to ensure that the average time required to solve the puzzle will remain more or less the same, such that not more than a single block will be added to the network every 10 minutes.

With the Nonce being a variable factor that can be changed by miners to give desired and acceptable hash value, miners get to compete towards finding the accurate Nonce (Golden Nonce). This Golden Nonce will be used to generate an acceptable hash for the next block on the blockchain. The miner who is able to generate the valid hash will be rewarded with 12.5 bitcoin.

The Nonce is an integer value with 32 bits of memory. This means it has a limited range of around 4 billion values. In other words, an average mining device could exhaust all combinations within a minute; and for more advanced equipments, less than a second.

So finding the right hash value should easy, shouldn’t it? In fact, even with 4 billion different combinations, the chance of finding a valid hash is still exceptionally small. There is always a chance that no valid hash exists within that 4 billion combination of Nonce.

Fortunately, there is an extra element in the block that help solves the problem, the timestamp. As timestamp is constantly refreshing, this effectively resets the range of possible hash output values every second.

There is also a different dimension to mining that facilitates the process.

Remember a block is a collection of transactions on the Bitcoin blockchain network. Transactions takes place all the time but a new block is only added every 10 mins. Transactions pending confirmations are being put in an area called the mempool. Miners pick up these transactions from the pool and add them to the block.

With the limited Block size, miners have to pick and choose transactions to be included in the block. And remember the property of hashfunction – a small change in input would yield a totally different output. This means the miners can always change the transactions to be included in the block to yield different hash values which could potentially fit the targeted level of hash value.

With this, the calculation could be done continuously without any idle time. By testing different value of the nonce, the change of timestamp and selection of transactions, miners compete to find the golden nonce that meets the acceptable value of hash output. The fastest miner who succeed would be able to earn Bitcoin as reward.

So for those wondering what the millions of bitcoin miners consuming huge supply of electricity are meant for, well now you know what it is all about.

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64093.86
ETH 3123.80
USDT 1.00
SBD 3.94