Repository navigation
refactor(key-wallet)!: validate child indexes at construction with ChildIndex - #1328
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
…hildIndex` `ChildNumber::Normal` and `Hardened` now hold a `ChildIndex`, a `u32` below 2^31 that can only be built through `ChildIndex::new`, `new_const` or deserialization, all of which check the range. Account indexes (`AccountType`, collections, wallet and manager accessors) take `ChildIndex`, so derivation paths built from them can no longer fail at runtime. - `from_normal_idx` and `from_hardened_idx` are removed; use the variants directly. - `from_idx` takes a `ChildIndex` and no longer returns a `Result`. - `dip9` path builders and `AccountType::derivation_path` are infallible. - `DerivationPathBuilder` is removed.
78d26db to
0733b9d
Compare
|
Review superseded by a later review of 🔴 Review failed in 17m 28s Planner (8s) Review (security · full): 44 findings Judge |
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
⏸️ Review incomplete: The judge failed. Retry with /manki review.
- Review again
About this review
- Reviewed
0733b9d - How Manki reviews
|
✅ Review complete in 15m 29s Started automatically, since no review of this commit had finished. Planner (5s) Review (security · full): 35 findings Judge (11m 0s) Posted: 9 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
Create an issue for this to track it for later. Manki approves once every warning is handled.
Started automatically, since no review of this commit had finished.
Pre-existing · 2 warnings
This PR did not cause these, so none of them block: each is on lines the PR did not change, or the code fails the same way without the PR.
⚠️ Bound identity top-up private keys derive the registration index twice
Warning, not blocking · Pre-existing · Correctness · Moderate · key-wallet/src/account/derivation.rs:165
Already broken before this PR. Two checks found the same problem on dev at key-wallet/src/account/derivation.rs:163, so it doesn't block this PR.
What goes wrong: The account key already includes the hardened registration index, but the master-to-child helper appends that level again before the leaf. The resulting private key does not match the standard top-up path or the key derived at the same leaf from the account xpub. The same extra step is present in the ECDSA, BLS, and EdDSA account helpers.
How to fix it
Make the account path the single source for the registration level and append only the leaf in the shared child derivation helper. Verify the ECDSA result against DerivationPath::identity_top_up_path and the account xpub, and preserve discovery of any keys already issued under the duplicated path.
- Create an issue for this
⚠️ Generated hardened addresses report a non-hardened derivation path
Warning, not blocking · Pre-existing · Correctness · Quick fix · key-wallet/src/managed_account/address_pool.rs:444
Already broken before this PR. Two checks found the same problem on dev at key-wallet/src/managed_account/address_pool.rs:444, so it doesn't block this PR.
What goes wrong: An AbsentHardened pool derives the key with a hardened child but saves an unhardened child in AddressInfo.path. A caller using the stored path cannot reproduce the key: Ed25519 rejects the normal step, and ECDSA derives a different key.
How to fix it
Validate the index once and choose its hardening from pool_type. Use that same child for actual derivation and recorded metadata, and correct existing stored metadata for hardened pools without changing their addresses.
- Create an issue for this
7 suggestions are not listed.
Checked and left out: 2 findings (1 disproved, 1 unproven)
Disproved by a check of the code · 1 finding
- Derivation path decoding may allocate from an untrusted length prefix ·
key-wallet/src/bip32.rs:856
TheDerivationPathimpls pass decoding straight to Vec:: (bip32.rs:847, 856). Whether that reserves memory from the length prefix depends on grovedb-bincode 2.1.0, the workspace's renamed bincode package, and Manki refused to read its source, so the allocation behaviour is unchecked.
Not proven, so not listed · 1 warning
- Consumer
dashpay/platformbreaks on the dip9 path builders that no longer returnResult·key-wallet/src/dip9.rs:636
A check of the code could not confirm it.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
0733b9d, round 1 - 3893 changed lines read in 15m 29s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 18.1M in (14.5M from cache) · 187k out · about $19.76 at API prices
- Runner: self-hosted · started after 6s · peak memory 7.7 GiB of 30.0 GiB
- How Manki reviews
|
Bots are done — your move: post |
Ed25519 only derives hardened children, but `ExtendedEd25519PubKey::decode` built a `ChildNumber::Normal` from bytes with bit 31 clear. It now reads the child as hardened, as it did before `ChildIndex`.
The test discarded the derived path, so it passed whatever the path held. It now checks that the maximum index lands hardened in the BIP44 path and that the first index past it is rejected.
|
Review superseded by a later review of 🔴 Review failed in 3m 1s Planner (6s) Review (security · full): 0 findings Judge |
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
⏸️ Review incomplete: GPT 6.2 Sol · high failed after retries. Manki starts one more review of this commit on its own within a few minutes. If that one does not finish either, retry with /manki review.
- Review again
About this review
- Reviewed
eb5dcab - How Manki reviews
|
Bots are done — your move: post |
|
Review superseded by a later review of 🔴 Review failed in 4m 29s Started automatically, since no review of this commit had finished. Planner (8s) Review (security · full): 0 findings Judge |
There was a problem hiding this comment.
⏸️ Review incomplete: GPT 6.2 Sol · high failed after retries. Retry with /manki review.
Started automatically, since no review of this commit had finished.
- Review again
About this review
- Reviewed
eb5dcab - How Manki reviews
|
/manki review |
|
Review superseded by a later review of 🔴 Review failed in 3m 58s Planner (7s) Review (security · full): 0 findings Judge |
There was a problem hiding this comment.
⏸️ Review incomplete: GPT 6.2 Sol · high failed after retries. Retry with /manki review.
- Review again
About this review
- Reviewed
eb5dcab - How Manki reviews
|
✅ Review complete in 17m 35s Started automatically, since no review of this commit had finished. Planner (7s) Review (security · full): 37 findings Judge (12m 21s) Posted: 1 finding Review metadataConfig:
Account limits:
Judge decisions:
Timing:
Last reviewed
|
There was a problem hiding this comment.
Create an issue for this to track it for later. Manki approves once every warning is handled.
Caution
Claude subscription has used 93% of its weekly limit, past the 90% mark. It resets 2026-12-02 17:00 UTC.
Once a limit is used up, reviews on that account stop until it resets.
Started automatically, since no review of this commit had finished.
Earlier warnings, not fixed · 3 warnings
An earlier round listed these, and this round did not find them fixed, so they stay listed. None of them blocks.
key-wallet/src/wallet/backup.rs:51: Unbounded bincode decoding may allocate from an untrusted length (round 2)key-wallet/src/account/derivation.rs:165: Bound identity top-up private keys derive the registration index twice (round 1)key-wallet/src/managed_account/address_pool.rs:444: Generated hardened addresses report a non-hardened derivation path (round 1)
📌 4 follow-ups agreed for later
Agreed in their threads as later work. None of them blocks.
key-wallet/src/bip32.rs:614: RemovedChildNumberconstructors and struct variants breakdashpay/platformanddash-evo-toolon upgrade (view thread)key-wallet/src/wallet/helper.rs:16: Account index parameters change fromu32toChildIndex, so both consumer repos stop compiling on upgrade (view thread)key-wallet/src/derivation.rs:58: Public address derivation accepts unbounded amounts of work (view thread)key-wallet/src/bip32.rs:736: Serializing a 256-bit child number as a scalar loses its index and hardening (view thread)
Checked and left out: 1 finding
Rare trigger, so not listed · 1 warning
- Previously writable accounts can no longer be restored ·
key-wallet/src/bip32.rs:598
Trigger 2 of 10, below the cut-off of 4.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
eb5dcab, round 3 - 3912 changed lines read in 17m 35s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 17.9M in (14.6M from cache) · 183k out · about $18.23 at API prices
- Runner: self-hosted · started after 12s · peak memory 6.8 GiB of 30.0 GiB
- How Manki reviews
|
/self-reviewed |
|
Ready for review — |
There was a problem hiding this comment.
✅ Approved. All blocking threads are resolved, and no warning thread holds the approval.
What this does: BIP-32 child indexes and account indexes were plain u32 values. Every derivation call checked them at runtime and could fail.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Build key-wallet and run its tests with and without --all-features. Build key-wallet with --all-features so the BLS and Ed25519 code paths compile. Use a wallet created with WalletAccountCreationOptions::Default and one restored from a known mnemonic, built with --all-features.
- Run
cargo test -p key-wallet --lib bip32. Expect the bip32 tests to compile and pass without extra features. - Create a wallet and derive BIP44 account 0 receive addresses. Expect the same addresses as before the change for the same mnemonic.
- Back up a wallet created before this change and restore it. Expect it to decode and list the same accounts.
- Parse the path
m/44'/5'/0'/0/1. Expect it to format back to the same string. - Parse the path
m/2147483648. ExpectInvalidChildNumber(2147483648). - Decode a bincode or serde
ChildIndexholding2147483648. Expect an error. - Call
ChildIndex::new(0x8000_0000). ExpectErr(InvalidChildNumber). - Do derive
AccountType::Standard { index: ChildIndex::new_const(0x7FFFFFFF), .. }.derivation_path(Network::Testnet). Expectm/44'/1'/2147483647'.
…run 47064776213)
ChildNumber::NormalandHardenednow hold aChildIndex: au32below 2^31 that can only be built throughChildIndex::new,ChildIndex::new_const(checked at compile time in const contexts) or deserialization (serde and bincode), all of which check the range. The wire format is unchanged.Account-level indexes take
ChildIndexend to end (AccountType,ManagedAccountType, the account collections, wallet helpers, transaction building and thekey-wallet-manageraccessors), so the derivation paths built from them cannot fail at runtime.Breaking changes:
ChildNumber::from_normal_idxandfrom_hardened_idxare removed; useChildNumber::Normal(..)/Hardened(..)directly.ChildNumber::from_idxtakes aChildIndexand returnsChildNumber.ChildNumbervariants are tuple variants.dip9path builders andAccountType::derivation_pathno longer returnResult.AccountTypeindex fields,index()and the collection keys areChildIndex.DerivationPathBuilderis removed.DerivationPath::application_encryption_pathtakesrotation: ChildIndexand no longer returnsResult.ManagedPlatformAccount::newtakesChildIndexforaccountandkey_class.Address pool indexes stay
u32, since they are counters with arithmetic, and are validated when the child number is built.PR Hygiene ·
eb5dcabdash-spv(dash-spv/src/sync/filters/coinjoin_gap_discovery_tests.rs,dash-spv/src/sync/mempool/sync_manager.rs,dash-spv/src/test_utils/wallet.rsand 3 more) — QuantumExplorer or xdustinfacekey-wallet-manager(key-wallet-manager/benches/filter_scan.rs,key-wallet-manager/examples/wallet_creation.rs,key-wallet-manager/src/accessors.rsand 7 more) — QuantumExplorer or xdustinfacekey-wallet(key-wallet/benches/address_generation.rs,key-wallet/examples/account_types.rs,key-wallet/examples/basic_usage.rsand 62 more) — QuantumExplorer 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.Summary by CodeRabbit