In the last post (What is hashing?)we talked about hashing. If you do not know what hashing is you should read that post. This post will not make any sense without it.

Miners

Miners are people who support the network. They use powerful computers to solve and verify a block. Solving a block is a hashing problem.

Header Fields

Previous hash: points to the previous block

Transaction Summary: A summary of the all the transactions within the block.

The Answer: An answer to the problem

Proof of Work: Proof that the block has been solved.

The first two fields previous hash and transaction summary do not change.The last two fields are more interesting.

The Problem

A miner has to find the right answer that makes the hash of the entire block have an output of 5 or more leading zeros. The entire network knows what the end result should be (00000anythinghere). We just do not know what will get us there.

Miners hash the entire block by using the first 3 fields in the header. Previous Hash + Transaction summary + A Guess. (We do not know the answer yet) The hash of all three of these fields must have 5+ leading zeroes. Since the first two fields, previous hash and transaction summary do not change, all miners can do is keep changing their guess.

SHA256 (Previous Hash + Transaction Summary + Guess)

- Miners keep changing their guess until the result has 5+ leading zeros.

- SHA256 is the hashing function Bitcoin uses

When the right guess is made, we found our answer! We save that value in the block header along with the result. The guess gets added to the “Answer” field. The hash result gets added to the “Proof of Work” field. The miner then broadcasts the block to other miners.

Trust No One

Since anyone can be a miner we cannot blindly trust that they solved a block correctly. We have to verify it. If a miner claims that they solved block 52, we take that block and run the hash function. We use the same values the miner gave us. If our results match, we know that this block is legitimate. It can be added to the chain.

To say it another way, we run SHA256( Previous Hash + Transaction Summary + The Answer). The values are given to us by the miner who claimed to have solved block 52. If this matches the Proof of Work and it has at least 5 zeros, the block is valid.

The next block’s (Block 53) previous hash field will point to Block 52’s proof of work. Miner’s would have to try to find the right value (The Answer) for Block53 to add it to the blockchain.

Verifying a block is easy since we all know what the answer should be. Finding the answer is hard because SHA256 is a great one way function. As I said before, we do not know what will get us there.To appreciate how challenging this is try to find a message that creates 2 leading zeros using this hashing function.