AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 64 Monero

fix: use derivation indexes, not record counts, for new and discovered addresses (#3762)

Public commit record

What the developer wrote

Authored by Omar Hatem

100/100 · Strong
fix: use derivation indexes, not record counts, for new and discovered addresses (#3762)

* fix: use derivation indexes, not record counts, for new and discovered addresses

New receive/change addresses took their index from the number of records on the
page, and discovery started at the branch length. On BTC P2PKH/P2SH/P2TR pages
the count included legacy-derivation records, so "+" could jump from index 21 to
44 and leave a hole that a restore never scans.

- generateNewAddress / getChangeAddress use the lowest free index on the standard
chain (legacy records count only when they derive the same keys)
- discovery starts after the highest index on the branch, and the gap checks
compare derivation indexes instead of list positions

For branches with no holes (every restore) the numbers are the same as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: cover derivation index helpers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WdXRtX9wtPwW9gHVi5GZTa

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Uses a recognizable type or scope✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a bug in Cake Wallet's Bitcoin address handling. Previously, the wallet chose new receive/change addresses by counting how many address records existed, rather than by checking the actual derivation index. On some Bitcoin address types (P2PKH, P2SH, P2TR), this count could include legacy-derivation records, causing the wallet to skip ahead and create address 'holes' (for example, jumping from index 21 to 44). A wallet restored from seed would not scan those skipped indexes, so any funds sent to them could appear missing after restore. The fix makes new addresses use the lowest unused derivation index and makes address discovery continue from the highest used index, with added unit tests.

Recommended action

Review and merge the fix; ensure the new unit tests pass. Users who generated Bitcoin receive/change addresses on affected P2PKH/P2SH/P2TR pages before this fix should be advised to verify balances after restoring from seed, and to consider sweeping any funds sent to skipped indexes if they can identify them.

Security signals we found

01

Address gap/derivation index mismatch could cause funds to be missed on wallet restore

02

Fix replaces list-length/count-based indexing with derivation-index-based logic

03

Legacy derivation records could inflate counts and create unscanned address holes

04

Discovery gap check now uses addressRecord.index instead of list index

05

New unit tests added for index helpers and address generation/discovery

Risk score

Why this scored 64/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 10/15
Affected reach 12/15
Confidence 8/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.