Bitcoin Forum
September 20, 2018, 01:39:33 PM
 News: ♦♦ Bitcoin Core users must update to 0.16.3 [Torrent]. More info.
 Home Help Search Donate Login Register
 Pages: [1]
 Author Topic: A TECHNICAL question about blockchain, btc mining  (Read 121 times)
gorkem2020
Newbie

Offline

Activity: 8
Merit: 3

 September 08, 2018, 02:56:00 PMMerited by NeuroticFish (2), ETFbitcoin (1)

Hello everyone, this is my first topic here. I feel excited little bit lol. And sorry for my English, it is not my first language.

Ok so I've been interested in cryptoCurrencies since the August 2017, but lately I decided to learn more about the technology itself; blockchain. I know most of the parts about how it works. but some little details that I dont understand bothering me.

I have researched everywhere. I love researching and learning. But no success for this particular topic.

My questions is about mining (technical side). I understand how it works basically, I'm a home miner myself but couple things really annoying me.

1-) I'm looking at block 540494, its nonce is 2097181953 its hash is 00000000000000000024ada2........

so it starts with 18 leading zeros..

that means a miner starts from 0 calculates its hash with the nonce=0 IF no valid result, THEN increments nonce by 1. now nonce=1, and keep doing this until a hash is found with 18 leading zeros. Because current difficulty requires them to find a hash with 18 leading zeros, right?

Sub-question: I know difficulty changes every 2 weeks, it is now 7,019,199,231,177 but who decides how many leading zeros should be in the valid hash? is it something to do with "target difficulty" rather than the "difficulty number" itself? Are these 2 different difficulty parameters that define the difficulty?

So for this particular example (block 540494) the nonce is 2097181953

that means a miner tried every single nonce from 0 to 2,097,181,953, and calculated hash 2,097,181,953 (lets say 2 billions) times in total and found the valid result which is the hash starting with 18 zeros. (00000000000000000024ada2........)

Now what I dont understand is that an ASIC machine can hash 12 trillion times PER SECOND. and our nonce is 2,097,181,953. so that means winning miner spent only fraction of a second to calculate 2 billions hashes. But it cant be true because block time is 10 minutes, right? so what is wrong here?? What am I doing wrong with this calculation?

My understanding is like the following;

* Miner have a list of transactions and all the properties (headers I believe) to calculate the hash of the block.

* Miner calculates hashes for all the nonces between 0 and the current difficulty (it is now 7,019,199,231,177)

* IF miner finds a hash with at least 18 leading zeros (can be more than 18 zeros, right? since even if it has 20 leading zeros, it is still proof of the work.) that miner gets the reward.

* IF miner cant find a nonce between 0 - 7,019,199,231,177 then miner picks different set of transactions (since calculations with the current list of transactions wont be resulting valid hash.. So miner adds couple more transactions into the block and starts the whole process all over again with the new list of transactions.. hoping to find a valid hash with the nonce between 0 and 7,019,199,231,177 and with the new set of transactions.

So did I get it all wrong? and confused myself for nothing? 😄 or this is actually what is happening? I know there are couple of gurus here and can confirm if I'm right or wrong..

Thanks
1537450773
Hero Member

Offline

Posts: 1537450773

Ignore
 1537450773

1537450773
 Report to moderator
1537450773
Hero Member

Offline

Posts: 1537450773

Ignore
 1537450773

1537450773
 Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1537450773
Hero Member

Offline

Posts: 1537450773

Ignore
 1537450773

1537450773
 Report to moderator
1537450773
Hero Member

Offline

Posts: 1537450773

Ignore
 1537450773

1537450773
 Report to moderator
1537450773
Hero Member

Offline

Posts: 1537450773

Ignore
 1537450773

1537450773
 Report to moderator
achow101
Moderator
Legendary

Offline

Activity: 1526
Merit: 1631

 September 08, 2018, 04:24:43 PMMerited by Foxpup (6), Welsh (5), suchmoon (4), NeuroticFish (4)

1-) I'm looking at block 540494, its nonce is 2097181953 its hash is 00000000000000000024ada2........

so it starts with 18 leading zeros..

that means a miner starts from 0 calculates its hash with the nonce=0 IF no valid result, THEN increments nonce by 1. now nonce=1, and keep doing this until a hash is found with 18 leading zeros. Because current difficulty requires them to find a hash with 18 leading zeros, right?
Yes, and no. Yes, a miner started from 0 and incremented the nonce until they found a hash that met the proof of work requirements. No, the difficulty does not require them to find a hash with 18 leading zeroes.

The leading zeroes thing is just a simplification of how the proof of work check actually works. What actually happens is that there is some target value that is a 256 bit integer. Block hashes are interpreted as a 256 bit integer. So all that happens is that the block hash (interpreted as a 256 bit integer) is compared to the target value. The block hash must then be less than or equal to the target value. Because the target value is "small" (small in terms of the 256 bit number space), it will have many leading zeroes. But the zeroes themselves do not actually matter, all that matters is the value.

Sub-question: I know difficulty changes every 2 weeks, it is now 7,019,199,231,177 but who decides how many leading zeros should be in the valid hash? is it something to do with "target difficulty" rather than the "difficulty number" itself? Are these 2 different difficulty parameters that define the difficulty?
There is only one parameter that matters: the target value. The difficulty is just the inverse of the target divided by the maximum target value.

The difficulty readjustment is really a target readjustment. The target changes every 2016 blocks, which is approximately two weeks. It does not actually change every two weeks since it may take shorter or longer than 2 weeks to find 2016 blocks. The target is just scaled proportionally to the amount of time it took to mine 2016 blocks and the amount of time it should take to mine 2016 blocks (2 weeks). Of course there must have been a starting point for the target, and that is the maximum target value (so difficulty is the lowest) which is defined in the consensus rules. The maximum target value was used in the genesis block so that is the starting point for target adjustment.

So for this particular example (block 540494) the nonce is 2097181953

that means a miner tried every single nonce from 0 to 2,097,181,953, and calculated hash 2,097,181,953 (lets say 2 billions) times in total and found the valid result which is the hash starting with 18 zeros. (00000000000000000024ada2........)

Now what I dont understand is that an ASIC machine can hash 12 trillion times PER SECOND. and our nonce is 2,097,181,953. so that means winning miner spent only fraction of a second to calculate 2 billions hashes. But it cant be true because block time is 10 minutes, right? so what is wrong here?? What am I doing wrong with this calculation?

My understanding is like the following;

* Miner have a list of transactions and all the properties (headers I believe) to calculate the hash of the block.

* Miner calculates hashes for all the nonces between 0 and the current difficulty (it is now 7,019,199,231,177)

* IF miner finds a hash with at least 18 leading zeros (can be more than 18 zeros, right? since even if it has 20 leading zeros, it is still proof of the work.) that miner gets the reward.

* IF miner cant find a nonce between 0 - 7,019,199,231,177 then miner picks different set of transactions (since calculations with the current list of transactions wont be resulting valid hash.. So miner adds couple more transactions into the block and starts the whole process all over again with the new list of transactions.. hoping to find a valid hash with the nonce between 0 and 7,019,199,231,177 and with the new set of transactions.
That is close. Miners don't usually re-select transactions after every set of nonces is exhausted. Usually they will change something within the block they already have. Specifically, they will set some value in their coinbase transaction that is known as the extra nonce. This extra nonce is then incremented every time the nonce runs out so that the merkle root is different and thus the nonces can be tried again. Furthermore, miners may change things like the block timestamp and block version number in order to get different candidate blocks.

* Miner have a list of transactions and all the properties (headers I believe) to calculate the hash of the block.
Transactions are just transactions. There are no transaction headers. The block contains the transactions themselves and then the hash of all of the transactions is included in the merkle root which is in the block header.

* Miner calculates hashes for all the nonces between 0 and the current difficulty (it is now 7,019,199,231,177)
No, the nonce is a 32 bit integer. It can only have the 32 bit integer values. It does not change with the difficulty.

* IF miner finds a hash with at least 18 leading zeros (can be more than 18 zeros, right? since even if it has 20 leading zeros, it is still proof of the work.) that miner gets the reward.
A block hash is valid so long as it is less than or equal to the current target. So one with more leading zeroes is inherently less than, thus it will still be accepted.

gorkem2020
Newbie

Offline

Activity: 8
Merit: 3

 September 08, 2018, 09:06:55 PM

achow101 thanks a lot, it all makes sense now. Great explanation. And what you said led me more digging into details.

this is what I understand, in summary;

example for block 540494

Code:

difficulty = 7019199231177.173

maxTarget (Decimal) 26959535291011309493156476344723991336010898738574164086137773096960

target = maxTarget / difficulty

target (decimal) = 3840827764407250020633179921320621786723403550981928027

so calculated hash must be less than or equal to the target value...

Code:

which is represented as follows;

0000000000000000002819A0FFFFFFFF791A56A92A5F71C70648653408B0B45B

and using the nonce '2097181953' the valid hash for this block;

so it is clear to see that the hash is less than the target...

I understand why there are zeros. it is just the representation. it all makes sense now..

Just one more thing, so the nonce has nothing to do with the difficulty number right?  so nonce can be greater than difficulty value? they are not related at all? if they are not related what is the maximum number a nonce can be? when the miner decides to change something in the block?

EDIT: I believe it can be 2147483647 at most. which is the largest 32bit value. so when it hits this number, miner decides to change something else within the block

bob123
Hero Member

Offline

Activity: 686
Merit: 562

 September 09, 2018, 09:23:16 AM

Just one more thing, so the nonce has nothing to do with the difficulty number right?

Correct.

so nonce can be greater than difficulty value? they are not related at all? if they are not related what is the maximum number a nonce can be?

Currently, the difficulty is 6,727,225,469,722.
And the nonce is a 4 byte (32 bit) number. So max value = 4.294.967.295

The nonce CAN be greater than the difficulty IF the difficulty is extremely low.
But nonce and difficulty are not related at all..

when the miner decides to change something in the block?

When he has tried out all nonces without a single one leading to a hash below the current target.

 ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀ .ChipMixer.{ MIXING REINVENTED FOR YOUR PRIVACY #.ChipMixer. ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀
gorkem2020
Newbie

Offline

Activity: 8
Merit: 3

 September 09, 2018, 12:00:16 PM

Just one more thing, so the nonce has nothing to do with the difficulty number right?

Correct.

so nonce can be greater than difficulty value? they are not related at all? if they are not related what is the maximum number a nonce can be?

Currently, the difficulty is 6,727,225,469,722.
And the nonce is a 4 byte (32 bit) number. So max value = 4.294.967.295

The nonce CAN be greater than the difficulty IF the difficulty is extremely low.
But nonce and difficulty are not related at all..

when the miner decides to change something in the block?

When he has tried out all nonces without a single one leading to a hash below the current target.

isnt the difficulty 7,019,199,231,177.173 right now? not 6,727,225,469,722

And I thought max value of a 32 bit can be 2,147,483,647 where did the 4,294,967,295 come from?

bob123
Hero Member

Offline

Activity: 686
Merit: 562

 September 09, 2018, 12:21:17 PM

isnt the difficulty 7,019,199,231,177.173 right now? not 6,727,225,469,722

You are right. The last difficulty was 6,727,225,469,722. Adjustment happened ~400 blocks ago.
Don't know where this old data came from

And I thought max value of a 32 bit can be 2,147,483,647 where did the 4,294,967,295 come from?

32 bit can represent 232 (= 4.294.967.296) different numbers. So from 0 to 4.294.967.295.

2,147,483,647 is the max number if you want to store positive and negative values inside a 32 bit variable.
But the overall amount of values a 32 bit integer can represent is 4.294.967.296

 ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀ .ChipMixer.{ MIXING REINVENTED FOR YOUR PRIVACY #.ChipMixer. ░░░░░▄▄██████▄▄░░▄████▀▀▀▀▀▀████▄░███▀░░░░░░░░░░▀█▀████░░░▄██████▄▄░░░██░░░░░█████████░░░░██▌░░░░█████████████████░░░░█████████████████░░░░░███████████████████▄░░▀██████▀░░░████▀█▄▄░░░░░░░░░░▄███░░▀████▄▄▄▄▄▄████▀░░░░░▀▀██████▀▀
gorkem2020
Newbie

Offline

Activity: 8
Merit: 3

 September 09, 2018, 01:13:21 PM

isnt the difficulty 7,019,199,231,177.173 right now? not 6,727,225,469,722

You are right. The last difficulty was 6,727,225,469,722. Adjustment happened ~400 blocks ago.
Don't know where this old data came from

And I thought max value of a 32 bit can be 2,147,483,647 where did the 4,294,967,295 come from?

32 bit can represent 232 (= 4.294.967.296) different numbers. So from 0 to 4.294.967.295.

2,147,483,647 is the max number if you want to store positive and negative values inside a 32 bit variable.
But the overall amount of values a 32 bit integer can represent is 4.294.967.296

alright yeah things are clearer now haha thanks.
 Pages: [1]