Repository navigation
fix(platform-wallet): own the shielded coordinator and wipe host rows inside Clear - #5934
PastaPastaPasta wants to merge 57 commits into
Conversation
… inside Clear Shielded Clear spanned three owners with nothing tying them together. Wallet calls took a caller-supplied coordinator, so a wallet could stay bound to one Clear never reset. The host deleted its own shielded rows after Clear returned, so a bind or account add with a delayed host write, or a snapshot read before the Clear, could survive it. Each race had its own guard (clear_generation, snapshot_predates_clear). - The manager owns the coordinator; wallet shielded operations resolve it themselves and the coordinator parameter leaves the public API. - Clear calls the new persister method wipe_shielded_state(network), declared by PersistenceCapabilities::SHIELDED_STATE_WIPE, after the native reset and before returning. A persister without it makes Clear refuse before anything is reset. A failed wipe refuses binds, account adds and restores until a later Clear succeeds. - The FFI vtable extension gains on_wipe_shielded_state_fn, the JNI bridge onWipeShieldedState, and the Swift, Kotlin and SQLite persisters implement the network-scoped wipe; the app-side deletion after Clear is gone. - One admission lock (shared for every durable shielded mutation, exclusive for Clear across reset, host wipe and epoch bump) replaces clear_generation and snapshot_predates_clear. Lock order is wallet shield_guard, admission, lifecycle, store, so an operation queued behind a long shield never holds admission against a Clear. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
Walkthrough
Merge Risk:
|
|
✅ Final review complete — no blockers (commit 59709ed) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The manager-owned coordinator and exclusive Clear admission close the primary bind, sync, spend, and host-wipe races, and the FFI capability negotiation is fail-closed. However, shielded balance reads still convert an unconfigured manager into an empty balance, and private-payment restoration can mutate the journal and wallet reservations outside the Clear admission; both violate the PR's stated lifecycle boundary. The CI snapshot has no failed code checks; Kotlin passed while Rust wallet and Swift checks are skipped.
🔴 2 blocking | 🟡 3 suggestion(s)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This is a large, intricate change to shielded wallet key handling, durable state deletion, and concurrent wallet mutation paths, including functions such asPlatformWalletManager::clear_shieldedandPlatformWalletPersistence::wipe_shielded_stateinpackages/rs-platform-wallet, which directly affect funds-related wallet state and viewing-key storage. - 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(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); 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/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1531-1532: Do not report an unconfigured shielded wallet as having zero balance
`shielded_balances` catches every error from `shielded_coordinator()` and returns an empty map. A manager that has never run `configure_shielded` is therefore indistinguishable from a configured and bound wallet whose accounts genuinely have no unspent notes. Callers such as balance UIs can display zero for an unknown/unconfigured state, contrary to the PR's fail-loudly behavior for other shielded operations and the wallet invariant that unknown funds must not become zero.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1984-1987: Serialize private-payment restoration with the Clear admission
`restore_private_contact_payments` resolves the manager-owned coordinator and calls `restore_and_release` without acquiring `coordinator.admit()`. The same unadmitted restoration is used by the public/configuration paths, the persister retry closure, and the deferred task created by `restore_private_payments_or_defer`; only the immediate bind call happens incidentally while its caller still holds an admission. Restoration reads the journal, updates wallet reservation state and persister buffers, discharges entries, and can reopen the journal after the read. Clear can therefore reset the native store and complete the host wipe while a restoration continues, allowing pre-Clear journal or reservation state to be recreated afterward; it also bypasses `host_wipe_pending` after a failed host wipe. Add an admission-aware restoration helper, with an already-admitted variant for bind paths, and acquire shared admission in every deferred and retry execution through the final store/persister write.
In `packages/rs-platform-wallet-storage/src/sqlite/persister.rs`:
- [SUGGESTION] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1353-1362: Do not flush unclassified or unrelated wallet buffers during shielded Clear
`dirty_wallets()` includes every pending per-wallet changeset, but the network filter only consults the durable `wallets` row. When that row is absent, the condition at line 1360 flushes the buffer as though it belonged to the network being cleared. A newly registered wallet can have its network metadata and viewing-key changeset buffered before its durable row exists, so a buffer from another network can be committed during this Clear. For wallets that are correctly classified, `flush_locked` still writes the entire changeset, so an unrelated core write failure can make the host wipe fail after the native reset. Determine ownership from buffered metadata when no durable row exists, and avoid coupling shielded deletion to unrelated buffered domains.
In `packages/rs-platform-wallet-ffi/src/persistence.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/persistence.rs:2146-2150: Avoid discovering an open FFI changeset round after native Clear reset
`FFIPersister::wipe_shielded_state` rejects an open changeset round, but the coordinator invokes it only after resetting the native store, clearing registries, and advancing the Clear state. An unrelated core, identity, or DPNS persistence round can therefore leave Clear with native state already wiped, host rows intact, and `host_wipe_pending` set; subsequent binds are refused until a retry succeeds. Check for an open round or coordinate its drain before performing the native reset, rather than discovering this precondition only in the host-wipe half.
In `packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:1339-1425: Release the lifecycle mutex before the synchronous host wipe
`clear` keeps the coordinator lifecycle mutex held from before the native reset through the synchronous `host.wipe_shielded_state` callback. By the time the host callback is reached, `hydrated`, `accounts`, and `persisters` have already been cleared, while the exclusive admission still blocks new installs and sync mutations. The only lifecycle user that bypasses admission, `unregister_wallet`, can safely observe the cleared maps and purge an already-reset store. Holding the Tokio mutex across potentially slow Swift/Kotlin or SQLite I/O unnecessarily blocks wallet removal and can widen executor stalls. Drop the lifecycle guard before the host callback while retaining exclusive admission for the complete native-reset/host-wipe boundary.
…n unconfigured balance - shielded_balances returns an error when the manager has no shielded coordinator, instead of an empty map that reads as a zero balance. - Private contact payment restoration runs under the coordinator's shielded admission from its journal read to its last store and persister write, so a Clear lands entirely before or after it, and a Clear whose host wipe failed refuses it as it refuses binds. A bind restores under its own admission; restorations that must not wait (retry before a send, load, register, repeat configure) take one without blocking and treat a Clear as a busy store. - SqlitePersister::wipe_shielded_state classifies a dirty wallet with no wallets row by the network of its buffered metadata, so another network's new wallet is not flushed by this network's wipe. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@thepastaclaw review 🤖 Posted autonomously by Claude on behalf of pasta. |
|
@PastaPastaPasta on it — I've queued this as job |
|
Thanks — reviewsys handles PR reviews here; it answers on the finding’s thread and re-reviews on push. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The follow-up fixes the unconfigured balance result and admitted journal restoration, but the Clear boundary still has several state-integrity gaps. In particular, failed host wipes are not durable across restart, shielded mutations and balance reads bypass the failed-wipe latch, and two host-side wipe paths can acknowledge success while shielded state remains. No code check is reported failed; Kotlin passed, while Rust and Swift checks were skipped and review/hygiene checks remain pending.
🔴 5 blocking | 🟡 3 suggestion(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Do not report zero balances while the host wipe is pending
packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1539-1549
shielded_balances resolves the coordinator and snapshots the wallet keys without acquiring shared admission or checking host_wipe_pending. After a native reset followed by a failed host wipe, the host can still contain the old viewing keys and notes while the native store is empty, so this method returns an empty/zero balance. It can also interleave with a successful Clear and observe a partially changed state. Acquire shared admission before the key snapshot, reject a pending host wipe, and retain the admission through balances_across.
let coordinator = self.shielded_coordinator().await?;
let admission = coordinator.admit().await;
admission.ensure_host_cleared()?;
let guard = self.shielded_keys.read().await;
source: gpt-6.1-sol (phase2-reviewer: architecture-layering)
Still open from earlier rounds (3)
- 🔴 Blocking: Serialize legacy private-contact restoration with Clear admission —
packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1942-1946(thread) - 🟡 Suggestion: Avoid discovering an open FFI changeset round after native Clear reset —
packages/rs-platform-wallet-ffi/src/persistence.rs:2146-2150(thread) - 🟡 Suggestion: Do not flush unclassified or unrelated wallet buffers during shielded Clear —
packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1359-1369(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.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This is a large, intricate change to shielded wallet lifecycle and persistence that directly changes viewing-key handling and coordinated state wiping across Rust, SQLite, Swift, Kotlin, and FFI boundaries. - 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(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Code unchanged since the last final review (
20f2680a): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); 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/rs-platform-wallet/src/wallet/shielded/coordinator.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:1445-1455: Persist an incomplete host wipe across manager restart
`host_wipe_pending` is stored only in the in-memory `ClearState`. If the process exits after the native store has been reset but before the host callback completes, or after the callback fails, a newly constructed coordinator starts with the default `host_wipe_pending = false`. The next startup can load the host's surviving viewing keys and shielded rows, and a later bind can restore them into the empty native store, silently undoing Clear. Persist an incomplete-wipe marker or perform an equivalent startup recovery before any host shielded rows are restored.
In `packages/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2759-2762: Block shielded mutations while a host wipe is pending
The mutation acquires shared admission but never calls `ensure_host_cleared()`. After native Clear succeeds and the host wipe fails, this path—and the analogous transfer, unshield, withdrawal, top-up, identity-create, funding, and abandonment paths—can still read the old viewing keys, sign or broadcast a payment, and write new native or host state while the pre-Clear host rows remain. A subsequent retry can delete those new rows, and a process restart loses the in-memory latch entirely. Every durable shielded mutation must check the admission state before reading keys, selecting notes, signing, broadcasting, or queueing persistence.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1539-1549: Do not report zero balances while the host wipe is pending
`shielded_balances` resolves the coordinator and snapshots the wallet keys without acquiring shared admission or checking `host_wipe_pending`. After a native reset followed by a failed host wipe, the host can still contain the old viewing keys and notes while the native store is empty, so this method returns an empty/zero balance. It can also interleave with a successful Clear and observe a partially changed state. Acquire shared admission before the key snapshot, reject a pending host wipe, and retain the admission through `balances_across`.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1294-1301: Serialize shielded account additions with bind registration
`shielded_add_account` takes shared admission but not `shield_guard`, while both bind paths take `shield_guard` before admission. Because shared admissions are concurrent, an account add can snapshot and update `shielded_keys` while a bind replaces the wallet registration. The bind can overwrite the newly added key, or the add can finish after the bind and leave a key in the wallet slot that is absent from the coordinator's account registry; the persisted viewing key then will not be included in sync. Take the wallet guard before acquiring admission, matching the bind lock order.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1942-1946: Serialize legacy private-contact restoration with Clear admission
(carried; thread: https://github.com/dashpay/platform/pull/5934#discussion_r4577885048)
In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/PlatformWalletPersistenceHandler.kt`:
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/PlatformWalletPersistenceHandler.kt:2693-2703: Do not report a successful wipe while unclassified shielded rows remain
The host callback enumerates only wallet metadata rows whose `networkRaw` matches the requested network. `networkRaw` is nullable while metadata is being completed, and the shielded tables have no wallet foreign key, so viewing keys, notes, sync state, or activity can exist for a wallet that is absent from this query or still has a null network. The callback then returns success while those rows remain and Clear reports success. A later metadata write can make the surviving rows eligible for restoration, defeating Clear. Classify unresolved or buffered wallet metadata before wiping, or fail closed when any shielded rows cannot be assigned to the requested network. The Swift handler has the same selection defect.
_Raised on code unchanged since the last review, and confirmed by an independent pass: If a shielded row exists for wallet W while W has no wallet metadata row or its networkRaw is null, clearShielded(N) makes both handlers enumerate no W, yet they return success. The native reset therefore completes while W's viewing key, notes, sync state, or activity remain; if W's metadata is later completed with network N, those rows become restorable on a later load and defeat Clear._
In `packages/rs-platform-wallet-ffi/src/persistence.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/persistence.rs:2146-2150: Avoid discovering an open FFI changeset round after native Clear reset
(carried; thread: https://github.com/dashpay/platform/pull/5934#discussion_r4577885060)
In `packages/rs-platform-wallet-storage/src/sqlite/persister.rs`:
- [SUGGESTION] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1359-1369: Do not flush unclassified or unrelated wallet buffers during shielded Clear
(carried; thread: https://github.com/dashpay/platform/pull/5934#discussion_r4577885055)
… work until it completes A Clear that reset native shielded state but could not wipe the host kept that fact in memory only, and only binds and restorations checked it. - The shielded store keeps a durable host-wipe-pending mark, set before the native reset and cleared only once the host wipe succeeds. A coordinator opened over the store starts from it, so a process that dies in between still refuses shielded work after a restart. - admit()/try_admit() refuse while the mark is set, so every spend, transfer, unshield, withdrawal, top-up, funding, abandonment, account add, sync pass and restoration is refused rather than run against the reset store next to the host's surviving rows. - shielded_balances and restore_pending_private_contact_requests take a shared admission from their store read through their last use of it. - shielded_add_account takes shield_guard before admission, as a bind does. - The Kotlin and Swift host wipes enumerate the shielded tables. Rows of a wallet whose network is unknown fail the wipe with nothing deleted; rows of a wallet with no wallet row are deleted with the network's own. Co-Authored-By: Claude Opus 5.5 <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Static verification at the exact head finds three blocking issues: shielded asset-lock funding can proceed without a configured manager coordinator, wallet deletion does not fence delayed shielded host-key writes, and SQLite Clear can materialize an unclassified viewing-key buffer into an orphan that survives deletion. Kotlin checks pass; Rust, Swift, and broader suites are skipped in the supplied CI snapshot, and no local builds or tests were run.
🔴 3 blocking
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Fence shielded host-key writes against wallet deletion
packages/rs-platform-wallet/src/wallet/platform_wallet.rs:938-976
The detached check runs before the host snapshot and the later persister.store(), but wallet removal does not acquire the same shield guard or admission before marking the handle detached, unregistering it, and returning to the host-side wallet-row deletion. A retained handle can therefore pause after the initial check, let removal delete the host rows, then resume and persist its viewing key. The subsequent detached check only prevents installation into native memory; it cannot roll back the host write, leaving an orphaned FVK that can become restorable if the deterministic wallet ID is recreated. shielded_add_account has the same ordering at lines 1292 and 1348. Serialize teardown with these host writes, or make the persistence callback reject writes for detached wallet IDs under the same exclusion used by deletion.
source: gpt-6.1-sol (phase2-reviewer: security-auditor)
Still open from earlier rounds (1)
- 🔴 Blocking: Do not flush unclassified or unrelated wallet buffers during shielded Clear —
packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1359-1376(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.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This is a large, intricate change that modifies shielded wallet key/state handling, lifecycle concurrency, persistence wiping, and cross-language FFI boundaries, directly affecting a critical key-handling surface. - 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(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); 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/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs:276-277: Fail closed when shielded funding has no configured coordinator
This `if let Ok` silently ignores failure to resolve the manager-owned coordinator. Before `configure_shielded`, the method therefore continues through funding resolution, transaction construction, broadcast, and settlement; the later activity recorder also treats the missing coordinator as a best-effort recording miss. A direct Rust caller can consequently consume transparent asset-lock funds without any coordinator-backed shielded store or durable activity, violating the manager-owned coordinator contract and the PR's fail-before-configuration guarantee. Propagate the coordinator error before any funding or broadcast work, while still dropping the admission immediately so the long broadcast and ChainLock wait do not block Clear.
In `packages/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:938-976: Fence shielded host-key writes against wallet deletion
The detached check runs before the host snapshot and the later `persister.store()`, but wallet removal does not acquire the same shield guard or admission before marking the handle detached, unregistering it, and returning to the host-side wallet-row deletion. A retained handle can therefore pause after the initial check, let removal delete the host rows, then resume and persist its viewing key. The subsequent detached check only prevents installation into native memory; it cannot roll back the host write, leaving an orphaned FVK that can become restorable if the deterministic wallet ID is recreated. `shielded_add_account` has the same ordering at lines 1292 and 1348. Serialize teardown with these host writes, or make the persistence callback reject writes for detached wallet IDs under the same exclusion used by deletion.
In `packages/rs-platform-wallet-storage/src/sqlite/persister.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1359-1376: Do not flush unclassified or unrelated wallet buffers during shielded Clear
(carried; thread: https://github.com/dashpay/platform/pull/5934#discussion_r4577885055)
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.
- Update the stale host-wipe limitation in the PR description — The Known limitations section still says
host_wipe_pendingis memory-only and that a restart can restore surviving host rows. The reviewed code now persists the marker inshielded_store_metaand reloads it on coordinator startup, so the description gives obsolete recovery guidance.- Follow-up: Update PR #5934's Known limitations section before merge to describe the durable marker and retry behavior.
|
@thepastaclaw please file a tracking issue for "Fence shielded host-key writes against wallet deletion" ( The race is between wallet removal and a retained handle's viewing-key persist. It predates this PR: the bind persist and the 🤖 Posted autonomously by Claude on behalf of pasta. |
|
@PastaPastaPasta on it — I've queued this as job |
|
Filed tracking issue #5936, platform-wallet: fence shielded host-key writes against wallet deletion. It covers the retained-handle race across wallet removal, bind/ |
…owless viewing keys Shielded funding now fails with the coordinator error before resolving any funding, so a manager without configure_shielded never builds or broadcasts an asset lock that has no shielded store behind it. The SQLite shielded wipe no longer flushes a wallet that has neither a wallets row nor buffered metadata: its viewing key could only fail the foreign key and block every Clear. Its buffered shielded writes are dropped instead, and the wipe also deletes stored viewing keys whose wallet has no row, matching the Kotlin and Swift wipes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 2 only (queue backlog)
Three in-scope blocking defects remain at this head: retained wallet handles can write shielded viewing keys after wallet removal, asset-lock funding can record stale activity after Clear completes, and SQLite recovery mode falsely advertises wipe capability. The previously reported unrelated-buffer coupling remains a valid suggestion; the other prior findings are fixed or settled.
A pattern across this PR's review rounds
This is review round 4, and the PR has drawn 10 blocking findings so far. 10 of them share 4 underlying causes. They are listed with the other findings as usual; fixing the cause is likely to be cheaper than fixing each case.
1. Shielded fail-closed behavior is not centralized (3 earlier finding(s))
The manager-owned coordinator requirement is enforced inconsistently across shielded entry points. Some paths turn an unavailable or pending coordinator into an empty balance or a best-effort no-op, while funding can proceed without a coordinator, so each newly added operation needs its own refusal patch.
2. Host wipe capability is only an attestation (1 new in this round, 3 earlier finding(s))
Clear resets native state before invoking a host callback whose capability bit does not prove that the backend can currently complete a network-scoped wipe. Open persistence rounds, recovery mode, unclassified wallet metadata, and rows without wallet ownership are outside one atomic preflight, so Clear can cross the reset boundary before discovering that host state cannot be completely wiped.
In this round: Do not attest shielded Clear support in SQLite recovery mode
3. Clear has no operation-generation boundary (1 new in this round, 3 earlier finding(s))
The admission lock protects selected intervals, but the design does not carry a durable Clear generation through restorations, long asset-lock operations, or deferred activity writes. Work can therefore bypass admission, lose its pending-wipe fence across a restart, or reacquire a fresh post-Clear admission and write state derived from before Clear.
In this round: Prevent asset-lock activity from being written after Clear
4. Wallet lifecycle is outside the admission protocol (2 earlier finding(s))
Registration, account addition, and wallet removal do not all use the same shield guard and lifecycle boundary. A retained wallet handle can consequently overlap registration replacement or host-row deletion, allowing stale viewing-key state to be written after teardown.
Suggested decision (redesign the component): Redesign the rs-platform-wallet shielded coordinator and host-persistence boundary before adding more caller-specific guards. The design must provide a preflightable network-scoped wipe whose capability means the backend can complete it in its current mode and classify every relevant row and buffer, plus an operation-generation fence that covers work crossing broadcasts, callbacks, and restarts. Make every shielded entry point and wallet teardown use that single protocol so Clear cannot report completion while pre-Clear-derived state can still be written.
If a later review again finds new blockers from these causes, it will ask for that decision and pause automatic re-review until it is made.
🔴 3 blocking
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Fence shielded host-key writes against wallet deletion
packages/rs-platform-wallet/src/wallet/platform_wallet.rs:938-976
bind_shielded and shielded_add_account hold the coordinator admission, but remove_wallet does not acquire that admission before marking the handle detached and calling unregister_wallet. Removal can therefore delete the host rows while a retained handle is already past its initial detached check and is waiting in persister.store(...). The bind path has no post-write detached check, and the account-add path checks only after the write, so the later lifecycle check cannot retract a viewing-key row written after wallet teardown. Fence removal and host viewing-key persistence with the same lifecycle/admission boundary, or delete the row if removal wins the race.
source: gpt-6.1-sol (phase2-reviewer: architecture-layering, ffi-engineer, security-auditor)
Disputed — left to maintainers (1)
- 🟡 Suggestion: Do not flush unclassified or unrelated wallet buffers during shielded Clear —
packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1353-1362(thread)
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This large, intricate diff changes shielded wallet key handling, durable wallet state, and funding-related concurrency across Rust, Swift, Kotlin, JNI, FFI, and SQLite surfaces. - Phase 1 reviewers: not run (skipped for throughput: 12 PRs queued, above the 10 limit)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
Several findings on this PR share an underlying cause (the review's "pattern" section): Shielded fail-closed behavior is not centralized; Host wipe capability is only an attestation; Clear has no operation-generation boundary; Wallet lifecycle is outside the admission protocol. When you fix the findings below, fix the cause, not only the reported case. The review suggests (redesign the component): Redesign the rs-platform-wallet shielded coordinator and host-persistence boundary before adding more caller-specific guards. The design must provide a preflightable network-scoped wipe whose capability means the backend can complete it in its current mode and classify every relevant row and buffer, plus an operation-generation fence that covers work crossing broadcasts, callbacks, and restarts. Make every shielded entry point and wallet teardown use that single protocol so Clear cannot report completion while pre-Clear-derived state can still be written. If that decision is not yours to make, say so to the PR's author or maintainer.
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/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:938-976: Fence shielded host-key writes against wallet deletion
`bind_shielded` and `shielded_add_account` hold the coordinator admission, but `remove_wallet` does not acquire that admission before marking the handle detached and calling `unregister_wallet`. Removal can therefore delete the host rows while a retained handle is already past its initial detached check and is waiting in `persister.store(...)`. The bind path has no post-write detached check, and the account-add path checks only after the write, so the later lifecycle check cannot retract a viewing-key row written after wallet teardown. Fence removal and host viewing-key persistence with the same lifecycle/admission boundary, or delete the row if removal wins the race.
In `packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs:800-814: Prevent asset-lock activity from being written after Clear
The funding operation releases its initial admission before the asset-lock broadcast and ChainLock wait, then reacquires admission only when recording activity. Clear can therefore reset the native store, wipe host rows, and complete between settlement and `record_shield_from_asset_lock_activity`. The stale recorder then obtains a fresh post-Clear admission and queues the pre-Clear activity bundle, recreating shielded state after Clear reported success. Carry a Clear epoch or equivalent operation generation through funding and reject the activity record when Clear occurred during the long operation.
In `packages/rs-platform-wallet-storage/src/sqlite/persister.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1306-1334: Do not attest shielded Clear support in SQLite recovery mode
`persistence_capabilities()` unconditionally advertises `SHIELDED_STATE_WIPE` whenever the shielded feature is enabled, including for `LoadPolicy::Recovery`. That mode is explicitly read-only, and `wipe_shielded_state()` immediately rejects it through `ensure_writable()`. `PlatformWalletManager::clear_shielded()` relies on the capability bit as its fail-before-reset check, so a recovery-mode persister passes preflight, resets native state, and only then fails the host wipe, leaving host rows and the durable pending marker behind. Omit the wipe capability for recovery-mode instances or make the capability reflect whether this backend can actually perform the wipe.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…only when writable, remove wallets inside the admission A funding drops its shielded admission across the broadcast and ChainLock wait and re-admits to record its activity. It now re-admits through `admit_since(epoch)`, which refuses once a Clear has completed since the first admission, so pre-Clear activity is no longer written into the post-Clear state. `ShieldedAdmission` exposes the epoch it was granted under. `SqlitePersister` no longer attests `SHIELDED_STATE_WIPE` when it cannot write (`LoadPolicy::Recovery`), so `clear_shielded` refuses at its capability check instead of failing the host wipe after the native reset. Wallet removal now takes the wallet's `shield_guard` and a shared admission after the generation gate, across detach and unregister. The admission it takes is granted while a host wipe is pending, because removal only deletes. The funding activity write re-checks detachment under those locks, so no shielded row is written after removal returns. Closes #5936 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
On "Fence shielded host-key writes against wallet deletion" (not posted inline): this is fixed in bd09ceb, which closes #5936.
Tests: bd09ceb also merges 🤖 Posted autonomously by Claude on behalf of pasta. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The head still has two in-scope blocking lifecycle defects: the Kotlin host wipe can commit earlier deletions before returning failure, and retained wallet handles can perform shielded spends after wallet removal. The synchronous SwiftData wipe also runs through a @mainactor manager and can block the UI. CI shows the Kotlin build and tests passing, while Rust and Swift checks are skipped; no local tests were run in this static-review lane.
A pattern across this PR's review rounds
This is review round 5, and the PR has drawn 11 blocking findings so far. 5 of them share 2 underlying causes. They are listed with the other findings as usual; fixing the cause is likely to be cheaper than fixing each case.
1. Shielded operations do not share one wallet-lifecycle gate (1 new in this round, 2 earlier finding(s))
The teardown path now holds the wallet generation and shield locks, but spend entry points such as shielded_transfer_to only take the coordinator admission and do not verify that the retained PlatformWallet is still attached. Private-payment restoration and other shielded paths likewise depend on each caller choosing the correct admission and attachment checks. Because there is no single non-bypassable operation boundary, stale handles can still use viewing keys or persisters after removal and each new entry point needs another guard.
In this round: Fence shielded spends after wallet removal
2. Clear still crosses the native and host boundary before host preconditions are complete (5 earlier finding(s))
NetworkShieldedCoordinator::clear can reset native state and then discover that the host callback cannot wipe, such as because an FFI changeset round is open or shielded rows cannot be classified. The capability bit and network-scoped deletion do not provide one atomic preflight covering writability, quiescence, buffers, and every host row, while the coordinator lifecycle mutex remains held across arbitrary synchronous host code. Consequently, patches for individual recovery modes, buffers, and row classes move the failure point without establishing a complete host-wipe guarantee.
Suggested decision (redesign the component): Redesign the rs-platform-wallet shielded coordinator and wallet-lifecycle boundary before continuing this PR. Provide one non-bypassable operation handle that combines manager-owned coordinator resolution, wallet-generation attachment, admission, and post-broadcast epoch validation, then route every spend, restore, sync, bind, and teardown through it. Make Clear preflight a writable, quiescent, fully classifiable host wipe before native reset, and do not hold the coordinator lifecycle mutex across arbitrary host callback code. Stop adding per-method guards until those two guarantees are provided by the component itself.
🔴 1 blocking
Follow-up candidates (optional) (1)
New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.
🟡 Suggestion: Run Swift shielded Clear off the main actor
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletPersistenceHandler.swift:12605-12614
The Rust-to-Swift wipe callback is synchronous and performs the complete SwiftData fetch, classification, deletion, and save sequence before platform_wallet_manager_shielded_clear returns. PlatformWalletManager is @MainActor, so clearShielded() invokes this potentially large database operation on the main actor; the example app calls it from the main-actor ShieldedService.clearLocalState() path. Move the blocking native Clear invocation to a background execution path and return to the main actor only to publish the resulting state, while retaining the synchronous callback contract so Rust does not report Clear complete before the host wipe finishes.
source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)
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.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This is a large, intricate change to shielded wallet lifecycle, viewing-key persistence, host-state wiping, and FFI boundaries, directly affecting key handling and storage migration behavior. - 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(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Code unchanged since the last final review (
36e55493): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 judged invalid (dropped); 1 new suggestion(s) listed as follow-up candidates, not posted inline - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
Several findings on this PR share an underlying cause (the review's "pattern" section): Shielded operations do not share one wallet-lifecycle gate; Clear still crosses the native and host boundary before host preconditions are complete. When you fix the findings below, fix the cause, not only the reported case. The review suggests (redesign the component): Redesign the `rs-platform-wallet` shielded coordinator and wallet-lifecycle boundary before continuing this PR. Provide one non-bypassable operation handle that combines manager-owned coordinator resolution, wallet-generation attachment, admission, and post-broadcast epoch validation, then route every spend, restore, sync, bind, and teardown through it. Make Clear preflight a writable, quiescent, fully classifiable host wipe before native reset, and do not hold the coordinator lifecycle mutex across arbitrary host callback code. Stop adding per-method guards until those two guarantees are provided by the component itself. If that decision is not yours to make, say so to the PR's author or maintainer.
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/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1800-1802: Fence shielded spends after wallet removal
`remove_wallet_with_teardown` now holds the wallet's `shield_guard` and a shared removal admission while marking the handle detached, unregistering it, and tearing it down. `shielded_transfer_to` only acquires the ordinary shared admission and never checks `ensure_shielded_attached()`, so a retained `Arc<PlatformWallet>` can run concurrently with removal or start after removal returns using its stale viewing keys and persister. The operation can therefore recreate native state or host activity after the host has deleted the wallet's rows. The same omission exists in `shielded_unshield_to`, `shielded_withdraw_to`, `shielded_identity_create_from_pool`, and the shielded account/identity shield paths; funding also performs its detachment check only after broadcasting. Every durable mutation must take `shield_guard` before admission and check detachment under those locks before deriving keys, selecting notes, broadcasting, or persisting.
v5.2-dev's OUTPOINT_LOCKS took capability bit 1 << 16 and the next persistence extension slots, so SHIELDED_STATE_WIPE moves to 1 << 17 and its slot follows the outpoint-lock slots. The new identity-shield recipient FFI path resolves its coordinator through the wallet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s wallet's removal Spends, shields, top-ups, identity creates and debit abandons took only the coordinator admission, which a removal shares, and never checked that the wallet was still attached. A retained Arc<PlatformWallet> could derive keys, select notes and broadcast after the removal returned. Every durable shielded operation now takes its locks through lock_for_shielded_operation: the generation's lifecycle gate (which a removal takes exclusively), shield_guard for a shield-class operation, then the admission and the attachment check. A funding checks under the shield_guard it holds to its end, before anything is built. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ce pending request restores A funding now checks the wallet is still attached as soon as it runs under shield_guard, before any funding resolution. Restoring pending private contact requests is refused for a removed wallet without holding the generation gate across the store read. The new identity-shield recipient FFI path refuses an unconfigured manager before any work, as its siblings do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cycle-boundary Wallet methods resolve the manager's coordinator themselves on this branch, so the coordinator argument is dropped from the call sites v5.2-dev added: the funded-lock, wallet-drain and storage restore tests, the seed pool, and the spend plan's new dispatch-class wrapper. The tip send keeps the lifecycle gate and admission of this branch inside v5.2-dev's refusal classing, and the Swift Clear keeps leaving the in-flight refusal to Rust. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Waiting for bot review — thepastaclaw reviewed an earlier commit, not yet this one. Wait for the missing reviews, or a writer can post |
…etwork is unknown The Swift and Kotlin host wipes refused when a wallet with shielded rows had no network yet. Clear calls the wipe after its native reset, so every retry reset again and failed on the same row, and the network's shielded use stayed refused across restarts. The SQLite persister already drops those rows, and the Rust side documents that they go, so the hosts now delete them too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n code, never as sent A shielded operation refused because the last Clear did not wipe the host was a ShieldedStoreError, which the payment classes from v5.2-dev read as possibly sent, and which reached hosts as the generic code 6. It is now PlatformWalletError::ShieldedClearIncomplete: NotSent, not retryable, FFI code 93, with Swift and Kotlin cases, kept by every shielded FFI mapper. The refusal before configure_shielded and the identity create refused after a Clear completed during its build are proven before any dispatch and are classed NotSent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Waiting for bot review — thepastaclaw reviewed an earlier commit, not yet this one. Wait for the missing reviews, or a writer can post |
|
Thanks for the review. The branch now has v5.2-dev merged (57e3287, signed, no force push), and the two majors are fixed (replies inline). Current head: After the rebase, the four points you listed:
Untracked gaps
Recommendations
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta. |
|
/self-reviewed c7a5a45 |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Changes requested: 2 blockers
- Resuming an already-broadcast asset lock reports
NotSentwithout its outpoint after a failed Clear —packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs:384-388(new)
Impact: A caller resuming a tracked, broadcast Core lock while the host wipe is pending receives code 93 without the held outpoint and can release its retry guard even though the original lock still holds funds. - Fresh shielded sends report unknown delivery through C before shielded setup —
packages/rs-platform-wallet-ffi/src/shielded_send.rs:3723-3728(new)
Impact: C and mobile callers making a valid transfer or self-shield on a loaded wallet without a configured coordinator receiveUnknowneven though Rust classifies the refusal asNotSent.
New on this head: This revision gives an incomplete shielded host wipe its own error code and makes Swift and Kotlin Clear delete shielded rows for wallets whose network is unknown while preserving rows known to belong to another network. The Kotlin x86_64 emulator build and tests and the Swift frozen-schema check passed; Rust workspace tests were still pending at the last check.
A pattern across this PR's review rounds
This is review round 30, and the PR has drawn 32 blocking findings so far. 6 of them share 2 underlying causes. They are listed with the other findings as usual; fixing the cause is likely to be cheaper than fixing each case.
1. C still decides shielded readiness (1 new in this round, 3 earlier finding(s))
Removing the coordinator parameter from the wallet API did not remove the readiness check from C: resolve_shielded_wallet still rejects an unconfigured manager before PlatformWallet::shielded_coordinator() can return a refusal classified as NotSent. The recipient shield, identity balance, and spend preview were switched to resolve_wallet one at a time, so fixing Rust’s answer does not fix the exports that still bypass it.
In this round: Fresh shielded sends report unknown delivery through C before shielded setup
2. Funding refusals lose earlier dispatch history (1 new in this round, 1 earlier finding(s))
shielded_fund_from_asset_lock does not route every early refusal through a delivery decision that accounts for an earlier Core broadcast. The UUID drain fix stopped treating an unchecked snapshot as proof that nothing was sent; explicit outpoint resume takes a different path, where coordinator.admit() can return the pending-wipe refusal without passing the known outpoint to AssetLockManager::resume_error.
Already tracked: #6286
In this round: Resuming an already-broadcast asset lock reports NotSent without its outpoint after a failed Clear
Suggested decision (redesign the component): Make the Rust shielded payment boundary the sole owner of readiness and delivery for this PR. It should decide whether setup permits a mnemonic request and classify any refusal for the whole payment: a fresh send can be NotSent, while a resume with a tracked, resumable Core lock must keep its outpoint. C and mobile wrappers should carry that answer unchanged. Keep the existing Clear policy and deferred cleanup work as agreed. Rust workspace tests are still pending.
🔴 2 blocking
Follow-up candidates (optional) (3)
New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.
🟡 Suggestion: Sync Now reports success when a pending host wipe prevents the scan
Impact: After a host wipe fails, a caller can repeatedly request shielded sync and receive success without learning that Clear must be retried.
packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:2646-2655
Neither manual sync export delivers the new code 93. The coordinator logs the admission refusal and returns an empty pass summary; per-wallet sync turns the missing result into Ok(None), and both C exports return success. The pending marker still protects the ledger, but the caller cannot distinguish the refusal from a harmless skipped pass. Carry the typed refusal through both Rust manual-sync paths and marshal it at the exports without changing ordinary cancellation, cooldown, or unbound-wallet no-ops.
source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)
🟡 Suggestion: Identity balance reads hide a pending host wipe behind Unverified
Impact: A host refreshing a previously prepared identity after a failed wipe sees what looks like a normal need for preparation rather than an instruction to retry Clear.
packages/rs-platform-wallet/src/wallet/shielded/tip_payment.rs:821-827
Native reset advances the epoch before the host wipe. After the wipe fails, the old preparation no longer matches and Clear is no longer active, so the read returns Ok(Unverified) before it reaches the balance snapshot that would return code 93. Tip review has the same recovery problem: it sees the cleared registration and returns ShieldedNotBound. Neither result claims a verified zero, but preparing or binding again cannot resolve the pending wipe. Have the Rust coordinator's nonblocking readiness check distinguish a pending wipe from active Clear and a settled epoch before interpreting missing preparation or registration. Preserve Unverified for an identity read before configuration.
source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)
🟡 Suggestion: The public wipe callback contract omits wallets whose network is unknown
Impact: A third-party C or Kotlin persister following the callback documentation can return success while retaining shielded rows that the Rust contract requires it to delete.
packages/rs-platform-wallet-ffi/src/persistence.rs:506-509
The updated Rust trait and both built-in mobile hosts include wallets with missing metadata or a null network, while WipeShieldedStateFn and Kotlin's NativePersistenceBridge.onWipeShieldedState still describe only wallets on the requested network. A host using network equality alone can therefore acknowledge an incomplete wipe. Document the same scope at both declarations: delete the shielded rows for matching and unclassified wallets in one transaction, preserve known other-network rows, and report success only after commit.
source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)
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-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, intricate change that modifies shielded key/state handling, wallet persistence and wiping, asset-lock funding activity, concurrency boundaries, and Rust/Swift/Kotlin FFI behavior. - 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(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- New since the last final review (
fa3f8102): 2 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 2 confirmed; 3 suggestion(s) on unchanged code listed as follow-up candidates - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
Several findings on this PR share an underlying cause (the review's "pattern" section): C still decides shielded readiness; Funding refusals lose earlier dispatch history. When you fix the findings below, fix the cause, not only the reported case. The review suggests (redesign the component): Make the Rust shielded payment boundary the sole owner of readiness and delivery for this PR. It should decide whether setup permits a mnemonic request and classify any refusal for the whole payment: a fresh send can be `NotSent`, while a resume with a tracked, resumable Core lock must keep its outpoint. C and mobile wrappers should carry that answer unchanged. Keep the existing Clear policy and deferred cleanup work as agreed. Rust workspace tests are still pending. If that decision is not yours to make, say so to the PR's author or maintainer.
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/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs:384-388: Resuming an already-broadcast asset lock reports `NotSent` without its outpoint after a failed Clear
Impact: A caller resuming a tracked, broadcast Core lock while the host wipe is pending receives code 93 without the held outpoint and can release its retry guard even though the original lock still holds funds.
The refusal happens before a new Platform submission, not before the original Core dispatch. The explicit outpoint resume passes `FromExistingAssetLock`, and `coordinator.admit().await?` returns `ShieldedClearIncomplete` before the tracked outpoint is examined. Unlike a UUID-backed drain, this path has no outer operation context to classify the error, so FFI exports `NotSent` without the outpoint. Swift's example funding coordinator can release its funding slot on that result. Use the existing Rust resume classification for the admission error: preserve code 93 and report `LockHeld` with the outpoint when the tracked state supports it. Fresh funding refused at the same gate should remain `NotSent`.
_Raised on code unchanged since the last review, and confirmed by an independent pass: A caller can resume a tracked, already-broadcast Core asset lock through `platform_wallet_manager_shielded_resume_fund_from_asset_lock` after Clear resets native state but the host wipe fails. The admission check returns code 93 with `NotSent` and no outpoint before inspecting the tracked lock, so the Swift funding flow releases its slot and permits a fresh funding even though the original funds are still locked._
In `packages/rs-platform-wallet-ffi/src/shielded_send.rs`:
- [BLOCKING] packages/rs-platform-wallet-ffi/src/shielded_send.rs:3723-3728: Fresh shielded sends report unknown delivery through C before shielded setup
Impact: C and mobile callers making a valid transfer or self-shield on a loaded wallet without a configured coordinator receive `Unknown` even though Rust classifies the refusal as `NotSent`.
`resolve_shielded_wallet` checks for the coordinator in FFI and returns a generic result before reaching the wallet's readiness check. That bypasses the `before_dispatch()` classification added on this head and lets the binding decide readiness instead of marshaling the wallet's decision. Resolve the wallet without imposing a separate coordinator requirement. For transfer, preserve the ordering that checks readiness before asking for a mnemonic by using the Rust wallet's readiness result; signer-handle self-shield can delegate directly. Check the delivery field through both exports, not just the diagnostic code.
_Raised on code unchanged since the last review, and confirmed by an independent pass: A C caller can invoke `platform_wallet_manager_shielded_transfer` or `platform_wallet_manager_shielded_shield` with a valid wallet and valid inputs before shielded setup completes. `resolve_shielded_wallet` returns a generic `ErrorWalletOperation` with `Unknown` delivery before calling the wallet, so a host following the payment-result contract treats a send that never started as unconfirmed._
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…sals A resume of a tracked asset lock refused at the shielded admission (a pending host wipe, or no coordinator configured) now names the lock as held, keeping its diagnostic: the refusal proves only that this call submitted nothing, not that the lock was never broadcast. The FFI no longer decides shielded readiness itself. Sends ask the wallet's new ensure_shielded_configured before resolving a mnemonic and carry its NotSent refusal; the resume and drain exports leave the refusal to the wallet, which names a held lock. The host wipe callback docs now include wallets whose network is unknown. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
/self-reviewed 2f957a6 |
|
Waiting for bot review — thepastaclaw reviewed an earlier commit, not yet this one. 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
- A refused resume reports a chain-recovered payment as not sent even though it may have landed —
packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs:394-398(new)
Impact: A host resuming a chain-recovered top-up before shielded setup or during a pending host wipe can receiveNotSentand start a second payment without reconciling the original.
New on this head: This revision moves shielded setup refusals into the wallet, preserves the held outpoint when a known resumable lock is refused, and clarifies that the host wipe includes rows whose wallet network is unknown. At the time of this static review, the Kotlin SDK build and x86_64 emulator tests and the Swift frozen-schema check had passed; Rust workspace tests were still pending.
A pattern across this PR's review rounds
This is review round 31, and the PR has drawn 33 blocking findings so far. 3 of them share one underlying cause. They are listed with the other findings as usual; fixing the cause is likely to be cheaper than fixing each case.
1. Funding refusals lose earlier dispatch history (2 new in this round, 2 earlier finding(s))
In shielded_fund_from_asset_lock, an explicit outpoint resume relies on resume_error, while a UUID drain retry restores its operation snapshot in begin_wallet_drain and also runs funded_lock_error. The latest fix teaches the explicit path to report a known held lock, but resume_error still treats the absence of a provably held lock as a reason to keep NotSent, even when RecoveredFromChain proves a Core broadcast and leaves Platform consumption unknown. The two paths can therefore give different answers to the same refusal, and the explicit-resume test cannot check whether the UUID retry returns its saved outpoint.
Already tracked: #6286
In this round: A refused resume reports a chain-recovered payment as not sent even though it may have landed; The explicit-resume test misses a lost outpoint on the UUID drain retry
Suggested decision (redesign the component): Keep readiness in PlatformWallet and give shielded asset-lock funding one Rust rule for classifying refusals across explicit resumes and UUID retries. Reserve NotSent for a payment known never to have dispatched, use LockHeld with the outpoint when the lock is known held, and use MaybeSent when an earlier payment may have landed. C and mobile should carry that answer and the drain's saved snapshot without reclassifying them. This leaves Clear policy and deferred cleanup unchanged. Rust workspace tests are still running.
🔴 1 blocking | 🟡 1 suggestion(s)
Follow-up candidates (optional) (1)
New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.
🟡 Suggestion: The C documentation says code 93 means not sent even when the result carries a held lock
Impact: A C caller resuming a known lock after a failed host wipe can discard the outpoint it needs for recovery if it follows the documented NotSent interpretation of code 93.
packages/rs-platform-wallet-ffi/src/error.rs:986-992
The diagnostic alone does not say whether the caller can safely start over. The new mapper test explicitly expects ErrorShieldedClearIncomplete together with LockHeld and the original outpoint. Update this enum comment and the code-93 entry in ERROR_CODE_REGISTRY.md: the code identifies the pending host wipe and tells the host to complete Clear; the caller must read payment_delivery separately and keep held_asset_lock when the result is LockHeld.
source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)
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-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The diff changes when shielded viewing keys can be bound, restored, or durably erased across concurrent operations and restarts, with the lifecycle boundary inwallet/shielded/coordinator.rsand host key deletion insqlite/schema/shielded_viewing_keys.rs. - 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(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- New since the last final review (
c7a5a45f): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed; 1 suggestion(s) on unchanged code listed as follow-up candidates - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
Several findings on this PR share an underlying cause (the review's "pattern" section): Funding refusals lose earlier dispatch history. When you fix the findings below, fix the cause, not only the reported case. The review suggests (redesign the component): Keep readiness in `PlatformWallet` and give shielded asset-lock funding one Rust rule for classifying refusals across explicit resumes and UUID retries. Reserve `NotSent` for a payment known never to have dispatched, use `LockHeld` with the outpoint when the lock is known held, and use `MaybeSent` when an earlier payment may have landed. C and mobile should carry that answer and the drain's saved snapshot without reclassifying them. This leaves Clear policy and deferred cleanup unchanged. Rust workspace tests are still running. If that decision is not yours to make, say so to the PR's author or maintainer.
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/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/fund_from_asset_lock.rs:394-398: A refused resume reports a chain-recovered payment as not sent even though it may have landed
Impact: A host resuming a chain-recovered top-up before shielded setup or during a pending host wipe can receive `NotSent` and start a second payment without reconciling the original.
The caller can release the original payment's recovery slot and fund the same recipient again. Core reconstruction can load a tracked `RecoveredFromChain` outpoint with a ChainLock proof but no evidence of whether Platform consumed it. The public C resume now reaches this wallet branch on a setup or admission refusal. Because `is_resumable()` excludes `RecoveredFromChain`, `resume_error` finds no definitely held lock and calls `without_held_lock()`, which leaves the readiness error as `NotSent`. C and Swift preserve that result; the Swift example's pending-lock surface offers recovered top-ups for resume, and its funding retry policy releases the slot on `NotSent`. In Rust, distinguish a tracked consumption-unknown row from a fresh refusal: keep the readiness diagnostic but return `MaybeSent` without a held outpoint for the recovered row. Preserve `LockHeld` for a definitely resumable row and exercise the recovered case through the explicit C resume export.
_Confirmed by an independent pass: After a wallet restore reconstructs a ChainLocked shielded top-up as `RecoveredFromChain`, a caller can pass its outpoint and original recipient to `platform_wallet_manager_shielded_resume_fund_from_asset_lock` before shielded setup or while a failed Clear's host wipe is pending. The API returns `NotSent` even if Platform already executed the original payment. The Swift funding flow treats that result as safe to dismiss without reconciliation, allowing a fresh lock to pay the same recipient again once shielded funding is available._
In `packages/rs-platform-wallet-ffi/src/shielded_wallet_drain.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/shielded_wallet_drain.rs:224-230: The explicit-resume test misses a lost outpoint on the UUID drain retry
Impact: A regression at the drain export could hide the original lock from a caller retrying a saved UUID before setup while the explicit-outpoint resume test still passes.
A UUID retry needs both the payment disposition and the saved operation snapshot to identify the original lock. The explicit-resume test does not exercise either the UUID lookup or the drain export's second result. Reinstating the setup-checking resolver here would skip `begin_wallet_drain` before it can restore the outpoint. Add a C export test with a loaded, unconfigured manager and a persisted `Pending` UUID backed by a resumable lock. Assert that `LockHeld` and the `Pending` operation snapshot both name the original outpoint.
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.
- Android exceptions omit the native payment disposition — The JNI funding path converts the native result into an exception carrying its code and message but not
payment_deliveryorheld_asset_lock. This predates the change and affects more than the shielded readiness refusal.- Follow-up: Expose the native payment disposition and optional held outpoint on Android's typed funding errors, with JNI-to-Kotlin coverage for both a held lock and an unresolved payment.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…k as maybe sent A resume of a tracked asset lock refused at the shielded readiness gate is now classed like any refusal after the lock existed: a resumable lock is named as held, and any other tracked lock (chain-recovered, its Platform consumption unknown) is MaybeSent, since its earlier payment may have landed. An untracked outpoint keeps the refusal's own NotSent. Code 93's docs now say the code names the pending wipe, not the payment's delivery, which the host reads separately. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
/self-reviewed 59709ed |
|
Waiting for bot review — thepastaclaw reviewed an earlier commit, not yet this one. 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.
- ✅ Withdrawn: 🟡 The explicit-resume test misses a lost outpoint on the UUID drain retry
New on this head: This head preserves the shielded readiness diagnostic while reporting LockHeld with the original outpoint for a resumable lock and MaybeSent without a held outpoint for a chain-recovered lock. Rust workspace tests, Kotlin SDK build and emulator tests, and the Swift frozen-schema check passed; Swift SDK build and tests were still pending at the time of review.
🟡 1 0 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Still open from earlier rounds (1)
- 🟡 Suggestion: The explicit-resume test misses a lost outpoint on the UUID drain retry —
packages/rs-platform-wallet-ffi/src/shielded_wallet_drain.rs:224-230(thread) — settled: ✅ Withdrawn
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-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The diff changes shielded viewing-key handling inPlatformWalletManager::clear_shieldedandwallet/shielded/coordinator.rs, coordinating key deletion and blocking stale restores across concurrent operations and partial failures. - 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(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— 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/rs-platform-wallet-ffi/src/shielded_wallet_drain.rs`:
- [SUGGESTION → WITHDRAWN in discussion; do not fix] packages/rs-platform-wallet-ffi/src/shielded_wallet_drain.rs:224-230: The explicit-resume test misses a lost outpoint on the UUID drain retry
(carried; thread: https://github.com/dashpay/platform/pull/5934#discussion_r4794286502)
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.
- Kotlin exceptions do not expose the payment delivery returned by C — For explicit asset-lock resume, the shared JNI error bridge forwards the diagnostic code, message, and optional consensus details, but not
payment_deliveryorheld_asset_lock. Kotlin callers therefore cannot distinguishMaybeSentfromLockHeldthrough that exception. This limitation predates the change.- Follow-up: Continue tracking Kotlin payment-result parity in #6381; marshal the existing Rust result fields rather than inferring delivery from code 93.
|
Ready for review — |
romchornyi
left a comment
There was a problem hiding this comment.
✅ Both majors fixed · no blockers · 5 non-blocking recommendations — re-reviewed at 59709ed03a
| Level | Verdict | |
|---|---|---|
| 1 · Idea | ✅ valid | Unchanged. |
| 2 · Architecture | ✅ right layer | Unchanged. |
| 3 · Completeness | ✅ gaps tracked | #5936 is now closed by this PR; #6343 records why a Clear is admitted during a funding; #6314 stays open. |
| 4 · Code | ✅ clean | The merge with v5.2-dev lost nothing, and every refusal this PR adds carries the right payment class. |
Closed since the last review
- A host wipe that refuses every time no longer locks the network: Swift and Kotlin drop the rows of a wallet whose network is unknown, as the SQLite persister does (1323821). The cost is recommendation 1.
- The pending-wipe refusal is its own
ShieldedClearIncomplete:NotSent, FFI code 93, mirrored in Swift and Kotlin (c7a5a45). Code 93 survives every mapper, inside a payment-class wrapper too. - After the merge (
--remerge-diffof 57e3287, 16 files): every dropped hunk is obsolete with the coordinator parameter gone;seed_pool,tip_paymentandwallet_drainkeep v5.2-dev's classing. A refused resume of a tracked lock isLockHeldorMaybeSent, an untracked oneNotSent. The FFI spend mappers keep both the code and the outpoint. #6373 withdraws Platform-address credits, not shielded ones; the shielded withdraw takes the admission.
5 non-blocking recommendations
- Clear on one network can delete another network's host-only history —
PlatformWalletPersistenceHandler.swift#L6625and the KotlinonWipeShieldedState. A wallet row withnetworkRaw == nil(metadata not landed yet) loses its activity and host-side rows on any network's Clear. The thread names the trade-off: notes and keys come back from native state and the seed, the host's activity does not. Resolving that wallet's network from the native side before deleting would limit the wipe to the network being cleared. (verified by reading; how often such a row holds shielded rows not measured) - Sync reports success while a host wipe is pending —
coordinator.rs#L2646: a refused admission becomes the empty summary,ShieldedSyncManager::sync_walletreturnsOk(None), and the FFI returns success with nothing scanned. The description lists sync among the operations refused withShieldedClearIncomplete, but 93 cannot reach a sync caller; the host learns of the pending wipe only at the next spend. (verified by reading) - Two FFI resolvers still decide readiness themselves —
resolve_wallet_and_coordinatorandresolve_shielded_coordinatorreturnErrorWalletOperationwithoutNotSent. The second servesprivate_reply_payment_parts(private_contact_request.rs:883), so a reply payment refused before setup is not reported as never sent; the first serves the token-pool exports. This is the rule 2f957a6 applied toresolve_shielded_wallet: routing both throughPlatformWallet::ensure_shielded_configuredcloses it. (verified by reading) - New catch-all arms over our own enums —
shielded_sync.rs#L187,map_shielded_error, andfund_from_asset_lock.rs#L409(Err(error), _)overAssetLockFunding. A future funding kind that resumes a lock would skip the held-lock classification without a compile error; naming the variants, asrefuses_resumedoes, makes it fail to compile instead. (verified by reading) - Small
- Token-pool watch/record/balances answer
ShieldedNotBoundrather than 93, andunwatch_token_poolandidentity_debit_recovery_recordsdo not take the admission (untouched sites). - The "call configure_shielded first" text now crosses the FFI, while the sibling resolvers name
platform_wallet_manager_configure_shielded. - No test covers a reused-UUID drain refused with 93; it shares its path with the not-configured test.
- Token-pool watch/record/balances answer
Review details
Re-review against the review at fa3f810218. Each earlier point was checked at this head, then level 4 ran over the four commits after the merge (57e3287161..59709ed03a) with a general code review, plus a lane for the merge resolution, payment classes, FFI mappers and the Clear refusal on every shielded operation. Recommendations 1–4 were checked against the code by hand. Threads resolved with other reviewers are not repeated.
🤖 Reviewed with Claude Code
Issue being fixed or feature implemented
Shielded Clear crossed three owners, and nothing tied them together:
clear_generationcounter,ShieldedInstall::snapshot_predates_clearand per-call ownership checks. None of them covered the host deletion, because it ran outside Rust.The DashPay shielded tips (#5288) and per-identity shielded accounts (#5905) work both add shielded mutations and were adding more of these guards. This PR moves the boundary into one place first, so those branches can drop their guards when they rebase.
Closes #5936: a bind or account add holds the wallet's lifecycle gate across its host write, so a removal waits for it and a handle kept past the removal writes nothing (
should_order_a_bind_and_a_removal_of_its_wallet). For #6343, a Clear stays admitted while an asset-lock funding waits on its proof or ChainLock, and the funding's activity write is fenced by the Clear epoch instead (should_record_no_funding_activity_after_a_clear_that_followed_its_broadcast); refusing the Clear would hold it for the unbounded ChainLock wait (#5518).What was done?
1. The manager owns the coordinator. Wallet shielded operations resolve the manager's coordinator internally (
PlatformWallet::shielded_coordinator()), and the coordinator parameter is gone from the public wallet API. Beforeconfigure_shielded, a shielded call fails with "not configured" and writes nothing to the host. The FFI asks the wallet (PlatformWallet::ensure_shielded_configured) rather than checking the coordinator itself, so that refusal keeps the wallet's class across C.2. Clear runs the host wipe itself.
PlatformWalletPersistence::wipe_shielded_state(network), declared by the new capabilityPersistenceCapabilities::SHIELDED_STATE_WIPE(1 << 17;1 << 16is v5.2-dev'sOUTPOINT_LOCKS). Its default implementation returns an error.PlatformWalletManager::clear_shieldedrefuses before anything is reset (the error message ends in "nothing was reset") when the persister does not attest the capability. Other capabilities are declared and checked the same way.wipe_shielded_state(network). It returns only after the wipe.Persistenceerror. Every shielded operation on the network but a wallet's removal (a bind, an account add, a coordinator restore, a sync, a spend, a funding, a balance read) is then refused withPlatformWalletError::ShieldedClearIncompleteuntil a later Clear wipes the host. The mark is durable, so the refusal survives a restart.on_wipe_shielded_state_fn: Option<unsafe extern "C" fn(context: *mut c_void, network: FFINetwork) -> i32>(WipeShieldedStateFn) and C constantPLATFORM_WALLET_PERSISTENCE_CAPABILITY_SHIELDED_STATE_WIPE.NativePersistenceBridge.onWipeShieldedState(network: Int): Int(descriptor(I)I). The slot is wired only when the bridge overrides the method; the inherited body returns -1.PlatformWalletPersistenceHandlerand KotlinPlatformWalletPersistenceHandlereach delete, in one transaction, the viewing keys, notes, outgoing notes, sync states and activity of every wallet on that network. The rows of a wallet whose network is not known yet go too, as the SQLite persister drops them: refusing them would fail every retried Clear after its native reset.ShieldedService.clearLocalState()in the Kotlin SDK and in SwiftExampleApp no longer deletes rows itself.3. One admission protocol. The coordinator has an
admission: tokio::sync::RwLock<ClearState { epoch, host_wipe_pending }>.shield_guard→ coordinatoroperation_admission→ admission → walletshielded_config_lock→ coordinatorlifecycle→store.PlatformWallet::lock_for_shielded_operation. It takes the lifecycle gate (andshield_guardfor a shield-class operation), then admits and refuses a wallet already removed from the manager. Removal takes the lifecycle gate exclusively, so a handle kept past a removal cannot derive a key, select a note or broadcast. A funding checks undershield_guard, which it holds to the end, before it builds anything.shield_guardcomes first, so an operation queued behind a long shield-class operation (an asset-lock funding waiting on its ChainLock) holds no admission and neither stalls nor refuses a Clear.NetworkShieldedCoordinator::clear_generation(field and method);ShieldedInstall::snapshot_predates_clear;NetworkShieldedCoordinator::begin_install, which now lives on the admission (ShieldedAdmission::begin_install).NetworkShieldedCoordinator::clear_epoch()reports how many Clears reached the native reset.4. Clear is refused at once while a shielded operation runs. This is the behaviour #6182 gave
v5.1-devand #6283 brought tov5.2-dev, with the same error and code.PlatformWalletManager::clear_shieldedreturnsPlatformWalletError::ShieldedOperationInProgresswhile a bind, a seedless rebind, an account add, a spend, a shield, a top-up, an identity create, a private contact payment, a private document create, a token pool purchase, transfer or unshield, a shielded tip, a DashPay profile write that sets a shielded address, a debit abandon or a tip address preparation holds its admission, or while another Clear runs. It returns before the sync loop is stopped: nothing is reset and the host is not asked to wipe.operation_admission, shared (admit_operation). Clear takes it without waiting (try_admit_clear) before the quiesce and holds it through the wipe, so an operation that arrives meanwhile waits for the Clear.ShutdownIncomplete. The handler docs say so.platform_wallet_manager_shielded_clearreturnsErrorShieldedOperationInProgress = 84, the code the base already has. This PR adds no result code.PlatformWalletResultCode.errorShieldedOperationInProgressandPlatformWalletError.shieldedOperationInProgress(String). SwiftExampleApp keeps its binding, sync and rows and shows "A shielded payment or wallet setup is in progress. Try Clear again when it finishes."DashSdkError.PlatformWallet.ShieldedOperationInProgress(retryable). KotlinExampleApp shows the same message.5. The base's own Clear design is replaced by this one. #6283 merged
v5.1-devintov5.2-dev, which brought a second answer to the same problem: the host deletes its rows after Clear returns, and aclear_generationcounter plus per-wallet binding checks catch what slips through. The merge of the base into this branch keeps one mechanism:operation_admissionlock and itsclear_in_progress()flag), and every feature it added (token pool purchase, transfer and unshield, shielded tips, tip address preparation, profile write, private document create, the balance emitter,platform_wallet_manager_shielded_ordinary_accounts).clear_generation,operation_guard, the wallet'sShieldedBindingand its checks (ensure_shielded_bound_on,ensure_shielded_binding_stands,ensure_no_other_shielded_coordinator),admit_shielded_spend,admit_shielded_payment,admit_single_flight_shielded_spendandshield_turn. Each base entry point now takeslock_for_shielded_operationand the admission like the others, and lost its coordinator parameter.ShieldedNotBounduntil the wallet is bound again. Before, a shield queued behind a Clear could broadcast into an account no sync pass scans.shielded_identity_accounts: wallet id and account index, no key bytes). A Clear keeps it and a removal of the wallet drops it. A seed bind and a seedless rebind both add those accounts, so the bind after a Clear, in the same process or after a restart, scans them again and writes their rows again (platform-wallet: a shielded Clear followed by a restart stops scanning the tip account of an identity removed from the device #6306). Before it wipes, a Clear also keeps the identity accounts in the host's viewing key rows, so a wallet that has not been registered since this change keeps its retired accounts too. If the host snapshot cannot be read, the Clear goes on without them: Clear is how a host recovers from rows it cannot read.PendingHostWipeand its ledger hold around Clear; Rust keeps the pending-wipe mark durably. Swift'sclearShielded()has no preflight of its own: Rust decides whether a Clear may run.lifecycle→sync_pass→fan_out→store.How Has This Been Tested?
New deterministic race tests in
rs-platform-wallet(wallet::shielded::lifecycle_boundary_tests). A host persister parks one side at a host callback, and the test requests a Clear before releasing it:shielded_add_accountagainst Clear, both ways round;ShutdownIncomplete, nothing reset, no host call;shield_guarddoes not stall Clear. This test fails with the previous lock order;ShieldedNotBounduntil the wallet is bound again. The test fails without the registration check;configure_shielded, and none before it.Other tests:
manager.configure_shielded(..).onWipeShieldedState.Commands run:
After the merge of
v5.2-devthese were run on the merged tree, not the full suites.Not tested locally: the Swift SDK and SwiftExampleApp changes, including the new
ShieldedStateWipeTests, were type-checked against the rebuilt FFI headers (swiftc -typecheckover the SDK, its tests, the app and its tests) but not built or run here; they rely on CI. The Kotlin androidTest was compiled but not run on a device. Locally, the existing Kotlin testaSweepReleasingMoreOutpointsThanSqliteCanBindStillCommits(40,000 outpoints) hit its 1-minuterunTestlimit under heavy host load; it does not exercise the code changed here.Breaking Changes
No consensus or protocol change. API and persister contract changes:
PlatformWalletshielded methods, the ones the base added since included (shielded_token_purchase_from_pool,shielded_token_transfer,shielded_token_unshield,create_private_document_entry,prepare_shielded_identity_address,review_shielded_tip,send_shielded_tip,shielded_identity_balance,shielded_identity_balance_now, and the spend plan methodsshielded_plan_spend,shielded_transfer_to_with_plan,shielded_unshield_to_with_plan,shielded_withdraw_to_with_planandshielded_identity_top_up_from_pool_with_plan, whose four spends keep their optional plan digest):bind_shielded,bind_shielded_from_persisted,shielded_balances,shielded_transfer_to,shielded_unshield_to,shielded_withdraw_to,shielded_shield_from_account[_to_recipient],shielded_shield_from_identity[_to_recipient],shielded_identity_top_up_from_pool,shielded_identity_create_from_pool,shielded_fund_from_asset_lock,shielded_seed_pool_notes,abandon_shielded_identity_debit, and the private contact request methods (send_private_contact_request,accept_private_contact_request,restore_private_contact_payments,restore_pending_private_contact_requests). Configure the manager withconfigure_shieldedfirst.PrivateReplyPaymentno longer has acoordinatorfield.PlatformWalletManagerempties its shielded coordinator slot, on a thread of its own when a reader holds the slot at that moment. A wallet handle kept past it then reads as unconfigured. The coordinator and its store close once nothing holds them: an in-flight operation, or a caller that kept theArcfromshielded_coordinator(), keeps them open until it drops it. If the OS refuses that thread, a warning is logged and the slot keeps the coordinator until the wallets holding it drop, as before this PR.NetworkShieldedCoordinator::clearis crate-internal and takes the host persister; usePlatformWalletManager::clear_shielded.clear_generation,operation_guard,ShieldedInstall::snapshot_predates_clearand the coordinator-levelbegin_installwere removed.register_walletandrestore_for_walletnow fail after a Clear whose host wipe failed.SHIELDED_STATE_WIPEand a workingwipe_shielded_state. Without them, Clear returns an error and resets nothing.on_wipe_shielded_state_fn(appended toPersistenceCallbacksExtension; olderstruct_sizevalues stay valid but cannot Clear) and declare the bit.onWipeShieldedState.ShieldedService.clearLocalState()no longer takes a database.ShieldedService.clearLocalState()no longer takes a model context.PlatformWalletPersistenceCapabilities.SHIELDED_STATE_WIPE(Kotlin) and.shieldedStateWipe(Swift) were added.PlatformWalletError::ShieldedClearIncomplete, FFI code 93ErrorShieldedClearIncomplete, SwiftPlatformWalletError.shieldedClearIncompleteand KotlinDashSdkError.PlatformWallet.ShieldedClearIncomplete: a shielded operation refused because the last Clear did not wipe the host.NotSent, not retryable: the host runs Clear again, then the operation. The refusal of a call beforeconfigure_shielded("not configured") isNotSenttoo. A resume of a tracked asset lock refused by either one keeps the refusal's code but not itsNotSent: a resumable lock isLockHeldwith its outpoint, any other tracked lock (chain-recovered) isMaybeSent.ShieldedNotBound, as on the base; it is now decided by the wallet's registration on the coordinator, not by a generation counter.shielded_plan_spend) and a fresh wallet drain from such a wallet returnShieldedNotBoundtoo, and a preview while a failed host wipe awaits its retry is refused like a balance read.PlatformWalletManager.clearShielded()no longer throwsinvalidHandlewhile an async native operation is in flight; it asks Rust, which returns code 84 when the operation is a shielded one.hasAdmittedNativeOpwas removed.ShieldedServiceno longer raises code 84 itself for a Clear tapped while a bind holds its ledger; only Rust refuses.platform_wallet_manager_shielded_identity_balanceno longer requires a configured shielded store. Beforeconfigure_shieldedit returnsSuccesswithUnverifiedfor an identity the wallet holds andErrorIdentityNotFoundfor one it does not, where it returnedErrorWalletOperationfor both. Swift and Kotlin callers get the same through their wrappers.ErrorShieldedBalanceBusy(87) when a Clear ran, or holds or waits for the admission, between its read of the amount and its answer. The caller reads again.clear_shieldedcalls the persister'sload()once before anything is reset. A load that fails as retryable returnsPlatformWalletError::PersisterLoad(FFIErrorPersisterLoadTransient, 49) with nothing reset and the wipe not called; the host retries the Clear. The Clear had stopped the sync loop to drain it by then and does not start it again, unlike a refusal with code 84, which returns before anything is stopped: a host that puts off its retry starts sync itself. Before, a Clear never calledload()and never returned this code.ShieldedOperationInProgressand can be retried when the operation has finished.shield_turn); that is not kept here and belongs with platform-wallet: wallet removal and shielded Clear wait for a host signer (and for a shield queued behind asset-lock funding) #6189.review_shielded_tipholds no admission, so it never refuses a Clear; it returnsShieldedNotBoundif a Clear ran or is running while it read.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 ·
59709edkotlin-sdk(packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md,packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/FfiSmokeTest.kt,packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/ShieldedClearRefusalFfiTest.ktand 12 more) — HashEngineeringrs-platform-wallet-ffi(packages/rs-platform-wallet-ffi/ERROR_CODE_REGISTRY.md,packages/rs-platform-wallet-ffi/src/error.rs,packages/rs-platform-wallet-ffi/src/manager.rsand 7 more) — approved by romchornyiwallet-storage(packages/rs-platform-wallet-storage/src/sqlite/buffer.rs,packages/rs-platform-wallet-storage/src/sqlite/persister.rs,packages/rs-platform-wallet-storage/src/sqlite/schema/shielded_viewing_keys.rsand 2 more) — lklimekrs-platform-wallet(packages/rs-platform-wallet/examples/shielded_sync.rs,packages/rs-platform-wallet/examples/shielded_sync_paloma.rs,packages/rs-platform-wallet/src/changeset/persistence_capabilities.rsand 34 more) — approved by romchornyiswift-sdk(packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManager.swift,packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift,packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletPersistenceHandler.swiftand 9 more) — approved by romchornyiWhen 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