Skip to content

fix(platform-wallet): hold the lifecycle gate and Clear admission across credit pool spends - #6178

Merged
QuantumExplorer merged 6 commits into
v5.1-devfrom
fix/platform-wallet-shielded-spend-lifecycle-gate
Nov 24, 2026
Merged

QuantumExplorer merged 6 commits into
v5.1-devfrom
fix/platform-wallet-shielded-spend-lifecycle-gate

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

What this does. Seven kinds of payment out of the shielded credit pool (send to a shielded address, unshield to a platform address, withdraw to Core, top up an identity, create an identity, shield from a platform account, shield from an identity) now register themselves with the wallet before they start, and stay registered until they finish. While one is registered, deleting the wallet waits for it, and a shielded Clear cannot run under it. A payment started on a wallet that was already deleted (or deleted and re-created) is refused before anything is signed, and so is a payment started after a Clear, until the wallet's shielded accounts are set up again.

Value. Before this, a payment that was still building its proof could outlive the wallet it came from: the wallet could be deleted, and the payment would then write its activity and recovery records back and broadcast anyway. A Clear could also wipe the notes and the saved retry record a payment had just stored, while the payment went on to broadcast. The token pool payments already had this protection; these seven did not.

Risks.

Issue being fixed or feature implemented

The Rust half of #5868 ("hold the generation lifecycle guard across transition construction, broadcast and the activity/recovery writes in the shielded spend paths"). Confirmed still open on v5.1-dev: shielded_token_transfer, shielded_token_unshield, shielded_token_purchase_from_pool, the private contact request payment and create_private_document_entry take generation_payment_guard() and check is_current_generation(); the seven credit pool spends took neither that nor the coordinator's operation_guard().

The Swift half (wrapper admission, #6060) is #6179. No open pull request covered either half; #5863 on v5.2-dev admits one Swift wrapper only.

What was done?

PlatformWallet::admit_shielded_spend(coordinator) takes, in this order:

  1. the wallet generation's lifecycle gate (generation_payment_guard()), then checks is_current_generation() and returns WalletRemovedBeforeSend for a stale handle;
  2. the coordinator's operation admission (operation_guard());
  3. the wallet's shielded_config_lock, only long enough to check ensure_shielded_bound_on(coordinator), and returns ShieldedNotBound if the handle's keys are not the ones installed on this coordinator since its last Clear.

It returns the gate and the admission in one value, ShieldedSpendAdmission. Each of these holds it from before it reads its keys until it returns:

PlatformWallet method Held through
shielded_transfer_to proof, broadcast, settlement
shielded_unshield_to same
shielded_withdraw_to same
shielded_identity_top_up_from_pool same, plus the local balance write
shielded_identity_create_from_pool same, plus the local identity registration
shielded_shield_from_account / _to_recipient input selection, proof, signature, broadcast
shielded_shield_from_identity / _to_recipient identity read, proof, signature, broadcast, local balance write

Why the bound check. A Clear drops the wallet's registration on the coordinator but not the keys the wallet handle holds, and a shield needs no note from the cleared store. Without the check, a shield admitted right after a Clear would debit for an account no scan reads until the next bind.

Why the config lock is not held through the spend. The token pool spends hold it until they settle, so that no bind replaces the accounts meanwhile. Doing the same here made every bind of the wallet wait for the proof and the result, including a host's routine re-bind of an unchanged account list (synchronous on the main actor on iOS), and ran one wallet's transfers one at a time. Neither was true on v5.1-dev. The Clear ordering does not need the hold: the admission is held through the spend, and the Clear generation is compared under it.

Lock order. Gate, admission, config lock (released after the check), then shield_guard, then the wallet manager lock and the shielded store. That is the order bind_shielded uses, so a spend and a bind cannot wait on each other. The three methods that took shield_guard first now take it after admission. I checked every other holder of shield_guard (the bind install, asset-lock funding, abandon_shielded_identity_debit): none takes the gate, the admission or the config lock while holding it. All callers of the seven methods are FFI entry points that hold none of them.

A queued shield-class spend holds nothing. An identity top-up and the two shields run one at a time on a wallet (shield_guard), and an asset-lock funding holds that guard across a ChainLock wait with no deadline. admit_single_flight_shielded_spend takes the admission and then tries the guard; if another operation holds it, the spend gives the admission back, waits holding nothing, and is admitted again, with both checks repeated, when its turn comes. So a payment that has not started keeps neither a removal nor a Clear waiting, as on v5.1-dev, and a wallet removed meanwhile is refused at its turn. The admission is never awaited under shield_guard nor the reverse. Only one spend at a time waits this way: the others wait on a per-wallet shield_turn mutex, taken before everything else, holding nothing. Without it two queued spends would hand shield_guard to each other and never find it free.

Signers. The gate is taken before the signature, not after it as a contact request does. Taking it after would take it while shield_guard is held, the reverse of a bind's order. WalletGeneration::teardown_guard's doc now names the four operations that sign under the gate (these three and write_dashpay_profile, which already did). #6189 has the follow-up design.

FFI. platform_wallet_manager_shielded_identity_create_from_pool had its own result match whose catch-all turned WalletRemovedBeforeSend into ErrorWalletOperation. It now sends the two admission refusals through map_spend_result, like the other spend exports. The match moved into map_identity_create_result, which returns the identity id beside the result; the export still stores it through the raw output pointer, and only for the two outcomes that carry one, so the caller's buffer may stay uninitialised as before.

How this composes with the Clear refusal (#6182, merged into this branch). clear() uses try_write() on operation_admission and returns ShieldedOperationInProgress instead of waiting. A spend here holds the read side, so a Clear issued during any of these payments is refused, and Clear waits on nothing a spend holds, so the two cannot deadlock. A Clear is not refused for a shield-class spend that is only queued. Clear itself is not touched here. Both are now run by tests, below.

Before / after

let wallet = manager.get_wallet(&id).await.unwrap();
manager.remove_wallet(&id).await?;
wallet.shielded_transfer_to(&coordinator, seed, 0, &recipient, amount, memo, prover).await
  • Before: the call went on with the removed wallet's handle. With bound keys still on the handle it could reserve notes, record activity, save a retry record and broadcast.
  • After: Err(PlatformWalletError::WalletRemovedBeforeSend(<wallet id hex>)), nothing read, reserved, recorded or sent.
// a transfer is building its proof
manager.remove_wallet(&id).await
  • Before: returned at once; the transfer carried on.
  • After: returns once the transfer has returned.
coordinator.clear().await?;
wallet.shielded_shield_from_identity(&coordinator, 0, &identity_id, amount, &signer, prover).await
  • Before: the shield used the keys still on the handle, debited the identity and recorded activity for an account the coordinator no longer scans.
  • After: Err(PlatformWalletError::ShieldedNotBound) until bind_shielded runs again.

Public interface changes

No signature changes. Behaviour changes on platform_wallet::PlatformWallet:

  • The nine public methods in the table above can now return PlatformWalletError::WalletRemovedBeforeSend for a stale handle and PlatformWalletError::ShieldedNotBound for a handle not bound on the coordinator since its last Clear (both existing variants). Before, a stale handle got whatever the spend ran into later, or no error at all; a spend after a Clear went ahead on the cached keys.
  • They take the lifecycle gate and the coordinator's operation admission themselves and hold them until they return, and take shielded_config_lock for the binding check, so they must not be called by code that already holds any of them. Each method's doc now says so.
  • A bind, an account add or a tip account preparation on the same wallet does not wait for one of these spends, and two of them on one wallet still run concurrently, as on v5.1-dev.
  • PlatformWalletManager::remove_wallet waits for one of these spends in flight, its signature included.
  • NetworkShieldedCoordinator::clear returns ShieldedOperationInProgress while one of these spends runs (the refusal from fix(platform-wallet): refuse a shielded Clear while a shielded operation runs #6182).

FFI (rs-platform-wallet-ffi):

  • platform_wallet_manager_shielded_identity_create_from_pool returns NotFound (98) for a removed wallet, where its catch-all returned ErrorWalletOperation. Swift maps 98 to PlatformWalletError.notFound and Kotlin to DashSdkError.PlatformWallet.NotFound; neither needed a change.
  • Through every credit pool spend export, a removed wallet is NotFound and an unbound one is ErrorWalletOperation, as for the token pool spends. No new result code.

Internal additions: PlatformWallet::admit_shielded_spend, PlatformWallet::admit_single_flight_shielded_spend, the shield_turn field, ShieldedSpendAdmission, map_identity_create_result in the FFI crate, and test-only NetworkShieldedCoordinator::has_admitted_operation.

Not covered here

How Has This Been Tested?

New wallet/shielded/spend_admission_tests.rs, on a wallet created through PlatformWalletManager and bound on a file-backed coordinator:

  • should_refuse_a_credit_pool_spend_from_a_wallet_no_longer_current: all seven spends on a bound handle whose wallet was removed, and again after it was re-created under the same id, get WalletRemovedBeforeSend.
  • should_refuse_a_credit_pool_spend_after_a_clear_until_the_wallet_is_bound_again: all seven get ShieldedNotBound after a Clear and are admitted again after a rebind.
  • should_hold_removal_and_clear_admission_until_a_credit_pool_spend_returns: five of the seven, held at the key slot after their admission (the test waits for the admission rather than sleeping), keep the coordinator reporting an admitted operation (the condition Clear's try_write() reads) and the teardown gate untakeable, while the config lock stays free; both are released once the spend returns. The two shields read the wallet manager first, so should_hold_removal_and_clear_admission_while_a_shield_runs holds them there and asserts the same.
  • should_hold_nothing_while_a_shield_class_spend_waits_for_another: a top-up and each shield, queued behind a held shield_guard, leave no operation admitted and the teardown gate free, and are admitted once the guard is released.
  • should_refuse_a_queued_shield_class_spend_whose_wallet_was_removed_meanwhile: a real remove_wallet completes while the spend is queued, and the spend then gets WalletRemovedBeforeSend.
  • should_run_every_shield_class_spend_that_waited_for_another: two top-ups and both shields queued behind one holder all return once it releases. Each spend is polled until it waits before the holder releases; with the turn removed the test fails.
  • should_refuse_a_clear_while_a_credit_pool_spend_runs: a real clear() during a transfer held at the store returns ShieldedOperationInProgress at once, the transfer then returns still bound, and a Clear afterwards goes through.
  • should_tell_a_spend_queued_after_a_clear_that_the_wallet_is_not_bound: a Clear is not refused for a queued top-up, a second top-up issued after it gets ShieldedNotBound without waiting for its turn, and the first gets it when its turn comes.
  • should_hold_a_wallets_removal_until_a_transfer_held_at_the_store_returns: a transfer held inside the operation, past key derivation at note selection, with a real remove_wallet issued meanwhile: the removal completes only after the transfer returns.

In the FFI crate: should_map_spend_admission_refusals_in_identity_create_as_other_spends and should_return_an_identity_id_only_on_success_and_unconfirmed_create.

Commands, all with CARGO_INCREMENTAL=0:

  • cargo test -p platform-wallet --all-features --locked --lib -- spend_admission_tests: 10 passed.
  • cargo test -p platform-wallet --all-features --locked --lib -- shield: 517 passed, 0 failed (after merging v5.1-dev). (An earlier run of this filter had one failure in balance_emitter_tests::should_emit_once_a_failed_scan_releases_the_store, a timing test in code this change does not touch; it passed 3 of 3 alone and in this run.)
  • cargo test -p platform-wallet --all-features --locked --lib -- private_contact_request_payment_tests: 8 passed.
  • cargo test -p platform-wallet-ffi --all-features --locked --lib -- shield: 110 passed.
  • cargo clippy -p platform-wallet -p platform-wallet-ffi --all-targets --all-features --locked -- -D warnings: clean.
  • cargo fmt --all.

Not yet verified

  • No iOS or Android build, and no device or simulator run.
  • No test drives a funded spend through its proof and broadcast with a removal or Clear in flight: the deepest pause is at the shielded store, before note selection. That needs funded notes and a scripted network this crate's unit tests do not have. In particular nothing reaches the local identity registration at the end of an identity create; a comment at that guard says it must stay outside the keyset's block.

Breaking Changes

None for consensus. Callers of the Rust API see the behaviour changes listed under "Public interface changes".

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

🤖 Generated with Claude Code

PR Hygiene · 6a3e126

  • Bots — thepastaclaw requested changes — dismiss the review or push a fix
  • Self-review — post /self-reviewed
  • Reviewer requests paused — your 5 review slots are occupied; this PR is excluded from reviewers' queues. Required approvals still count without a slot.
  • Build green
  • Approvals
    • rs-platform-wallet-ffi (packages/rs-platform-wallet-ffi/src/shielded_send.rs) — HashEngineering or ZocoLini or llbartekll or romchornyi
    • rs-platform-wallet (packages/rs-platform-wallet/src/wallet/core/generation.rs, packages/rs-platform-wallet/src/wallet/platform_wallet.rs, packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs and 2 more) — HashEngineering or ZocoLini or llbartekll or romchornyi

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

…oss credit pool spends

Seven spends from the shielded credit pool (transfer, unshield,
withdraw, identity top-up, identity create, shield from a platform
account, shield from an identity) held neither the wallet generation's
lifecycle gate nor the coordinator's operation admission. A handle kept
across a wallet removal could go on to record activity, arm a recovery
row and broadcast after the removal completed, and a Clear could purge
the store a spend had just reserved notes in.

Each of them now takes both through one helper, before it reads its
keys and until it has settled, as the token pool spends already do. A
handle whose wallet was removed or re-created is refused with
WalletRemovedBeforeSend before anything is signed.

Refs #5868

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 20 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9aa9b5e and 6a3e126.

Files selected for processing: 6

  • packages/rs-platform-wallet-ffi/src/shielded_send.rs
  • packages/rs-platform-wallet/src/wallet/core/generation.rs
  • packages/rs-platform-wallet/src/wallet/platform_wallet.rs
  • packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs
  • packages/rs-platform-wallet/src/wallet/shielded/mod.rs
  • packages/rs-platform-wallet/src/wallet/shielded/spend_admission_tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 23, 2026
@thepastaclaw

thepastaclaw commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

⛔ Final review complete — 2 blocking finding(s) (commit 6a3e126) · triage: critical

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 2 only (queue backlog)

Changes requested: 5 blockers

  • Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1991-1993 (new)
    Impact: An iOS user who taps Clear or deletes the spending wallet while an ordinary transfer is proving or waiting for confirmation can lose UI responsiveness until the spend returns.
  • Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3354-3358 (new)
    Impact: If a user removes the wallet during an identity-funded shield and the result cannot be confirmed, re-importing the wallet and retrying can debit the identity again after the first payment has executed.
  • A shield queued behind Clear can debit funds before the wallet is rebound — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1746-1755 (new)
    Impact: If Clear wins admission over an address- or identity-funded shield, the payment can debit credits while the wallet's scanner cannot see the account or reconcile its activity until rebind.
  • An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3354-3358 (new)
    Impact: A Rust host using an external signer cannot remove the wallet while the signer still awaits approval, even though the operation has not published a payment.
  • A queued top-up or shield can block wallet removal and Clear indefinitely — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2078-2089 (new; not shown inline, see below)
    Impact: If Core asset-lock funding stalls waiting for a ChainLock, submitting a shielded identity top-up or a shield from a Platform address or identity on the same wallet can block wallet removal and network-wide Clear before the new payment starts.

PR #6178 adds wallet-generation and shielded Clear guards to seven credit-pool operations, rejecting stale wallet handles before spending and holding both guards until the operation returns. On the reviewed head, the Swift frozen-schema check passed, Linux Rust wallet tests were running, and the Kotlin SDK build and tests were queued; no CI code check had failed.

🔴 5 blocking | 🟡 3 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: A queued top-up or shield can block wallet removal and Clear indefinitely
Impact: If Core asset-lock funding stalls waiting for a ChainLock, submitting a shielded identity top-up or a shield from a Platform address or identity on the same wallet can block wallet removal and network-wide Clear before the new payment starts.
packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2078-2089

Teardown now inherits a finality wait from an operation that has not selected inputs or started a proof. The top-up and both inbound shield implementations take the generation and coordinator read guards before awaiting shield_guard. Asset-lock funding holds that mutex across its ChainLock fallback (fund_from_asset_lock.rs:211,417–420), and its public FFI passes no deadline (shielded_send.rs:2325–2327). The queued spend therefore pins both teardown writers. A non-waiting Clear would return busy rather than hang, but it still could not succeed, and native removal would still wait. Keep the bind lock order and return a retryable before-send error on mutex contention, or wait without either admission and revalidate before retrying. Test that a contended spend does not pin either guard.

source: gpt-6.2-sol (phase2-reviewer: general, architecture-layering, rust-quality, security-auditor)

Review provenance

Source: reviewer 1: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 4: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); reviewer 5: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 6: gpt-6.2-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6.2-sol (agent: phase2-reviewer, role: rust-quality); reviewer 8: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — The shared admission guard requires careful lock-order and lifetime review across seven wallet paths, but it changes when operations may proceed rather than how funds are selected, signed for, or transferred.
  • Phase 1 reviewers: not run (skipped for throughput: 11 PRs queued, above the 10 limit)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort high); agent phase2-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:2078-2089: A queued top-up or shield can block wallet removal and Clear indefinitely
  Impact: If Core asset-lock funding stalls waiting for a ChainLock, submitting a shielded identity top-up or a shield from a Platform address or identity on the same wallet can block wallet removal and network-wide Clear before the new payment starts.
  Teardown now inherits a finality wait from an operation that has not selected inputs or started a proof. The top-up and both inbound shield implementations take the generation and coordinator read guards before awaiting `shield_guard`. Asset-lock funding holds that mutex across its ChainLock fallback (`fund_from_asset_lock.rs:211,417–420`), and its public FFI passes no deadline (`shielded_send.rs:2325–2327`). The queued spend therefore pins both teardown writers. A non-waiting Clear would return busy rather than hang, but it still could not succeed, and native removal would still wait. Keep the bind lock order and return a retryable before-send error on mutex contention, or wait without either admission and revalidate before retrying. Test that a contended spend does not pin either guard.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1991-1993: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend
  Impact: An iOS user who taps Clear or deletes the spending wallet while an ordinary transfer is proving or waiting for confirmation can lose UI responsiveness until the spend returns.
  Both actions now wait on the main actor for the rest of the spend. Swift's synchronous `clearShielded()` blocks in FFI while `NetworkShieldedCoordinator::clear()` awaits the admission writer (`coordinator.rs:1612–1613`); the sync drain budget does not cover that wait. The spend wrappers also launch detached FFI calls without incrementing the native-operation count, so `deleteWallet` can pass its guard, delete identity keys, and then block in FFI on the generation writer (`PlatformWalletManager.swift:2769–2814`). Land #6179 and #6182, or equivalent fixes, before or with this change. Deletion must refuse before touching host state, and Clear must return a retryable busy result before stopping sync or wiping data. #6179 alone does not cover Clear.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3354-3358: Removal requested during proof building can erase an unconfirmed debit's recovery record
  Impact: If a user removes the wallet during an identity-funded shield and the result cannot be confirmed, re-importing the wallet and retrying can debit the identity again after the first payment has executed.
  The original removal request can erase the only durable record that prevents a second debit. The new guard makes a removal requested before the record exists wait while the shield saves the signed transition, broadcasts it, and potentially returns `ShieldedSpendUnconfirmed` with the record still armed (`operations.rs:1234–1237,1305–1317`). The waiting removal then unregisters the wallet and deletes that row (`wallet_lifecycle.rs:927,996–997`; `file_store.rs:1732–1739`). A waiting Clear on this head can do the same. #6011 tracks the existing purge after an ambiguous return, but this patch newly makes a request already issued during proof construction wait and perform that purge without another user decision. Preserve the unresolved guard through teardown, or refuse teardown before destructive work until the debit is reconciled or explicitly abandoned. Test a teardown requested before the recovery record is written.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1746-1755: A shield queued behind Clear can debit funds before the wallet is rebound
  Impact: If Clear wins admission over an address- or identity-funded shield, the payment can debit credits while the wallet's scanner cannot see the account or reconcile its activity until rebind.
  A shield can write activity and broadcast immediately after the reset removes its account from the scanner. Clear advances `clear_generation` and empties the coordinator's account and persister registries (`coordinator.rs:1694–1711`), but leaves the wallet handle's cached keys intact. The new admission checks only wallet-generation liveness; when its read guard is granted after Clear, the inbound shields can use the cached keys and spend transparent credits without needing any notes from the cleared store. The stale-key gap existed on the base, but this patch introduces the wait behind Clear and must validate both orderings at that boundary. Reuse `ensure_shielded_bound_on` after admission and before using keys, with the binding held stable under the existing lock order. Test that a shield admitted after Clear returns `ShieldedNotBound` before signing.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3354-3358: An open signing prompt can prevent wallet removal before anything is sent
  Impact: A Rust host using an external signer cannot remove the wallet while the signer still awaits approval, even though the operation has not published a payment.
  Removal now waits on a caller-controlled signing future before there is anything to protect from teardown. The identity shield takes the lifecycle gate before the builder awaits `Signer::sign`; address-funded shielding and identity creation likewise await signatures under the gate. The native `Signer` trait imposes no deadline, and `WalletGeneration::teardown_guard` explicitly promises not to wait for external signing (`generation.rs:446–451`). Keep preparation interruptible by removal or move signing outside the teardown gate, then recheck the generation, coordinator binding, and prepared inputs before persisting or dispatching. The contact-request path already demonstrates a post-sign generation check.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2881-2884: Shielded identity creation reports a removed wallet as a generic failure
  Impact: If removal wins between FFI handle lookup and shielded identity creation, the caller gets `ErrorWalletOperation` instead of the documented `NotFound` refusal.
  The caller cannot distinguish a removed wallet from other identity-create failures by result code. The new admission returns `WalletRemovedBeforeSend`, but the identity-create export's separate result match sends it to the catch-all (`shielded_send.rs:1094–1097`). Other spends use `map_spend_result`, which preserves the existing `NotFound` conversion. Route the new refusal through that conversion without changing the arm that returns an identity ID for an unconfirmed creation.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:5144-5167: The guard test can pass without protecting broadcast or settlement
  Impact: A regression that drops admission after the initial wallet reads can pass this test even though removal or Clear can race broadcast and persistence again.
  The test observes both guards only at the first wallet lock. Its fixture never binds a shielded account, so releasing the locks does not take any operation through proof, broadcast, or settlement. The fixed 100 ms sleep also does not establish that the spawned future reached admission before the assertions. Keep the entry-point sweep but poll to a known pending point or use an explicit barrier. Add a bound, funded path with a deterministic pause at submission or settlement, and verify that teardown is excluded there and can proceed after the spend returns.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1735-1740: A public spend can deadlock if its caller already holds the lifecycle gate
  Impact: A Rust integrator wrapping a spend in `CoreWallet::generation_payment_guard()` can hang if removal queues before the spend tries to acquire its own read guard.
  The spend waits behind the queued teardown writer, and the writer waits for the caller's outer read guard. Tokio's write-preferring lock cannot grant that second read. The restriction is documented on the private helper, while the public guard tells callers to hold it across payment publication. Document on the affected public spend methods that they acquire the guard internally and must not be called with it already held.
Out-of-scope follow-up suggestions (3)

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.

  • Clear can still race other shielded payments — Token purchases, private contact request payments, and private document creates hold the generation gate but lack coordinator admission, so Clear can purge state they are still using. This patch does not change those paths.
    • Follow-up: Address their lock ordering and Clear admission in #6176.
  • Asset-lock funding can still publish after removal — The asset-lock operation itself is not fenced against wallet removal, even when no credit spend queues behind it. Protecting publication is separate from excluding teardown during an unbounded finality wait.
    • Follow-up: Use #5516 to fence asset-lock persistence and broadcast without holding the generation gate during the ChainLock wait.
  • Swift shutdown can outlive an unregistered native spend call — The Rust guards protect the wallet generation and shielded store, not the Swift manager handle's lifetime. An unregistered detached FFI call is not counted in Swift's shutdown drain.
    • Follow-up: Cover the Swift manager lifetime in #6179, as tracked in #6060.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

…ar until the wallet is bound again

Review follow-up on the spend admission:

- the admission also takes the wallet's shielded configuration lock and
  checks the binding, as the token pool spends do. The keys a handle
  holds outlive a Clear, and a shield needs no note from the cleared
  store, so a shield admitted after a Clear could debit for an account
  no scan reads. It is now refused with ShieldedNotBound;
- the identity-create export maps WalletRemovedBeforeSend to NotFound,
  as the other spend exports do;
- the public spend methods say that they take the gate, the admission
  and the configuration lock themselves, and teardown_guard names the
  operations that sign under the gate;
- the tests run on a bound wallet, wait for the admission instead of
  sleeping, and hold a transfer inside the operation, at the store,
  while a real removal waits.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

Changes requested: 6 blockers

  • Rebinding a wallet on iOS freezes the UI while its credit-pool transfer is in flight — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1774-1779 (new)
    Impact: An iOS app that rebinds a wallet during a transfer stops processing UI events until the transfer finishes, even when the account list is unchanged.
  • Identity creation requires initialized memory for a write-only C output — packages/rs-platform-wallet-ffi/src/shielded_send.rs:1060 (new)
    Impact: A C caller that supplies an uninitialized 32-byte ID buffer as permitted by the export’s contract reaches undefined behavior when the wallet result is mapped, even if the spend is refused.
  • A queued top-up or shield can block wallet removal and Clear indefinitely — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2136-2144 (carried)
    Impact: A wallet client that queues a top-up or inbound shield while asset-lock funding awaits a ChainLock can leave native removal and Clear waiting even though the queued spend has not started.
  • Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2025-2028 (thread, carried)
    Impact: An iOS user who clears shielded state or deletes the spending wallet can block the main actor until the in-flight spend returns.
  • Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3469-3473 (thread, carried)
    Impact: If removal was requested while an identity-funded shield was building and the shield’s result is unconfirmed, re-importing the wallet and retrying can debit the identity a second time.
  • An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3469-3477 (thread, carried)
    Impact: A native host cannot finish removing a wallet while a credit-pool spend’s external signer is awaiting approval, even though the spend has not been sent.

New on this head: This revision checks the coordinator’s Clear generation before admitting credit-pool spends, aligns the identity-create FFI refusal codes with the other spend exports, and expands the admission tests. The Kotlin SDK emulator build and tests are still pending; no failed code checks were reported.

🔴 6 blocking | 🟡 3 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: A queued top-up or shield can block wallet removal and Clear indefinitely
Impact: A wallet client that queues a top-up or inbound shield while asset-lock funding awaits a ChainLock can leave native removal and Clear waiting even though the queued spend has not started.
packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2136-2144

An operation still waiting its turn can prevent teardown indefinitely. Asset-lock funding holds shield_guard over its finality wait (fund_from_asset_lock.rs:211–236), and user-facing funding can supply no ChainLock deadline. A top-up or inbound shield takes the generation reader and coordinator admission before waiting for that same guard. Native removal and this head’s Clear then wait on the queued spend, which has not built or published anything. Documentation and #6189 track the regression but do not bound the wait. Make pre-operation admission interruptible while queued, or use a lock-order-safe admission protocol that does not pin teardown while the spend is waiting its turn.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)

Still open from earlier rounds (3)

  • 🔴 Blocking: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2025-2028 (thread)
  • 🔴 Blocking: Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3469-3473 (thread)
  • 🔴 Blocking: An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3469-3477 (thread)
Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — In platform_wallet.rs, PlatformWallet::admit_shielded_spend holds three ordered guards across asynchronous work in seven funds-movement paths, changing whether those operations can sign or broadcast during wallet removal or Clear.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane 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 (dd132cf0): 3 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 2 confirmed, 1 not confirmed (no longer blocking)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-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:1774-1779: Rebinding a wallet on iOS freezes the UI while its credit-pool transfer is in flight
  Impact: An iOS app that rebinds a wallet during a transfer stops processing UI events until the transfer finishes, even when the account list is unchanged.
  A routine rebind can now freeze the main actor for the rest of proof generation and confirmation. Swift’s `shieldedTransfer` runs in a detached task, so the main actor can enter the synchronous `bindShielded` while it runs. For example, Sync Now rebinds every non-mirror wallet, including a wallet with a transfer in flight. The Swift bind checks shutdown and sync-stop state, not spend contention. Its FFI call joins a worker running `bind_shielded_from_persisted`, which waits for `shielded_config_lock` at line 1194 before it can recognize an unchanged registration. Credit transfers did not hold that mutex on the previous head; they now hold it through settlement. Neither #6179 nor #6182 changes this bind path. Keep the binding stable, but make synchronous bind return a retryable busy result from Rust or let Swift await the native bind off the main actor.

  _Confirmed by an independent pass: An iOS app can start a funded `shieldedTransfer` and then call `bindShielded` for the same wallet on the main actor while the detached transfer is proving or awaiting confirmation. Even an unchanged rebind synchronously joins the native worker, which waits for the transfer's configuration lock before checking whether the registration changed, leaving the UI unresponsive until the transfer returns._
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2136-2144: A queued top-up or shield can block wallet removal and Clear indefinitely
  Impact: A wallet client that queues a top-up or inbound shield while asset-lock funding awaits a ChainLock can leave native removal and Clear waiting even though the queued spend has not started.
  An operation still waiting its turn can prevent teardown indefinitely. Asset-lock funding holds `shield_guard` over its finality wait (`fund_from_asset_lock.rs:211–236`), and user-facing funding can supply no ChainLock deadline. A top-up or inbound shield takes the generation reader and coordinator admission before waiting for that same guard. Native removal and this head’s Clear then wait on the queued spend, which has not built or published anything. Documentation and #6189 track the regression but do not bound the wait. Make pre-operation admission interruptible while queued, or use a lock-order-safe admission protocol that does not pin teardown while the spend is waiting its turn.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1774-1779: Transfers from separate accounts on the same wallet now wait for each other
  Impact: A client making concurrent transfers from two funded shielded accounts on one wallet cannot start selecting notes for the second until the first fully settles.
  A separate account now waits for the first transfer’s proof and network result. The incremental change holds one wallet-wide configuration mutex through settlement, even though transfer only needs a stable binding. Note selection and reservation already happen atomically under the store write lock, and shield-class operations that need stronger ordering have `shield_guard`. A configuration read guard for spends and a write guard for bind, account add, and tip-account preparation would preserve exclusion against configuration changes without serializing independent transfers.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1773-1775: A self-shield can debit credits for an account the wallet does not scan
  Impact: A Rust wallet client that funds a newly added shielded account can be debited while the resulting note remains absent from the scanned balance.
  A funded wallet can move credits into a newly added account and still show no note after sync. A Rust caller can bind account 0, successfully add account 1 with `shielded_add_account`, then call `shielded_shield_from_account` to fund it. Account addition persists the viewing key and publishes it to `shielded_keys`, but does not register that account with the coordinator (lines 1616–1627). The new admission check relies on the coordinator pointer and Clear generation as evidence that the keys are installed; both still match. The self-shield reads account 1 from the local slot at lines 3287–3298, then signs and broadcasts using that key without looking it up in the scanner registry or needing an existing note. The credits are not destroyed, but the scanner cannot find them until the account is registered and scanned. A direct coordinator unregister can leave the same mismatch without changing the Clear generation, so a one-time registry lookup alone does not fence all mutations. Verify the selected account and viewing key against the installed registration before signing, and keep that registration stable through the spend.

  _Raised as blocking. An independent pass did not find a failure someone would actually hit, so it does not block: `shielded_add_account` persists the key and inserts it into the wallet's local slot without updating the scanner registry; it explicitly tells callers to rebind with the full account list. The new admission check verifies coordinator identity and Clear generation, not account membership, so the reported self-shield can still succeed without the scanner seeing the note. But the base and previous reviewed head already allowed the same sequence, including the mismatch after a direct coordinator unregister; the PR neither creates nor worsens it._
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2025-2028: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518087)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3469-3473: Removal requested during proof building can erase an unconfirmed debit's recovery record
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518099)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3469-3477: An open signing prompt can prevent wallet removal before anything is sent
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518114)

In `packages/rs-platform-wallet-ffi/src/shielded_send.rs`:
- [BLOCKING] packages/rs-platform-wallet-ffi/src/shielded_send.rs:1060: Identity creation requires initialized memory for a write-only C output
  Impact: A C caller that supplies an uninitialized 32-byte ID buffer as permitted by the export’s contract reaches undefined behavior when the wallet result is mapped, even if the spend is refused.
  A caller can provide valid identity-create inputs and a writable output array, then read the array only on success or an unconfirmed broadcast. The new `&mut *out_identity_id` instead creates a typed Rust reference to an initialized `[u8; 32]` before the mapper sees the result. The null check does not establish initialization. The old export wrote through the raw pointer only in the two arms that produced an ID, and the new initialized-sentinel test checks only that refusals do not overwrite it. Return an optional ID from the mapper and call `out_identity_id.write(id)` only when an ID is present, preserving both the refusal codes and the untouched-on-error contract.

  _Confirmed by an independent pass: A C caller can pass valid identity-create inputs and an uninitialized but writable 32-byte output buffer, then read it only on a result code that promises an ID. The export forms and passes `&mut [u8; 32]` from that buffer before inspecting the result, so the call has undefined behavior even on an ordinary refusal such as `ShieldedNotBound` that should leave the buffer untouched._

In `packages/rs-platform-wallet/src/wallet/shielded/spend_admission_tests.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/spend_admission_tests.rs:401-410: The guard test can pass without protecting broadcast or settlement
  Impact: A future change that releases admission before the final local wallet write can pass the admission suite while letting teardown race that write.
  The new tests cover entry and note selection, but not local settlement. The bound fixture, admission probe, and store pause improve the earlier test; the transfer then exits on an empty store and the assertion accepts any result except the two admission refusals. The guard is correctly scoped today, but moving it into the existing inner block of `shielded_identity_create_from_pool` would still pass the suite while leaving `add_identity` outside the guard. One deterministic test at a successful spend’s local write, using an injected result rather than a live peer, would catch that regression.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 24, 2026
…heck only

Review follow-up:

- a credit pool spend held the wallet's shielded configuration lock
  until it settled. Every bind of the wallet, a host's routine re-bind
  of an unchanged account list included, then waited for the proof and
  the result, and the wallet's transfers ran one at a time. The lock is
  now taken to read the binding and released at once; the gate and the
  coordinator's admission are still held through the spend;
- the identity-create result mapper returns the identity id instead of
  writing through a reference to the caller's output buffer, which a C
  caller may leave uninitialised. The export stores it through the raw
  pointer, and only when an id is present, as it did before.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 24, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

Changes requested: 4 blockers

  • A queued top-up or shield can block wallet removal and Clear indefinitely — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2139-2150 (carried)
    Impact: A wallet host that starts a top-up or inbound shield while same-wallet asset-lock funding is stalled on finality can lose access to native removal and Clear even though the queued payment has not started.
  • Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1770-1784 (thread, carried)
    Impact: An iOS user who taps Clear or deletes the spending wallet during proof generation or confirmation can lose UI responsiveness until the spend returns.
  • An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3484-3488 (thread, carried)
    Impact: A Rust host using an external signer cannot remove the wallet while the signer awaits approval, even though the spend has not been sent.
  • Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3484-3488 (thread, carried)
    Impact: If a host removes a wallet during an identity-funded shield that returns unconfirmed, re-importing the wallet and retrying can debit the identity again after the original payment executes.

New on this head: This revision releases the configuration lock after the shielded binding check while retaining the lifecycle and Clear guards through each spend, and writes the identity-create C output only for results that carry an ID. No code check had failed when reviewed; Rust workspace tests and the Kotlin SDK emulator build and tests were pending.

🔴 4 blocking | 🟡 1 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🔴 Blocking: A queued top-up or shield can block wallet removal and Clear indefinitely
Impact: A wallet host that starts a top-up or inbound shield while same-wallet asset-lock funding is stalled on finality can lose access to native removal and Clear even though the queued payment has not started.
packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2139-2150

A queued payment can prevent teardown without building or dispatching a transition. The public funding export passes no ChainLock deadline (shielded_send.rs:2343–2359), and shielded_fund_from_asset_lock holds shield_guard across that fallback. If the host starts a top-up or inbound shield while funding is still pending, the new payment takes both admission readers before it waits for that same mutex. Removal and Clear then wait on those readers for as long as finality is unavailable; on this head the queued Clear writer also blocks later admissions on the coordinator. On the base, a payment waiting for shield_guard held neither reader. #6189 tracks this regression, but does not prevent it here. Make the pre-send mutex wait interruptible, or return a retryable busy result on contention before retaining either reader.

source: muse-spark-1.3-contributor (phase1-reviewer: rust-quality)

Still open from earlier rounds (3)

  • 🔴 Blocking: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1770-1784 (thread)
  • 🔴 Blocking: An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3484-3488 (thread)
  • 🔴 Blocking: Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3484-3488 (thread)
Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — In platform_wallet.rs, admit_shielded_spend and its seven callers change whether shielded funds movements can reach signing and broadcast, coordinating three locks and holding two guards across asynchronous proof generation, broadcast, and settlement.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane 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 (f2230052): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 not confirmed (no longer blocking)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-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:2139-2150: A queued top-up or shield can block wallet removal and Clear indefinitely
  Impact: A wallet host that starts a top-up or inbound shield while same-wallet asset-lock funding is stalled on finality can lose access to native removal and Clear even though the queued payment has not started.
  A queued payment can prevent teardown without building or dispatching a transition. The public funding export passes no ChainLock deadline (`shielded_send.rs:2343–2359`), and `shielded_fund_from_asset_lock` holds `shield_guard` across that fallback. If the host starts a top-up or inbound shield while funding is still pending, the new payment takes both admission readers before it waits for that same mutex. Removal and Clear then wait on those readers for as long as finality is unavailable; on this head the queued Clear writer also blocks later admissions on the coordinator. On the base, a payment waiting for `shield_guard` held neither reader. #6189 tracks this regression, but does not prevent it here. Make the pre-send mutex wait interruptible, or return a retryable busy result on contention before retaining either reader.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1777-1784: Rebinding without the spending account can erase a transfer’s recovery record during broadcast
  Impact: An SDK client that rebinds a multi-account wallet with a shorter account list can receive an unconfirmed transfer result after the wallet has erased the signed transition it needs for automatic recovery.
  An unconfirmed transfer can lose its saved transition before it returns. The public bind APIs support replacing the account list: a client can bind `[0, 1]`, send from funded account 1, then run a primary-account rebind with `[0]` while confirmation is outstanding (`[0]` is also the Swift SDK default). The transfer has already saved the exact transition and handed over its note reservation before awaiting the network (`operations.rs:5096–5112`). This head drops the configuration guard after the binding check, unlike the previous reviewed head. Bind and transfer take compatible readers, and transfer does not take the bind’s `shield_guard`. `register_locked` skips recovery records with nonempty nullifiers when checking displaced owners, then purges account 1 (`coordinator.rs:878–892,952–955`); `purge_subwallet` deletes its durable record (`file_store.rs:1761–1775`). If confirmation fails, settlement reports an unconfirmed spend without recreating that record. Keep identical and additive binds fast, but make Rust reject a bind that would drop an actively spending account before changing its registration or purging state.

  _Raised as blocking. An independent pass did not find a failure someone would actually hit, so it does not block: The race is reachable: while a transfer from account 1 awaits confirmation, rebinding from [0, 1] to [0] can delete its durable recovery record. The bind and transfer hold compatible read guards, the transfer does not hold shielded_config_lock during broadcast, and settle_failed_spend does not recreate the record. The last reviewed head prevented this overlap, but the merge base already allowed the same sequence: shielded_transfer_to held no configuration guard, and the bind, purge, and settlement paths are unchanged. This head therefore leaves a real pre-existing defect that the PR neither introduces nor worsens._
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1770-1784: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518087)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3484-3488: An open signing prompt can prevent wallet removal before anything is sent
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518114)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3484-3488: Removal requested during proof building can erase an unconfirmed debit's recovery record
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518099)

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-self-review Waiting for the author to post /self-reviewed label Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 24, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

Changes requested: 4 blockers

  • Two queued top-ups can hang after the active shield finishes — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1810-1819 (new)
    Impact: A wallet SDK client that submits two identity top-ups on the same bound wallet while a shield is running can be left waiting for both calls even after the shield finishes.
  • An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3525-3526 (thread, carried)
    Impact: A Rust host with a funded, bound wallet cannot finish removing it while an identity-funded shield awaits external signing approval, even though nothing has been broadcast.
  • Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3525-3526 (thread, carried)
    Impact: A user who removes a wallet during an identity-funded payment to a third party can lose the retry protection and pay twice if they re-import the wallet and retry an unconfirmed payment.
  • Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2066-2068 (thread, carried)
    Impact: An iOS user who clears shielded state or deletes a wallet during a funded shielded transfer can block the main actor until the transfer returns on this head.

New on this head: On e90d15a, shield-class spends release their wallet lifecycle and Clear admission guards while waiting for the single-flight lock, then repeat the wallet and binding checks before proceeding. The Kotlin SDK emulator build and tests passed; PR Hygiene and the review check are still pending.

🔴 4 blocking | 🟡 1 suggestion(s)

Still open from earlier rounds (3)

  • 🔴 Blocking: An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3525-3526 (thread)
  • 🔴 Blocking: Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3525-3526 (thread)
  • 🔴 Blocking: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2066-2068 (thread)
Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — PlatformWallet::admit_shielded_spend changes which of seven funds-moving operations may proceed to signing and broadcast, with overlapping lifecycle and Clear guards that must remain correct across asynchronous execution.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane 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 (d28af0bb): 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.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-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:1810-1819: Two queued top-ups can hang after the active shield finishes
  Impact: A wallet SDK client that submits two identity top-ups on the same bound wallet while a shield is running can be left waiting for both calls even after the shield finishes.
  Neither top-up has to reach note selection. Two positive-amount calls to `shielded_identity_top_up_from_pool` on a current, bound wallet can both queue on `shield_guard` while a shield holds it. When the shield finishes, Tokio assigns the permit to the first waiter, which immediately drops it at line 1819 and hands it to the second. On a current-thread runtime with no contention on the admission locks, the first waiter completes re-admission, fails `try_lock()` because the permit is already assigned, and queues again before the second is polled. The second then hands the permit back and requeues in the same way. That cycle needs no new requests or network activity. Serialize entry to this retry loop with a per-wallet mutex acquired before either admission guard, and add a current-thread regression test that parks two callers behind one holder and requires both to finish after it releases.

  _Confirmed by an independent pass: A Rust SDK caller on a current-thread Tokio runtime can start two positive-amount `shielded_identity_top_up_from_pool` calls on the same bound, current wallet while an in-flight shield holds `shield_guard`. Once the shield finishes, if the admission locks are uncontended, the two calls repeatedly hand the mutex permit to each other and requeue, so neither reaches note selection or returns._
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3525-3526: An open signing prompt can prevent wallet removal before anything is sent
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518114)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3525-3526: Removal requested during proof building can erase an unconfirmed debit's recovery record
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518099)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2066-2068: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518087)

In `packages/rs-platform-wallet/src/wallet/shielded/spend_admission_tests.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/spend_admission_tests.rs:313-327: The admission sweep no longer checks either inbound shield after it starts
  Impact: A future change that releases admission immediately after acquiring the single-flight lock could pass the suite for both inbound shield paths.
  The new queue tests verify that a waiting shield releases both guards and rechecks admission, not that a running shield keeps them. This revision removes `ShieldFromAccount` and `ShieldFromIdentity` from the guard-hold sweep: both reach a wallet-manager read before the key-slot pause and return early on the unfunded fixture. The old sweep checked exclusion at the first lock, not at settlement. Restore that narrower check without a funded network fixture: poll each shield to the configuration lock after the liveness read, then hold the wallet-manager write lock and let it advance past admission. At the subsequent wallet-manager read, assert that both guards are still held.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 24, 2026
…t for the guard

Two shield-class spends that both waited on shield_guard gave it up at
once and handed it to each other: each re-took its admission, found the
guard already assigned to the other, and queued again, for ever. One
spend at a time now waits for the guard; the others wait their turn on
a mutex of their own, holding nothing.

Also restores the two shields to the check that a running spend keeps
its admission, held at the wallet manager they read first.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 24, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

Changes requested: 3 blockers

  • Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3540-3541 (thread, carried)
    Impact: A wallet client that requests removal while an identity-funded shield is proving can lose its recovery record and debit the identity a second time if it reimports the wallet and retries an already-executed payment.
  • An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3540-3541 (thread, carried)
    Impact: A Rust host that requests wallet removal while an external signer is waiting for approval can be left waiting indefinitely even though the payment has not been sent.
  • Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2081-2083 (thread, carried)
    Impact: On the current target branch, an iOS user who invokes Clear during a funded credit-pool transfer can lose UI responsiveness for the rest of proof generation and confirmation.

New on this head: This revision adds a per-wallet turn mutex so only one queued shield-class spend retries admission at a time, and restores tests that check both inbound shields retain admission once running. The Kotlin SDK build and emulator tests passed on the reviewed head; no code checks were failing, and review and PR Hygiene checks were still pending.

🔴 3 blocking | 🟡 2 suggestion(s)

Still open from earlier rounds (3)

  • 🔴 Blocking: Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3540-3541 (thread)
  • 🔴 Blocking: An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3540-3541 (thread)
  • 🔴 Blocking: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2081-2083 (thread)
Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — In platform_wallet.rs, admit_shielded_spend and admit_single_flight_shielded_spend introduce intricate lock ordering and re-admission logic that directly governs whether shielded credit-pool payments can proceed to signing and broadcast during wallet deletion or Clear.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane 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; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-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`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:1822-1824: A top-up started after Clear can wait for a ChainLock instead of reporting that the wallet is unbound
  Impact: A Rust caller submitting a top-up after Clear can wait indefinitely for unrelated funding instead of receiving `ShieldedNotBound` and knowing to rebind.
  The new turn mutex moves the first binding check behind a potentially unbounded wait. Asset-lock funding can hold `shield_guard` while awaiting a ChainLock without a deadline. If a top-up queues behind it, that top-up holds `shield_turn` but drops admission, so Clear can complete. A second top-up started after Clear waits for the turn and cannot reach the binding check; the previous head checked the binding before waiting on `shield_guard`. Keep the one-waiter rule, but on a contended turn run the existing admission check and drop any successful admission before waiting. Recheck authoritatively after acquiring the turn. A regression test can hold the original guard across Clear and require the second top-up to return `ShieldedNotBound` before releasing it.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3540-3541: Removal requested during proof building can erase an unconfirmed debit's recovery record
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518099)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3540-3541: An open signing prompt can prevent wallet removal before anything is sent
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518114)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2081-2083: Clear and Delete Wallet can freeze the iOS UI during a credit-pool spend
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518087)

In `packages/rs-platform-wallet/src/wallet/shielded/spend_admission_tests.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/spend_admission_tests.rs:611-616: The livelock test can release the guard without confirming that multiple spends are queued
  Impact: The regression test can pass without exercising the competing waiters that trigger the livelock, and every run incurs a fixed 200 ms delay.
  The test checks for unfinished tasks and idle admission before releasing `in_flight`, but those checks also pass for tasks that have not yet been polled. The regression requires multiple callers to have reached their wait before the holder releases the guard. Pin each spend future and poll it to `Pending` while holding `shield_guard`, then release the guard and drive the same futures concurrently under the timeout. In this fixture the other locks are uncontended, so that establishes the queue without depending on elapsed time.

…ycle-gate

Conflict in the shielded coordinator: the test-only has_admitted_operation
next to try_admit_clear from #6182. Both kept.

With #6182 merged a Clear refuses while a shielded operation is admitted,
so the admission tests now run the real Clear: refused at once during a
credit pool spend, not refused for a spend that is only queued. A spend
that queues behind a contended turn after that Clear is told at once that
the wallet is not bound, and the livelock test polls each spend until it
waits instead of sleeping.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

Changes requested: 2 blockers

  • Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3573-3574 (thread, carried)
    Impact: A Kotlin or Rust caller who removes a wallet during an identity-funded payment can lose the record that prevents a second debit after re-import if the first payment executed but its confirmation was lost.
  • An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3573-3574 (thread, carried)
    Impact: A native Rust host that removes a wallet while an external signer awaits approval cannot complete removal until the signer returns or the host cancels the spend, even though nothing has been sent.

New on this head: This revision merges v5.1-dev, checks wallet liveness and binding before waiting for a contended shield turn, and rechecks them when the turn arrives. It also makes the queue regression test deterministic and adds coverage for Clear refusing an active spend without blocking one that is only queued. The Kotlin emulator build and tests passed; no code checks were failing, and PR Hygiene and review checks remained pending.

🔴 2 blocking

Still open from earlier rounds (2)

  • 🔴 Blocking: Removal requested during proof building can erase an unconfirmed debit's recovery record — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3573-3574 (thread)
  • 🔴 Blocking: An open signing prompt can prevent wallet removal before anything is sent — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3573-3574 (thread)
Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — In platform_wallet.rs, admit_shielded_spend and admit_single_flight_shielded_spend use intricate lock ordering and re-admission checks to change which credit-pool spends can reach signing and broadcast and to prevent removal or Clear from interrupting settlement.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane 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 (35aaaa28): 1 nitpick(s) on unchanged code dropped
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — rust-quality (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-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:3573-3574: Removal requested during proof building can erase an unconfirmed debit's recovery record
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518099)
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:3573-3574: An open signing prompt can prevent wallet removal before anything is sent
  (carried; thread: https://github.com/dashpay/platform/pull/6178#discussion_r4673518114)

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 24, 2026
@QuantumExplorer
QuantumExplorer merged commit 6273ff1 into v5.1-dev Nov 24, 2026
30 of 32 checks passed
@QuantumExplorer
QuantumExplorer deleted the fix/platform-wallet-shielded-spend-lifecycle-gate branch November 24, 2026 02:17
QuantumExplorer added a commit that referenced this pull request Nov 24, 2026
…spends' admission

The previous commit removed `shielded_config_lock` from
`admit_shielded_spend` for all ten spends. For the seven credit pool
spends that widened a window that exists on v5.1-dev: a bind that drops an
account and waits its turn no longer held back a transfer from that
account that started after it, and the bind could then purge the
transfer's saved transition (#6196).

`admit_shielded_spend` is back to what #6178 merged, with its tests. The
three payments this branch admits use `admit_shielded_payment`, which
reads the binding without the lock: they never waited for a bind on
v5.1-dev, so they neither hang behind one queued on an asset-lock funding
nor gain or lose anything against #6196.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants