Why is the target stored in compact form in the block header?

2

Why is the target converted to "Bits" and not stored in full in the block header?

For example, why:

{
"hash" : "000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506",
"height" : 100000,
"bits" : "1b04864c",
"difficulty" : 14484.16236123,
}

and not:

{
"hash" : "000000000003ba27aa200b1cecaad478d2b00432346c3f1f3986da1afd33e506",
"height" : 100000,
"target" : "000000000004864c000000000000000000000000000000000000000000000000",
"difficulty" : 14484.16236123,
}

Is it to save space?

inersha

Posted 2015-04-03T10:17:05.127

Reputation: 2 618

1There isn't a need for that level of accuracy, but there is a need to conserve space in the header, because clients typically store the block headers in RAM. – morsecoder – 2015-04-03T18:55:58.210

Answers

3

Your rendition is longer if nothing else, the entire header is only 80 bytes long. The encoding of "bits" is historical and is left over from the pre-release 0.1.0 client. There's other things in the header which could have been encoded better (the nonce should have been longer, and the version read as a bitfield not an int, and an aux merkle root would have been nice), but as it is there's no really great reason to change anything due to the amount of inertia behind the current formation.

Anonymous

Posted 2015-04-03T10:17:05.127

Reputation: 12 846

What do you mean by aux merkle root? Also, it'd be nice to have accurate times in both the header (and associated w/ individual Txs) – Wizard Of Ozzie – 2015-04-04T05:06:27.443

A dedicated part of the merkle tree just for axillary data like UTXO commitments. Timestamps on transactions would be completely meaningless, they only exist to allow for difficulty adjustments. There's no use for them that wouldn't rely on them being correct to some degree, if there was a way of making sure the timestamps were correct we wouldn't need a block chain to begin with. – Anonymous – 2015-04-04T07:14:00.650

1"historical"? Does this mean there is no current use for bits in the block header? I am wondering why it is there at all, assuming a full node syncs from block 0 and can calculate difficulty on its own for each block... – pinhead – 2017-04-12T19:54:32.393