2

I am attempting to decode a Block and have managed to decode the Coinbase transaction but after the transaction, there is huge gaps in them that I do not understand.

Taking this Block as a sample: 0000000000000000002e5b55bf93c89cc3a41de24d762fa4f68e725da3b089ba

Here is my attempt to decode this block:

===== Block Begin =====

00000020 - Transaction Version

15F11A82BE84CCCAF4E59CFC0C89EF01CAD854DC15F33D000000000000000000 - Block Hash

CC2DCEAF96439181993C564CBE889F60FDB98E8EFD4E524D9EEA3C54CF400504 - Merkle Root

2BDF8F5A - Timestamp

DC975D17 - Bits

3E2A4065 - Nonce

FD8704 - Total Transaction

01000000 - Transaction Version

01 - Coinbase has 1 transaction

===== Coinbase Begin =====

0000000000000000000000000000000000000000000000000000000000000000 - coinbase hash

FFFFFFFF - index

45 - txin script length (69)

-> 03 - bytes in height

-> 43CA07FA - height

-> BE6D6DCAEEFE495F6BCA08E10FF6D24555166C2456D8129213354E32FD73EB1B141AB00100000000000000036507000F312D7B080100275C012F736C7573682F - txin

00000000 - sequence

03 - 3 output in coinbase

AA5CB94C00000000 - output satoshis from coinbase

19 - Coinbase Output Script Length (25)

76 - OP_DUP

A9 - OP_HASH160

14 - 20 bytes

7C154ED1DC59609E3D26ABB2DF2EA3D587CD8C41 - hash data

88 - OP_EQUALVERIFY

AC - OP_CHECKSIG

00000000 - Lock Time

===== Coinbase End =====

000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1 - outpoint ?

B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33 - ?

02000000 - Tx Version

6B - TxIn SigScript Length (107)

48 - TxIn SigScript Length (72)

3045022100FAD6F0A91A89A90D17800B55B1B1E424338BFB5D72D3970ED95310AFEB4734A50220120B24AF1444E520EB77ECE73DB6D9775159220B089D28948BC9DBC156C2492F01 - TxIn SigScript

21 - TxIn SigScript Length (33)

02227CEDFAB55D1B7642D47A5AC92638ED8822A23C3DDADF88DEFEA45A37F5935E - TxIn SigScript

FFFFFFFF - TxIn Sequence

02 - TxOut Count

F0874B0000000000 - Satoshis (BTC 0.0495)

17 - Length (23)

A9 - OP_HASH160

14 - 20 bytes

98808E526D3737F044F2DD5445A27DB39BAD821D - hash data

87 - OP_EQUAL

92F6E73600000000 - Satoshis (BTC 9.21171602)

19 - Length (25)

76 - OP_DUP

A9 - OP_HASH160

14 - 20 bytes

B08F46E4D21CD0547A8A1E2E43E5440284F710A4

88 - OP_EQUALVERIFY

AC - OP_CHECKSIG

00000000 - Lock Time

=====================

01000000 - ?

01 - ?

DE74875C17CE6730AF727B52913FAB9FF7922BBA806932785A824A8CAA649E8D0100000000FFFFFFFF02D5C267130000000017A91433A9DB4ED408225EFE4B00DC55F962B52E8769B987A7C6D10200000000220020701A8D401C84FB13E6BAF169D59684E1 ... more data ...

It seems like after I have decoded the Coinbase transaction, the first proper transaction after the Coinbase, I hit a problem trying to resolve:

000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33

Only after that point, does the data look abit more familiar with the 02000000 which I have guessed is the Tx Version followed by what seems to be TxIn Script data and so on.

I would like some help to understand how to decode the Block as this is only that far I can guess after reading the Bitcoin documentations found online which are not documented in a uniformed and easy to ready manner.

Thanks for the help in advance.

1

The format for blocks is described here: https://bitcoin.org/en/developer-reference#serialized-blocks

The format for transactions is mostly described here: https://bitcoin.org/en/developer-reference#raw-transaction-format

However some transactions are segwit transactions, so they have a few additional fields that are not described in the above documentation. Those fields are described here: https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki


Your decoding is a bit wrong:

00000020 - Transaction Version

That's the block version, not transaction version.

01000000 - Transaction Version

01 - Coinbase has 1 transaction

You've actually missed two fields here. The first 7 bytes of the transaction are 01000000000101. These are as follows:

01000000 - Transaction version
00 - Segwit marker byte
01 - Segwit flag byte
01 - Number of inputs

Note that the segwit marker and flag bytes are only found in segwit transactions and indicate that a given transaction is a segwit transaction.

===== Coinbase Begin =====

The transaction version and the count after it all belong as part of the coinbase transaction. The count is not of the number of transactions but rather the number of inputs. A transaction is composed of inputs and outputs, not other transactions.

-> BE6D6DCAEEFE495F6BCA08E10FF6D24555166C2456D8129213354E32FD73EB1B141AB00100000000000000036507000F312D7B080100275C012F736C7573682F - txin

No, that's still part of the scriptSig. It itself is not a transaction input. This is just arbitrary data in the scriptSig of the coinbase transaction that miners put there.

00000000 - Lock Time

===== Coinbase End =====

000000002C6A4C2952534B424C4F434B3AA5BA6C5D1EFFA2034E994BEEE65C619DE2D2A1 - outpoint ?

B91892F193C170CAB74F152EAE0000000000000000266A24AA21A9ED85F7D06CCF8014D990E0242ACC0433EAF134732094E9A083A45AC3799259C9170000000001000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33 - ?

No, there are three outputs but you have only decoded one of them.

The proper decoding is as follows:

0000000000000000 - Amount in satoshis
2c - scriptPubKey is 44 bytes
6a - OP_RETURN
4c - OP_PUSHDATA1
29 - Push 41 bytes to stack
52534b424c4f434b3aa5ba6c5d1effa2034e994beee65c619de2d2a1b91892f193c170cab74f152eae - 41 bytes of data
0000000000000000 - Amount in satoshis
26 - scriptPubKey is 38 bytes
6a - OP_RETURN
24 - Push 36 bytes to stack
aa21a9ed85f7d06ccf8014d990e0242acc0433eaf134732094e9a083a45ac3799259c917 - 36 bytes of data. This data is the witness commitment as described in [BIP 141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki#Commitment_structure)

There is actually a next part of the transaction that you don't have in your breakdowt. It is the witness data and the locktime.

01 - One witness stack item 20 - Stack item is 32 bytes in length 0000000000000000000000000000000000000000000000000000000000000000 - Stack item 00000000 - locktime

Then the next transaction starts with 01000000014FFBE86D2805AF78459BBF5FA3432A5E9C84D408F7921BF2095488B9DDC39D33... and is decoded like the coinbase transaction above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.