Proof-of-Work: Block Difficulty

 So how do we adjust the size of this circle?

How do we set and change the target?

This all happens through the difficulty, which is a representation of the number of expected

computations required to find a block.

Again, we can’t predict how many computations anyone produces to solve the puzzle, but we

can approximate based on how quickly the puzzle is solved on average.

The difficulty is implemented as a requirement of a leading number of zeros on the block

header hash.

This is why the example block at the start of this section had many zeros at the start

of its block hash.

As the number of zeros increases, so will the difficulty, and vice versa.

This difficulty adjusts with the global hashrate.

We know that the amount of computing power in the network will always be changing, as

miners join and leave the network, but we want to maintain a block time of ten minutes.

For this reason, we have to raise and lower the difficulty alongside the hashpower growth

and decay of the network.

The way we recalculate this difficulty is with the equation on the slide: difficulty

is equal to itself times the ratio of two weeks to the time taken to mine the previous

2016 blocks.

Every two weeks, we check to see how long it took to calculate those 2016 blocks.

If every block took exactly 10 minutes, then it should have taken precisely two weeks to

produce those 2016 blocks.

If we took too long, it’s because the puzzle was too hard to solve, and if we didn’t

take long enough, then the puzzle was too easy.

We make adjustments on the puzzle difficulty accordingly going forward.

A quick sanity check to see if your understanding is correct.

Let’s say that the current difficulty is 10.

Then what’s the new difficulty if the time to mine 2016 blocks is exactly two weeks?

Yes, it’s still 10!

The puzzle was precisely as hard as we wanted, so the difficulty stays exactly the same.

What about when the time to mine those 2016 blocks is just one week?

Or a staggering 4 weeks?

If time to mine is one week, then the difficulty is 20!

We mined those blocks in half the expected time, meaning that the puzzle was half as

hard as necessary, so we make it twice as difficult.

If the time to mine is 4 weeks now, the difficulty is now 5!

We mined those blocks in twice the expected time, meaning that the puzzle was twice as

hard as necessary, so we make it half as difficult.

So, the difficulty is inversely proportional to the time to mine.

Proof-of-Work: Coinbase Transaction