Repository navigation
fix(wallet-core): confirm and pin provision_wallet's entropy source as a CSPRNG - #381
Merged
Emmyt24 merged 2 commits intoSep 28, 2026
Conversation
…s a CSPRNG provision_wallet's mnemonic generation depended transitively on tiny-bip39's Mnemonic::new, which draws entropy from rand::thread_rng() only when the crate's default `rand` feature is enabled. Generate the 128-bit entropy from OsRng explicitly and build the mnemonic with Mnemonic::from_entropy, so the guarantee no longer rests on a dependency default. Documents the source on WalletSeed::generate, in Cargo.toml and in docs/architecture.md, and adds a collision smoke test. Closes Octo-Protocol-org#319
|
@Favourice01 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…re/audit-provision-entropy-source # Conflicts: # crates/wallet-core/src/derive.rs # docs/architecture.md
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.
Closes #319
Audit finding
Call chain before this PR (tiny-bip39 2.0.0, rand 0.8.5 per
Cargo.lock):provision_wallet(crates/wallet-core/src/provision.rs) →WalletSeed::generate()WalletSeed::generate()→bip39::Mnemonic::new(MnemonicType::Words12, …)tiny-bip39-2.0.0/src/mnemonic.rs:66Mnemonic::new(#[cfg(feature = "rand")]) →crypto::gen_random_bytes(16)tiny-bip39-2.0.0/src/crypto.rs:24gen_random_bytes→rand::thread_rng().fill_bytes(..)ThreadRng= ChaCha12 block RNG, seeded and periodically reseeded fromOsRng.So the source was a CSPRNG. But the guarantee was implicit: it only exists while tiny-bip39's default
randfeature is on, and the algorithm is arandimplementation detail that a version bump could change without anyone noticing.Change
WalletSeed::generate()now fills 16 bytes of entropy fromrand::rngs::OsRng(getrandom(2)), zeroizes the buffer, and builds the mnemonic withMnemonic::from_entropy.Mnemonic::newis no longer called.WalletSeed::generate()records the source, plus a doc-test.Cargo.toml(tiny-bip39,rand),crates/wallet-core/Cargo.toml, anddocs/architecture.md("Entropy source (load-bearing)").Tests
generated_mnemonics_never_collide_across_a_large_sample: draws 10,000 mnemonics with no collision, then checks that two fullgenerate()calls differ. This is a smoke test, not a randomness-quality audit.WalletSeed::generate.cargo test -p octo-wallet-core: all pass.