Author

Topic: Blocknumber not part of the header (Read 272 times)

Tym
newbie
Activity: 15
Merit: 14
April 07, 2020, 02:14:26 AM
#9
Thank you so much @pooya87!
Appreciate it!
legendary
Activity: 3472
Merit: 10611
April 06, 2020, 10:47:34 AM
#8
You said: "then decode its signature script to get the height"
Would you mind explaining this step more detailed to me?

after block number 227,835 all blocks must include the block height in their coinbase transaction. they do it by including the number in their only input's signature script. if you are unfamiliar with transaction structure and scripts read [1] and [2].
numbers exist as bytes inside a script and bytes should be pushed to the stack with the appropriate push OP code. this push must be the first pushed item and the rest can be anything.
example from last block: https://blockchair.com/bitcoin/transaction/02d8cdb103f50532e2f18d9d1f85c016468ee0294908d387e38f80b99410d893
signature script is:
Code:
03348809041f4e8b5e7669702f7777772e6f6b65782e636f6d2ffabe6d6db388905769d4e3720b1e59081407ea75173ba3ed6137d32308591495198155ce020000004204cb9a2a31601215b2ffbeaf1c4e00
decoding this script is like this:
03 -> push following 3 bytes
348809 -> in little endian = 624692
041f... -> the rest can be anything

[1] https://bitcoin.org/en/developer-reference#transactions
[2] https://en.bitcoin.it/wiki/Script
Tym
newbie
Activity: 15
Merit: 14
April 06, 2020, 09:24:40 AM
#7
if you mean as an SPV client then you still have to take additional steps to "verify" the block height because SPV clients only download block headers which does  not contain any block header field. so you have to download the first transaction of the block (aka coinbase transaction) and then decode its signature script to get the height.

Hello pooya87,

I just read your answer.
You said: "then decode its signature script to get the height"

Would you mind explaining this step more detailed to me?

I'd love to read your answer! Thanks!
Tym
staff
Activity: 4284
Merit: 8808
April 04, 2020, 09:08:17 AM
#6
Only full nodes can verify a blocknumber since they know the whole chain.
In addition to the other excellent responses you've received here, SPV nodes (lite clients) also know the height even without BIP34 because they process all the prior headers too.  If they didn't they'd have no clue about the appropriate difficulty or total work in the chain, and so they couldn't validate the header.
legendary
Activity: 3472
Merit: 10611
April 03, 2020, 11:31:05 PM
#5
I want to verify the blocknumber as a client which doesn't have full access to the chain.

if you mean as an SPV client then you still have to take additional steps to "verify" the block height because SPV clients only download block headers which does  not contain any block header field. so you have to download the first transaction of the block (aka coinbase transaction) and then decode its signature script to get the height.
Tym
newbie
Activity: 15
Merit: 14
April 03, 2020, 05:50:40 AM
#4
My question: Is there some kind of an agreement out there (i.e. a BIP) which tells that the blocknumber should be stored for example in the "extra data"-field within the coinbase transaction?
BIP34, looks like you already knew the answer prior to posting this question because your guess too specific :p
For the "blocknumber", the equivalent must be bitcoin's "block height".

Thanks! Thats what i was looking for Wink
HCP
legendary
Activity: 2086
Merit: 4361
April 03, 2020, 05:19:36 AM
#3
I believe the reason that "blocknumber" (aka Height) is not used as an identifier is explained by this:
Since multiple blocks can have the same height during a block chain fork, block height should not be used as a globally unique identifier. Instead, blocks are usually referenced by the hash of their header (often with the byte order reversed, and in hexadecimal).

So, as stated, the unique identifier for a given block is the hash of the header.
legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
April 03, 2020, 05:19:24 AM
#2
My question: Is there some kind of an agreement out there (i.e. a BIP) which tells that the blocknumber should be stored for example in the "extra data"-field within the coinbase transaction?
BIP34, looks like you already knew the answer prior to posting this question because your guess too specific :p
For the "blocknumber", the equivalent must be bitcoin's "block height".
Tym
newbie
Activity: 15
Merit: 14
April 03, 2020, 05:03:45 AM
#1
Hello,

compared to Ethereum there is no field "blocknumber" in a bitcoin-header. Only full nodes can verify a blocknumber since they know the whole chain.

My question: Is there some kind of an agreement out there (i.e. a BIP) which tells that the blocknumber should be stored for example in the "extra data"-field within the coinbase transaction?

I want to verify the blocknumber as a client which doesn't have full access to the chain.

I would love to read your answers.

Thanks,
Tym
Jump to: