Bitcoin difficulty all time

Difficulty

Contents

What is «difficulty»?

Difficulty is a measure of how difficult it is to find a hash below a given target.

The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target. Mining pools also have a pool-specific share difficulty setting a lower limit for shares.

How often does the network difficulty change?

What is the formula for difficulty?

difficulty = difficulty_1_target / current_target

(target is a 256 bit number)

difficulty_1_target can be different for various ways to measure difficulty. Traditionally, it represents a hash where the leading 32 bits are zero and the rest are one (this is known as «pool difficulty» or «pdiff»). The Bitcoin protocol represents targets as a custom floating point type with limited precision; as a result, Bitcoin clients often approximate difficulty based on this (this is known as «bdiff»).

How is difficulty stored in blocks?

Each block stores a packed representation (called «Bits») for its actual hexadecimal target. The target can be derived from it via a predefined formula. For example, if the packed target in the block is 0x1b0404cb (stored in little-endian order: cb 04 04 1b ), the hexadecimal target is

Note that this packed format contains a sign bit in the 24th bit, and for example the negation of the above target would be 0x1b8404cb in packed format. Since targets are never negative in practice, however, this means the largest legal value for the lower 24 bits is 0x7fffff. Additionally, 0x008000 is the smallest legal value for the lower 24 bits since targets are always stored with the lowest possible exponent.

How is difficulty calculated? What is the difference between bdiff and pdiff?

The highest possible target (difficulty 1) is defined as 0x1d00ffff, which gives us a hex target of

It should be noted that pooled mining often uses non-truncated targets, which puts «pool difficulty 1» at

So the difficulty at 0x1b0404cb is therefore:

Here’s a fast way to calculate bitcoin difficulty. It uses a modified Taylor series for the logarithm (you can see tutorials on flipcode and wikipedia) and relies on logs to transform the difficulty calculation:

To see the math to go from the normal difficulty calculations (which require large big ints bigger than the space in any normal integer) to the calculation above, here’s some python:

What is the current difficulty?

Current difficulty, as output by Bitcoin’s getDifficulty.

What is the maximum difficulty?

There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224).

The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we’re ok.)

Can the network difficulty go down?

Yes it can. See discussion in target.

What is the minimum difficulty?

The minimum difficulty, when the target is at the maximum allowed value, is 1.

What network hash rate results in a given difficulty?

The difficulty is adjusted every 2016 blocks based on the time it took to find the previous 2016 blocks. At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find. If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced. If they took less than two weeks, the difficulty is increased. The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.

To find a block, the hash must be less than the target. The hash is effectively a random number between 0 and 2**256-1. The offset for difficulty 1 is

and for difficulty D is

The expected number of hashes we need to calculate to find a block with difficulty D is therefore

The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds. That means the hash rate of the network was

Читайте также:  Пулы для майнинга sia

over the previous 2016 blocks. Can be further simplified to

without much loss of accuracy.

At difficulty 1, that is around 7 Mhashes per second.

At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was

How soon might I expect to generate a block?

The average time to find a block can be approximated by calculating:

where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.

For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:

and find that it takes just under 24 hours on average.

Источник

Difficulty in Mining

Enjoyed the article? Share:

Difficulty is a value used to show how hard is it to find a hash that will be lower than target defined by system.

The Bitcoin network has a global block difficulty. Valid blocks must have a hash below this target. Mining pools also have a pool-specific share difficulty setting a lower limit for shares.

Contents

Bitcoin mining difficulty [ edit ]

In Bitcoin network there’s global difficulty set for all blocks. For block to be considered legitimate it has to have hash value lower than set target.

Difficulty changes every 2016 blocks. This is calculated using following formula:

where target is a 256-bit number.

Difficulty_1_target can take various values. Traditionally it’s a hash function first 32 bits of which are equal to 0 while all the rest are 1 (it is also called pdiff or pool difficulty). Bitcoin protocol provides target as a type with floating point and limited accuracy. Different Bitcoin clients often determine cryptocurrency difficulty based on this data.

Storing cryptocurrency difficulty in blocks [ edit ]

Every block contains a packed version (called «Bits») of hexadecimal target.

Using following formula target can be obtained from any block. For example if a target packed in a block appears as 0x1b0404cb its hexadecimal version will look as following:

Maximum value for this field is 0x7fffff while minimum is 0x008000.

Maximum possible target (with difficulty equal to 1) is defined as 0x1d00ffff which appears as following in hexadecimal numeration:

Next is an easy way of difficulty calculation. It uses an altered version of Taylor series to logarithm and relies on logs to transform difficulty calculation.

Maximum, current and minimum difficulty [ edit ]

Current difficulty can be found out by using Bitcoin command line ‘getDifficulty’.

Due to target function not having minimum value maximum difficulty can be calculated only approximately as following: maximum_target / 1 (as 0 would lead the equation to being infinitely big) which is an inconcievable number (

Minimum difficulty is just equal to 1.

Difficulty changes [ edit ]

Difficulty is changed every 2016 blocks based on the time it took to discover 2016 previous blocks. If a block is found every 10 minutes (as it was intended initially for even emission) finding 2016 blocks will take exactly 2 weeks. If previous 2016 blocks were found in more than two weeks the cryptocurrency mining difficulty will be lowered, and if they were mined faster then that it will be raised. The more (or less) time was spent on finding the previous 2016 blocks the more will difficulty be lowered (raised).

To mine a block hash has to be lower than targer (proof-of-work). Hash is a random number between 0 and 2*256-1.

Difficulty is set as if we found previous 2016 blocks at the speed of one block per 10 minutes

Average time of finding a single block can be calculated using this formula: time = difficulty * 2**32 / hashrate where ‘difficulty’ is the current cryptocurrency difficulty level of BTC difficulty network and ‘hashrate’ is the amount of hashes a miner finds per second.

What is the current difficulty? [ edit ]

Current difficulty online, as output by Bitcoin’s getDifficulty.

What is the maximum difficulty? [ edit ]

There is no minimum target. The maximum difficulty is roughly: maximum_target / 1 (since 0 would result in infinity), which is a ridiculously huge number (about 2^224). [This is not correct, target can be zero, but most hash functions produce all zeroes at such a low frequency it’s practically impossible, not actually impossible]

The actual maximum difficulty is when current_target=0, but we would not be able to calculate the difficulty if that happened. (fortunately it never will, so we’re ok.)

Can the network difficulty go down? [ edit ]

What is the minimum BTC difficulty? [ edit ]

The minimum difficulty, when the target is at the maximum allowed value, is 1.

What network hash rate results in a given difficulty? [ edit ]

The difficulty is adjusted every 2016 blocks based on the time it took to find the previous 2016 blocks. At the desired rate of one block each 10 minutes, 2016 blocks would take exactly two weeks to find. If the previous 2016 blocks took more than two weeks to find, the difficulty is reduced. If they took less than two weeks, the difficulty is increased. The change in difficulty is in proportion to the amount of time over or under two weeks the previous 2016 blocks took to find.

Читайте также:  За сколько времени можно получить биткоин

To find a block, the hash must be less than the target. The hash is effectively a random number between 0 and 2**256-1. The offset for difficulty 1 is

and for difficulty D is

The expected number of hashes we need to calculate to find a block with difficulty D is therefore

The difficulty is set such that the previous 2016 blocks would have been found at the rate of one every 10 minutes, so we were calculating (D * 2**48 / 0xffff) hashes in 600 seconds. That means the hash rate of the network was

over the previous 2016 blocks. Can be further simplified to

without much loss of accuracy.

At difficulty 1, that is around 7 Mhashes per second.

At the time of writing, the difficulty is 22012.4941572, which means that over the previous set of 2016 blocks found the average network hash rate was

How soon might I expect to generate a block? [ edit ]

The average time to find a block can be approximated by calculating:

where difficulty is the current difficulty, hashrate is the number of hashes your miner calculates per second, and time is the average in seconds between the blocks you find.

For example, using Python we calculate the average time to generate a block using a 1Ghash/s mining rig when the difficulty is 20000:

and find that it takes just under 24 hours on average.

Источник

Difficulty

A mechanism for regulating the time it takes to mine a block.

What is the difficulty?

The difficulty is a number that regulates how long it takes for miners to add new blocks of transactions to the blockchain .

This difficulty value updates every 2 weeks to ensure that it takes 10 minutes (on average) to add a new block to the blockchain.

Why is the difficulty important?

Because it ensures that blocks of transactions are added to the blockchain at regular intervals, even as more miners join the network.

If the difficulty remained the same, it would take less time between adding new blocks to the blockchain as new miners join the network.

When does the difficulty change?

The difficulty adjusts every 2016 blocks (roughly every 2 weeks).

At this interval, each node takes the expected time for these 2016 blocks to be mined (2016 x 10 minutes), and divides it by the actual time it took (however many minutes):

If miners were able to solve each block more quickly than expected; say 9 minutes per block for example, you’d get a number like this

Each node then uses this number to adjust the difficulty for the next 2016 blocks:

  • If the number is greater than 1 (i.e. blocks were mined quicker than expected), the difficulty increases.
  • If the number is less than 1 (i.e. blocks were mined slower than expected) the difficulty decreases.

And that’s it. Every miner on the bitcoin network now works with this new difficulty for the next 2016 blocks.

The difficulty will only adjust by a factor of 4 at most (i.e. a number not greater than 4 or less than 0.25). This is to prevent abrupt changes from one difficulty to the next.

How does the difficulty control time between blocks?

Okay, I’ll start with a simple example and go from there.

1. Simple example

Let’s say I give you a range of numbers from 1 to 100.

Now, you are able to randomly generate a number between 1 and 100 once every minute. And your goal is to generate a number below my target number.

So let’s say I set the target at 50:

Seeing as you’re only able to generate a number between 1 and 100 once a minute, this should take you 2 minutes.

But that’s too easy. Now I lower the target to 20, which means you’re only going to be able to generate a winning number 1/5 of the time, or once every 5 minutes:

The lower the target, the more difficult it gets to generate a winning number.

It’s not going to be 5 minutes every time because you could get lucky with the first number you generate. But over the long run it will work out to be 5-minute intervals.

Therefore, based on how many numbers you are able to generate per minute, I can use the height of the target to control how long it takes you to find a winning number.

Introducing the difficulty…

I’m a computer, and instead of telling you the target value directly, I find it easier to give you the target by dividing the range of numbers with a new number

This new number is able to control the height of the target.

This new number is the difficulty , and it’s used as an easy way for me to modify the height of the target.

Here’s the equation for finding the target:

Furthermore, I can use this difficulty value to help me set the target to any level I want:

The higher the difficulty, the lower the target.

Читайте также:  Как определить вирус майнинга

So I use the difficulty to control the target , and therefore how long it takes for you to generate a winning number.

2. Bitcoin example.

The difficulty in bitcoin works in exactly the same way – it’s used to set a target value, and miners keep generating numbers (hashing their candidate blocks) in the hope that they will find a number lower than this target value:

And seeing as miners are able to generate thousands of numbers (hash values) per minute, bitcoin uses ridiculously big numbers:

The numbers in bitcoin are just on a much bigger scale.

And due to the fact that there are now thousands of miners trying to find winning numbers, to ensure that a winning number is found every 10 minutes (instead of every few seconds), the range of successful numbers ends up being absolutely tiny:

Even though that difficulty number looks big, the target is still absurdly difficult to get under. It’s like a lottery.

Introducing hexadecimal numbers…

Because these target numbers are so big, computers prefer to work with them in hexadecimal format.

That’s why the hash values for blocks look like this: 000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506 – it’s hexadecimal.

And even though it’s got letters in there, it’s still a number. So the target is a hexadecimal value, and miners are trying to get a hexadecimal hash value below the target.

In fact, you can easily convert between hexadecimal and “normal numbers” (better known as decimal numbers):

Target for block 100,000

Hexadecimal 000000000004864c000000000000000000000000000000000000000000000000
Decimal 1861311314983800126815643622927230076368334845814253369901973504

Hash for block 100,000

Hexadecimal 000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506
Decimal 1533267872647776902154320487930659211795065581998445848740226310

So that’s why you usually see the hash and the target as bunches of numbers and letters – they’re in hexadecimal as opposed to decimal (which is what humans are more familiar with). But just remember that both these decimal and hexadecimal numbers have the same value, and you can easily convert between the two.

Awkwardly, the difficulty is usually given in decimal format, whereas the hashes and targets are stored in hexadecimal. But as I say, they’re both numbers, and as long as you convert them to the same format you can still work with them.

Block 100,000 header. The target is hexadecimal, but it is stored in a compact format in the block header (called bits ).

Example: Finding the target using the difficulty.

Let’s work out target for block 100,000 using the difficulty. But let’s do it mostly in decimal numbers, because they’re easier to understand.

Here’s the difficulty for block 100,000 (as found in the block header):

Now, let’s note down the equation we’re going to use to find the target:

And let’s get the targetmax and difficulty ready to insert it in to the equation.

  • The targetmax is a fixed value, and it can be found here.
  • I got the difficulty from the block header information I pasted above.

The targetmax is currently in hexadecimal format though, so let’s convert that to decimal.

I know targetmax is a hexadecimal number because it starts with 0x, which is a prefix to signify that what comes next is hexadecimal (the 0x isn’t part of the number, it’s just a note). Plus the presence of letters within the value is a dead giveaway anyway.

Now we can just plug these numbers in to the equation and away we go:

So when the miner was trying to solve block 100,000, she wanted to get a hash for her candidate block that would be below 1861311315012765306929610463010191006516769515973403833769533170 .

Check it…

Let’s compare this with the hash she got for the block to check that she was genuinely successful (i.e. her hash for the block was below the target):

Oh yeah, the hash is in hexadecimal format. Sorry. Let me convert from hexadecimal to decimal again so that we can compare the two numbers:

Yep, that hash is a smidgin smaller than the target. But it is lower, so the hash is successful and the block can be added to the blockchain.

Both the target and block hash would be stored as hexadecimal numbers inside the block header, so here’s what they look like if we convert them both back to hexadecimal:

Where can I find the current difficulty?

You can find the current difficulty by entering the getdifficulty command in to your bitcoin client:

The difficulty can also be found with getmininginfo (amongst other mining info).

  • Alternatively, if you haven’t got your bitcoin client at hand, you can always find the the difficulty at: http://chainquery.com/bitcoin-api/getdifficulty
  • And if you’re interested in looking at how the difficulty has changed over time, here’s a website with a chart: https://bitcoinwisdom.com/bitcoin/difficulty

By Greg Walker, 26 March 2015

Last Updated: 28 Mar 2020

  • 28 Mar 2020: updated html for h1 headers and subheadings — now dynamic from yaml
  • 28 Mar 2020: updated html for h1 headers and subheadings
  • 26 Nov 2019: typos/fixes — thanks to @JKristjan
  • 09 Oct 2019: renamed browser to explorer, glossary to guide, and guide to beginners

I’ll let you know about cool website updates, or if something seriously interesting happens in bitcoin.

Источник

Оцените статью