What is the format of coinbase input scripts?

8

The input script of the coinbase transaction of block number 1 (right after the genesis block) looks like this: 04ffff001d010b

How do I recognize this as a coinbase transaction?

Do I simply know that this is a coinbase transaction because it is the first transaction in the block?

Does the coinbase script have to have a special format?

Jan

Posted 2012-10-06T13:59:31.563

Reputation: 451

I tried to find the answer on the Bitcoin wiki, but that particular page is empty even though it is linked from the protocol specification page: https://en.bitcoin.it/wiki/Coinbase_transaction

– Jan – 2012-10-06T13:59:41.190

Answers

6

A coinbase transaction is characterised by "previous_output" field of the transaction being 32 bytes of zeros and 4 bytes of 0xFF. It should be the first transaction of the block, but I'm not sure whether all the clients enforce this rule. The signature script of the coinbase transaction need not obey the Script protocol, but as far as I remember the first block's script pushes data onto the stack and then pops it off. The data encoded in the Genesis Block represents the famous headline of Times:

The Times 03/Jan/2009 Chancellor on brink of second bailout for banks

And was used as a way to prove that the block was created no sooner than on 2009 01 03, but can also be speculated that it relates to Satoshi's intent when creating Bitcoin - to counter debt-driven currencies.

ThePiachu

Posted 2012-10-06T13:59:31.563

Reputation: 42 235

Yes, the coinbase must be the first and only the first transaction of a block. This is a network rule, and any client not enforcing it risks ending up on a fork. – Pieter Wuille – 2012-10-07T00:25:58.863

1

Coinbase input scripts can contain arbitrary data. No data is required currently. Bitcoind creates coinbase input scripts so that they are properly-formed scripts, but this is not required.

theymos

Posted 2012-10-06T13:59:31.563

Reputation: 8 416

3As of BIP34, nversion==2 blocks are required to have the block height encoded as a minimal-size data push in the coinbase. – Pieter Wuille – 2012-10-06T18:44:54.673

2Also, the size of the coinbase script must be between 2 and 100 bytes. – Pieter Wuille – 2012-10-07T00:24:36.433