user4334: 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?

user4334: 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.


user2306: 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.

4334: <p>How do I determine a block's <a href="http://chimera.labs.oreilly.com/books/1234000001802/ch08.html#extra_nonce" rel="nofollow">extranonce</a> value? I know they are in the coinbase transaction, but where? How do I decode the part that is the extranonce?</p>
 4334: <p>From <a href="https://bitcointalk.org/index.php?topic=988542.msg10771576#msg10771576" rel="nofollow">here</a>:</p>

<blockquote>
  <p>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.</p>

<pre><code>{
   ...
    "vin" : [
        {
            "coinbase" : "03443b0403858402062f503253482f",
            "sequence" : 4294967295
        }
    ],
   ...
}
</code></pre>
  
  <p>can be interpreted as:</p>

<pre><code>03 = push 3 bytes onto the stack
443b04 = 3 bytes pushed onto the stack &lt;-- Block index
03 = push 3 bytes onto the stack
858402 = 3 bytes pushed onto the stack &lt;-- The extranonce
06 = push 6 bytes onto the stack
2f503253482f = 6 bytes pushed onto the stack &lt;-- arbitrary data
</code></pre>
  
  <p>EDIT: This format was defined by <a href="https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki" rel="nofollow">BIP34</a> and applies to blocks with
  version >= 2. I'm not sure how the extranonce was managed before that.</p>
</blockquote>
 2306: <p>In Bitcoin v0.1.5 to v0.3.24, the coinbase scriptSig contained:</p>

<pre><code>txNew.vin[0].scriptSig &lt;&lt; nBits &lt;&lt; ++bnExtraNonce;
</code></pre>

<p>In Bitcoin v0.4.0 to v0.5.3, it changed to:</p>

<pre><code>pblock-&gt;vtx[0].vin[0].scriptSig = CScript() &lt;&lt; pblock-&gt;nTime &lt;&lt; CBigNum(nExtraNonce);
</code></pre>

<p>Bitcoin v0.6.0 to v0.6.3:</p>

<pre><code>pblock-&gt;vtx[0].vin[0].scriptSig = (CScript() &lt;&lt; pblock-&gt;nTime &lt;&lt; CBigNum(nExtraNonce)) + COINBASE_FLAGS;
</code></pre>

<p>Bitcoin v0.7.0 to current:</p>

<pre><code>txCoinbase.vin[0].scriptSig = (CScript() &lt;&lt; nHeight &lt;&lt; CScriptNum(nExtraNonce)) + COINBASE_FLAGS;
</code></pre>

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

<p>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 <code>bnExtraNonce</code> to <code>nExtraNonce</code>.)</p>

<p>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.</p>

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