Skip to content

fix(primitives): default minimum chain work to Core's mainnet floor - #2

Open
MeABzZz wants to merge 1 commit into
BTCDecoded:mainfrom
MeABzZz:criticals/min-chain-work
Open

MeABzZz wants to merge 1 commit into
BTCDecoded:mainfrom
MeABzZz:criticals/min-chain-work

Conversation

@MeABzZz

@MeABzZz MeABzZz commented Oct 21, 2026 •

Copy link
Copy Markdown

What remains after main

blvm-primitives main is still 7b27888, the base of this branch, so nothing on main overlaps this PR and there was nothing to merge (no push).

On main, BlockValidationConfig::default() and any config that leaves out n_minimum_chain_work get a floor of 0. Since consensus bbdaccb a skip also needs an assume-valid hash, so a floor of 0 is no longer exploitable on its own. But any caller that sets a hash (blvm-node#31, the -assumevalid=<hash> CLI from blvm#11, a library user) has its skip gated on no chain work. This PR changes that:

  • n_minimum_chain_work defaults to Core v31.1's mainnet nMinimumChainWork, 0x1128750f82f4c366153a3a030, both in Default and in serde when the field is omitted.
  • Adds the MAINNET_ASSUME_VALID_HEIGHT / MAINNET_ASSUME_VALID_HASH / MAINNET_MINIMUM_CHAIN_WORK constants, with Core's values. The hash is stored in internal byte order.
  • assume_valid_hash stays None by default, because the default doesn't know the network.

Verification (Rust 1.88.0, branch head e2405f5 = main 7b27888 + this PR)

test main's values (mutation: n_minimum_chain_work: 0, #[serde(default)]) this branch
default_minimum_chain_work_is_the_mainnet_floor FAILED ok
omitted_minimum_chain_work_deserializes_to_the_floor FAILED ok
mainnet_constants_match_core_v31_1 ok (constants only) ok
  • Full cargo test: 45 passed, 0 failed (plus 1 ignored doc test).
  • cargo clippy --all-targets: 3 warnings on main and 3 on the branch (identical), none in src/config.rs.
  • rustfmt --edition 2024 --check src/config.rs: clean.

Review notes

  • Builds on: blvm-consensus bbdaccb (a skip needs a hash). This floor is the second gate.
  • Merge order: independent. After the blvm-primitives release that includes this, regenerate blvm-consensus tests/fixtures/consensus_config_default.json (the regen helper is in tests/config_golden.rs), or that golden test fails. No other consensus test depends on a floor of 0.
  • Decision: a mainnet floor in a network-agnostic default means a testnet or regtest caller that sets a hash but no work will never skip (safe, but surprising). The alternative is to keep 0 and require every caller to set the floor.

BlockValidationConfig::default armed assume-valid at height 938343 with
n_minimum_chain_work 0. Connect skips scripts when
height < assume_valid_height && best_header_chainwork >= n_minimum_chain_work,
so with a floor of 0 any chain with any work skipped every script below
the height. A config that set only the height also got 0 from serde.

Set the floor to Bitcoin Core v31.1 mainnet nMinimumChainWork
(src/kernel/chainparams.cpp, CMainParams), in Default and as the serde
default. Export the matching defaultAssumeValid height and hash as
constants. No test network reaches the mainnet floor, so they verify every
script unless the caller sets their own values.

The hash stays unset in this network-agnostic default: connect rejects a
block at the assume-valid height whose hash differs, so a mainnet hash
here would reject testnet and signet blocks at that height. blvm-node sets
the per-network hash.
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.

1 participant