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

fix: don't leave a ghost WalletInfo row when wallet creation fails (#3830)

Public commit record

What the developer wrote

Authored by Omar Hatem

98/100 · Strong
fix: don't leave a ghost WalletInfo row when wallet creation fails (#3830)

* fix: don't leave a ghost WalletInfo row when wallet creation fails

EVM wallet init() saves the WalletInfo row (through saveAddressesInBox)
before save() writes the wallet file, and WalletCreationVM only set a
FailureState when process() threw. Any failure in that window left a row
without a wallet file, so the wallet showed up in the list but could never
be opened:

PathNotFoundException: Cannot open file,
path = '.../wallets/polygon/<name>/<name>'

The reproducible trigger is "restore from private key" for an EVM chain:
the keys form validates only the wallet name, so a non-hex or empty key
reached EthPrivateKey.fromHex inside init(), after the row was saved.

- EVMChainWalletService.restoreFromKeys rejects an invalid private key
with a BadKeysException before anything is persisted.
EVMChainUtils.isValidPrivateKey accepts a 32-byte hex key, optionally
0x-prefixed, with 0 < k < secp256k1 order.
- WalletCreationVM._create removes the WalletInfo row when process()
throws, but only if the wallet directory holds no wallet file for that
name. That is the same check _validateWalletInfoBoxData uses, so a row
is dropped only when the startup validation would not re-create it. A
failure after the wallet files exist keeps today's behaviour.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: only drop the WalletInfo row when the wallet directory is empty

The cleanup gate matched the "<name>/<name>" path substring that
_validateWalletInfoBoxData uses. Directory.listSync joins entries with
the platform separator, so on Windows the substring never matches and
the row was dropped on every failure, even with wallet files on disk
(Cursor Bugbot). The check also assumed every coin names its on-disk
files after the wallet, which Decred does not before save().

Delete the row only when the directory is missing or empty: a failed
EVM restore writes nothing before the throw, so the ghost row still goes
away, and any coin that got as far as writing a file keeps today's
behaviour.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: accept every private key that restored before, reject only unusable ones

The first revision of isValidPrivateKey required exactly 32 bytes. The
wallet never had that rule: EthPrivateKey.fromHex takes any even-length
hex, the address and every signature derive from the integer value of
the bytes, and the key is stored as entered, so a 62- or 128-character
input produced a working wallet. Re-restoring such an input on a new
device would have been refused.

Now the check rejects only what never produced a usable wallet: hex that
does not parse (previously a throw inside init() after the WalletInfo
row was saved) and keys that are zero modulo the secp256k1 order, which
have no key pair.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Uses a recognizable type or scope✓ Provides detailed explanatory context✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This commit fixes a bug in Cake Wallet where creating or restoring an EVM wallet could leave a 'ghost' wallet entry in the app's list. The ghost appeared because the wallet's metadata was saved to the app's database before the actual wallet file was written. If the next step failed—for example, because the private key was invalid—the app showed a wallet that could never be opened. The fix validates the private key before saving anything, and cleans up the metadata row if the wallet file was never actually created. It also makes sure the cleanup only happens when the wallet directory is empty, so it doesn't accidentally delete real wallets.

Recommended action

Treat as a reliability/DoS bug rather than an active exploit. Review whether other wallet services (non-EVM) have the same metadata-before-file persistence pattern and apply similar early validation and cleanup. Verify the directory-empty check behaves correctly on all supported platforms, especially Windows. No immediate security advisory is required, but a release note mentioning the fix is appropriate.

Security signals we found

01

State inconsistency between database metadata and on-disk wallet files

02

Untrusted user input (private key) reaching cryptographic initialization before validation

03

Ghost wallet entry causing persistent UI error (PathNotFoundException) on subsequent opens

04

Cleanup logic gated on empty directory to avoid deleting wallets with persisted files

05

Cross-platform path handling corrected (previous substring match failed on Windows)

Risk score

Why this scored 45/100

Our methodology →
Potential impact 12/30
Exploitability 8/25
Stealth signal 6/15
Affected reach 7/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.