Repository navigation
v9.12.0 — a header is no longer believed about the difficulty it declares
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, defaultSPV.POW_LIMIT_BITS(0x1d00ffff, difficulty 1 — the proof-of-work limit of mainnet and testnet).minWorksets a floor above it. bitsare read as the node reads them: negative, zero and overflowing values refused, shifting before the zero test, per Bitcoin'sSetCompactandCheckProofOfWork.- A header is exactly 80 bytes, re-parsed, so every checked field comes from the bytes its hash covers. An object stating a
merkleRootis refused by name; hex with trailing junk no longer arrives as a clean 80 bytes.verifyHeaderChainuses the same snapshot instead of trusting any object with avalidProofOfWorkmethod. NotaryHash.verifytakesblockHashAtHeight— 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.powLimitandminWorkare parsed strictly. bn.js reads1e21as23521andparseInt('1d00ffzz', 16)is0x1d00ff; 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