Repository navigation
Conversation
`[u8; 64]` is `Copy`, so a caller holding the master secret in a `Zeroizing` buffer had to deref it to pass by value, materializing an extra un-scrubbed stack copy of the 64-byte master seed at the call boundary. Take `&[u8; 64]` so such a caller passes `&*buf` with no extra copy. No callers within rust-dashcore; the only known consumer is dashpay/platform. Co-Authored-By: Claude Opus 4.8 <[email protected]>
📝 WalkthroughWalkthroughThe public ChangesSeed Bytes API Update
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@key-wallet/src/wallet/initialization.rs`:
- Around line 329-342: The `from_seed_bytes` docs currently overstate the
zero-copy behavior: `Seed::new(*seed_bytes)` still creates a transient stack
copy even though the caller-side copy is avoided. Update
`Wallet::from_seed_bytes` (and the related `Seed::new` call path) so the
implementation either accepts a `&[u8; 64]`-based zeroizing path end-to-end or,
if that is not changing, tighten the doc comment to say only the call-boundary
copy is avoided.
- Around line 337-338: The public Wallet::from_seed_bytes signature change is a
breaking API update, so update the PR title to use a breaking-change semantic
marker such as fix!: or refactor!:. Make sure the title clearly signals
downstream consumers that the change affects the Wallet::from_seed_bytes
interface.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 27202d6c-8a43-439f-99db-167c9bd066b9
📒 Files selected for processing (1)
key-wallet/src/wallet/initialization.rs
| /// Takes the seed by reference so a caller holding it in a zeroizing buffer | ||
| /// can pass `&*buf` without materializing an extra un-scrubbed by-value copy | ||
| /// of the 64-byte master secret at the call boundary (`[u8; 64]` is `Copy`). | ||
| /// | ||
| /// # Arguments | ||
| /// * `seed_bytes` - The seed bytes array | ||
| /// * `network` - Network to create accounts for | ||
| /// * `account_creation_options` - Specifies which accounts to create during initialization | ||
| pub fn from_seed_bytes( | ||
| seed_bytes: [u8; 64], | ||
| seed_bytes: &[u8; 64], | ||
| network: Network, | ||
| account_creation_options: WalletAccountCreationOptions, | ||
| ) -> Result<Self> { | ||
| Self::from_seed(Seed::new(seed_bytes), network, account_creation_options) | ||
| Self::from_seed(Seed::new(*seed_bytes), network, account_creation_options) |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the relevant symbols and inspect their definitions.
rg -n "pub fn from_seed_bytes|struct Seed|impl Seed|Zeroize|from_seed\(" key-wallet/src -S
echo
echo "---- file outline ----"
ast-grep outline key-wallet/src/wallet/initialization.rs --view expanded || true
echo
echo "---- seed-related files ----"
fd -a "seed.rs|Seed.rs" key-wallet/src || trueRepository: dashpay/rust-dashcore
Length of output: 4963
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Read the relevant slices if the symbols are found.
sed -n '300,380p' key-wallet/src/wallet/initialization.rsRepository: dashpay/rust-dashcore
Length of output: 2493
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the Seed type definition and constructors if present.
rg -n "pub struct Seed|impl Seed|fn new\(" key-wallet/src -SRepository: dashpay/rust-dashcore
Length of output: 2917
Avoid implying the intermediate copy is gone
from_seed_bytes avoids the caller-side copy, but Seed::new(*seed_bytes) still creates a transient [u8; 64] on the stack. If the goal is to avoid any un-scrubbed intermediate, this needs a &[u8; 64]-based zeroizing path; otherwise tighten the doc to say only the call-boundary copy is avoided.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@key-wallet/src/wallet/initialization.rs` around lines 329 - 342, The
`from_seed_bytes` docs currently overstate the zero-copy behavior:
`Seed::new(*seed_bytes)` still creates a transient stack copy even though the
caller-side copy is avoided. Update `Wallet::from_seed_bytes` (and the related
`Seed::new` call path) so the implementation either accepts a `&[u8; 64]`-based
zeroizing path end-to-end or, if that is not changing, tighten the doc comment
to say only the call-boundary copy is avoided.
| pub fn from_seed_bytes( | ||
| seed_bytes: [u8; 64], | ||
| seed_bytes: &[u8; 64], |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect PR title against allowed semantic prefixes and breaking-change convention.
gh pr view --json title,number -q '.title'
fd pr-title.yml .github/workflows --exec cat {}Repository: dashpay/rust-dashcore
Length of output: 821
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the relevant function and nearby context.
FILE="key-wallet/src/wallet/initialization.rs"
wc -l "$FILE"
sed -n '300,380p' "$FILE"
# Find declarations/usages of from_seed_bytes.
rg -n "from_seed_bytes" "$FILE" key-wallet/src -g '!target'Repository: dashpay/rust-dashcore
Length of output: 2681
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Show the change around the public initializer and any related call sites.
git diff --unified=20 -- key-wallet/src/wallet/initialization.rs
printf '\n---\n'
rg -n "from_seed_bytes\(" key-wallet/srcRepository: dashpay/rust-dashcore
Length of output: 236
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Compare the current commit with its parent around the public API.
git rev-parse --verify HEAD
git show --stat --oneline --format=fuller HEAD -- key-wallet/src/wallet/initialization.rs
printf '\n--- parent diff ---\n'
git diff --unified=20 HEAD^ HEAD -- key-wallet/src/wallet/initialization.rsRepository: dashpay/rust-dashcore
Length of output: 3504
Use a breaking-change PR title marker The public Wallet::from_seed_bytes signature changed, so the PR title should use a breaking semantic form like fix!: or refactor!: to warn downstream consumers.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@key-wallet/src/wallet/initialization.rs` around lines 337 - 338, The public
Wallet::from_seed_bytes signature change is a breaking API update, so update the
PR title to use a breaking-change semantic marker such as fix!: or refactor!:.
Make sure the title clearly signals downstream consumers that the change affects
the Wallet::from_seed_bytes interface.
Source: Path instructions
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #842 +/- ##
==========================================
- Coverage 73.44% 73.36% -0.09%
==========================================
Files 324 324
Lines 72577 72577
==========================================
- Hits 53306 53245 -61
- Misses 19271 19332 +61
|
|
Closing in favor of #843. This change only removed one call-boundary copy; the underlying issue is that |
What
Wallet::from_seed_bytestook the 64-byte seed by value ([u8; 64]). Because[u8; 64]isCopy, a caller that holds the master secret in a zeroizing buffer(
Zeroizing<[u8; 64]>) has to dereference it to pass by value — materializing anextra, un-scrubbed stack copy of the master secret at the call boundary that the
caller's zeroizing wrapper does not cover.
This changes the signature to take
&[u8; 64], so such a caller can pass&*bufwith no extra copy. The body derefs into the (already
Zeroize-deriving)Seed.Why
Minor secret-hygiene improvement: fewer transient, un-zeroized copies of the HD
master seed on the stack. Surfaced from
dashpay/platform'screate_wallet_from_seed_bytes, which wraps the seed inZeroizingbut is forcedto make the by-value copy to call this function.
Breaking change
from_seed_bytesnow takes&[u8; 64]. There are no callers withinrust-dashcore (the FFI
wallet_create_from_seedusesWallet::from_seed, notfrom_seed_bytes). The only known consumer isdashpay/platform(
rs-platform-wallet), which will updatefrom_seed_bytes(*seed)→from_seed_bytes(&*seed)when it bumps the key-wallet rev.Test
cargo check -p key-walletclean; no internal call sites to update.🤖 Generated with Claude Code
Summary by CodeRabbit