<blockquote>
  <p>When a transaction happen, the miners compute a value called "prof of work". This value is calculated in order to get a 0 value (or something very closed to 0) for the hash of the value + the transaction + the last pow.</p>
</blockquote>

<p>The miner does not perform the PoW on each transaction individually, but on a <strong>set</strong> of transactions, whose combined size is less than approximately 1MB when serialized (There is a 1MB limit for non-SegWit parts and 4MB limit for the entire structure including SegWit parts).</p>

<p>The set of transactions is placed into a structure called a <code>block</code>. The block has a header which contains, among other things, a timestamp, the <code>target</code>, a <code>nonce</code>, the hash of the previous block's header, and the merkle root of the set of transactions in <em>this</em> block. The actual representation of the transactions in the block structure is a simple serialized list.</p>

<p>Miners can choose which transactions they wish to include in a block and in what order. However, the usual method is to sort transactions by highest paying fee and select the first bunch of transactions which fit within the block size limit.</p>

<p>The merkle root is calculated by placing the transaction ids (the hash of the serialized transaction) into a binary tree where each parent's value is the hash of the concatenation of its two children's values. The value of the root of this tree is then placed into the block header, along with the other necessary information.</p>

<p>Proof-of-Work is then performed by taking a hash of this block header, and the proof of work is successful if the resulting hash is less than the value specified by the <code>target</code>, which determines the difficulty. The target indicates how many leading zeroes the hash must have - the more leading zeroes, the smaller the possible range of hashes becomes, making it more difficult to produce a matching hash. This difficulty is adjusted according to a consensus algorithm which attempts to make blocks created on average every 10 minutes - using historical data from the past 2016 blocks and their timestamps.</p>

<p>The Proof-of-Work is essentially brute-forcing the double-SHA256 of the block header by using different value for the <code>nonce</code> in the header until the resulting hash of the header is a value which is less than the target. The nonce can be randomly selected, but it is more sensible to simply cycle through all possible 32-bit integer values in order.</p>

<blockquote>
  <p>But i have read the miner discover new bitcoins too. Is it another form of mining ? I do not see the link between the POW calculation and the new bitcoins)</p>
</blockquote>

<p>Each block must contain at least one transaction in its set, which must appear first in the list. This is known as the <code>coinbase</code> transaction. Unlike other transactions, it has no UTXOs as inputs - but its virtual input is newly generated coins plus the aggregate of fees paid in all transactions in this block. Newly generated coins must be strictly less than or equal to <code>50 &gt;&gt; floor(block_height / 210000)</code> bitcoin, which determines that the number of new bitcoins which may be generated is halved approximately every 4 years (210000 blocks).</p>

<p>The coinbase can also be used to include an extra nonce value because the <code>nonce</code> in the regular block header is too small (32-bits), and its entire range can be exhausted by modern miners more quickly than new transactions are added to the block. Mining pools also usually insert their name into the coinbase transaction so it can be public knowledge.</p>

CC BY-SA 4.0
2019-08-24T08:04:57.567Z
2019-08-24T08:04:57.567Z
Mark H
<p>My goal is to understand bitcoin.</p>

<p>I have read what happens during a transaction and have a question about it:</p>

<p>When a transaction happen, the miners compute a value called "prof of work". This value is calculated in order to get a 0 value (or something very closed to 0) for the hash of the value + the transaction + the last pow.</p>

<p>So the miner work is to calculate a prof of work. But i have read the miner discover new bitcoins too. Is it another form of mining ? I do not see the link between the POW calculation and the new bitcoins)</p>

<p>Thanks </p>

CC BY-SA 4.0
2019-08-24T05:18:43.463Z
Your question is a collection of many questions, and they have been answered before. Check out the search function on this site, and then report back with any other questions you may have :)
chytrik
CC BY-SA 4.0
2019-08-24T05:31:10.077Z
I have read a lot of things, including on stackexchange but this questions are very confusing for me. This is why i have compiled them... Thanks
Bob5421
CC BY-SA 4.0
2019-08-24T07:08:05.600Z
Please split up your question in individual questions per topic. This is a Q&A site, not a forum, and the goal is making good questions with good answers searchable.
Pieter Wuille
CC BY-SA 4.0
2019-08-24T07:11:07.100Z
thanks for your answer, i have edit the first question
Bob5421
<mining-theory><proof-of-work>
Mining operation calculation
Bob5421
# Mining operation calculation

(Asked by: username_0 on 2019-08-24)

My goal is to understand bitcoin.

I have read what happens during a transaction and have a question about it:

When a transaction happen, the miners compute a value called "prof of work". This value is calculated in order to get a 0 value (or something very closed to 0) for the hash of the value + the transaction + the last pow.

So the miner work is to calculate a prof of work. But i have read the miner discover new bitcoins too. Is it another form of mining ? I do not see the link between the POW calculation and the new bitcoins)

Thanks

**Tags:** mining-theory, proof-of-work

> **Comments:**
> **username_1**: Your question is a collection of many questions, and they have been answered before. Check out the search function on this site, and then report back with any other questions you may have :)  
> **username_0**: I have read a lot of things, including on stackexchange but this questions are very confusing for me. This is why i have compiled them... Thanks  
> **username_2**: Please split up your question in individual questions per topic. This is a Q&A site, not a forum, and the goal is making good questions with good answers searchable.  
> **username_0**: thanks for your answer, i have edit the first question  

---

## 1 answers

### Answer by username_3 on 2019-08-24. Score: 2

> When a transaction happen, the miners compute a value called "prof of work". This value is calculated in order to get a 0 value (or something very closed to 0) for the hash of the value + the transaction + the last pow.

The miner does not perform the PoW on each transaction individually, but on a **set** of transactions, whose combined size is less than approximately 1MB when serialized (There is a 1MB limit for non-SegWit parts and 4MB limit for the entire structure including SegWit parts).

The set of transactions is placed into a structure called a `block`. The block has a header which contains, among other things, a timestamp, the `target`, a `nonce`, the hash of the previous block's header, and the merkle root of the set of transactions in *this* block. The actual representation of the transactions in the block structure is a simple serialized list.

Miners can choose which transactions they wish to include in a block and in what order. However, the usual method is to sort transactions by highest paying fee and select the first bunch of transactions which fit within the block size limit.

The merkle root is calculated by placing the transaction ids (the hash of the serialized transaction) into a binary tree where each parent's value is the hash of the concatenation of its two children's values. The value of the root of this tree is then placed into the block header, along with the other necessary information.

Proof-of-Work is then performed by taking a hash of this block header, and the proof of work is successful if the resulting hash is less than the value specified by the `target`, which determines the difficulty. The target indicates how many leading zeroes the hash must have - the more leading zeroes, the smaller the possible range of hashes becomes, making it more difficult to produce a matching hash. This difficulty is adjusted according to a consensus algorithm which attempts to make blocks created on average every 10 minutes - using historical data from the past 2016 blocks and their timestamps.

The Proof-of-Work is essentially brute-forcing the double-SHA256 of the block header by using different value for the `nonce` in the header until the resulting hash of the header is a value which is less than the target. The nonce can be randomly selected, but it is more sensible to simply cycle through all possible 32-bit integer values in order.

> But i have read the miner discover new bitcoins too. Is it another form of mining ? I do not see the link between the POW calculation and the new bitcoins)

Each block must contain at least one transaction in its set, which must appear first in the list. This is known as the `coinbase` transaction. Unlike other transactions, it has no UTXOs as inputs - but its virtual input is newly generated coins plus the aggregate of fees paid in all transactions in this block. Newly generated coins must be strictly less than or equal to `50 >> floor(block_height / 210000)` bitcoin, which determines that the number of new bitcoins which may be generated is halved approximately every 4 years (210000 blocks).

The coinbase can also be used to include an extra nonce value because the `nonce` in the regular block header is too small (32-bits), and its entire range can be exhausted by modern miners more quickly than new transactions are added to the block. Mining pools also usually insert their name into the coinbase transaction so it can be public knowledge.


---

