2

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?

1 Answer 1

2

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 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 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, you will see the coinbase data 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.

2
  • 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
    Commented Sep 30, 2019 at 1:00
  • @dingyo777 it is not possible to determine it with certainty who mines the block. You can refer to the answer here for more information.
    – Ugam Kamat
    Commented Sep 30, 2019 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.