<blockquote>
  <p>he is inputting any arbitrary values, in order to get a value that can be hashed into something with certain preceding zeros. When he got that value, he put that value into the blockchain and generate a new block.</p>
</blockquote>

<p>It happens in reverse.<br>
First the miner builds the new block itself. Then builds its header, then hashes that header. Also what the miner looks for is <em>not</em> preceding zeros, but instead is a number (hash result interpreted as integer) that is smaller than the <a href="https://en.bitcoin.it/wiki/Target" rel="nofollow noreferrer">target</a>.  </p>

<p>The steps are something like this:</p>

<ol>
<li>Take 0 to max (to fill the block) number of transaction from mempool</li>
<li>Build the mandatory coinbase transaction</li>
<li>Build the hashMerkleRoot based on 1&amp;2</li>
<li>Fill the block header fields: Version, hashPrevBlock and Bits are unchanging; hashMerkleRoot, Time and Nonce can change</li>
<li>Start a loop and change the variables on its iterations and hash the header.</li>
<li>Convert the result of the hash to an integer and compare it with the target.</li>
<li>Break out of the look and publish the result if <code>hash &lt;= target</code> or if someone else were luckier and found and published the same block.</li>
</ol>

<p>You can find more information in these links:<br>
<a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Block_hashing_algorithm</a><br>
<a href="https://en.bitcoin.it/wiki/Proof_of_work" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Proof_of_work</a></p>

<blockquote>
  <p>Then how is this contributing, or say, relating to the confirmations?</p>
</blockquote>

<p>Confirmation is when a transaction is included in a block that was found. 1 confirmation means the transaction is inside the last found block, any subsequent number shows the depth of the transaction compared to the block height of that time and is an indication of how hard it would be to perform a double spend.  <a href="https://en.bitcoin.it/wiki/Confirmation" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/Confirmation</a></p>

CC BY-SA 4.0
2019-12-07T19:05:00.580Z
2019-12-07T19:15:40.963Z
2019-12-07T19:15:40.963Z
Coding Enthusiast
<p>When miners build valid blocks with transactions, they put in significant amount of compute work to generate a hash of the block header that meets the difficulty requirement. Blockchain is a chain of blocks where each block header references the hash of the header of the previous block. The hash of the block header is calculated using all the elements of the block, which includes the transactions it contains. If a component of the block is changed in any way, it will generate a completely different hash.</p>

<p>Confirmation is a direct reference to the difficulty of removing a transaction from the blockchain. If a transaction is included in a block that has 5 blocks mined after it, then an attacker who wants to exclude that particular transaction would have to perform "work" (compute hashes that match the difficulty requirement) to mine the block containing the transaction and all subsequent blocks after it. This is a total of 6 blocks and hence that particular transaction is said to have 6 confirmations.</p>

<p>If the transaction is mined in a block with sufficient confirmations, than the cost of excluding that transaction is very high as the attacker would have to perform the compute work. Thus, in the mining process the miners through their heavy compute work add finality to the transactions.</p>

CC BY-SA 4.0
2019-12-07T20:08:22.713Z
2019-12-07T20:08:22.713Z
Ugam Kamat
<p>Based on my knowledge I know (maybe wrong) when a miner is doing hash, he is inputting any arbitrary values, in order to get a value that can be hashed into something with certain preceding zeros. When he got that value, he put that value into the blockchain and generate a new block.</p>

<p>Then how is this contributing, or say, relating to the confirmations? Since the miners are just guessing arbitrary values to get the 0000000 preceded hash.</p>

<p>I think I must have some misunderstanding. I want to know how the hash-guessing is related to confirming the transactions.</p>

CC BY-SA 4.0
2019-12-07T19:26:47.710Z
Related: https://bitcoin.stackexchange.com/q/51286/5406, https://bitcoin.stackexchange.com/q/331/5406, https://bitcoin.stackexchange.com/a/760/5406
Murch
CC BY-SA 4.0
2019-12-07T22:30:07.857Z
Related: https://bitcoin.stackexchange.com/questions/83951/how-does-proof-of-work-inspire-trust-when-the-work-is-just-guessing/83953#83953
chytrik
<transactions><blockchain><mining-theory><block><confirmations>
How Bitcoin mining contributes to confirmations?
gudako
# How Bitcoin mining contributes to confirmations?

(Asked by: username_0 on 2019-12-07)

Based on my knowledge I know (maybe wrong) when a miner is doing hash, he is inputting any arbitrary values, in order to get a value that can be hashed into something with certain preceding zeros. When he got that value, he put that value into the blockchain and generate a new block.

Then how is this contributing, or say, relating to the confirmations? Since the miners are just guessing arbitrary values to get the 0000000 preceded hash.

I think I must have some misunderstanding. I want to know how the hash-guessing is related to confirming the transactions.

**Tags:** transactions, blockchain, mining-theory, block, confirmations

> **Comments:**
> **username_1**: Related: https://bitcoin.stackexchange.com/q/51286/5406, https://bitcoin.stackexchange.com/q/331/5406, https://bitcoin.stackexchange.com/a/760/5406  
> **username_2**: Related: https://bitcoin.stackexchange.com/questions/83951/how-does-proof-of-work-inspire-trust-when-the-work-is-just-guessing/83953#83953  

---

## 2 answers

### Answer by username_3 on 2019-12-07. Score: 1 | Accepted answer

> he is inputting any arbitrary values, in order to get a value that can be hashed into something with certain preceding zeros. When he got that value, he put that value into the blockchain and generate a new block.

It happens in reverse.  
First the miner builds the new block itself. Then builds its header, then hashes that header. Also what the miner looks for is *not* preceding zeros, but instead is a number (hash result interpreted as integer) that is smaller than the [target](https://en.bitcoin.it/wiki/Target).

The steps are something like this:

1. Take 0 to max (to fill the block) number of transaction from mempool
2. Build the mandatory coinbase transaction
3. Build the hashMerkleRoot based on 1&2
4. Fill the block header fields: Version, hashPrevBlock and Bits are unchanging; hashMerkleRoot, Time and Nonce can change
5. Start a loop and change the variables on its iterations and hash the header.
6. Convert the result of the hash to an integer and compare it with the target.
7. Break out of the look and publish the result if `hash <= target` or if someone else were luckier and found and published the same block.

You can find more information in these links:  
<https://en.bitcoin.it/wiki/Block_hashing_algorithm>  
<https://en.bitcoin.it/wiki/Proof_of_work>

> Then how is this contributing, or say, relating to the confirmations?

Confirmation is when a transaction is included in a block that was found. 1 confirmation means the transaction is inside the last found block, any subsequent number shows the depth of the transaction compared to the block height of that time and is an indication of how hard it would be to perform a double spend. <https://en.bitcoin.it/wiki/Confirmation>


---

### Answer by username_4 on 2019-12-07. Score: 1

When miners build valid blocks with transactions, they put in significant amount of compute work to generate a hash of the block header that meets the difficulty requirement. Blockchain is a chain of blocks where each block header references the hash of the header of the previous block. The hash of the block header is calculated using all the elements of the block, which includes the transactions it contains. If a component of the block is changed in any way, it will generate a completely different hash.

Confirmation is a direct reference to the difficulty of removing a transaction from the blockchain. If a transaction is included in a block that has 5 blocks mined after it, then an attacker who wants to exclude that particular transaction would have to perform "work" (compute hashes that match the difficulty requirement) to mine the block containing the transaction and all subsequent blocks after it. This is a total of 6 blocks and hence that particular transaction is said to have 6 confirmations.

If the transaction is mined in a block with sufficient confirmations, than the cost of excluding that transaction is very high as the attacker would have to perform the compute work. Thus, in the mining process the miners through their heavy compute work add finality to the transactions.


---

