Repository navigation
fix(key-wallet): normalize a mnemonic phrase once, into a wiped buffer - #1274
Merged
Merged
Conversation
Mnemonic::from_phrase tried each wordlist with bip39's parse_in, which normalizes the phrase to NFKD again for every language it is given. When the phrase is not already NFKD, each try builds a new normalized String, grown as it is built, and none of them is wiped. from_phrase now normalizes the phrase once, into a Zeroizing buffer allocated at its final size, and tries each wordlist with parse_in_normalized. A phrase that is already NFKD, such as one from Mnemonic::phrase, is used as it is, without a copy. Which phrases parse, and in which language, is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 5 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Contributor
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #1274 +/- ##
==========================================
- Coverage 80.71% 80.71% -0.01%
==========================================
Files 291 291
Lines 77818 77841 +23
==========================================
+ Hits 62813 62830 +17
- Misses 15005 15011 +6
|
xdustinface
approved these changes
Nov 1, 2026
3 of 4 tasks
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.
Follow-up to #1271.
Mnemonic::from_phrasetries each wordlist withbip39::Mnemonic::parse_in, which normalizes the phrase to NFKD each time it is called. When the phrase isn't already NFKD, for example an NFC phrase with accented words, each try builds a new normalizedString. That string grows as it is built, and none of these copies is wiped. With English first and nine more wordlists, that is up to ten copies.from_phrasenow normalizes the phrase once into aZeroizing<String>, allocated at its final size so it never reallocates, and tries each wordlist withparse_in_normalized. A phrase that is already NFKD, such as one fromMnemonic::phrase, is used as it is, with no copy. The same phrases parse as before, in the same language order, with the same error text.Copies made inside
bip39andunicode-normalizationthemselves aren't covered.Changelog
Mnemonic::from_phraseinkey-walletnormalizes a non-NFKD phrase once, into a buffer that is wiped when droppedTests
test_nfkd_zeroizing_normalizes_into_an_exact_size_buffer: NFKD input isn't copied, and NFC input is normalized into a buffer whose capacity equals its length.test_from_phrase_nfc_input_matches_nfkdandtest_from_phrase_round_trip_all_languagescover parsing.dev.-D warnings(all features and targets), and thekey-walletandkey-wallet-ffitests.🤖 Generated with Claude Code
PR Hygiene ·
7a665ff/skip-botsproceeds without the ones not yet reported/self-reviewedkey-wallet(key-wallet/src/mnemonic.rs) — QuantumExplorer or ZocoLini or xdustinfaceWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.