<p>Realistic miners run through all 2^32 possible nonces in much less than a second.</p>

<p>If a transaction occurred after you started your nonce search, then your block won't include that transaction. There's no problem with that.</p>

<p>If the time changed after you mined your block, then your block won't have the exact right time. Again, no problem with that.</p>

<p>And if you think about it, there <em>can't</em> be any problem with that. How would anyone know when you mined the block or whether the transaction occurred before or after you mined the block? It's mining that allows bitcoin to agree on these things, so if you mined the block, you're the one who gets to choose.</p>

CC BY-SA 3.0
2018-01-22T23:52:10.367Z
where does 2^32 comes from? is it the max possible nonce? or is it agreed share of the pool mining? if it take only a second, what do I do the rest of 10 minutes?
Prostak
CC BY-SA 3.0
2018-01-22T23:53:52.360Z
There are 2^32 possible nonces since the nonce is 32-bits. Perhaps you have the misconception that there's one magic block that every miner is trying to mine. A miner is trying to mine any valid block that pays him the reward. If he can't mine a particular block, he'll just trying again with a slightly different block. If he has lots of fast hardware, he may be trying to mine 100's of possible different blocks at once. On average, someone somewhere succeeds once every 10 minutes. That's how hard mining is.
David Schwartz
CC BY-SA 3.0
2018-01-22T23:59:46.100Z
thanks for responding btw! you are right, I did have this misconception... but does it mean, that it might be impossible to find jackpot with certain criterias.... i mean, it just does not exist... so let's say i have m and t, and no matter of nonce i use, it is impossible to get a hash with certain 0? so that means, that you have to modify time or merkleRoot ?
Prostak
CC BY-SA 3.0
2018-01-23T00:09:55.030Z
@Prostak Right. It's trivial to get a new merkleRoot by just slightly changing the transaction that pays you the mining reward. So that gets you a whole new block to try all 2^32 nonces on.
David Schwartz
CC BY-SA 3.0
2018-01-23T00:23:40.937Z
When you say "100's of possible different blocks at once", what do you mean? what variants do they introduce to block? time? and change transaction list? or is there a way to modify smth else?
Prostak
CC BY-SA 3.0
2018-01-23T00:33:57.790Z
Typically they change the transaction that pays them the block reward and transaction fees. Changing one byte in the transaction is sufficient to give them an entirely new block to try all 2^32 nonces on.
David Schwartz
CC BY-SA 3.0
2018-01-22T23:29:00.957Z
2018-01-22T23:29:00.957Z
David Schwartz
<p>As a miner, <em>you</em> choose your own <code>merkleRoot</code> and <code>time</code>.</p>

<p>This is the same reason why different miners are looking for different nonces - your <code>merkleRoot</code> contains <em>your</em> reward transaction, while the <code>merkleRoot</code> for a different miner contains <em>their</em> reward transaction.</p>

CC BY-SA 3.0
2018-01-22T23:55:35.340Z
what do you mean "you choose"? do you mean that you choose transactions to pick to the block? but in that case, you also don't choose, because you have to take transactions that occurred before... as I understand, the max transactions are 2400, so you have to take at least this max
Prostak
CC BY-SA 3.0
2018-01-22T23:56:51.470Z
You don't have to take transactions that occurred before. You have your choice of valid transactions. And you can introduce your own transactions if you want. Mining is how we agree on which transactions occurred so if you mine a block, you get to choose for that block. So long as they're valid, of course.
David Schwartz
CC BY-SA 3.0
2018-01-22T23:56:59.947Z
Yes, I mean that miners choose the transactions that they would like to include in a block. This how miners can drive transaction costs up, by choosing to only include transactions with high included transaction fees. If miners were somehow required to include the oldest transactions, then nobody would bother including any transaction fees.
Greg Hewgill
CC BY-SA 3.0
2018-01-23T00:06:55.840Z
@DavidSchwartz correct me if I am wrong, but you have to pick transactions BEFORE you start picking the nonce? because merkleRoot  changes the result? in other words, if you mined the successful nonce, you can't change transactions list after? so you have to pick the exact transactions before starting to mine?
Prostak
CC BY-SA 3.0
2018-01-23T00:07:14.500Z
@GregHewgill same question pls ^^
Prostak
CC BY-SA 3.0
2018-01-23T00:09:07.883Z
@Prostak You have to decide what block you want to mine before you try to mine it. Then you try to mine it by trying all 2^32 nonces. You almost always fail, so you just start the process over again with a different block. And any realistic mining operation is trying to mine hundreds of possible blocks at once. Once you find a nonce, you have mined that exact block. Changing it in any way breaks the hash and so makes it invalid.
David Schwartz
CC BY-SA 3.0
2018-01-23T00:09:23.640Z
Yes, you choose the transactions you would like to include *before* you start mining. When you find a successful nonce, it is in your best interest to broadcast that immediately, because you want your block reward.
Greg Hewgill
CC BY-SA 3.0
2018-01-23T00:28:49.760Z
thanks guys, i've learnt from you that nonce is relatively small number... i thought that all 10 minutes, all miners around the world trying iterating via hash possibilities.... i mean that nonce itself was a hash with 2^160 possibilites... so all 10 minutes, miners iterating their own way these 2^160 ... but it seams that miner iterating playing the guessing game with variables themselfs, not with just nonce... @GregHewgill
Prostak
CC BY-SA 3.0
2018-01-22T23:04:23.997Z
2018-01-22T23:04:23.997Z
Greg Hewgill
<p>In bitcoin, miners hash the header twice with the SHA256 function. This header consists of the fields listed below:</p>

<ul>
<li>version (v)</li>
<li>previousHashBlock (p)</li>
<li>merkleRoot (m)</li>
<li>time (t)</li>
<li>difficulty (d)</li>
<li>nonce (n)</li>
</ul>

<p>Let's simplify and say that I am a pool miner with nonce range from 1-100. So if I do my share and find that on 9th minute the Nonce value of 91, solves the puzzle (proof of work). But by the time I send to network, merkleRoot and time has changed, so the nonce that I've found is not true anymore. We know that hash changes dramatically with slightest change of input, but in this formula, not one but TWO variable change constantly throughout my mining period (in this case 9 minute). Transaction occured and time changed.
So how does this formula hold true thoughout the mining time?</p>

<p><code>SHA256(v + p + m + t + d + n(91)) =&gt; 0000000asd8f686asd6das</code></p>

<p>Where <strong>m</strong> and <strong>t</strong> changes constantly? Wouldn't 91 be irrelevant at the time of finding?</p>

<mining-pools><merkle-tree><block-interval>
How does mining work on the moving target (variables change every second)?
Prostak
# How does mining work on the moving target (variables change every second)?

(Asked by: username_0 on 2018-01-22)

In bitcoin, miners hash the header twice with the SHA256 function. This header consists of the fields listed below:

* version (v)
* previousHashBlock (p)
* merkleRoot (m)
* time (t)
* difficulty (d)
* nonce (n)

Let's simplify and say that I am a pool miner with nonce range from 1-100. So if I do my share and find that on 9th minute the Nonce value of 91, solves the puzzle (proof of work). But by the time I send to network, merkleRoot and time has changed, so the nonce that I've found is not true anymore. We know that hash changes dramatically with slightest change of input, but in this formula, not one but TWO variable change constantly throughout my mining period (in this case 9 minute). Transaction occured and time changed.
So how does this formula hold true thoughout the mining time?

`SHA256(v + p + m + t + d + n(91)) => 0000000asd8f686asd6das`

Where **m** and **t** changes constantly? Wouldn't 91 be irrelevant at the time of finding?

**Tags:** mining-pools, merkle-tree, block-interval


---

## 2 answers

### Answer by username_1 on 2018-01-22. Score: 2 | Accepted answer

Realistic miners run through all 2^32 possible nonces in much less than a second.

If a transaction occurred after you started your nonce search, then your block won't include that transaction. There's no problem with that.

If the time changed after you mined your block, then your block won't have the exact right time. Again, no problem with that.

And if you think about it, there *can't* be any problem with that. How would anyone know when you mined the block or whether the transaction occurred before or after you mined the block? It's mining that allows bitcoin to agree on these things, so if you mined the block, you're the one who gets to choose.

> **Comments:**
> **username_0**: where does 2^32 comes from? is it the max possible nonce? or is it agreed share of the pool mining? if it take only a second, what do I do the rest of 10 minutes?  
> **username_1**: There are 2^32 possible nonces since the nonce is 32-bits. Perhaps you have the misconception that there's one magic block that every miner is trying to mine. A miner is trying to mine any valid block that pays him the reward. If he can't mine a particular block, he'll just trying again with a slightly different block. If he has lots of fast hardware, he may be trying to mine 100's of possible different blocks at once. On average, someone somewhere succeeds once every 10 minutes. That's how hard mining is.  
> **username_0**: thanks for responding btw! you are right, I did have this misconception... but does it mean, that it might be impossible to find jackpot with certain criterias.... i mean, it just does not exist... so let's say i have m and t, and no matter of nonce i use, it is impossible to get a hash with certain 0? so that means, that you have to modify time or merkleRoot ?  
> **username_1**: @username_0 Right. It's trivial to get a new merkleRoot by just slightly changing the transaction that pays you the mining reward. So that gets you a whole new block to try all 2^32 nonces on.  
> **username_0**: When you say "100's of possible different blocks at once", what do you mean? what variants do they introduce to block? time? and change transaction list? or is there a way to modify smth else?  
> **username_1**: Typically they change the transaction that pays them the block reward and transaction fees. Changing one byte in the transaction is sufficient to give them an entirely new block to try all 2^32 nonces on.  

---

### Answer by username_2 on 2018-01-22. Score: 1

As a miner, *you* choose your own `merkleRoot` and `time`.

This is the same reason why different miners are looking for different nonces - your `merkleRoot` contains *your* reward transaction, while the `merkleRoot` for a different miner contains *their* reward transaction.

> **Comments:**
> **username_0**: what do you mean "you choose"? do you mean that you choose transactions to pick to the block? but in that case, you also don't choose, because you have to take transactions that occurred before... as I understand, the max transactions are 2400, so you have to take at least this max  
> **username_1**: You don't have to take transactions that occurred before. You have your choice of valid transactions. And you can introduce your own transactions if you want. Mining is how we agree on which transactions occurred so if you mine a block, you get to choose for that block. So long as they're valid, of course.  
> **username_2**: Yes, I mean that miners choose the transactions that they would like to include in a block. This how miners can drive transaction costs up, by choosing to only include transactions with high included transaction fees. If miners were somehow required to include the oldest transactions, then nobody would bother including any transaction fees.  
> **username_0**: @username_1 correct me if I am wrong, but you have to pick transactions BEFORE you start picking the nonce? because merkleRoot  changes the result? in other words, if you mined the successful nonce, you can't change transactions list after? so you have to pick the exact transactions before starting to mine?  
> **username_0**: @username_2 same question pls ^^  
> **username_1**: @username_0 You have to decide what block you want to mine before you try to mine it. Then you try to mine it by trying all 2^32 nonces. You almost always fail, so you just start the process over again with a different block. And any realistic mining operation is trying to mine hundreds of possible blocks at once. Once you find a nonce, you have mined that exact block. Changing it in any way breaks the hash and so makes it invalid.  
> **username_2**: Yes, you choose the transactions you would like to include *before* you start mining. When you find a successful nonce, it is in your best interest to broadcast that immediately, because you want your block reward.  
> **username_0**: thanks guys, i've learnt from you that nonce is relatively small number... i thought that all 10 minutes, all miners around the world trying iterating via hash possibilities.... i mean that nonce itself was a hash with 2^160 possibilites... so all 10 minutes, miners iterating their own way these 2^160 ... but it seams that miner iterating playing the guessing game with variables themselfs, not with just nonce... @username_2  

---

