Author

Topic: Nonce and extranonce algorithm (Read 3305 times)

copper member
Activity: 1498
Merit: 1528
No I dont escrow anymore.
May 07, 2015, 05:38:37 PM
#10
I've got one more question. When I first thought of the nonce and the hashing algo I was under the assumption that once all the hashing is done there is then a calculation made with the nonce and then we get our block hash result.

This to me doesn't know look right. If it isn't please could someone tell me at what stage does the nonce come in when the calculations are being made?

The nonce is part of the data that is hashed for the blockhash. Thus it influences the result of the hashing function. Once you have the hash it is compared to the target. If your hash is below the traget value we have a new block, if not you change the data (e.g. nonce = nonce +1), hash and compare again. Once you have tried all possible nonces you have to change something different in order to get hash values for the block you did not try yet. There are several options, e.g. the transactions to include, the timestamp of the block or what is called the extranonce.
jr. member
Activity: 45
Merit: 4
May 07, 2015, 04:25:20 PM
#9
I've got one more question. When I first thought of the nonce and the hashing algo I was under the assumption that once all the hashing is done there is then a calculation made with the nonce and then we get our block hash result.

This to me doesn't know look right. If it isn't please could someone tell me at what stage does the nonce come in when the calculations are being made?
legendary
Activity: 1344
Merit: 1024
Mine at Jonny's Pool
April 28, 2015, 02:09:41 PM
#8
Thank you Danny, appreciate the help.

Can I re-phrase the last part as what I was asking was simpler than what I think I have actually written down.

All I wanted to know is usually does hashing take longer or finding the correct nonce when it is being computed (on average from your experience)?

Hashing is extremely fast.

The typical AntMiner S4 ASIC completes 2,000,000 hashes each second.

Finding a nonce that results in a low enough hash requires the hash to be calculated MANY times, and takes on average approximately 10 minutes.  On average, across the entire world, approximately 249,187,460,000,000,000,000 (that's 2.49X1020) hashes are calculated before someone somewhere happens across a block and nonce combination that hashes to a value less than the current target.
I know you typically don't pay attention to anyone with a signature campaign; however, in the interest of providing clarity to the part of your statement I bolded, you are missing a few zeros.  An S4 is a 2 TH/s machine, meaning it will complete 2,000,000,000,000 hashes per second.

Using bitcoinwisdom.com reported network hash rate of 347.453128 PH/s, (as of the writing of this post) and an average expected block time of 600 seconds, one would expect a total of 2.084718768x1020 hashes worldwide to find a block.
jr. member
Activity: 45
Merit: 4
April 28, 2015, 01:38:19 PM
#7
Cool, I'm more clued up now. Thanks for your help Danny  Grin
legendary
Activity: 3472
Merit: 4794
April 28, 2015, 12:42:18 PM
#6
Again, thank you very much this has helped me understand the process a lot.

One last question. In your last bit of reply you say the hash has to be calculated many times; are you saying everytime a nonce (or altranonce) is changed all the input is re-hashed? I'm not entirely sure of the entire algorithm calculation but I was under the assumption that parts of the calculations can be 're-used' (or some of the calculation results are kept whilst some are re-calculated to get the required to difficulty).

The reason I came to this conclusion was this spreadsheet which looks as if this is how it works (see link below).

If this is not the case am I correct in assuming the entire process is re-calculated everytime a new nonce is tried?

https://www.dropbox.com/s/2erhq2uum7fvdc2/Bitcoin.xlsx?dl=0

You are correct.

Because most of the block header stays the same when the nonce is incremented, and some of the rounds in the hashing process are therefore unaffected, it is possible to take some shortcuts reducing the amount of bit manipulation that must be done to determine if the hash will result in a low enough value.  This makes it possible to check more nonces in a shorter amount of time and using less power than if the entire double SHA256 calculation had to be completed from the beginning all the way through the end.
jr. member
Activity: 45
Merit: 4
April 28, 2015, 12:29:49 PM
#5
Again, thank you very much this has helped me understand the process a lot.

One last question. In your last bit of reply you say the hash has to be calculated many times; are you saying everytime a nonce (or altranonce) is changed all the input is re-hashed? I'm not entirely sure of the entire algorithm calculation but I was under the assumption that parts of the calculations can be 're-used' (or some of the calculation results are kept whilst some are re-calculated to get the required to difficulty).

The reason I came to this conclusion was this spreadsheet which looks as if this is how it works (see link below).

If this is not the case am I correct in assuming the entire process is re-calculated everytime a new nonce is tried?

https://www.dropbox.com/s/2erhq2uum7fvdc2/Bitcoin.xlsx?dl=0
legendary
Activity: 3472
Merit: 4794
April 28, 2015, 11:14:29 AM
#4
Thank you Danny, appreciate the help.

Can I re-phrase the last part as what I was asking was simpler than what I think I have actually written down.

All I wanted to know is usually does hashing take longer or finding the correct nonce when it is being computed (on average from your experience)?

Hashing is extremely fast.

The typical AntMiner S4 ASIC completes 2,000,000,000,000 hashes each second.

Finding a nonce that results in a low enough hash requires the hash to be calculated MANY times, and takes on average approximately 10 minutes.  On average, across the entire world, approximately 249,187,460,000,000,000,000 (that's 2.49X1020) hashes are calculated before someone somewhere happens across a block and nonce combination that hashes to a value less than the current target.

Edit: I received a PM pointing out that I accidentally stated that an AntMiner S4 ASIC completes 2,000,000 hashes each second.  It actually completes 2,000,000,000,000 hashes each second.  I've corrected it in this post.
jr. member
Activity: 45
Merit: 4
April 28, 2015, 10:35:04 AM
#3
Thank you Danny, appreciate the help.

Can I re-phrase the last part as what I was asking was simpler than what I think I have actually written down.

All I wanted to know is usually does hashing take longer or finding the correct nonce when it is being computed (on average from your experience)?
legendary
Activity: 3472
Merit: 4794
April 28, 2015, 10:23:13 AM
#2
I'm slightly confused as to the algorithm especially the extranonce part?

From what I understand (please correct me if I'm wrong)..after all the hashing work is done and the target level still not achieved one can change the nonce to achieve the needed '0s' in the output.

A double SHA256 hash of the block header is calculated.  If the resulting hash value is not lower than the target difficulty, then the nonce (which is a value in the block header) is incremented.  Then the double SHA256 hash is calculated again.  If the resulting hash value is not lower than the target difficulty, then the nonce is incremented.  This continues until either a hash value is found that is less than the target, or all 4,294,967,296 possible nonce values have been tried.

Is this the point where if nonce cannot achieve this the extranonce comes in?

That depends on the mining software.  There are a few ways to adjust the header after all the nonce values have been attempted.  The timestamp can be adjusted.  The order of the transactions in the block can be manipulated, or the extranonce can be altered.

If so what is this extranonce and what changes happen here (eg are these random brute-force changes or calculated changes?)

extranonce is part of the input to the generation transaction.  How it is adjusted depends on the miner or mining pool.

Also, I read somewhere (on this forum) that most of the time an extranonce is needed to be changed as most of the time the nonce doesn't achieve the desired difficulty (if I have understood the info above correctly), if this is the case should you just skip brute forcing the nonce and go on to change the extranonce in the first place?

After adjusting the extranonce the mining equipment tries all 4,294,967,296 possible nonce values again with the new block header.  If that doesn't work, then the header is adjusted again and the mining equipment tries all 4,294,967,296 possible nonce values again with the new block header.  This continues until someone finds a combination of block header and nonce value that result in a low enough hash value.  It is faster and easier to change the nonce then to rebuild the merkle root (which must be done if the extranonce or transactions are adjusted).  Therefore, it is always best to try all 4,294,967,296 possible nonce values before going to the effort of modifying the extranonce.

Lastly, in terms of %, what % takes most time (if you were to speak theoretically) to calculate (ie why does it take approx 10 minutes to get the correct output) is it the hashing (any particular part) or the nonce (or extranonce)?

Hope my questions make sense

It is impossible to know the result of a hash before you calculate it (just like it's impossible to know the result of rolling a die before you roll it).  The difficulty is intentionally set so that it will take the entire world mining power on average 10 minutes to get lucky enough to stumble across a valid hash (much like I could create a dice game where the "difficulty" is the number of sixes you have to roll in a row in order to "Win".  I could then adjust the "difficulty" by increasing or decreasing the number of sixes needed for a win.)
jr. member
Activity: 45
Merit: 4
April 28, 2015, 09:46:44 AM
#1
I'm slightly confused as to the algorithm especially the extranonce part?

From what I understand (please correct me if I'm wrong)..after all the hashing work is done and the target level still not achieved one can change the nonce to achieve the needed '0s' in the output. Is this the point where if nonce cannot achieve this the extranonce comes in? If so what is this extranonce and what changes happen here (eg are these random brute-force changes or calculated changes?)

Also, I read somewhere (on this forum) that most of the time an extranonce is needed to be changed as most of the time the nonce doesn't achieve the desired difficulty (if I have understood the info above correctly), if this is the case should you just skip brute forcing the nonce and go on to change the extranonce in the first place?

Lastly, in terms of %, what % takes most time (if you were to speak theoretically) to calculate (ie why does it take approx 10 minutes to get the correct output) is it the hashing (any particular part) or the nonce (or extranonce)?

Hope my questions make sense
Jump to: