Skip to content

C2: Add WordsMemory/PassphraseMemory and use cached ExtKey in PsbtOperations#911

Open
DavidGershony wants to merge 1 commit into
mainfrom
security/c2-walletwords-secure-memory
Open

C2: Add WordsMemory/PassphraseMemory and use cached ExtKey in PsbtOperations#911
DavidGershony wants to merge 1 commit into
mainfrom
security/c2-walletwords-secure-memory

Conversation

@DavidGershony

Copy link
Copy Markdown
Collaborator

Summary

Reduce mnemonic exposure by adding zero-allocation ReadOnlyMemory<char> accessors and fixing PsbtOperations to use the cached ExtKey instead of re-reading .Words.

Changes

  • WalletWords.cs: Add WordsMemory and PassphraseMemory properties that expose the backing char[] without creating new string copies. Add security documentation to the Words getter.
  • PsbtOperations.cs: Replace _hdOperations.GetExtendedKey(walletWords.Words, walletWords.Passphrase) with walletWords.GetOrDeriveExtKey(_hdOperations) to use the cached key and avoid extra mnemonic string allocations.

Rationale

Every call to .Words creates a new string on the managed heap that cannot be deterministically zeroed. By preferring GetOrDeriveExtKey() (which derives once and caches), we minimize the number of mnemonic string copies that linger in memory.

Testing

All 154 shared tests pass.

…rations

Add ReadOnlyMemory<char> properties (WordsMemory, PassphraseMemory) to
WalletWords for zero-allocation read access to mnemonic data. The backing
char arrays are already zeroed on Dispose().

Add security documentation to the Words getter warning that each access
creates an unzeroed string copy on the managed heap.

Fix PsbtOperations.SignTransaction to use GetOrDeriveExtKey() instead of
accessing .Words directly, reducing unnecessary string allocations of
the mnemonic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant