5 ms·
How is the hash compared to a difficulty? The current difficulty is 609482680... How do you compare a hash to a number to determine if it's greater than the num
by Moral_ 13y ago
How is the hash compared to a difficulty? The current difficulty is 609482680... How do you compare a hash to a number to determine if it's greater than the number?
- jadeddrag 13y ago"What is the formula for difficulty? difficulty = maximum_target / current_target (target is a 256 bit number)" source: https://en.bitcoin.it/wiki/Difficulty https://en.bitcoin.it/wiki/Difficulty
- blibble 13y agothe proof of work requires miners to generate some value such that HASH(block_value, generated_value) begins with fn(difficulty) zeros. miners choose a value for generated_value, hash it and hope it comes out with the required number of zeros, if not they try again, and again, and again until they (or someone else) finds a value. for simplicity let's say the fn(x) = x. difficulty of 5? hash must have 5 zeros at the beginning: 00000XXXXXXXXXXXXXXXXXXXXXXXXX 10? must have 10: 0000000000XXXXXXXXXXXXXXXXXXXX each zero you add on requires exponentially more time.
- brainburn 13y agoI know the docs say it has to be a bunch of zeroes at the start, the actual test is whether or not the generated value is below a certain number.
- ars_technician 13y agoWhen you are looking at a binary number, the number of zeros at the start is the exact same thing as making sure the number is below a certain threshold.
- lololomg 13y agoNo it's not the exact same thing. Example: Treshold = 001010 If you check 001011 or 001001 then the number of leading zeros are the same but one number is below the threshold and the other is not.
- letstryagain 13y agoNot exactly the same thing. Consider this example: Threshold is 001010 The numbers 001001 and 001011 have the same number of leading zeroes but one is below the threshold and the other is not.
- ars_technician 13y agoWhat I said is correct, but I suppose ambiguous. What I mean to say is that counting MSB zeros does specify that the number will be below a threshold, just not an arbitrary threshold like the one you gave in your example. For a more concrete example, if the requirement is that a 16-bit word is less than 4096, you only have to verify that it leads with 4 zeros.
- letstryagain 13y agoYes but Bitcoin uses 'below number X' which has more precision than just counting leading zeroes.
- nilkn 13y agoSo the procedure described by blibble isn't actually used in the client software? I've always thought that's how it worked since that is what is written in the original Bitcoin paper (which has for a long time been my only source of information on the protocol).
- maaku 13y agoYes blibble's procedure has nothing to do with the actual calculation. The protocol says to treat the 256-bit hash as a little-endian integer, and then check if that is less than the target value. The target value is an integer value that is stored as a custom-format floating point value in the block header and adjusted every 2016 blocks. "Difficulty" per se doesn't actually exist at the protocol level, it's a purely human-interface concern.
- jadeddrag 13y agoYou're mostly correct, except the difficulty number is not exactly the same as the number of leading zeros.
- baddox 13y agoHence the "for simplicity let's say the fn(x) = x."
- maaku 13y agoThe serialized hash is interpreted as a 256-bit integer with little-endian semantics. It is then compared to see if it is less then the target value (which difficulty is really just a short-hand for).