Repository navigation
Description
Summary
On a witness-pruned datadir, -reindex-chainstate -assumevalid=<non-null hash> appears to allow local state mutation before proving the supplied hash is usable for witness-pruned historical replay.
The startup guard currently rejects only a null AssumedValidBlock(). It logs that the hash must be above the witness-pruned range, but source order does not enforce that before snapshot chainstate deletion and coins DB wipe paths can run. The later semantic predicate does check that the hash is known, on the best-header chain, and covers the block being validated, but that check is reached after the destructive startup path.
This is not a claimed consensus-acceptance bug. I did not find evidence that the node accepts an invalid chain. The concern is fail-closed startup/recovery behavior: a typo, unknown hash, off-chain hash, or too-low hash may destroy or invalidate recoverable local state before the node proves the recovery command can work.
Affected Branch/Ref
Reviewed as of 2026-06-29:
- Current HEAD:
3e036bdbf9ffb11824ac97b0ef2239f0e3d054b2 origin/0.1.x:3e036bdbf9ffb11824ac97b0ef2239f0e3d054b2origin/main:ddda32b385f8aff485439a93d01bc990b3a4a7c1- No
origin/developbranch was advertised byorigin;origin/mainis the default branch. - The requested files have no diff between
origin/0.1.xandorigin/main. - Open PRs checked: Reject non-P2MR raw funding outputs #37, Add independent CHECKDATASIGPQC vector coverage #38, Verify libbitcoinpqc tagged subtree imports #41, Add independent CHECKDATASIGADDPQC vector coverage #42, Add P2MR data-hash proof fixtures #43, Fix PQC data-hash counter accounting #46, Add independent P2MR commitment vectors #47. None edit
src/node/chainstatemanager_args.cpp,src/node/chainstate.cpp,src/validation.cpp, ortest/functional/feature_witness_pruning.py. - GitHub searches for existing issues/PRs matching
assumevalid,witness-pruned, andreindex-chainstatedid not return an existing matching item.
Candidate Severity and Why
WARN / candidate P2.
Reason: this appears to be a local destructive recovery-safety issue. A witness-pruned node may wipe chainstate or delete snapshot chainstate before proving the supplied -assumevalid value can actually cover stripped historical witness data. I did not prove consensus divergence or invalid-chain acceptance.
Impact
A witness-pruned operator attempting recovery with an unusable non-null -assumevalid value may lose the existing chainstate and/or snapshot chainstate before the node discovers that historical witness-dependent validation still cannot proceed locally.
This can turn a recoverable startup/configuration error into a more expensive recovery path requiring archive peers, snapshot reload, or fresh sync. The risk is highest for:
- unknown but syntactically valid hashes
- hashes not on the best-header chain
- hashes below or inside the stripped witness range
- boundary hashes around the last stripped / first unstripped block
- datadirs with an active assumeutxo snapshot chainstate
Source Evidence
-assumevalid parsing accepts syntactically valid non-null hex without semantic validation:
src/node/chainstatemanager_args.cpp:40-45parses-assumevalidwithuint256::FromUserHex()and stores the result.src/test/validation_chainstatemanager_tests.cpp:1221-1232confirms-assumevalid=0x12is accepted, while invalid characters and overlong hex are rejected.
The witness-pruned -reindex-chainstate guard rejects only null:
src/node/chainstate.cpp:66-78checksoptions.wipe_chainstate_db && chainman.m_blockman.m_have_witness_pruned.- It returns only when
chainman.AssumedValidBlock().IsNull(). - For any non-null hash, it logs: "The supplied hash must be above the witness-pruned range."
- I did not find an enforcement of that statement before state mutation.
Snapshot chainstate deletion can happen before this guard:
src/node/chainstate.cpp:187-198detects and deletes an existing snapshot chainstate whenoptions.wipe_chainstate_dbis true.- This occurs before
CompleteChainstateInitialization()runs the witness-pruned guard. src/validation.cpp:6732-6747implementsDeleteSnapshotChainstate().src/validation.cpp:5993-6030removes the snapshot base-blockhash file and destroys the LevelDB directory.
Coins DB wipe can happen after the non-null-only guard but before semantic validation of the hash:
src/node/chainstate.cpp:105-113callschainstate->InitCoinsDB(... should_wipe=options.wipe_chainstate_db).src/validation.cpp:1990-2008passes.wipe_data = should_wipe.src/dbwrapper.cpp:230-233callsleveldb::DestroyDB()whenwipe_datais true.
The semantic check exists, but later:
src/validation.cpp:2410-2424checks whether the assumed-valid block is known, whetherm_best_headersatisfies minimum work, and whether both the assumed-valid block and best header contain the block being validated as an ancestor.src/validation.cpp:2433-2439uses that inCanSkipScriptChecks().src/validation.cpp:4826-4835uses it inNeedsWitnessForValidation().src/validation.cpp:3207-3226,src/validation.cpp:3405-3443, andsrc/validation.cpp:3513-3522then route missing witness cases into temporary witness recovery.
That means the predicate needed to reject unknown/off-chain/too-low hashes exists, but the startup path does not appear to run it before destructive local state actions.
Existing Test Coverage
test/functional/feature_witness_pruning.py covers:
-txindexincompatible with explicit witness pruning: lines 155-164- witness pruning behavior and service flag changes: lines 171-232
- historical verbose
getblockandgetrawtransactionrefusal: lines 234-252 - recent unpruned block behavior: lines 254-260
- witness compaction startup recovery/cleanup: lines 262-287
- witness pruning depth n-1/n/n+1 storage behavior: lines 289-310
- P2P stripped/witness block behavior: lines 312-337
-txindexrefusal on a witness-pruned datadir: lines 344-352-reindexrefusal on a witness-pruned datadir: lines 354-362-reindex-chainstatewith no-assumevalidrefusal: lines 364-373-reindex-chainstatewith an above-range-assumevalidsucceeds: lines 375-379- startup compaction with
-reindex-chainstateand an above-range-assumevalid: lines 458-476
Related unit coverage exists for the later semantic gate:
src/test/validation_chainstatemanager_tests.cpp:214-254checksNeedsWitnessForValidation()/ script-skip behavior for assumed-valid ancestry and alternate-chain cases.
Missing Boundary Tests
I did not find explicit functional coverage for witness-pruned -reindex-chainstate with:
- unknown non-null
-assumevalid - hash below the stripped witness range
- hash inside the stripped witness range but not covering all stripped blocks
- exact last stripped block
- first unstripped block
- off-best-header-chain hash
- snapshot chainstate present during refusal
- assertions that refusal happens before
chainstate/wipe or snapshot chainstate deletion
The exact last-stripped vs first-unstripped cases should pin the intended boundary, especially because compaction is file-granular and because the current semantic predicate treats same-height ancestry as covering the candidate block.
Reproduction Plan / Blocker
I did not run a live repro in this pass; this report is based on source order, tests, and GitHub branch/PR state. The workspace did not have an existing build directory, and I avoided creating build/test artifacts while preparing this draft.
Suggested repro:
- Extend
test/functional/feature_witness_pruning.pyafter witness compaction has occurred and before the existing above-range success case. - Stop the witness-pruned node.
- Record evidence that
chainstate/and any snapshot chainstate directory exist before the attempted restart. - Restart with
-fastprune -reindex-chainstate -assumevalid=<unknown nonzero 64-hex hash>. - Assert the node refuses before any
Wiping LevelDBor snapshot deletion log appears, and before the recorded chainstate/snapshot state changes. - Repeat for below-range, inside-range, exact-last-stripped, and first-unstripped hashes.
- Add a variant with an active snapshot chainstate to prove refusal does not delete the snapshot before the assumevalid preflight.
On current source, I expect the non-null startup guard to pass and the coins DB wipe path to be reachable before the later witness-validation gate discovers the hash cannot cover stripped history. The exact runtime symptom may be refusal, startup stall, or witness-recovery scheduling depending on peer availability, so the repro should assert mutation ordering rather than only a final process exit string.
Proposed Fix Direction
Add a preflight for witness-pruned -reindex-chainstate before any local state deletion or coins DB wipe.
The preflight should validate that a non-null AssumedValidBlock() is:
- present in the loaded block index
- on the best-header chain
- backed by sufficient chain work
- high enough to cover every witness-pruned block that would otherwise require witness-dependent validation during chainstate replay
The existing IsAssumedValidAncestor() / NeedsWitnessForValidation() logic is close to the needed semantic check, but startup should run an equivalent check before DeleteSnapshotChainstate() and before InitCoinsDB(... should_wipe=true).
If any pre-refusal mutation is intentionally accepted, document that behavior explicitly and add tests proving the intended mutation and recovery semantics.
Acceptance Criteria
- Witness-pruned
-reindex-chainstatevalidates the supplied non-null-assumevalidbefore any coins DB wipe. - Snapshot chainstate is not deleted before the same preflight succeeds.
- Unknown, off-chain, below-range, inside-range, exact-last-stripped, and first-unstripped hashes have explicit functional coverage.
- Tests assert both the final error/success behavior and that refused cases do not mutate
chainstate/or snapshot chainstate. - Existing valid above-range
-assumevalidrecovery still succeeds. - Any accepted pre-refusal mutation is documented and tested.
Activity