1

The bits field is the compact representation of the target.

Example:

bits: 1d00ffff
target: 00ffff0000000000000000000000000000000000000000000000000000

bits: 1cfff00
target: ffff0000000000000000000000000000000000000000000000000000

But these two actually represent the same number.

int(target) -> 26959535291011309493156476344723991336010898738574164086137773096960 for both of the above targets.

What (if anything) makes bits a unique representation of the target?


Clarification:

In regular interactions with numbers, this kind of thing doesn't really matter, as a few leading zeros don't affect how we interpret the number. However, in Bitcoin, the bits field is used as part of the hash of the block. Therefore, a different bits representation would produce a different hash of the block.

Stephen C
  • 113
  • 1
  • 5

1 Answers1

4

In short: no, the nBits encoding is not unique (there may be multiple 32-bit values that correspond to the same 256-bit target), but the nBits value as required by the network consensus rules is unique.

The reason for that is that all calculations happen on the target, which is then converted (using a deterministic algorithm) into nBits format. That nBits value is then required to match the value in the block header.

Pieter Wuille
  • 105,497
  • 9
  • 194
  • 308
  • Yeah, I guess I was hoping for some more technical details? What is the algorithm to make sure everyone is using the same rep of bits? – Stephen C Apr 19 '19 at 23:11
  • 1
    @StephenCowley The point of consensus rules is that everyone uses the same ones; if they don't, they'd end up on their own chain. So by definition everyone who follows Bitcoin's consensus rules uses the same algorithm. In Bitcoin Core, that code is https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/pow.cpp#L71 and https://github.com/bitcoin/bitcoin/blob/v0.17.1/src/arith_uint256.cpp#L226L247 – Pieter Wuille Apr 19 '19 at 23:15