Repository navigation
fix: keep each wallet's shielded accounts when an Android Clear registers it again - #6171
Conversation
A shielded Clear resets the Rust coordinator, which drops every wallet's registration, and then registers the loaded wallets again. It registered every wallet but the mirror with account [0], whatever accounts the wallet had been bound with, and it read the mirror once before the pass, so a wallet that became the mirror and bound its own accounts after that read could be registered with [0] afterwards. ShieldedService now remembers the account list of each bind it made that went through, per manager, recorded in the same ledger lifecycle step as the native call. Clear marks them dropped in the step of its Rust reset and registers each other wallet again with the accounts it had, [0] only for a wallet the service never registered. Whether a wallet is the pass's to register is decided inside the step that binds it: a wallet bound since the reset, the current mirror and a service that left the manager are left alone. The native bind and its record are not cancellable between the two, so a caller cancelled while the native call runs no longer reports a failed bind for a wallet Rust did register. Closes #5989 Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
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 50 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. |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
✅ Final review complete — no blockers (commit 82c7073) · triage: normal |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 2 only (queue backlog)
Changes requested: 3 blockers
- Clear can replace a newer shielded account selection with an old one —
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:565-569(new)
Impact: Android SDK apps that rebind a secondary wallet through the public manager or reimport a removed wallet can have Clear resume scanning obsolete accounts and miss payments to the intended accounts. - A cancelled or superseded wallet switch can leave a wallet unscanned after Clear —
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:553-564(new)
Impact: Android SDK users who switch displayed wallets during Clear can stop seeing incoming shielded payments for a still-loaded wallet until it is rebound. - A bind cancelled before JNI starts can still replace the wallet’s scan accounts —
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:524-531(new)
Impact: Android SDK callers that cancel a queued account change can still have the previous accounts stop scanning and their local scan and recovery state purged.
The patch adds a per-manager ledger to Android’s ShieldedService so Clear can restore non-default account selections and leave subsequent binds alone. This was a static review; the Kotlin SDK build and x86_64 emulator tests were still pending, and no code checks had failed.
🔴 3 blocking | 🟡 1 suggestion(s)
Review provenance
Source: reviewer 1: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — ShieldedService.kt changes how reset, rebind, and coroutine cancellation interact, making this more than a straightforward local fix without changing funds movement, cryptography, consensus, or storage migrations. - Phase 1 reviewers: not run (skipped for throughput: 11 PRs queued, above the 10 limit)
- Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt`:
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:565-569: Clear can replace a newer shielded account selection with an old one
Impact: Android SDK apps that rebind a secondary wallet through the public manager or reimport a removed wallet can have Clear resume scanning obsolete accounts and miss payments to the intended accounts.
Clear can put wallet B back on `[1, 2]` after the app successfully switched it to `[0]`. Bind B through `ShieldedService.bindEngine` with `[1, 2]`, then call the public `PlatformWalletManager.bindShielded` with `[0]` before Clear or after the Room wipe but before the fleet pass reaches B. The manager call replaces the Rust registration without taking the service’s mutex or updating its ledger, so the fleet pass replays `[1, 2]` in either case. The ledger also outlives removal and reimport of the same seed under the same manager because the wallet ID is deterministic. Routing all binds through the service would still not make the ledger authoritative: Rust installs the account set before hydration, which can then return an error. The book assigns this recovery decision to `rs-platform-wallet`. Have the native owner capture the registrations the reset actually drops, then restore them after the host wipe only for the same live wallet generation and only where no newer registration has landed. Kotlin should perform the Room wipe and forward the recovery operation.
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:553-564: A cancelled or superseded wallet switch can leave a wallet unscanned after Clear
Impact: Android SDK users who switch displayed wallets during Clear can stop seeing incoming shielded payments for a still-loaded wallet until it is rebound.
Clear can restart sync with wallet B missing from the native coordinator. After Clear restores A and snapshots A as the display wallet for the fleet pass, a concurrent `bind(B)` can publish B as the display wallet before it acquires the lifecycle mutex. If the fleet step reaches the new `isMirror` check before B registers, it skips B. Cancelling B while it waits, or switching to C before B reaches `isLatest(turn)`, leaves B’s native bind unrun, and the pass never revisits B. The base pass would have attempted B because its snapshot still named A. Make recovery depend on whether a native registration actually exists, not on which wallet the UI has selected.
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:524-531: A bind cancelled before JNI starts can still replace the wallet’s scan accounts
Impact: Android SDK callers that cancel a queued account change can still have the previous accounts stop scanning and their local scan and recovery state purged.
An account change can now reach Rust after its caller cancels it while it is still queued for I/O. `NonCancellable` wraps the entire manager call, including teardown-gate admission and the dispatch to `Dispatchers.IO`; the base call made that dispatch with the caller’s job. This is not just delivery of an already-completed result: `register_locked` replaces the account set and purges state for dropped accounts. Keep admission and dispatch cancellable and preserve only the outcome of a call that actually completed, using the existing `TeardownGate.opReturningCompletedResult` pattern at the manager’s JNI boundary.
In `packages/kotlin-sdk/sdk/src/test/kotlin/org/dashfoundation/dashsdk/services/ShieldedServiceTest.kt`:
- [SUGGESTION] packages/kotlin-sdk/sdk/src/test/kotlin/org/dashfoundation/dashsdk/services/ShieldedServiceTest.kt:418-432: The new race test passes without running Clear or either bind path
Impact: A regression in production recovery or in recording a completed bind during cancellation can pass the new test.
The test verifies that the mutex serializes two updates to a test-owned ledger. It never calls `clearLocalState`, `bind`, or `bindEngine`, so it cannot catch production code that skips a pending display bind or loses a completed bind’s outcome on cancellation. Exercise the production paths with a controllable native bind and verify that a superseded bind leaves the wallet eligible for recovery and that a bind completed during cancellation is the one the next Clear preserves.
Out-of-scope follow-up suggestions (1)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- A direct manager bind can still run between the native reset and the Room wipe — The service mutex does not cover direct manager calls. On both the base and this head, such a bind can restore pre-Clear Room rows after the native reset but before Android deletes them.
- Follow-up: Close this existing admission gap in #5934, which moves the host wipe under native Clear admission.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…ers it again The first version of this fix kept a record in the Kotlin service of the accounts it had bound each wallet with. Review showed the record is not authoritative: a bind made on the manager, a wallet removed and imported again, or a bind that failed after Rust installed its accounts all leave it wrong, and a Clear would then put a wallet back on an old list. Rust already holds the answer. A wallet handle keeps its shielded keys across a Clear, which drops only the coordinator's registration. So: - `PlatformWallet::shielded_ordinary_account_indices()` returns the accounts a host passes to bind the wallet again (identity accounts, which a bind adds itself, left out). - `platform_wallet_manager_shielded_ordinary_accounts` and the JNI export `shieldedOrdinaryAccounts` marshal it; `PlatformWalletManager.shieldedOrdinaryAccounts` exposes it in Kotlin. - Clear's fleet pass reads that list inside the step that binds, and uses the default account only for a wallet Rust holds no accounts for. The Kotlin record, the non-cancellable bind and the in-step mirror check are removed; `bind` and `bindEngine` behave as before this pull request. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Updated after discussion: 1 finding(s) of this review were settled in the inline threads; 1 blocking finding(s) still stand.
- ✅ Withdrawn: 🟡 Reading shielded accounts from a native balance callback aborts the process
Changes requested: 1 blocker
- Clear can replace a newer shielded account selection with an old one —
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:743-746(thread, carried)
Impact: An Android SDK app that switches a secondary wallet to account 0 through the public manager during Clear can see the bind succeed but stop receiving scan results for that account.
New on this head: This revision removes the Kotlin account ledger. After Clear wipes local state, the Android SDK reads each non-displayed wallet’s retained account indices from Rust and passes them back to bind. The Rust workspace tests and Kotlin x86_64 emulator build and tests were pending when checked; no code check had failed.
🔴 1 blocking | 🟡 4 3 suggestion(s)
Still open from earlier rounds (1)
- 🔴 Blocking: Clear can replace a newer shielded account selection with an old one —
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:743-746(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — The change spans Rust, FFI, JNI, and Kotlin and requires checking concurrency during Clear, but it preserves existing scan registrations without changing key handling, funds movement, or consensus rules. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(lane failed),glm-5.3-flash(not used above high effort; tier asks max) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/wallet/WalletManagerRoundTripTest.kt`:
- [SUGGESTION] packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/wallet/WalletManagerRoundTripTest.kt:400-405: The Clear test passes even if the second wallet is never registered again
Impact: Android emulator CI can pass this regression test even when Clear leaves the secondary wallet out of subsequent shielded scans.
The test detects a rebind to `[0]` but not a skipped or failed rebind that leaves the registry empty. Both assertions read retained wallet keys, which Clear deliberately leaves intact when it empties the coordinator’s registration map; the preceding test explicitly verifies that distinction. Assert the live account set for the second wallet after `clearLocalState`, for example through a test-only probe of the native local balance snapshot, which reports `Unbound` when there is no registration and includes account indices when ready.
- [SUGGESTION] packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/wallet/WalletManagerRoundTripTest.kt:394-398: The offline Clear test can start a live testnet scan
Impact: The Android emulator test can make a live DAPI request and run network-dependent teardown instead of remaining offline.
Stopping sync in `finally` cannot prevent a request that has already started. `Sdk.create` does not connect at construction, but the fixture’s default testnet configuration selects live DAPI endpoints. Clear starts the shielded worker, which calls `sync_now(false)` before its first sleep and can reach the encrypted-note stream before the test’s stop call. Use a mocked or local DAPI transport, or suppress the worker restart in this fixture while still exercising fleet recovery.
In `packages/rs-platform-wallet-ffi/src/shielded_sync.rs`:
- [SUGGESTION → WITHDRAWN in discussion; do not fix] packages/rs-platform-wallet-ffi/src/shielded_sync.rs:818-825: Reading shielded accounts from a native balance callback aborts the process
Impact: A C ABI consumer that calls the new account getter inline from a shielded balance callback can lose the process instead of receiving an FFI error.
An inline account read can terminate the host. The balance emitter runs on a Tokio task and invokes the C callback synchronously. The getter then calls `runtime().block_on` from inside an active runtime, which panics; a panic reaching this `extern "C"` frame aborts before the outer JNI guard could catch it. The normal Kotlin path dispatches onto `Dispatchers.IO`, so it does not hit this calling context. Avoid nested `block_on` or reject that context before entering it. The existing `catch_query_panic` helper can contain unexpected unwinds on builds that support them, but it cannot replace the early check on abort builds.
In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/WalletManagerNative.kt`:
- [SUGGESTION] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/WalletManagerNative.kt:629-638: The new Android recovery bridge has no caller in the reference Swift app
Impact: Android adds a native recovery API with no consumer or coverage in the reference Swift app, contrary to the Kotlin SDK’s bridge rule.
`packages/kotlin-sdk/CLAUDE.md` permits bridging an FFI function only when the reference Swift app has a caller. Swift Clear does not re-register wallets inline, but its subsequent Sync Now path does run a fleet rebind; that path still uses the default account and does not call this export. The lack of an immediate iOS behavior change does not satisfy the caller rule. When moving recovery into Rust, expose the shared recovery operation and use it from Swift’s existing post-Clear rebind path as well, rather than adding an unused Swift wrapper for the getter.
In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt`:
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:743-746: Clear can replace a newer shielded account selection with an old one
(carried; thread: https://github.com/dashpay/platform/pull/6171#discussion_r4673436337)
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix. |
The on-device Clear test read the wallet's accounts only. The keys outlive the reset, so it would also have passed if the wallet was never registered again, and the Clear it ran restarted the sync loop against live endpoints. Clear's fleet pass is now its own internal function. The test runs the reset and then that pass, with no sync restart, and waits for Rust to announce the wallet as unbound after the reset and as registered after the pass, before it checks the accounts. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Changes requested: 1 blocker
- Clear can replace a newer shielded account selection with an old one —
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:765-770(thread, carried)
Impact: An Android SDK app that switches a secondary wallet to account 0 while Clear is restoring that wallet can miss incoming payments to account 0 even though the switch succeeds.
New on this head: This revision extracts Android Clear’s fleet re-registration step so the emulator test can observe the secondary wallet leave and rejoin the native registry without starting a shielded scan. The Kotlin SDK build and x86_64 emulator suite passed on the reviewed head; review and PR Hygiene checks are pending.
🔴 1 blocking | 🟡 2 suggestion(s)
Still open from earlier rounds (1)
- 🔴 Blocking: Clear can replace a newer shielded account selection with an old one —
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:765-770(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — The fix changes wallet re-registration ordering and adds a read path across Rust, FFI, JNI, and Kotlin, but it does not change key handling, funds movement, or consensus rules. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(lane failed),glm-5.3-flash(not used above high effort; tier asks max) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/wallet/WalletManagerRoundTripTest.kt`:
- [SUGGESTION] packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/wallet/WalletManagerRoundTripTest.kt:424-434: The recovery test passes when the second wallet registers but its ledger fails to restore
Impact: Android emulator CI can pass the fleet-recovery test even if the secondary wallet is registered with an unavailable local ledger.
The new wait catches a skipped registration, but it also accepts `RestoreIncomplete`. Rust installs the coordinator registration and publishes the wallet’s keys before restoring its local ledger. If the restore fails, the fleet pass logs the error and continues, so both the non-`Unbound` wait and the retained-key assertion can pass. Wait for `Ready` and assert the account indices from that coordinator snapshot. In this fixture, `Ready` confirms hydration without requiring a scan or a known balance.
- [SUGGESTION] packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/wallet/WalletManagerRoundTripTest.kt:372-374: The test’s SDK setup still makes live quorum requests without a shielded scan
Impact: Running the regression test can send background HTTP requests to the default testnet quorum service even though the fixture is documented as offline.
The extracted fleet pass removes the shielded scan, but the new claim that nothing contacts the network overlooks fixture setup. `setUp` creates the default adaptive testnet SDK. On a successful build, `rs-sdk-ffi/src/sdk.rs` spawns `refresh_quorum_caches`, which requests both current and previous quorum lists from the trusted provider. The test does not await the prefetch, so it can pass either way. To keep the fixture offline, use testnet connection overrides that point both DAPI and the quorum provider at local endpoints.
In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt`:
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:765-770: Clear can replace a newer shielded account selection with an old one
(carried; thread: https://github.com/dashpay/platform/pull/6171#discussion_r4673436337)
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix. |
… again The fleet pass test accepted any state other than unbound, so a wallet whose registration went through but whose ledger failed to restore would have passed. It now waits for the ready state and takes the accounts from that coordinator snapshot. The two new tests no longer claim that nothing contacts the network: they start no shielded sync, but they share this class's SDK fixture. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Nothing blocks: no blocking finding stands on this head.
Not counted: 1 disputed blocking finding(s) left to maintainers.
New on this head: The latest commit tightens the Android Clear regression test: after observing the secondary wallet become Unbound, it waits for a new Ready snapshot and verifies that the coordinator restored accounts 1 and 2. The Kotlin SDK build and x86_64 emulator tests passed on this head; the Rust workspace tests were still pending.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Disputed — left to maintainers (1)
- 🔴 Blocking: Clear can replace a newer shielded account selection with an old one —
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.kt:565-569(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — The fix changes Clear and rebind ordering across Kotlin, JNI, FFI, and Rust, but it reads existing account indices and reuses the existing bind rather than changing key handling, funds movement, or consensus. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(lane failed),glm-5.3-flash(not used above high effort; tier asks max) - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.
No unresolved findings remain from the prior review on this head.
Not approved: 1 blocking finding(s) are disputed and left to the maintainers.
|
Bots are done — your move: post |
Basic explanation
What this does. On Android, a shielded Clear resets the Rust shielded store, which drops every wallet's registration, and then registers the loaded wallets again. It registered every wallet except the displayed one (the "mirror") with account
[0], whatever accounts the wallet had before. After this change the app asks Rust which accounts each wallet has and registers it with those.Value. An app built on the SDK that binds a wallet with accounts other than
[0]no longer silently loses them (they stop being scanned) every time the user presses Clear.ShieldedService.boundAccountscan no longer say[1]while Rust scans[0].Risks. Small. One new read-only function from Rust through the FFI and JNI to Kotlin; nothing existing changes signature. KotlinExampleApp binds every wallet with
[0], so its behaviour is the same before and after. A native library older than the Kotlin code would lack the new JNI symbol; both are built from the same commit.Before and after
Wallets A (the mirror, bound with
[0]) and B (bound with[1, 2]), Clear pressed:[0][0](accounts 1 and 2 are no longer scanned)[0][1, 2]The late-mirror case: A is the mirror, Clear has reset Rust and read "the mirror is A"; then B becomes the mirror and binds
[1].boundAccounts[0](the fleet pass treated B as an "other" wallet and replaced its registration)[1][1](the pass reads[1]from Rust and registers the same accounts again)[1]A wallet Rust holds no accounts for (loaded, never bound) still comes back with
[0], as today.Issue being fixed or feature implemented
Closes #5989.
ShieldedService.clearLocalStatere-binds the mirror and then ranbindEngine(mgr, other.walletId, dbPath)for every other loaded wallet.bindEnginedefaultsaccountstolistOf(0), and Rust's bind replaces the wallet's ordinary account set, so:[0];[0].ShieldedServiceis part of the SDK andbind/bindEnginetake any account list, so a consumer can hit both even though KotlinExampleApp cannot.What was done?
Rust already holds the answer: a wallet handle keeps its shielded keys across a Clear, which drops only the coordinator's registration. So the host reads the list from Rust and passes it to the existing bind. It keeps no copy of its own.
platform-wallet):PlatformWallet::shielded_ordinary_account_indices(), the wallet's bound accounts without the identity accounts (a bind adds those itself and refuses them from a host).platform-wallet-ffi):platform_wallet_manager_shielded_ordinary_accounts, which only marshals that list into a caller buffer.WalletManagerNative.shieldedOrdinaryAccountsandPlatformWalletManager.shieldedOrdinaryAccounts(walletId): List<Int>.ShieldedService.clearLocalState: the fleet pass reads that list inside the same ledger lifecycle step as the bind, so no bind of this service can change the accounts between the read and the bind.NEVER_BOUND_ACCOUNTS([0]) is used only when Rust holds none. The mirror skip is the one the base branch has.History of this pull request. The first commit kept a record in the Kotlin service of the accounts it had bound each wallet with. Review showed it was not authoritative (a bind made on the manager, a wallet removed and imported again, or a bind that failed after Rust installed its accounts all left it wrong), so the second commit removes it together with the non-cancellable bind and the in-step mirror check it needed.
bindandbindEnginebehave as on the base branch.One gap that stays. A bind made directly on
PlatformWalletManagerbetween the pass's read and its bind is outside the service's lock and can be replaced by the list read just before it. The base branch replaces with[0]unconditionally, at any time since the reset. Nothing in this repository binds directly on the manager (both call sites are in the service), and the wallet's next bind puts it right. Closing it means Rust choosing the accounts under its own lock, in the same step as the registration; that operation is tracked in #6194 and touches the bind entry points #5934 (v5.2-dev) restructures, so it is not done here.Out of scope, on purpose:
AppContainer.rebindWalletScopedServicespasses the default[0]for every wallet on each rebind pass. That is the caller's choice of arguments, and it is unchanged.Public interface changes
Rust,
platform-walletPlatformWallet::shielded_ordinary_account_indices(&self) -> Vec<u32>(featureshielded). Ascending. The accounts of the wallet's last bind plus any added since, without identity accounts. Unchanged by a Clear. Empty for a wallet never bound on this handle.C ABI,
platform-wallet-ffiplatform_wallet_manager_shielded_ordinary_accounts(handle, wallet_id_bytes, out_accounts: *mut u32, accounts_capacity: usize, out_count: *mut usize).*out_count = 0.ErrorWalletOperation, outputs untouched.accounts_capacity:ErrorInvalidParameternaming both numbers, nothing written. A bind accepts at most 64 accounts, so a 64-entry buffer always holds the list of a wallet bound through the FFI.JNI and Kotlin
WalletManagerNative.shieldedOrdinaryAccounts(managerHandle: Long, walletId: ByteArray): IntArray(internal), symbolJava_org_dashfoundation_dashsdk_ffi_WalletManagerNative_shieldedOrdinaryAccounts. Passes a 64-entry buffer; an index that does not fit a JVMintthrows instead of being bit-cast.suspend fun PlatformWalletManager.shieldedOrdinaryAccounts(walletId: ByteArray): List<Int>. Runs onDispatchers.IO; throws a mappedDashSdkErrorfor an unknown wallet.ShieldedService.registerOtherWalletsAgain(mgr, dbPath): the fleet pass, split out ofclearLocalStateso the on-device test can run it.ShieldedService.bind,bindEngine(default[0]kept) andengineBindOtherWalletskeep their signatures and behaviour. Observable change: afterclearLocalState, a non-mirror wallet is registered with the accounts Rust holds for it (before:[0]).Swift: nothing changes.
Comparison with Swift
SwiftExampleApp/Core/Services/ShieldedService.swift: Swift'sclearLocalStateregisters nothing again. It resets Rust, wipes SwiftData and stops. The next Sync Now (manualSync) binds the mirror withboundAccountsand engine-binds the other wallets with the default[0]. Swift's service lives in the example app, not in the SDK, and all its callers pass[0], so the question of other account lists does not come up there.This is a knowing exception to the Kotlin SDK rule "bridge an FFI function only when the reference Swift app has a caller for it": the new FFI function has no Swift wrapper and no Swift caller, because a caller there would change nothing. The shared Rust operation in #6194 is the one both platforms' post-Clear rebind paths would call.
How Has This Been Tested?
cargo test -p platform-wallet --all-features --locked --lib -- should_report_only_the_ordinary_accounts should_keep_the_ordinary_accounts should_report_no_ordinary_accounts: 3 passed.should_report_only_the_ordinary_accounts_of_a_bound_wallet(bound[2, 1]with an identity account prepared:[1, 2])should_keep_the_ordinary_accounts_after_a_clear_and_register_them_againshould_report_no_ordinary_accounts_for_a_wallet_never_boundcargo test -p platform-wallet-ffi --all-features --locked --lib -- should_return_the_ordinary_accounts_after_clear_through_the_export should_return_no_accounts_for_an_unbound_wallet should_refuse_an_unknown_wallet should_refuse_a_buffer_too_small_for_the_ordinary_accounts: 4 passed.cargo clippy -p platform-wallet -p platform-wallet-ffi -p rs-unified-sdk-jni --all-targets --all-features --locked -- -D warnings: clean.cargo fmt --all -- --check: clean.packages/kotlin-sdkwith Homebrew JDK 17:./gradlew :sdk:compileDebugAndroidTestKotlin :sdk:testDebugUnitTest --tests '*ShieldedService*' --tests '*ShieldedEngineBindPlan*' :app:compileDebugKotlin: BUILD SUCCESSFUL.WalletManagerRoundTripTestand compile; they run in CI's emulator job, not locally:shieldedOrdinaryAccountsOutliveAClearAndBindAgain: the JNI read before a bind, after it, after a Clear, and after binding again with the list read back.shieldedClearRegistersAnotherWalletAgainWithItsOwnAccounts: two wallets, the second bound throughShieldedService.bindEnginewith[2, 1]. It runs the native reset and then the service's fleet pass (registerOtherWalletsAgain, the part ofclearLocalStatebetween the Room wipe and the sync restart), so it starts no shielded sync. It waits for Rust to announce the second wallet as unbound after the reset and as ready (registered, ledger restored) after the pass, and requires that coordinator snapshot to hold accounts 1 and 2 (the bug gives[0]).Not yet verified
build_android.shwas not run, and nothing loaded the native library locally: the JNI symbol name, its(J[B)[Idescriptor and the array handling are checked only by the two on-device tests above, which have not run yet. A mismatch would surface asUnsatisfiedLinkError.clearLocalStateas a whole (reset, Room wipe, mirror re-bind, fleet pass, sync restart) is not run by a test: its sync restart would contact live endpoints. The on-device test covers the reset and the fleet pass.[0]from its UI.Breaking Changes
None.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
82c7073/self-reviewedkotlin-sdk(packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/wallet/WalletManagerRoundTripTest.kt,packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/WalletManagerNative.kt,packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/services/ShieldedService.ktand 2 more) — HashEngineeringrs-platform-wallet-ffi(packages/rs-platform-wallet-ffi/src/shielded_sync.rs) — HashEngineering or ZocoLini or llbartekll or romchornyirs-platform-wallet(packages/rs-platform-wallet/src/wallet/platform_wallet.rs,packages/rs-platform-wallet/src/wallet/shielded/viewing_key_bind_tests.rs) — HashEngineering or ZocoLini or llbartekll or romchornyiWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.