Bitcoin Blockchain hashing

2 22
Avatar for Bharti
Written by
3 years ago

This is the continuation of my previous article –https://read.cash/@Bharti/blockchain-hashing-explained-part-1-b6dd8e87

diagram block header

A block header has:

• The version number of block

• the current time stamp

• The difficulty target

• hash of previous block

• nonce

• Merkle root hash

Merkle tree

diagram merkle tree

Above is an example of Merkle tree.

Here each non leaf node is a hash of values of the child nodes. Leaf nodes are the lowest part of the tree. Here they are L 1 to L 4.

Child nodes. Just above the leaf nodes (data blocks) are the child nodes marked as Hash 0-0, hash 0-1 and so on. The leaf nodes are feeding the child node. The child nodes are feeding into nodes named Hash 0, hash 1.

Root nodes are the highest labelled as top hash.

So why is Merkle tree important in a block chain?

Each block has thousands of transactions. If we store all the data in a block in a series, it will be very time inefficient and finding any data of a particular transaction will be time consuming. But by using a Merkle tree it becomes easier and less time consuming to find whether a transaction belongs to that particular block or not.

diagram merkle tree hash finding

If we want to find whether a particular transaction belongs to a block, we need not look at each individual hash and see whether it belongs to that block. We can follow the trail of that has and it will lead to the data. It reduces the time significantly.

Hashing in mining-

Mining means searching for a new block that will be added to the block chain. Miners ensure that the chain keep on growing. There is a cap for each crypto currency, for Bitcoin it is 21 million that is there will be only 21 million bitcoin. If miners were given the liberty then they would find out all the bitcoins. Also there is a time gap between creations of each block, for Bitcoin it is 10 minutes. If this time gap is removed then there will be more collision as more hash functions will be generated. Also there would be more mining block, because due to over mining, new blocks will be created simultaneously and this will result in more blocks not getting to be part of the chain.

The difficulty level is also set to restrict block creation. It is like a puzzle game, the winner gets the reward. For bitcoin the difficulty is of 64 string character, equivalent to the SHA-256 output and it begins with a bunch of zeroes. The greater the number of zeroes, the greater is the difficulty. After every 2016 block the difficulty level increases.

The bitcoin mining process-

When a new block arrives the first thing that happens is that the content of that block is hashed. If the difficulty target is less than the hash then it is automatically added to the block chain and everyone acknowledges it. But this is rarest of rare case. Here ‘nonce’ comes in. Nonce is an arbitrary string that is linked to the hash of that block. It is then compared with the difficulty level. If it is found to be less than the difficulty level then the nonce is changed and this process will go on till the requirement is met. And then that block id added to the block chain.

To summarise it:-

• The contents of a block is converted to hash

• A nonce is attached to it

• It is hashed again.

• This final hash is compared with the difficulty level

• If found less, then the nonce is changed and the process is repeated.

• If it is found OK then it is added to the chain and the ledger is updated

• The miners are rewarded in bitcoin who made this possible.

The process is completely random in selecting the nonce. Then the software keeps on generating strings till the goal is reached. It is called proof of work.

What is hash rate?

It means how fast the hashing operation is taking place while mining. A high rate means more machines are working in the mining process. The difficulty level is increased is hash rate is high, and difficulty level us decreased if hash rate is slow.

4
$ 0.23
$ 0.23 from @TheRandomRewarder
Sponsors of Bharti
empty
empty
empty
Avatar for Bharti
Written by
3 years ago

Comments

You have good knowledge of blockchain technology. You could add that the above applies to all Bitcoin versions, including Bitcoin Cash and Bitcoin SV.

$ 0.00
3 years ago

I have added it.

$ 0.00
3 years ago