1

How do I determine a block's extranonce value? I know they are in the coinbase transaction, but where? How do I decode the part that is the extranonce?

2 Answers 2

4

In Bitcoin v0.1.5 to v0.3.24, the coinbase scriptSig contained:

txNew.vin[0].scriptSig << nBits << ++bnExtraNonce;

In Bitcoin v0.4.0 to v0.5.3, it changed to:

pblock->vtx[0].vin[0].scriptSig = CScript() << pblock->nTime << CBigNum(nExtraNonce);

Bitcoin v0.6.0 to v0.6.3:

pblock->vtx[0].vin[0].scriptSig = (CScript() << pblock->nTime << CBigNum(nExtraNonce)) + COINBASE_FLAGS;

Bitcoin v0.7.0 to current:

txCoinbase.vin[0].scriptSig = (CScript() << nHeight << CScriptNum(nExtraNonce)) + COINBASE_FLAGS;

So the coinbase scriptSig field has changed over time, but it has always placed the extranonce as the second item.

In Bitcoin v0.1.5, the size was unlimited, and in more current versions, it's 4 bytes or less. (This is caused by the switch from bnExtraNonce to nExtraNonce.)

There are some other odd details - in v0.1.5, it only resets when the client resets, but in later versions it resets on every new block.

Of course, this is just what the core client does. Other miners or pools might do something else.

1

From here:

The extranonce can be found in the coinbase data from a coinbase transaction. This data can be interpreted as a script pushing data onto the stack and the extranonce is the second value.

{
   ...
    "vin" : [
        {
            "coinbase" : "03443b0403858402062f503253482f",
            "sequence" : 4294967295
        }
    ],
   ...
}

can be interpreted as:

03 = push 3 bytes onto the stack
443b04 = 3 bytes pushed onto the stack <-- Block index
03 = push 3 bytes onto the stack
858402 = 3 bytes pushed onto the stack <-- The extranonce
06 = push 6 bytes onto the stack
2f503253482f = 6 bytes pushed onto the stack <-- arbitrary data

EDIT: This format was defined by BIP34 and applies to blocks with version >= 2. I'm not sure how the extranonce was managed before that.

2
  • This answer says extranonce is 3 bytes, yet it's 8 bytes…
    – Geremia
    Commented Mar 14, 2015 at 18:52
  • Actually that last bit did use to have a meaning - it's a vote for P2SH.
    – Nick ODell
    Commented Mar 14, 2015 at 18:54

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.