Skip to content

blockchain: refuse a v2 header committing to a height below the BLAKE2b activation - #2

Merged
paulscode merged 1 commit into
paulscode:blake2bfrom
Kilombino:header-v2-height
Oct 15, 2026
Merged

paulscode merged 1 commit into
paulscode:blake2bfrom
Kilombino:header-v2-height

Conversation

@Kilombino

Copy link
Copy Markdown

Follow-up to #1, as you suggested: refuse a v2 header that commits to a height below the BLAKE2b activation, as Knots does in CheckBlockHeader (bad-version-sha256d).

  • CheckHeaderV2Sanity(header, params) is the context-free part of Knots' CheckBlockHeader for v2 headers: the committed height must be a BLAKE2b height, and a network without BLAKE2b configured takes no v2 header (ErrUnsupportedProofOfWork, as in checkHeaderV2Context). It needs only the header, so it covers the case where the real height isn't known yet (an orphan block); checkHeaderV2Context still checks the committed height against the real one once it is.
  • Called next to checkBlockSanity in ProcessBlock and CheckConnectBlockTemplate, and in verifychain. CheckBlockHeaderSanity keeps its signature (neutrino calls it with powLimit only); the new function is exported so neutrino's context-free check can call it too, which I can send once this is tagged.
  • TestCheckHeaderV2Sanity: the real activation header (961640) is accepted, the same header committing to 961639 is refused with ErrBadHeaderV2, a classic header passes, and a network without BLAKE2b refuses the v2 one.

go test ./... passes except TestHelp (getblock/getblockheader verbose results have no help for mm_rhs), which fails the same on blake2b without this change.

…KE2b activation, as Knots does in CheckBlockHeader

CheckHeaderV2Sanity is the context-free part of Knots' CheckBlockHeader for BLAKE2b headers:
a v2 header must commit to a height where BLAKE2b proof of work is required
(bad-version-sha256d), and a network without BLAKE2b configured takes no v2 header. It needs
only the header, so it runs where the real height is not known yet (an orphan block), next to
checkBlockSanity in ProcessBlock and CheckConnectBlockTemplate, and in verifychain;
checkHeaderV2Context still checks the committed height against the real one. Exported for
light clients (neutrino's context-free header check). Tests: a header committing to the
activation height and one to the block below it, and a network without BLAKE2b.
@paulscode
paulscode merged commit 88e39e6 into paulscode:blake2b Oct 15, 2026
@paulscode

Copy link
Copy Markdown
Owner

Thanks, merged. It matches Knots' bad-version-sha256d rule and already sat on v0.25.1-blake2b.7. Tests pass for blockchain, chaincfg, txscript and mempool, and the new test fails when the rule is disabled. A block that passes the context check always passes this rule, so nothing valid is refused, including the block at 961640, testnet4 and the networks without BLAKE2b, and invalid orphans are now dropped earlier. TestHelp fails the same way on the base (the mm_rhs help strings).

Two nits if you send the neutrino follow-up: no test covers the call sites (removing the call in process.go fails nothing), and the comment in checkProofOfWork still says the height question is answered only in the context check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants