Skip to content

test(consensus): pin connect_block PoW check with mainnet block-1 vectors - #25

Open
MeABzZz wants to merge 1 commit into
BTCDecoded:mainfrom
MeABzZz:tests/connect-pow-vectors
Open

MeABzZz wants to merge 1 commit into
BTCDecoded:mainfrom
MeABzZz:tests/connect-pow-vectors

Conversation

@MeABzZz

@MeABzZz MeABzZz commented Oct 21, 2026

Copy link
Copy Markdown

What this does

Test-only. Ports tests/connect_pow_check.rs from #23 onto current main. Main fixed the bug in bbdaccb: connect_block now checks proof of work unconditionally. This PR only pins that behaviour, and there are no src/ changes.

The vectors use mainnet block 1 (00000000839a8e68…eb6048), rebuilt from its coinbase so the merkle root is checked as well.

test what it pins
vector_is_mainnet_block_1 The vector hashes to the real block-1 hash and meets its own target
connect_accepts_mainnet_block_1 A valid block connects
connect_rejects_hash_above_target_with_correct_bits Correct nBits with a nonce that misses the target is rejected ("proof of work")
connect_rejects_hash_above_target_without_ancestor_lookup New vs #23. The same rejection with no difficulty_ancestor lookup. Before bbdaccb this path skipped PoW.
connect_regtest_pow_boundary Regtest boundary: a hash at the target passes and one above it fails

Verification

  • On main (a9fb32d, which includes bbdaccb), cargo test --test connect_pow_check gives 5 passed.
  • Mutation check: replacing the check at src/block/connect.rs:3313 (if !crate::pow::check_proof_of_work(..)) with if false gives 3 failed / 2 passed. The 3 rejection tests fail and the 2 acceptance and vector tests still pass, as expected. The file was then restored.
  • rustfmt --edition 2024 --check on the new file is clean.
  • Clippy on this test target reports only useless_conversion on script_sig/script_pubkey .into(). That matches the existing test style (segwit_suite.rs, integer_overflow_edge_cases.rs, …), so I left it as is. The whole-crate --all-targets clippy errors on main are pre-existing and unrelated to this PR.

Review notes

…tors

Ports tests/connect_pow_check.rs from BTCDecoded#23 onto bbdaccb, which made the
PoW check unconditional. Adds a case without the ancestor lookup, the
path that skipped PoW before bbdaccb.
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