<p>In the original source code there were little restrictions on what could be in the coinbase data of the coinbase transaction. I think the only restriction was that the coinbase data should be between 2 to 100 bytes. However, this lack of restriction on what can be within the coinbase data brought up a vulnerability. It was perfectly legal for miners to create a coinbase transaction <a href="https://bitcoin.stackexchange.com/questions/80644/identical-coinbase-transactions">identical to previous one</a> and mine it in a block at a height higher than where the "original" coinbase transaction. When this happened it led to the invalidation of the previous transaction.</p>

<p>This was fixed later when couple of blocks were mined with identical coinbase data. As per BIP-34, version-2 blocks must contain the block height index as a script push operation in the beginning of the coinbase field. For example, in your coinbase transaction this data is represented by the bytes <code>0x03400d03</code>. The first byte <code>0x03</code> indicates the script should push the next 3 bytes. The next three bytes <code>0x400d03</code> represent the block height 200,000 in little endian.</p>

<p>The rest of the coinbase data is free for the miners to use as per their will. This is mostly used as a space for extra-nonce. In the early days of Bitcoin, a miner could find a block by iterating through the nonce until the resulting hash was below the target. As difficulty increased, miners often cycled through all 4 billion values of the nonce (2<sup>32</sup>) without finding a valid block header hash. However, this was easily resolved by updating the block timestamp to account for the elapsed time. Because the timestamp is part of the header, the change would allow miners to iterate through the values of the nonce again with different results. </p>

<p>Once mining hardware became really efficient, however, this approach became increasingly difficult because the nonce values were exhausted in less than a second. Hence, the mining software needed more space for nonce values in order to find valid blocks. The timestamp could be stretched a bit, but moving it <a href="https://bitcoin.stackexchange.com/questions/30594/why-is-two-hours-the-maximum-acceptable-offset-for-bitcoin-blocks">too far into the future</a> would cause the block to become invalid. The solution was to use the coinbase transaction as a source of extra nonce values. Because the coinbase script can store between 2 and 100 bytes of data (~first 4 bytes reserved for block identification), miners started using that 96 byte space as extra nonce, allowing them to explore a much larger range of block header values to find valid blocks.</p>

<p>The mining pools also use the coinbase data as an identification of who mined the block. For example if you look at block <a href="https://blockstream.info/block/00000000000000000010c3808ffda2153a658ab7935f631c3a5a0016e3c317d1" rel="nofollow noreferrer">594,041</a>, you will see the <a href="https://blockstream.info/tx/d842e7cab5f7d26973f0cbe525b695455c7d70927d4744bc05310d7e70ff385e?expand" rel="nofollow noreferrer">coinbase data</a> contain the bytes <code>0x4d696e656420627920416e74506f6f6c</code>. It represents "'Mined by AntPool" in ASCII. (Unfortunately the block you mentioned did not have any identification hence I had to use a different block that did have it). However, it is important to note that this data cannot be relied upon, as any miner can mine a block tomorrow with a data claiming it to be mined by a different pool, may be to hide its identity or frame others.</p>

CC BY-SA 4.0
2019-09-30T01:00:52.257Z
Thank you for your comment :)
It will be really helpful.

The reason why I want to decode coinbase tx is I want get who mines a block. But according to your answer, my approach is not reliable.

Then is there no reliable way to find out who mines a block?
dingyo777
CC BY-SA 4.0
2019-09-30T03:37:56.057Z
@dingyo777 it is not possible to determine it with certainty who mines the block. You can refer to the [answer](https://bitcoin.stackexchange.com/questions/90306/how-to-determine-the-geographic-distribution-of-the-hashrate) here for more information.
Ugam Kamat
CC BY-SA 4.0
2019-09-27T05:05:17.230Z
2019-09-30T03:54:38.413Z
2019-09-30T03:54:38.413Z
Ugam Kamat
<h1>Below is block result of block height 200,000</h1>

<pre><code>{  
   'hash':'000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf',
   'confirmations':396774,
   'strippedsize':247533,
   'size':247533,
   'weight':990132,
   'height':200000,
   'version':2,
   'versionHex':'00000002',
   'merkleroot':'a08f8101f50fd9c9b3e5252aff4c1c1bd668f878fffaf3d0dbddeb029c307e88',
   'tx':[  
      'dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10',
      'ee475443f1fbfff84ffba43ba092a70d291df233bd1428f3d09f7bd1a6054a1f',
      'e03a9a4b5c557f6ee3400a29ff1475d1df73e9cddb48c2391abdc391d8c1504a',
      'ffa0267c8f2af736858894d6f3e5081a05e2ec16dc98f78a80f376ce35077491',
...
      'd22795f708706cbcd67aaf2bb63e7defd9e0c6c13f4f263dfc36592c047c981a'
   ],
   'time':1348310759,
   'mediantime':1348307828,
   'nonce':4158183488,
   'bits':'1a05db8b',
   'difficulty':Decimal('2864140.507810974'),
   'chainwork':'00000000000000000000000000000000000000000000001ac073536b8dbae81c',
   'nTx':388,
   'previousblockhash':'00000000000003a20def7a05a77361b9657ff954b2f2080e135ea6f5970da215',
   'nextblockhash':'00000000000002e3269b8a00caf315115297c626f954770e8398470d7f387e1c'
}
</code></pre>

<h1>Below is coinbase transaction of 200000 block</h1>

<pre><code>{  
   'txid':'dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10',
   'hash':'dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10',
   'version':1,
   'size':192,
   'vsize':192,
   'weight':768,
   'locktime':0,
   'vin':[  
      {  
         'coinbase':'03400d0302ef02062f503253482f522cfabe6d6dd90d39663d10f8fd25ec88338295d4c6ce1c90d4aeb368d8bdbadcc1da3b635801000000000000000474073e03',
         'sequence':4294967295
      }
   ],
   'vout':[  
      {  
         'value':Decimal('50.63517500'),
         'n':0,
         'scriptPubKey':{  
            'asm':'04b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b OP_CHECKSIG',
            'hex':'4104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bac',
            'reqSigs':1,
            'type':'pubkey',
            'addresses':[  
               '1MdYC22Gmjp2ejVPCxyYjFyWbQCYTGhGq8'
            ]
         }
      }
   ]
}
</code></pre>

<h1>What I want to is decoding <code>vin.coinbaise</code></h1>

<p>I searched out some docs, but I failed to find out exact way of decoding this part: </p>

<pre><code>coinbase: 03400d0302ef02062f503253482f522cfabe6d6dd90d39663d10f8fd25ec88338295d4c6ce1c90d4aeb368d8bdbadcc1da3b635801000000000000000474073e03
</code></pre>

<p>Do you have any idea how to decode it?</p>

<transactions><blockchain><coinbase-transaction>
How to decode a coinbase transaction?
dingyo777
# How to decode a coinbase transaction?

(Asked by: username_0 on 2019-09-27)

# Below is block result of block height 200,000

```
{  
   'hash':'000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf',
   'confirmations':396774,
   'strippedsize':247533,
   'size':247533,
   'weight':990132,
   'height':200000,
   'version':2,
   'versionHex':'00000002',
   'merkleroot':'a08f8101f50fd9c9b3e5252aff4c1c1bd668f878fffaf3d0dbddeb029c307e88',
   'tx':[  
      'dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10',
      'ee475443f1fbfff84ffba43ba092a70d291df233bd1428f3d09f7bd1a6054a1f',
      'e03a9a4b5c557f6ee3400a29ff1475d1df73e9cddb48c2391abdc391d8c1504a',
      'ffa0267c8f2af736858894d6f3e5081a05e2ec16dc98f78a80f376ce35077491',
...
      'd22795f708706cbcd67aaf2bb63e7defd9e0c6c13f4f263dfc36592c047c981a'
   ],
   'time':1348310759,
   'mediantime':1348307828,
   'nonce':4158183488,
   'bits':'1a05db8b',
   'difficulty':Decimal('2864140.507810974'),
   'chainwork':'00000000000000000000000000000000000000000000001ac073536b8dbae81c',
   'nTx':388,
   'previousblockhash':'00000000000003a20def7a05a77361b9657ff954b2f2080e135ea6f5970da215',
   'nextblockhash':'00000000000002e3269b8a00caf315115297c626f954770e8398470d7f387e1c'
}

```

# Below is coinbase transaction of 200000 block

```
{  
   'txid':'dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10',
   'hash':'dbaf14e1c476e76ea05a8b71921a46d6b06f0a950f17c5f9f1a03b8fae467f10',
   'version':1,
   'size':192,
   'vsize':192,
   'weight':768,
   'locktime':0,
   'vin':[  
      {  
         'coinbase':'03400d0302ef02062f503253482f522cfabe6d6dd90d39663d10f8fd25ec88338295d4c6ce1c90d4aeb368d8bdbadcc1da3b635801000000000000000474073e03',
         'sequence':4294967295
      }
   ],
   'vout':[  
      {  
         'value':Decimal('50.63517500'),
         'n':0,
         'scriptPubKey':{  
            'asm':'04b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7b OP_CHECKSIG',
            'hex':'4104b0bd634234abbb1ba1e986e884185c61cf43e001f9137f23c2c409273eb16e6537a576782eba668a7ef8bd3b3cfb1edb7117ab65129b8a2e681f3c1e0908ef7bac',
            'reqSigs':1,
            'type':'pubkey',
            'addresses':[  
               '1MdYC22Gmjp2ejVPCxyYjFyWbQCYTGhGq8'
            ]
         }
      }
   ]
}

```

# What I want to is decoding `vin.coinbaise`

I searched out some docs, but I failed to find out exact way of decoding this part:

```
coinbase: 03400d0302ef02062f503253482f522cfabe6d6dd90d39663d10f8fd25ec88338295d4c6ce1c90d4aeb368d8bdbadcc1da3b635801000000000000000474073e03

```

Do you have any idea how to decode it?

**Tags:** transactions, blockchain, coinbase-transaction


---

## 1 answers

### Answer by username_1 on 2019-09-27. Score: 2 | Accepted answer

In the original source code there were little restrictions on what could be in the coinbase data of the coinbase transaction. I think the only restriction was that the coinbase data should be between 2 to 100 bytes. However, this lack of restriction on what can be within the coinbase data brought up a vulnerability. It was perfectly legal for miners to create a coinbase transaction [identical to previous one](https://bitcoin.stackexchange.com/questions/80644/identical-coinbase-transactions) and mine it in a block at a height higher than where the "original" coinbase transaction. When this happened it led to the invalidation of the previous transaction.

This was fixed later when couple of blocks were mined with identical coinbase data. As per BIP-34, version-2 blocks must contain the block height index as a script push operation in the beginning of the coinbase field. For example, in your coinbase transaction this data is represented by the bytes `0x03400d03`. The first byte `0x03` indicates the script should push the next 3 bytes. The next three bytes `0x400d03` represent the block height 200,000 in little endian.

The rest of the coinbase data is free for the miners to use as per their will. This is mostly used as a space for extra-nonce. In the early days of Bitcoin, a miner could find a block by iterating through the nonce until the resulting hash was below the target. As difficulty increased, miners often cycled through all 4 billion values of the nonce (232) without finding a valid block header hash. However, this was easily resolved by updating the block timestamp to account for the elapsed time. Because the timestamp is part of the header, the change would allow miners to iterate through the values of the nonce again with different results.

Once mining hardware became really efficient, however, this approach became increasingly difficult because the nonce values were exhausted in less than a second. Hence, the mining software needed more space for nonce values in order to find valid blocks. The timestamp could be stretched a bit, but moving it [too far into the future](https://bitcoin.stackexchange.com/questions/30594/why-is-two-hours-the-maximum-acceptable-offset-for-bitcoin-blocks) would cause the block to become invalid. The solution was to use the coinbase transaction as a source of extra nonce values. Because the coinbase script can store between 2 and 100 bytes of data (~first 4 bytes reserved for block identification), miners started using that 96 byte space as extra nonce, allowing them to explore a much larger range of block header values to find valid blocks.

The mining pools also use the coinbase data as an identification of who mined the block. For example if you look at block [594,041](https://blockstream.info/block/00000000000000000010c3808ffda2153a658ab7935f631c3a5a0016e3c317d1), you will see the [coinbase data](https://blockstream.info/tx/d842e7cab5f7d26973f0cbe525b695455c7d70927d4744bc05310d7e70ff385e?expand) contain the bytes `0x4d696e656420627920416e74506f6f6c`. It represents "'Mined by AntPool" in ASCII. (Unfortunately the block you mentioned did not have any identification hence I had to use a different block that did have it). However, it is important to note that this data cannot be relied upon, as any miner can mine a block tomorrow with a data claiming it to be mined by a different pool, may be to hide its identity or frame others.

> **Comments:**
> **username_0**: Thank you for your comment :) It will be really helpful.  The reason why I want to decode coinbase tx is I want get who mines a block. But according to your answer, my approach is not reliable.  Then is there no reliable way to find out who mines a block?  
> **username_1**: @username_0 it is not possible to determine it with certainty who mines the block. You can refer to the [answer](https://bitcoin.stackexchange.com/questions/90306/how-to-determine-the-geographic-distribution-of-the-hashrate) here for more information.  

---

