fix: Reject duplicate BitName registrations within a single block - #48
Open
giaki3003 wants to merge 1 commit into
Conversation
…inst the committed pre-block DB (never within the candidate block), so two same-name registrations connect and overwrite the canonical row, and disconnecting that block is non-invertible (the second revert deletes the shared row, the first then fails with Error::Missing), wedging the node on the losing branch during any reorg. Bug: w3-20260610-2220-rustl2-bitnames-bitassets- (primary) Finding: findings/20260610-2220-rustl2-bitnames-bitassets-same-block-duplicate-registration-disconnect-noninvertible.md Severity: R4-T2 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit 68317bc)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
State::validate_filled_transaction(lib/state/mod.rs) checks that a registered name is not already taken, but it reads the pre-block DB, so it cannot see a registration earlier in the same block.block::validate/block::prevalidate(lib/state/block.rs) reject double-spent outpoints but do not look at registration name hashes at all.Two registrations of the same name can therefore both be individually valid — distinct nonces give distinct commitments, so each burns a real reservation — and both connect. The second
apply_registrationoverwrites the canonicalbitnamesrow, and that overwrite is not invertible: on disconnect the secondrevert_registrationdeletes the shared row, and the first then fails withError::Missing. A node that connected such a block can no longer disconnect it, so it is stuck on that branch across a reorg.The fix
Add a per-block uniqueness check over
registration_name_hash()in bothvalidateandprevalidate, right next to the existing double-spend check, returning a newError::DuplicateBitNameRegistration. As defence in depth,apply_registrationnow returnsBitName::AlreadyRegisteredinstead of overwriting an existing row. Happy to move the new variant undererror::BitNameif you prefer it there.Tests
Adds
validate_rejects_duplicate_registration_within_block: two registrations for one name, each asserted to passvalidate_filled_transaction, with the containing block asserted to be rejected.Finding report (access-controlled): https://giaki3003.tech/#/findings/20260610-2220-rustl2-bitnames-bitassets-same-block-duplicate-registration-disconnect-noninvertible
First of a short series of 1 fixes for this repo, based on
master. The rest build on this branch and will follow.