Bitcoin Forum
May 25, 2024, 01:29:13 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: From a low level, how does difficulty work?  (Read 864 times)
Jaxkr (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250


View Profile
June 21, 2013, 04:42:28 PM
 #1

I'm having a really hard time wrapping my head around what the difficulty number means. I don't understand how it can be so high, and how it can affect the target. I have read the wiki page, and it didn't really help.

I understand how a rudimentary POW algorithm works. In fact, I've even written one. It hashes data, and adds a number on the end, and hopes that the resulting hash is prefixed with a certain amount of 0's (or any special character). I know that a hash that has a prefix of 5 zeroes is significantly more difficult than a hash that hash a prefix of 1 zero. Each nonce has a lower probability of producing that hash, therefore it's more difficult.
So why isn't the difficulty just a whole integer? A difficulty of 1 means that the hash needs to have one zero. A difficulty of 2 means that the hash needs two zeroes in front of it. And so on.
What does 19339258.272387 mean? And how does it affect the miner's target? Sorry for my cluelessness.
Birdy
Sr. Member
****
Offline Offline

Activity: 364
Merit: 250



View Profile
June 21, 2013, 04:51:11 PM
 #2

Afaik the difficult number just means it's 19339258.272387 times harder to find a new block than the first one that was ever created.
nimda
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1000


0xFB0D8D1534241423


View Profile
June 21, 2013, 04:56:15 PM
 #3

Looking for n-zeroes in front isn't precise enough: difficulty jumps exponentially with every digit. Instead, the miner looks for hashes that are numerically less than the target.

Here's the maximum target:
0x00000000FFFF0000000000000000000000000000000000000000000000000000

A maximum target means a minimum difficulty, because the higher the target, the more hashes are less than that target.

The difficulty is the maximum target divided by the current target.

As the current target goes down, it becomes harder to generate blocks. The current target is the denominator of the difficulty equation, so as current target goes down, "difficulty" goes up.

Make sense?
Jaxkr (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250


View Profile
June 21, 2013, 05:03:36 PM
 #4

Looking for n-zeroes in front isn't precise enough: difficulty jumps exponentially with every digit. Instead, the miner looks for hashes that are numerically less than the target.

Here's the maximum target:
0x00000000FFFF0000000000000000000000000000000000000000000000000000

A maximum target means a minimum difficulty, because the higher the target, the more hashes are less than that target.

The difficulty is the maximum target divided by the current target.

As the current target goes down, it becomes harder to generate blocks. The current target is the denominator of the difficulty equation, so as current target goes down, "difficulty" goes up.

Make sense?
Kind of. So the target is a 64 bit number that represents what the hash of the block in numeric form needs to be less than. So, the hash of the block is treated as a hex number, and compared to the target, and it has to be less than the target?
nimda
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1000


0xFB0D8D1534241423


View Profile
June 21, 2013, 05:06:16 PM
 #5

Make sense?
Kind of. So the target is a 64 bit number that represents what the hash of the block in numeric form needs to be less than. So, the hash of the block is treated as a hex number, and compared to the target, and it has to be less than the target?
Kind of. A sha256 hash is always a number, no matter how you represent it (hex or not). The target is also a number, and it can be represented however you want.

Regardless of format, the hash of the block's header is treated as a number, and it has to be less than the target.
Stephen Gornick
Legendary
*
Offline Offline

Activity: 2506
Merit: 1010


View Profile
June 21, 2013, 05:07:27 PM
 #6

So the target is a 64 bit number

A 256 bit number stored as a floating point and truncated:
- http://en.bitcoin.it/wiki/Target

Also more info here:

What is “difficulty” and how it relates to “target”?
 - http://bitcoin.stackexchange.com/q/8806/153

Unichange.me

            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █
            █


Jaxkr (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250


View Profile
June 21, 2013, 05:09:38 PM
 #7

Make sense?
Kind of. So the target is a 64 bit number that represents what the hash of the block in numeric form needs to be less than. So, the hash of the block is treated as a hex number, and compared to the target, and it has to be less than the target?
Kind of. A sha256 hash is always a number, no matter how you represent it (hex or not). The target is also a number, and it can be represented however you want.

Regardless of format, the hash of the block's header is treated as a number, and it has to be less than the target.
OK. The header contains a hash of the list of transaction in the block, so there is no computational incentive not to include transactions.
And the reason a large amount of zeros are needed prefixing the hash is because it make the value of the hash less than the target. Thank you for explaining that.  Smiley
Could a POW algorithm work just as well when the hash has to be greater than the target? Eg. It's prefixed with "fffffff" instead of "000000"?
Jaxkr (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250


View Profile
June 21, 2013, 05:12:42 PM
 #8

So the target is a 64 bit number

A 256 bit number stored as a floating point and truncated:
- http://en.bitcoin.it/wiki/Target

Also more info here:

What is “difficulty” and how it relates to “target”?
 - http://bitcoin.stackexchange.com/q/8806/153
Thanks. Can you link me to the formula used to convert difficulty to target? Is it simply the max target divided by the difficulty?
Rannasha
Hero Member
*****
Offline Offline

Activity: 728
Merit: 500


View Profile
June 21, 2013, 05:17:44 PM
 #9

Make sense?
Kind of. So the target is a 64 bit number that represents what the hash of the block in numeric form needs to be less than. So, the hash of the block is treated as a hex number, and compared to the target, and it has to be less than the target?
Kind of. A sha256 hash is always a number, no matter how you represent it (hex or not). The target is also a number, and it can be represented however you want.

Regardless of format, the hash of the block's header is treated as a number, and it has to be less than the target.
OK. The header contains a hash of the list of transaction in the block, so there is no computational incentive not to include transactions.
And the reason a large amount of zeros are needed prefixing the hash is because it make the value of the hash less than the target. Thank you for explaining that.  Smiley
Yes. You can imagine it in base-10: Suppose a 5 digit number (with prefix zeroes) needs to be smaller than 100, that means that you need at least 3 prefix zeroes (00099 and below).

Quote
Could a POW algorithm work just as well when the hash has to be greater than the target? Eg. It's prefixed with "fffffff" instead of "000000"?
Sure, there's no reason why the hash needs to be smaller than a small target. Might as well require it to be larger than some large target.
nimda
Hero Member
*****
Offline Offline

Activity: 784
Merit: 1000


0xFB0D8D1534241423


View Profile
June 21, 2013, 05:24:16 PM
 #10

Thanks. Can you link me to the formula used to convert difficulty to target? Is it simply the max target divided by the difficulty?
Yes.
maximum_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000

difficulty = maximum_target / current_target

multiply both sides by current_target:
current_target * difficulty = maximum_target

divide both sides by difficulty:
current_target = maximum_target / difficulty
Jaxkr (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250


View Profile
June 21, 2013, 05:53:05 PM
 #11

Thanks. Can you link me to the formula used to convert difficulty to target? Is it simply the max target divided by the difficulty?
Yes.
maximum_target = 0x00000000FFFF0000000000000000000000000000000000000000000000000000

difficulty = maximum_target / current_target

multiply both sides by current_target:
current_target * difficulty = maximum_target

divide both sides by difficulty:
current_target = maximum_target / difficulty

Thank you! Now I understand.
r3wt
Hero Member
*****
Offline Offline

Activity: 686
Merit: 504


always the student, never the master.


View Profile
June 21, 2013, 05:58:03 PM
 #12

fucking nerds. Tongue

My negative trust rating is reflective of a personal vendetta by someone on default trust.
Jaxkr (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250


View Profile
June 21, 2013, 06:02:21 PM
 #13

fucking nerds. Tongue
C'mon. If you're going to use this currency, might as well know how it works. Tongue
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!