Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Geremia on March 14, 2015, 01:22:31 AM



Title: Determining a Block's Extranonce Value
Post by: Geremia on March 14, 2015, 01:22:31 AM
How do I determine a block's extranonce (http://chimera.labs.oreilly.com/books/1234000001802/ch08.html#extra_nonce) value? I know they are in the coinbase transaction, but where?


Title: Re: Determining a Block's Extranonce Value
Post by: laurentmt on March 14, 2015, 03:25:53 PM
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.

Example
Quote
{
   ...
    "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 (https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki) and applies to blocks with version >= 2. I'm not sure how the extranonce was managed before that.


Title: Re: Determining a Block's Extranonce Value
Post by: Geremia on March 14, 2015, 03:56:30 PM
Example
Quote
{
   ...
    "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
I thought the extranonce was 8 bytes.


Title: Re: Determining a Block's Extranonce Value
Post by: laurentmt on March 14, 2015, 05:25:43 PM
I thought the extranonce was 8 bytes.
My guess is that the extranonce is 8 bytes max but is stored with a compressed representation for lower values.

The extranonce is outside the scope of the bitcoin protocol (BIP34 doesn't say anything about it) and it seems hard to find reliable information about how mining pools manage the coinbase data. Actually, I think different mining pools may enforce different formats.
I've found some sources indicating the 2nd value as the extranonce but I suspect that it's only true for some clients (bitcoind ?).

Investigation in progress...

EDIT:
After some forum archeology, I've found this interesting post (https://bitcointalk.org/index.php?topic=178629.msg1864506#msg1864506) related to a study done by Sergio_Demian_Lerner about extranonces.
It seems to confirm the script structure with the extranonce being the second value pushed onto the stack. I was puzzled by the first value but it may be the same value as the bits fields stored in the header.



Title: Re: Determining a Block's Extranonce Value
Post by: Geremia on March 14, 2015, 07:25:27 PM
On #eligius I asked Luke-Jr, operator of Eligius pool, and he said:
Quote
[12:08] <@Luke-Jr> throwing it on the end of the coinbase
[12:08] <@Luke-Jr> or in the middle
[12:08] <@Luke-Jr> I think most stratum pools use the end of it
[12:08] <@Luke-Jr> p2pool abuses an output
[12:09] <@Luke-Jr> GBT pools let miners put anything on the end, and at least BFGMiner does <extranonce><miner version>
It seems pretty arbitrary, then.

He also said that the BitcoinTalk post you cited is outdated.


Title: Re: Determining a Block's Extranonce Value
Post by: nickodell on March 14, 2015, 07:36:13 PM
EDIT: This format was defined by BIP34 (https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki) and applies to blocks with version >= 2. I'm not sure how the extranonce was managed before that.
I wrote a summary of how the coinbase scriptSig has changed over time here. (http://bitcoin.stackexchange.com/a/36461/2306)
You've pretty much got it right.


Title: Re: Determining a Block's Extranonce Value
Post by: laurentmt on March 14, 2015, 07:57:39 PM
I wrote a summary of how the coinbase scriptSig has changed over time here. (http://bitcoin.stackexchange.com/a/36461/2306)
You've pretty much got it right.
Thanks. It's bookmarked ! :)

It seems pretty arbitrary, then.
Yep !

He also said that the BitcoinTalk post you cited is outdated.
It is. I've linked this thread because I thought you might be interested by formats used in older blocks (before BIP34). It was just an inference from your previous post about nonces & hash values. My apologies if I was wrong.