Skip to content

v9.12.0 — a header is no longer believed about the difficulty it declares

Choose a tag to compare

@codenlighten codenlighten released this 29 Sep 17:39
· 211 commits to main since this release
ebd19cf

A block header is no longer believed about the difficulty it declares.

BlockHeader.validProofOfWork() answers one question: does the hash meet the target written in this header's own bits? Nothing capped that target, so a header could claim any difficulty and then meet it. With proof of work enabled:

declared bits nonces to mine it NotaryHash.verify(cert, { header }) in 9.11.2
0x1d00ffff (mainnet, difficulty 1) over 2,000,000, not found correctly refused
0x2000ffff 120 valid: true
0x2100ffff 1 valid: true

SPV.verifyHeaderChain accepted a whole chain of them. It matters wherever a header reaches the verifier from the same place as the thing it is meant to check independently: an offline certificate-and-header bundle, or one provider serving both.

What changed

  • The declared target is capped at powLimit, default SPV.POW_LIMIT_BITS (0x1d00ffff, difficulty 1 — the proof-of-work limit of mainnet and testnet). minWork sets a floor above it.
  • bits are read as the node reads them: negative, zero and overflowing values refused, shifting before the zero test, per Bitcoin's SetCompact and CheckProofOfWork.
  • A header is exactly 80 bytes, re-parsed, so every checked field comes from the bytes its hash covers. An object stating a merkleRoot is refused by name; hex with trailing junk no longer arrives as a clean 80 bytes. verifyHeaderChain uses the same snapshot instead of trusting any object with a validProofOfWork method.
  • NotaryHash.verify takes blockHashAtHeight — the hash your own chain source has at that height. No amount of proof of work detects an orphan: a block that lost a race carries real work.
  • powLimit and minWork are parsed strictly. bn.js reads 1e21 as 23521 and parseInt('1d00ffzz', 16) is 0x1d00ff; either would have lowered a floor silently.

Upgrading

Mainnet and testnet headers are unaffected, and the genesis block verifies under the default. Regtest headers declare 0x207fffff: pass powLimit: 0x207fffff for those. requirePow: false still switches every work check off together.

Retargeting is still not validated — a fork whose headers each clear the limit remains possible, which is what trustedHash and blockHashAtHeight are for.

Found while mirroring a hardening of the BRC-220 reference implementation, whose difficulty floor prompted the check.

Full notes: CHANGELOG.md