Author

Topic: From a low level, how does difficulty work? (Read 883 times)

sr. member
Activity: 420
Merit: 250
fucking nerds. Tongue
C'mon. If you're going to use this currency, might as well know how it works. Tongue
hero member
Activity: 686
Merit: 504
always the student, never the master.
fucking nerds. Tongue
sr. member
Activity: 420
Merit: 250
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.
hero member
Activity: 784
Merit: 1000
0xFB0D8D1534241423
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
hero member
Activity: 728
Merit: 500
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.
sr. member
Activity: 420
Merit: 250
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?
sr. member
Activity: 420
Merit: 250
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"?
legendary
Activity: 2506
Merit: 1010
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
hero member
Activity: 784
Merit: 1000
0xFB0D8D1534241423
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.
sr. member
Activity: 420
Merit: 250
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?
hero member
Activity: 784
Merit: 1000
0xFB0D8D1534241423
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?
sr. member
Activity: 364
Merit: 250
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.
sr. member
Activity: 420
Merit: 250
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.
Jump to: