mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:17:38 +00:00
AssumeUTXO: reject duplicate coins and empty snapshot groups #36500
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36500
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/assumeutxo-import-count"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem: Snapshot loading doesn't validate the announced coin count against the unique UTXOs loaded.
Repeated outpoints collapse into one coin, so a snapshot can repeat every record, announce the doubled count, and still match the committed UTXO hash.
loadtxoutsetthen reports the inflated count ascoins_loaded.Snapshot loading also accepts transaction groups with no coins.
They leave the UTXO hash unchanged and don't advance the coin count, so parsing them bypasses the interrupt check and can delay shutdown.
Fix: Compare the announced count with the unique coin count already produced by the existing UTXO statistics scan, and reject zero-count transaction groups while parsing the snapshot.
When both the content hash and coin count are wrong, loading reports the hash error first.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
loadtxoutsetRPC with a startup arg by l0rinc)If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
No verified findings are available from this review.
Review coverage was incomplete.
Reviewed:
e8e8cbcaa25b· Full review report · Previous reportspermalink
Could the new cases use the existing
node(nodes[1]) instead of adding a fifth node? Atbf7ea08,feature_assumeutxo.pypasses withsnapshot_node = self.nodes[1], both with and withoutnum_nodes = 4. The fifth node conflicts with #35307, which also setsnum_nodes = 5and usesnodes[4]. With both PRs merged (headd07900cf8),src/merges cleanly, butfeature_assumeutxo.pyfails on the duplicate-records case with "Can't activate a snapshot-based chainstate more than once".Tested
bf7ea08on regtest with a 299-coin snapshot. The new cases fail on the merge base (a8b69bd) and pass on the PR head. A file with duplicated records and a doubled count is accepted on the base (coins_loaded: 598) but rejected on the head with "Bad snapshot coins count: expected 598, got 299". A single empty group after the header is accepted on the base and rejected on the head.With 30M empty groups (990 MB) before a valid body, the base accepts the file in 2.13 s and exits 1.00 s after
stopis issued 1 s into the load. The head rejects it in 0.04 s. After either rejection,chainstate_snapshotis gone,getchainstatesshows one chainstate, and a valid snapshot then loads and survives a restart.The count check also catches a single repeated outpoint, both within a group and in a repeated group. In either case, the head rejects it with "Bad snapshot coins count: expected 300, got 299" and leaves one chainstate.
wallet_assumeutxo.pyandvalidation_chainstatemanager_testspass. Bothutxo_snapshotandutxo_snapshot_invalidfuzz targets ran for 10 minutes each on the head using libFuzzer without sanitizers, starting from an empty corpus, with no crashes (127k and 1.45M runs, respectively).Not tested: mainnet-size snapshots.
tACK
e8e8cbcaa2A repeated outpoint need not repeat the same coin. I appended a second record for an existing outpoint to the regtest snapshot, with a 500-byte script, and raised the count by one. On the base (
cce32b1687) the file loads withcoins_loaded300, andgettxoutreturns the original coin: the coins cache keeps the first record for an outpoint, so the content hash still matches. The head rejects the file with "Bad snapshot coins count: expected 300, got 299". With the extra record placed before the original, both reject it on the hash.The loaded UTXO set is still the committed one. What the base leaves unchecked is the reported count and the extra bytes in the file.
AssumeutxoDataholds no coin count, so this holds for a file matching any hardcoded entry, mainnet included.I built bitcoind at the head and at the base, and ran the head's
feature_assumeutxo.pyand a smallloadtxoutsetscript on both. The test fails on the base at the duplicate case and passes on the head. I can share the script.tACK
e8e8cbcaa2(re-ACK)The test uses four nodes and reuses nodes[1] for the invalid snapshot cases.
My saved 25 October run record (aarch64, Release) compares merge base
cce32b1687with this head:These results cover this PR head alone; I have not tested it combined with #36603 or on mainnet-size snapshots.
light code review ACK
e8e8cbcaa2Code looks good to me, only a light ACK as I'm new to this part of the code :)