Skip to content

fix(chain): clamp derivation index before apply_changeset - #2265

Open
busayo-OD wants to merge 1 commit into
bitcoindevkit:masterfrom
busayo-OD:clamp-derivation-index
Open

fix(chain): clamp derivation index before apply_changeset#2265
busayo-OD wants to merge 1 commit into
bitcoindevkit:masterfrom
busayo-OD:clamp-derivation-index

Conversation

@busayo-OD

Copy link
Copy Markdown

Fixes bdk_wallet/issues/60

Description

KeychainTxOutIndex::apply_changeset accepts ChangeSet::last_revealed values above BIP32_MAX_INDEX, violating an invariant relied on by the indexer. This PR clamps each last_revealed value to BIP32_MAX_INDEX before storing it.

The change follows the approach discussed in #1792, keeping changeset application infallible and monotone. The added regression test verifies that an out-of-range last_revealed value is clamped to BIP32_MAX_INDEX.

Notes to the reviewers

The test uses a non-wildcard descriptor and verifies the sanitization directly rather than reproducing the downstream panic itself. A wildcard descriptor with a large last_revealed causes replenish_inner_index to eagerly derive a very large number of script pubkeys before apply_changeset returns, making a direct reproduction of the downstream panic impractical.

Changelog notice

Clamp last_revealed to BIP32_MAX_INDEX when applying a ChangeSet to KeychainTxOutIndex.

Checklists

All Submissions

Bugfixes

  • This pull request breaks the existing API
  • I've added tests to cover the issue which are now passing
  • I'm linking the issue being fixed by this PR

KeychainTxOutIndex::apply_changeset accepts ChangeSet::last_revealed
values above BIP32_MAX_INDEX, violating an invariant relied on by
the indexer.

Clamp each last_revealed value to BIP32_MAX_INDEX before storing
it, keeping changeset application infallible and monotone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

'apply_changeset' the derivation index aren't sanitized

1 participant