Bitcoin Forum

Other => Beginners & Help => Topic started by: 1905 on August 25, 2011, 03:09:42 AM



Title: how does difficulty work exactly?
Post by: 1905 on August 25, 2011, 03:09:42 AM
i need to explain how difficulty works exactly. How does it calculate what the next difficulty will be and under what circumstances does it lower etc.


Title: Re: how does difficulty work exactly?
Post by: SomeoneWeird on August 25, 2011, 03:59:07 AM
i need to explain how difficulty works exactly. How does it calculate what the next difficulty will be and under what circumstances does it lower etc.

https://en.bitcoin.it/wiki/Difficulty


Title: Re: how does difficulty work exactly?
Post by: paulkoan on September 10, 2012, 04:23:22 AM
I have read that, and still don't fully get what difficulty is.  It is described as the difficulty in processing the next block - it which case it is just a measure.  But it is also described as a mechanism for ensuring that blocks are not uncovered to quickly - in which case it influences difficulty rather than measures it.

If it influences difficulty, and is based on how long previous blocks took to uncover, then how is this orchestrated through the network - how does everyone agree how long a block took?


Title: Re: how does difficulty work exactly?
Post by: obisunk on September 10, 2012, 04:50:06 AM
From what I understand:

Given the same hashrate, doubling the difficulty means doubling the time.  Therefore, you can say that difficulty scales linearly with time.

My assumption is based on the formula
Code:
time = difficulty * 2^32 / hashrate
listed on (https://en.bitcoin.it/wiki/Difficulty)

Example:
The current difficulty is ~2.7 million (http://bitcoincharts.com/ shows the difficulty number in the topmost dash).  If the difficulty doubled to 5.4 million and the network hashrate remained the same, then the expected time to solve a block would double (the expected number of blocks solved per unit time would be halved).

(edited for clarity)


Title: Re: how does difficulty work exactly?
Post by: JoelKatz on September 10, 2012, 04:52:18 AM
If it influences difficulty, and is based on how long previous blocks took to uncover, then how is this orchestrated through the network - how does everyone agree how long a block took?
The blocks are timestamped.


Title: Re: how does difficulty work exactly?
Post by: tiberiandusk on September 10, 2012, 04:57:02 AM
It is adjusted to keep the average time to find a block at 10 min.


Title: Re: how does difficulty work exactly?
Post by: paulkoan on September 10, 2012, 05:00:36 AM
If it influences difficulty, and is based on how long previous blocks took to uncover, then how is this orchestrated through the network - how does everyone agree how long a block took?
The blocks are timestamped.

By whom?  Or more clearly, how are clock errors in participants reduced, does the network agree what time it is somehow?


Title: Re: how does difficulty work exactly?
Post by: dotcom on September 10, 2012, 05:02:24 AM
i've been interested in this too


Title: Re: how does difficulty work exactly?
Post by: JoelKatz on September 10, 2012, 05:02:44 AM
By whom?  Or more clearly, how are clock error in participants reduced, does the network agree what time it is somehow?
Each block is timestamp by the entity that mined it. The block is accepted if the timestamp is roughly correct. Every 2,016 blocks, difficulty is adjusted based on the timestamps of the blocks to keep the average block mining rate at one per ten minutes. There's a slight oversimplification in the algorithm that results in the block discovery rate being a little higher than this if network hash rate is increasing.


Title: Re: how does difficulty work exactly?
Post by: DeathAndTaxes on September 10, 2012, 05:06:29 AM
By whom?  Or more clearly, how are clock errors in participants reduced, does the network agree what time it is somehow?

Blocks are timestamped by the person solving it.  The network does maintain a "network average time" which all nodes share so the timestamp of any new block can't deviate by more than 3 hours from network time.

The network attempts to solve one block per ten minutes.  Every 2016 blocks difficulty is recalculated.  The timestamp between the first and last block should be 2016 * 10 = 20,160 minutes (~14 days).  The difficulty necessary to make the prior 2016 blocks exactly 20,160 minutes is computed and that becomes the difficulty for the next 2016 blocks.

It is possible to spoof the timestamp of a block but only by so much.  An attacker can't really influence difficulty by any meaningful way because only the first and last block matter and they can only deviate from network time by more than 3 hours.


Title: Re: how does difficulty work exactly?
Post by: natd on December 08, 2013, 08:31:08 PM
 Can the difficulty go down as well?


Title: Re: how does difficulty work exactly?
Post by: VolanicEruptor on December 08, 2013, 08:34:53 PM
Just imagine 25 bitcoins falling out of the sky every 10 minutes.  
The more people there are who want these, the harder it is for each individual to catch a reasonable share. 
At this rate, all of our energy resources will be drained just so we can continue catching them with better efficiency.  In this sense, bitcoin is a virus about to destroy our world.  :)


Title: Re: how does difficulty work exactly?
Post by: alexb___ on December 08, 2013, 08:46:08 PM
Can the difficulty go down as well?
I tink it depends of the coins. For bitcoin, it can not. even if you stop mining.


Title: Re: how does difficulty work exactly?
Post by: musicchimp on December 08, 2013, 09:00:13 PM
That's a very good question but difficult to answer. I'll try and get back to you but it might be difficult


Title: Re: how does difficulty work exactly?
Post by: DeathAndTaxes on December 08, 2013, 09:08:10 PM
Can the difficulty go down as well?
I tink it depends of the coins. For bitcoin, it can not. even if you stop mining.

That is not correct. Difficulty can (and has) gone down. 

If the hashrate of the network doubles, then the time between blocks will be cut in half and next adjustment difficulty will double.
If the hashrate of the network is cut in half, then the time between blocks will double, and next adjustment difficulty will be cut in half.


Title: Re: how does difficulty work exactly?
Post by: dark143i on December 08, 2013, 09:42:43 PM
Can the difficulty go down as well?

Yes, When I was farming difficulty changed. Went down and up too. So definitely can go down. I hope that answers your question.  :)


Title: Re: how does difficulty work exactly?
Post by: USB mining on December 08, 2013, 10:29:48 PM
thanks for answers, I was looking for this a long time ago.


Title: Re: how does difficulty work exactly?
Post by: natd on December 08, 2013, 10:51:48 PM
thanks for answers, I was looking for this a long time ago.

ditto


Title: Re: how does difficulty work exactly?
Post by: Lander12 on April 27, 2014, 09:18:35 PM
Long time no post on this but need to ask a question on this topic.

Hypothetical - if Bitcoin takes a hard of enough crash to stop 95% of miners from mining it stops the block-chain from publishing new blocks and paying the other 10% of miner. I see this with other dead or dieng sha-256 coins out there which the block chain is frozen because the difficulty is "stuck" at a High level where its going to take years for the 2016 block to be reached. If BTC falls into this situation are there any plans to keep blocks moving at 1 per 10 mins if a crazy drop in mining power would happen and average block time goes into weeks? I was looking at the failure byte coin which got me thinking.         


Title: Re: how does difficulty work exactly?
Post by: cookiemonsterwhat on April 28, 2014, 02:42:26 AM
Despite knowing it, these days you can just go to bitcoinwisdom and it`ll state the next difficulty hike

It also explains the #`s on percent.



Title: Re: how does difficulty work exactly?
Post by: Shogen on April 28, 2014, 04:51:16 AM
If BTC falls into this situation are there any plans to keep blocks moving at 1 per 10 mins if a crazy drop in mining power would happen and average block time goes into weeks?

Currently, no.
I seriously doubt if majority of hashrate will left bitcoin all in a sudden, unless in an huge disaster causing world-wide internet and electricity outage.
I also doubt if the difficulty algorithm will be adjusted, as it will lead to hard fork.


Title: Re: how does difficulty work exactly?
Post by: durrrr on April 29, 2014, 02:21:32 PM
i dont think that the difficulty will ever be lower than it is at any point in time. meaning it only gets harder because it is growing and more poeple are adopting and to spread the wealth more the more users needed mining and supporting the network and the network gets bigger


Title: Re: how does difficulty work exactly?
Post by: JoelKatz on April 29, 2014, 08:58:25 PM
i dont think that the difficulty will ever be lower than it is at any point in time. meaning it only gets harder because it is growing and more poeple are adopting and to spread the wealth more the more users needed mining and supporting the network and the network gets bigger
There are a lot of marginal miners now with older miners that make just a bit more than the cost of the electricity needed to run them. If the price of Bitcoin drops significantly, they'll stop mining. However, even though there are a lot of them in number, they probably don't represent a huge fraction of the mining power out there. Still, it wouldn't surprise me if difficulty temporarily dropped a bit if the price of Bitcoin, say, dropped by 30%.


Title: Re: how does difficulty work exactly?
Post by: counter on April 30, 2014, 12:06:40 AM
huh, I always just imagined the code would be come more complex and harder to solve therefore making the difficulty higher then before.  This is a much more complex question then I'd assumed.


Title: Re: how does difficulty work exactly?
Post by: Nagato4 on April 30, 2014, 03:26:37 AM
huh, I always just imagined the code would be come more complex and harder to solve therefore making the difficulty higher then before.  This is a much more complex question then I'd assumed.

Indeed the code is pretty simple.
It just check the time taken for finding the 2016 blocks and update the "target" value accordingly.