Registry Mirror
Skip to content

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

SwiftExampleApp's Direct Purchase screen can now pay from the wallet's shielded balance instead of the identity's credits, using TokenPurchaseFromShieldedPool (state transition type 28). The wallet's credit pool notes pay the price and a fee. The tokens are minted as a note to the wallet's own address in the token's shielded pool. No identity is involved.

Before: the only option was "Direct purchase debits credits from this identity".
After: when Rust reports that the token has a shielded pool, a Pay with control offers Identity credits (unchanged) or Shielded pool. The shielded option shows the shielded balance, the pool fee estimate and price plus fee. A purchase that Platform accepts is reported as submitted, and a shielded sync confirms it once it lands.

This is the first of the three shielded token transitions (26, 27, 28). The other two are left out on purpose (see below).

Issue being fixed or feature implemented

Types 26 (TokenShieldedTransferWithShieldedFee), 27 (TokenUnshieldWithShieldedFee) and 28 (TokenPurchaseFromShieldedPool) have DPP builders and Drive handling. Nothing below the Rust libraries used them: there was no wallet operation, FFI, Swift or UI.

They are active in protocol version 15. They have been allowed since PV14 (TOKEN_SHIELDED_POOL_INITIAL_PROTOCOL_VERSION = 14), and #5969 changed the token bundle to bind the fee bundle's commitment from PV15 (v15.rs note 47). The marketplace move to PV16 (#5910) did not include them. No open PR or issue covered client support.

Why only type 28: platform-wallet syncs only the credit shielded pool; it tracks no token-pool notes, anchors or nullifiers. Types 26 and 27 spend token-pool notes, so they need a token-pool note sync first. Type 28 spends only credit-pool notes, which the wallet already has.

Left for follow-ups:

What was done?

rs-dpp

  • TokenPurchaseFromShieldedPoolTransitionV0::is_valid_token_count holds the token-count bound in one place. The transition's structure validation and the wallet's early refusal both call it. Behaviour is unchanged (see "In-place changes to shipped generations").

rs-sdk

rs-platform-wallet

  • operations::token_purchase_from_pool and PlatformWallet::shielded_token_purchase_from_pool do the whole purchase in Rust. Before reserving any note they check, in order:

    1. The token count (DPP's rule).
    2. The protocol requirement.
    3. That a verified fetch of the token's configuration has has_shielded_pool(), and the recorded anchor set.
      After every network read, the signing generation: the SDK's version must equal the verified network version, because PV15 adds the fee-bundle binding.
    4. The largest note count whose signed transition fits the size limit and action cap (3 notes today), sized with Orchard's Proof::expected_proof_size.

    After those checks they reserve notes for price plus fee, build at the checked version, record activity, broadcast with redrive, and settle.

  • Settlement: type 28's proof is only the token pool's balance, which binds neither the fee nullifiers nor the minted note. An accepted purchase therefore stays pending: the row stays Pending, the notes stay reserved and the recovery record stays. The result is ShieldedTokenPurchaseOutcome::Submitted. The credit-pool scan confirms it when it finds the fee bundle's change note, which the activity entry is keyed by, and the nullifier sync marks the notes spent.

  • Wallet removal: the purchase holds the wallet generation payment guard through settlement, so removing a wallet waits for a purchase in flight, and a purchase on a removed wallet is refused.

  • Follow-up sync: PlatformWalletManager::shielded_token_purchaser runs the purchase and requests a shielded sync itself when the outcome is submitted or unconfirmed.

  • token_shielded_purchase_availability answers whether the form may offer the shielded option: available, no shielded pool, or configuration unreadable.

  • New kinds: ShieldedFeeKind::TokenPurchase (fee estimate kind 5) and ShieldedActivityKind::TokenPurchase (tag 10, counterparty = token id).

  • Saved recovery records accept type 28.

  • INFO logs carry the stage and outcome only, with no note values.

rs-platform-wallet-ffi

  • platform_wallet_manager_shielded_token_purchase_from_pool(...) and platform_wallet_manager_shielded_token_purchase_availability(...) only marshal the arguments and map the result. Both stop a Rust panic before it reaches the C caller.
  • platform_wallet_shielded_estimate_fee accepts kind 5.

Swift SDK / SwiftExampleApp

  • New Swift API: shieldedTokenPurchaseFromPool(...), shieldedTokenPurchaseAvailability(...) and ShieldedFeeKind.tokenPurchaseFromPool.
  • TokenPurchaseActionView offers the shielded choice only on Rust's "available" answer. Otherwise it explains why, with Retry when the configuration couldn't be read.
  • Shielded Activity labels the kind "Token Purchase". It shows the token and "Tokens to: this wallet's shielded token pool", and says the tokens were minted only when the row is Confirmed.
  • TEST_PLAN.md adds SH-24 (purchase, implemented, not yet run on a device or simulator) and SH-25 to SH-27 (not implemented).
  • docs/sdk/sdk-parity-manifest.json adds shielded.token_purchase_from_pool (Swift partial, Kotlin unsupported), and PARITY_SUMMARY.md is regenerated.

Public interface changes

Layer Before After
C FFI none platform_wallet_manager_shielded_token_purchase_from_pool(...), platform_wallet_manager_shielded_token_purchase_availability(...) (0 available, 1 no pool, 2 unreadable)
C FFI platform_wallet_shielded_estimate_fee kinds 0 to 4 kinds 0 to 5
Persisted activity kindTag 0 to 9 0 to 10 (10 = token purchase)
Rust PlatformWalletError none ShieldedTooManyNotes, ShieldedProtocolVersionMismatch, TokenShieldedPoolDisabled, TokenConfigurationUnavailable
Rust enums none ShieldedTokenPurchaseOutcome, ShieldedTokenPurchaseAvailability; new variants ShieldedFeeKind::TokenPurchase, ShieldedActivityKind::TokenPurchase
Rust SDK no type 28 entry token_purchase_from_shielded_pool_requirement()
Swift none shieldedTokenPurchaseFromPool(...), shieldedTokenPurchaseAvailability(...), ShieldedFeeKind.tokenPurchaseFromPool

Source compatibility (Rust): ShieldedFeeKind, ShieldedActivityKind and PlatformWalletError are public and not #[non_exhaustive]. Rust code that matches them exhaustively must add the new variants before it compiles again. The persisted tags and the C ABI are unaffected, and there is no protocol change.

In-place changes to shipped generations

TokenPurchaseFromShieldedPoolTransitionV0::validate_structure (structure validation v0, selected by shipped PV14) now asks !Self::is_valid_token_count(self.token_count) instead of self.token_count == 0 || self.token_count > MAX_DISTRIBUTION_PARAM. The new predicate is token_count != 0 && token_count <= MAX_DISTRIBUTION_PARAM, so its negation is exactly the old condition. The order of checks and the error built (InvalidTokenAmountError(MAX_DISTRIBUTION_PARAM, token_count)) are unchanged, so no transition is accepted or refused differently. should_bound_the_token_count_at_the_shipped_protocol_version pins this at PlatformVersion::get(14): counts 0 and max + 1 are refused, and max is accepted.

How Has This Been Tested?

  • cargo fmt --all: clean.
  • cargo test -p platform-wallet --features shielded --lib -- token_purchase pending_spend: 26 passed. They cover:
    • fee and selection agreement;
    • invalid counts, zero price, and the three-versus-four-note boundary (nothing reserved, no record or activity);
    • activation refusal at protocol 13, and SDK/network version mismatch both ways;
    • no-pool and unreadable-configuration refusals, and the availability query;
    • a pool-balance outcome keeping the purchase pending with unspent notes, and an unconfirmed outcome kept pending;
    • wallet removal in both orders, and a sync requested only for an outcome that may be on the network;
    • a real-prover round trip: should_confirm_a_built_token_purchase_from_its_fee_bundle_change builds a type 28 from a note worth exactly price plus fee (zero-valued change), records it through the live path, scans only the fee-bundle change, and sees the row become Confirmed.
  • cargo test -p platform-wallet --features shielded --lib -- shielded::coordinator shielded::activity shielded::sync: 82 passed .
  • cargo test -p platform-wallet-ffi --features shielded --lib token_purchase (4 passed) and the fee estimate tests.
  • cargo test -p dash-sdk --lib should_refuse_a_generic_broadcast: 3 passed.
  • cargo test -p dpp --lib token_purchase_from_shielded_pool: 9 passed.
  • cargo clippy --all-targets --all-features --locked -- --no-deps -D warnings on dpp, dash-sdk, platform-wallet and platform-wallet-ffi: clean.
  • python3 scripts/check_sdk_parity_manifest.py --write-summary: OK.
  • Swift: a header-swap xcodebuild of SwiftExampleApp compiled with no Swift errors. Link errors appeared only for symbols missing from the borrowed xcframework.

Not tested: linking and running the app against a library built from this branch, and a real broadcast accepted by Drive. SH-24 in the test plan describes the manual run.

Breaking Changes

No protocol or consensus change, and no C ABI or persisted format change. The Rust items are additive, but see "Source compatibility (Rust)" above for exhaustive matches.

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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · c216f16

  • Bots — thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • 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 running
  • Approvals
    • sdk-parity — you own it
    • kotlin-sdk (packages/kotlin-sdk/PARITY_SUMMARY.md) — HashEngineering
    • dpp — you own it
    • rs-platform-wallet-ffi (packages/rs-platform-wallet-ffi/src/persistence.rs, packages/rs-platform-wallet-ffi/src/shielded_persistence.rs, packages/rs-platform-wallet-ffi/src/shielded_send.rs) — HashEngineering or ZocoLini or llbartekll or romchornyi
    • rs-platform-wallet (packages/rs-platform-wallet/src/error.rs, packages/rs-platform-wallet/src/manager/mod.rs, packages/rs-platform-wallet/src/manager/shielded_token_purchase.rs and 7 more) — HashEngineering or ZocoLini or llbartekll or romchornyi
    • rust-sdk (packages/rs-sdk/src/platform/transition/broadcast.rs, packages/rs-sdk/src/sdk/protocol_gate_tests.rs) — lklimek or shumkov
    • swift-sdk (packages/swift-sdk/Sources/SwiftDashSDK/Persistence/Models/PersistentShieldedActivity.swift, packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift, packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedActivityView.swift and 3 more) — 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.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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 added this to the v5.1.0 milestone Nov 22, 2026
@github-actions

github-actions Bot commented Nov 22, 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 22, 2026
@thepastaclaw

thepastaclaw commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 1b38910) · 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 1 + Phase 2

Changes requested: 7 blockers

  • A token-pool balance proof can confirm a purchase that did not execute — packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1847-1863 (new)
    Impact: A buyer can see “Purchase complete” and lose access to credit notes in the wallet even though those notes remain unspent and no tokens were minted for the purchase.
  • Purchases outside the wire or token-count limits can leave notes stuck in recovery — packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1782-1805 (new)
    Impact: A buyer whose payment needs four notes, or an SDK caller who supplies an above-limit raw count that the wallet can fund, can pay the proving cost and have notes held for a purchase that cannot execute.
  • The wallet can reserve credits for a purchase the network version cannot accept — packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1752-1763 (new)
    Impact: A funded buyer on a pre-PV14 network, or a buyer using an SDK pinned to PV14 after a PV15 upgrade, can wait for proving and have notes held for recovery instead of receiving a local version error.
  • Shielded Buy is enabled for direct-sale tokens that have no shielded pool — packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TokenActions/TokenPurchaseActionView.swift:299-305 (new)
    Impact: A funded buyer can select shielded payment for an ordinary direct-sale token, wait for proving, and have credit notes held pending recovery even though the token cannot be minted into a pool.
  • An in-flight purchase can recreate activity after its wallet is removed — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2085-2091 (new)
    Impact: A host that removes a wallet while a shielded purchase is waiting for a result can receive a new activity write for the removed wallet after teardown.
  • Immediate recovery after an unconfirmed purchase depends on which API was called — packages/rs-platform-wallet-ffi/src/shielded_send.rs:1501-1503 (new)
    Impact: After the same ambiguous purchase result, a Swift or C caller can trigger an immediate rebroadcast pass, while a direct Rust caller has to wait for another sync or request one itself.
  • Pending and failed activity details tell the buyer that tokens were minted — packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedActivityView.swift:317-326 (new)
    Impact: A buyer inspecting an unresolved or failed purchase sees “Purchased Token” and a mint confirmation beside the Pending or Failed status.

This PR adds direct token purchases funded by shielded credit notes, from the Rust wallet through the C binding to SwiftExampleApp. PR Hygiene and the PastaClaw review are pending; the reported checks show no failed code check and do not record a linked or executed Swift purchase. One verified nitpick was omitted under the ten-comment cap.

🔴 7 blocking | 🟡 3 suggestion(s)

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: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 8: 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) — The new spend path in operations.rs and fee calculation in note_selection.rs directly govern funds movement through fee-aware note reservation, transaction construction, broadcast, and settlement on success or failure.
  • 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 (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh verifier: gpt-6.2-sol — final-verifier; 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 — platform-versioning (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/shielded/operations.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1847-1863: A token-pool balance proof can confirm a purchase that did not execute
  Impact: A buyer can see “Purchase complete” and lose access to credit notes in the wallet even though those notes remain unspent and no tokens were minted for the purchase.
  A valid balance snapshot for an existing token pool is enough for this branch to mark the activity Confirmed, persist the selected notes as spent, and retire their recovery record. The wait request names the transition hash, but Drive verifies only `VerifiedTokenShieldedPoolBalance(token_id, balance)`: the proof binds neither the fee nullifiers nor the minted output. The type 22 analogy does not hold because its proof checks the submitted credit nullifiers. Keep the purchase pending on a balance snapshot alone and return the existing unconfirmed result across FFI. Use verified evidence tied to this purchase, such as inclusion of its exact fee-bundle change commitment in the credit-pool scan, and distinguish input consumption from evidence of minting. Test that a valid pool snapshot with unspent inputs neither confirms the row nor finalizes the notes.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1782-1805: Purchases outside the wire or token-count limits can leave notes stuck in recovery
  Impact: A buyer whose payment needs four notes, or an SDK caller who supplies an above-limit raw count that the wallet can fund, can pay the proving cost and have notes held for a purchase that cannot execute.
  These purchases can be proved and journaled before a known limit is enforced. With four notes, the two- and four-action Orchard proofs alone take 19,072 bytes; the six serialized actions push the purchase over 20,480 bytes even before the remaining fields. Selection checks funds and fees, not wire size or the versioned action cap. The SDK rejects the oversized request locally after recovery is armed, but the wallet's delivery classifier does not recognize that size error as never sent. Separately, the public API lets counts above `MAX_DISTRIBUTION_PARAM` reach a builder that only checks against `i64::MAX`; zero is rejected only after reservation and an anchor query. Reuse DPP's count and bundle limits before proving, and check the exact signed wire size before saving recovery. Keep zero price distinct from zero count. Test the three-to-four-note boundary and invalid counts, including that rejection does not leave a reservation or recovery record.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1752-1763: The wallet can reserve credits for a purchase the network version cannot accept
  Impact: A funded buyer on a pre-PV14 network, or a buyer using an SDK pinned to PV14 after a PV15 upgrade, can wait for proving and have notes held for recovery instead of receiving a local version error.
  The purchase starts with note selection rather than a network compatibility check. Drive-ABCI rejects type 28 below PV14, and the SDK broadcast requirement table has no type 28 entry. A minimum-version check alone is not enough: the SDK can verify a PV15 anchor response while retaining a PV14 construction pin, and the builder then omits the fee-bundle commitment that PV15 requires in the token-bundle signature. An endpoint refusal after dispatch is treated as potentially delivered, so recovery keeps the notes. Register the PV14 activation requirement using the SDK preflight and redrive pattern from #6051, and check the signing generation against the verified network version before proving. Test that pre-activation and incompatible-pin cases fail locally, while matching PV14 and PV15 cases proceed.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1765-1774: Exported diagnostics reveal shielded input and change values
  Impact: Anyone who receives a buyer's diagnostic archive can learn the total value of the selected notes and the intended change, even if the purchase failed before broadcast.
  The INFO event records `total_input` alongside the agreed price and fee, enough to derive the intended change and, for a single-input purchase, the exact value of that private note. SwiftExampleApp enables Rust file logging at INFO, and `LogExporter` copies complete session directories without redacting these fields. Log the operation stage and outcome without note values or unnecessary transaction-identifying fields, including in the success event.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TokenActions/TokenPurchaseActionView.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TokenActions/TokenPurchaseActionView.swift:299-305: Shielded Buy is enabled for direct-sale tokens that have no shielded pool
  Impact: A funded buyer can select shielded payment for an ordinary direct-sale token, wait for proving, and have credit notes held pending recovery even though the token cannot be minted into a pool.
  A price and a positive shielded credit balance enable Buy, but neither says the selected token supports shielded purchases. The Rust operation also goes straight to note selection, while Drive's `resolve_pooled_token` rejects configurations for which `has_shielded_pool()` is false. Have the Rust wallet read the verified token configuration and check the existing DPP accessor before reserving notes. Expose that result to the form so it can keep identity funding available without offering an impossible shielded purchase. Keep an unreadable configuration distinct from a disabled pool, and test a priced token with no pool.

In `packages/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:2085-2091: An in-flight purchase can recreate activity after its wallet is removed
  Impact: A host that removes a wallet while a shielded purchase is waiting for a result can receive a new activity write for the removed wallet after teardown.
  Removal can purge the wallet's shielded store while the detached purchase still holds the wallet, coordinator, and persister. When settlement resumes, `record_activity_status` finds no stored row, falls back to the captured pending row, and saves and queues it again. The retained `Arc`s keep the objects alive but do not keep that generation registered. In the Rust purchase entry point, take the generation payment guard, verify that the generation is current, and hold the guard through settlement, as the private-contact payment path does. Test both orderings: removal wins before the guarded call, and removal is requested while the result is pending.

In `packages/rs-platform-wallet-ffi/src/shielded_send.rs`:
- [BLOCKING] packages/rs-platform-wallet-ffi/src/shielded_send.rs:1501-1503: Immediate recovery after an unconfirmed purchase depends on which API was called
  Impact: After the same ambiguous purchase result, a Swift or C caller can trigger an immediate rebroadcast pass, while a direct Rust caller has to wait for another sync or request one itself.
  The new C export does more than map the purchase result. `poke_sync_on_unconfirmed` classifies wallet errors, looks up the sync manager, and schedules `sync_now(true)`, which can rebroadcast the saved purchase. The direct Rust entry point makes no such request. The book assigns sync orchestration and retry decisions to `rs-platform-wallet`; reusing an existing FFI helper does not make this policy marshalling. Move the recovery trigger into Rust manager orchestration, use the existing serialized sync path, and leave the export to forward arguments and map the result.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedActivityView.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedActivityView.swift:317-326: Pending and failed activity details tell the buyer that tokens were minted
  Impact: A buyer inspecting an unresolved or failed purchase sees “Purchased Token” and a mint confirmation beside the Pending or Failed status.
  The token ID identifies what the buyer intended to buy, not what executed: the wallet records it before broadcast, and the detail section checks only the kind tag and the ID length. This remains wrong even after the Rust confirmation path is fixed. Show the token ID and intended destination in neutral language, and reserve completed-mint wording for a purchase with a verified outcome.

In `packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md:294-297: The purchase test reuses IDs that now identify different flows on the target branch
  Impact: QA would have two meanings for SH-21 through SH-23 after conflict resolution, making the parity manifest's purchase test reference ambiguous.
  The purchase verification must point to one test. Target commit `5d14854adf` already uses SH-21 for shielding from an identity, SH-22 for topping up an identity, and SH-23 for restart recovery. The head also conflicts with the target in the parity manifest, generated Kotlin parity summary, and Swift test plan. Allocate unused IDs for the purchase and its follow-ups, update cross-references and the manifest, and regenerate the parity summary with both branches' capabilities present.

In `packages/rs-platform-wallet/src/wallet/shielded/activity.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/activity.rs:126: Existing exhaustive Rust matches stop compiling when clients upgrade platform-wallet
  Impact: Rust consumers that exhaustively match `ShieldedActivityKind` or `ShieldedFeeKind` must handle a new variant before they can rebuild.
  Appending `TokenPurchase` preserves the old persisted tags and does not break the C ABI, but both Rust enums are public and neither is `#[non_exhaustive]`. The PR's breaking-changes section calls the change entirely additive. Document the two new match cases as a Rust source-compatibility change; this does not require a Platform protocol bump.

@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-transitions branch from 25af9d6 to 4d450a2 Compare November 22, 2026 22:43
@github-actions

Copy link
Copy Markdown
Contributor

Your move: 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 22, 2026
@github-actions

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 22, 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: 2 blockers

  • A purchase stays Pending after another device spends its only input — packages/rs-platform-wallet/src/wallet/shielded/operations.rs:2075-2077 (new)
    Impact: A buyer using the same wallet on two devices can be told not to retry a purchase that can no longer execute, even after a complete sync and restart.
  • The wallet can reserve credits for a purchase the network version cannot accept — packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1905-1912 (thread, carried)
    Impact: A funded buyer whose wallet last verified PV14 can have credit notes held in recovery even after the purchase itself learns that the network has upgraded to PV15.

New on this head: The rebased revision adds wallet-side preflight checks and Rust-managed follow-up sync for shielded token purchases. A token-pool balance proof now leaves the purchase Pending, and Swift offers shielded funding based on Rust’s availability result and reports submission rather than minting. The Swift frozen-schema check, Rust wasm32 tests, JS build and package tests, and Kotlin emulator tests passed; Rust workspace tests are still pending.

🔴 2 blocking | 🟡 4 suggestion(s)

Still open from earlier rounds (1)

  • 🔴 Blocking: The wallet can reserve credits for a purchase the network version cannot accept — packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1905-1912 (thread)
Review provenance

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

  • Triage: critical by gpt-6.2-sol (effort low) — The new purchase flow in rs-platform-wallet's shielded/operations.rs changes how real funds move by selecting and reserving credit notes, broadcasting a shielded spend, and keeping the reservation pending until shielded sync confirms it.
  • 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 (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • New since the last final review (25af9d68): 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 — platform-versioning (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/shielded/operations.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:2075-2077: A purchase stays Pending after another device spends its only input
  Impact: A buyer using the same wallet on two devices can be told not to retry a purchase that can no longer execute, even after a complete sync and restart.
  The losing purchase has no path to a terminal status. A buyer can tap Buy on one device while a spend from another device using the same restored wallet consumes the sole selected note. Reservations are local, and a refusal after dispatch leaves the purchase Pending. This revision now relies on scan reconciliation to settle purchases: the verified scan calls `mark_spent` for the shared nullifier, which clears the reservation and deletes the redrive record. The other spend does not contain this purchase’s change commitment, so activity derivation cannot confirm the purchase. `release_stranded_spends` also skips it because it no longer has a matching reservation, even after the anchor expires. Reconcile Pending purchases using both the stored input nullifiers and the expected change commitment. A complete verified scan that covers the input spend can distinguish a competing spend from the purchase landing; an incomplete scan must not mark it Failed.

  _Confirmed by an independent pass: A user taps Buy with Shielded pool while another device restored from the same seed spends the one note selected for the purchase; the reservation is local, so the other spend can land first. The purchase is rejected for the spent nullifier, but the post-dispatch refusal leaves its activity Pending. Even after a complete verified sync and anchor expiry, Shielded Activity still shows a purchase that can never execute as Pending and tells the user the next sync will confirm it._
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:9787-9800: The settlement test can pass when the scan cannot confirm a purchase
  Impact: A change that keys purchase activity by the minted token note instead of the credit change note could leave successful purchases Pending without failing this test.
  The test proves that a pool-balance result leaves the row Pending, but it supplies the activity row by hand and uses identical placeholder actions in both bundles. It bypasses the production recorder and never feeds the credit change into scan reconciliation. Add an offline round-trip with distinct wallet-decryptable outputs in the two bundles, using the real builder or a fixed fixture. Record the row through the live path, scan only the fee-bundle change, and assert that the same row becomes Confirmed. An exact-price-plus-fee input also covers zero-valued change.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1905-1912: The wallet can reserve credits for a purchase the network version cannot accept
  (carried; thread: https://github.com/dashpay/platform/pull/6090#discussion_r4660233969)

In `packages/rs-platform-wallet/src/wallet/shielded/note_selection.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/note_selection.rs:82-84: The purchase note limit can drift when Orchard changes proof size
  Impact: After an Orchard update changes the proof length, the wallet could accept an oversized purchase or reject one that fits while its size test still passes.
  The constants are correct for the current pin, but both wallet sizing and its synthetic test use the same local copy of Orchard’s formula. The pinned Orchard revision exposes `Proof::expected_proof_size(actions)` and tests it against the circuit output. The pinned `grovedb-commitment-tree` already re-exports `Proof`, so use that API to size the placeholder proofs without adding a dependency. Keep the three-versus-four-note test for the wallet’s wire-size decision.

In `packages/rs-platform-wallet-ffi/src/shielded_send.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/shielded_send.rs:1570-1574: A worker panic in the availability check aborts the C host
  Impact: On an unwind-enabled build, a host checking whether shielded funding is available loses the process if the query worker panics, even though no purchase was attempted.
  `block_on_worker` calls `.expect("tokio worker panicked")` on the join result, and this new `extern "C"` export has no guard to catch the resulting unwind before the ABI boundary. Wrap the read-only export with `catch_panic_to_code` and return `ErrorWalletOperation`, as `platform_wallet_preview_data_contract_update` does. A spend-unconfirmed result would incorrectly imply a broadcast might have happened. This protection applies to unwind-enabled builds, not iOS profiles built with `panic = "abort"`.

In `packages/rs-dpp/src/state_transition/state_transitions/shielded/token_purchase_from_shielded_pool_transition/v0/state_transition_validation.rs`:
- [SUGGESTION] packages/rs-dpp/src/state_transition/state_transitions/shielded/token_purchase_from_shielded_pool_transition/v0/state_transition_validation.rs:40: The count-rule refactor has no regression test for shipped PV14
  Impact: Maintainers reviewing a future edit to the shared count predicate have no test pinned to the shipped validation boundary.
  The refactor is consensus-inert: the new predicate’s negation is exactly the old rejection condition, and validation order and error construction are unchanged. But the V0 structure tests run at `PlatformVersion::latest()`, while stable `v5.0.0` shipped PV14. The book’s in-place-edit checklist calls for a test at the last shipped version and a record of why the edit is inert. Exercise zero, the maximum, and one above it at `PlatformVersion::get(14)`, and record the equivalence at the edit and in the PR’s “In-place changes to shipped generations” section. No dispatcher or version-table change is needed.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Shared shielded activity logs can link a wallet to an on-chain output — The unchanged shared activity recorder logs entry_id at INFO. For a row with one visible output, that ID is the SHA-256 of its public note commitment. A recipient of an exported diagnostic archive can match it to the chain. The purchase already used this recorder on the prior reviewed head.
    • Follow-up: Open a wallet privacy follow-up to remove chain-linkable activity identifiers from exported diagnostics across shielded operations.

@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 22, 2026
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-transitions branch from 4d450a2 to 861b79d Compare November 23, 2026 00:07
@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions

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 23, 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

  • A successful purchase can show as Failed when its fee actions span two scan chunks — packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:2922-2923 (new)
    Impact: A buyer can see “no tokens were minted” for a purchase that landed and pay again by retrying with other notes before the next sync corrects the row.
  • A failed multi-note purchase keeps its untouched notes reserved — packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:2553-2561 (new)
    Impact: When another device spends one input of a pending purchase, the buyer sees Failed but cannot spend the untouched credits while the original anchor remains recorded.
  • The wallet can reserve credits for a purchase the network version cannot accept — packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1907-1911 (thread, carried)
    Impact: A buyer using an SDK pinned to PV14 can have credits held for recovery after a PV15 upgrade even though the purchase itself verified that PV15 is active.

New on this head: The four new commits add coverage for the shipped PV14 count rule and zero-value purchase change, reconcile displaced shielded spends, use Orchard’s proof-size API, and guard the availability read against unwinding across the C ABI. Rust workspace and wasm32 tests, the JS build and test suites, and the Kotlin SDK build and tests passed; the Swift SDK build and tests and review checks were still pending.

🔴 3 blocking

Still open from earlier rounds (1)

  • 🔴 Blocking: The wallet can reserve credits for a purchase the network version cannot accept — packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1907-1911 (thread)
Review provenance

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

  • Triage: critical by gpt-6.2-sol (effort low) — The new purchase flow in wallet/shielded/operations.rs, together with changes in note_selection.rs and coordinator.rs, introduces intricate funds-movement logic that selects and reserves shielded credit notes, broadcasts the spend, and reconciles it during sync.
  • 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 (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • New since the last final review (4d450a25): 2 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 2 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 — platform-versioning (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/shielded/coordinator.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:2922-2923: A successful purchase can show as Failed when its fee actions span two scan chunks
  Impact: A buyer can see “no tokens were minted” for a purchase that landed and pay again by retrying with other notes before the next sync corrects the row.
  A normal follow-up sync can persist Failed for a purchase that already minted tokens. The SDK fetches adjacent note ranges concurrently and verifies each response at its own height. When the fee bundle crosses a range boundary, the first response can prove the action revealing the input nullifier at height H while the next response proves an empty range at H−1. Orchard shuffles spends and outputs separately, so the wallet’s change can be in the second range. Both responses pass verification, and stream exhaustion lets the wallet publish the spent mark even though `covered_height` does not establish coverage through H. This predicate ignores that distinction and treats the missing change as proof of displacement. Keep the row Pending until the wallet proves a different spend or has contiguous coverage through the height that proved the input spent. Add a test where the first pass ends normally without that coverage and the next pass confirms the original row.

  _Confirmed by an independent pass: After a user submits a shielded token purchase that lands at height H, the follow-up sync can verify the range containing its spent input at H and an empty adjacent range at H−1, before the purchase's change existed. If the fee bundle straddles that range boundary, the wallet persists Failed and shows it in Shielded Activity even though the purchase minted the tokens._
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:2553-2561: A failed multi-note purchase keeps its untouched notes reserved
  Impact: When another device spends one input of a pending purchase, the buyer sees Failed but cannot spend the untouched credits while the original anchor remains recorded.
  A buyer can reserve two notes on one device for a purchase while a smaller payment on another device restored from the same seed uses only the larger note. When that payment lands, `mark_spent` clears the consumed note’s reservation and drops the purchase’s entire redrive record, but leaves the other reservation in place. The new branch saves Failed without releasing that note. Both note selection and spendable balance still exclude it, and `release_stranded_spends` skips it while the anchor is recorded. Once displacement is proved, release only the reservations that still belong to that activity under the same store write lock, and take the balance snapshot afterward. Test that the untouched note is immediately selectable, the consumed note remains spent, and another attempt’s reservation is not cleared.

  _Confirmed by an independent pass: A user submits a shielded token purchase that reserves two notes and gets an unconfirmed result after broadcast, while a smaller payment from a second device restored from the same seed lands using only the larger note. The next sync marks the purchase Failed but leaves the untouched note reserved, understating the spendable balance and preventing the user from spending that note while the purchase's anchor remains recorded._

In `packages/rs-platform-wallet/src/wallet/shielded/operations.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:1907-1911: The wallet can reserve credits for a purchase the network version cannot accept
  (carried; thread: https://github.com/dashpay/platform/pull/6090#discussion_r4660233969)

@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 23, 2026
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-transitions branch from 861b79d to af4a5f4 Compare November 23, 2026 01:08
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions

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
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-transitions branch from 10787d0 to 1b38910 Compare November 23, 2026 02:31
@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 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 23, 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

New on this head: This revision removes scan-based failure inference for shielded spends and updates the purchase flow to distinguish submission from confirmation. The wallet still confirms a purchase when a scan finds its fee-bundle change. Rust workspace tests and the JS build were pending at review time, with no failed code checks reported.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

Follow-up candidates (optional) (1)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: The SDK promises a result on the next sync even when a purchase stays Pending
Impact: A buyer whose only input was spent by another device can see an SDK error promising resolution on the next sync even though the purchase remains Pending.
packages/rs-platform-wallet/src/error.rs:1161-1163

Callers that display the SDK error set an expectation the wallet cannot meet. This revision removes the scan-based displacement rule, so observing only a competing spend can clear the sole reservation and saved transition without settling the purchase row. After a possibly delivered broadcast, settle_failed_spend can return ShieldedSpendUnconfirmed; map_spend_result forwards its text through C, and Swift preserves it. The example app now avoids promising a result on the next sync. Keep the do-not-resubmit guidance, but remove that promise from the shared error text, its Rustdoc, and the equivalent SPEND_PANIC_GUIDANCE. That wording change does not require implementing #6108.

        "Shielded {operation} was submitted but its execution result could not be \
         confirmed; it may already have executed on chain — do not re-submit: {reason}"

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

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 8: 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) — The new purchase flow in wallet/shielded/operations.rs and the changes in wallet/shielded/note_selection.rs implement a multi-step funds movement path that selects and reserves shielded credit notes, accounts for fees, and builds a version-specific shielded spend.
  • 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 (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • New since the last final review (10787d03): 1 suggestion(s) on unchanged code listed as follow-up candidates
  • 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 — platform-versioning (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. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
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 23, 2026
QuantumExplorer and others added 12 commits November 23, 2026 13:20
Adds a wallet operation and FFI entry point for
TokenPurchaseFromShieldedPool: the account's credit pool notes pay the
agreed price plus the pool-paid fee, and the tokens are minted as a note
to the account's own address in the token's shielded pool. Adds the
TokenPurchase fee kind (also fee estimate kind 5) and activity kind
(tag 10), and accepts type 28 in saved recovery records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d pool

Adds a "Pay with" choice (identity credits or shielded pool) to the
Direct Purchase screen, a thin Swift wrapper over the new FFI entry
point, a Token Purchase row in shielded activity, test plan rows SH-24
to SH-27 and the parity manifest capability.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g and check it before reserving notes

A token purchase from the shielded pool (type 28) is answered with a proof
of the token pool's balance, which binds neither the notes it spent nor the
tokens it minted. An accepted purchase is no longer confirmed or finalized
from it: it stays pending, its notes reserved and its recovery record
saved, and the shielded sync confirms it when it finds the fee bundle's
change note. The operation returns ShieldedTokenPurchaseOutcome::Submitted.

Before any note is reserved, the purchase now refuses a token count basic
structure refuses (0 or above MAX_DISTRIBUTION_PARAM), a network or SDK
below protocol version 14 (type 28 is registered with the SDK's broadcast
gate), an SDK whose version is not the verified network version (the PV15
fee binding would not match), a token without a shielded pool or whose
configuration cannot be read, and a purchase needing more than the three
notes that fit the 20,480-byte transition limit.

The wallet's generation payment guard is held from the liveness check
through settlement. A manager-level ShieldedTokenPurchaser runs the
purchase and requests the shielded sync on a submitted or unconfirmed
outcome, so the FFI export only forwards arguments. A new availability
query (and FFI export) tells a form whether the token can be bought from
the shielded pool. INFO logs carry the stage and outcome only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nswer and report it as submitted

The Direct Purchase form asks Rust whether the token can be bought from
the shielded pool and offers the Shielded pool choice only then, saying
why otherwise; identity funding stays available. A shielded purchase that
returns is reported as submitted, confirmed by the next shielded sync.
The Token Purchase activity detail shows the token id and "Tokens to:
this wallet's shielded token pool", and says the tokens were minted only
once the row is Confirmed. Adds the availability wrapper, updates SH-24
and the parity manifest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The wallet's early refusal of a token count now asks DPP's
is_valid_token_count, which the transition's structure validation also
uses, instead of repeating the bound. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sion 14

Exercises token counts 0, MAX_DISTRIBUTION_PARAM and
MAX_DISTRIBUTION_PARAM + 1 through validate_structure at the shipped
protocol version 14, and notes at the check that the predicate's negation
is exactly the condition it replaced, so moving the rule into
is_valid_token_count changed nothing that version accepts or rejects.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er spend consumed

A live spend left pending (an accepted token purchase, or any spend whose
result could not be read) stayed Pending forever once another spend of
one of its inputs landed, as from a second device on the same seed: the
scan's mark_spent dropped its reservation and recovery record, the
competing spend carries none of its outputs so activity derivation never
confirmed it, and the anchor-prune release no longer saw a reservation.

After a complete scan, activity reconciliation now marks Failed every
pending live spend row one of whose inputs is spent while none of its
wallet-visible outputs (at least the credit change every spend carries)
was observed. The scan sees a transition's input nullifiers and outputs
in the same pass, so the spend's own landing still confirms it. This
applies to every live spend kind, not only token purchases.

Also records the token purchase row through record_pending_token_purchase,
which an offline round trip now drives with a transition the real builder
proves: the row is keyed by the fee bundle's zero-valued change alone, and
scanning only that change confirms it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…expected_proof_size

The note-count bound for a shielded token purchase now takes each proof's
length from the pinned Orchard's Proof::expected_proof_size, through the
grovedb-commitment-tree re-export, instead of a local copy of the formula.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lity read off the C ABI

platform_wallet_manager_shielded_token_purchase_availability now runs
under catch_panic_to_code with ErrorWalletOperation, as the other
read-only exports do, so a panic in the read or the worker join cannot
unwind across the extern "C" frame.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its spend, and free its other notes

The note scan fetches adjacent position ranges concurrently and verifies
each at its own height, so one pass can see the action revealing an
input's nullifier at height H while the next range, proved at H-1, ends
before the spending transition's outputs. Such a pass marks the input
spent without having seen the change, and a pending spend that did land
could be marked Failed.

The scan now reports, per subwallet, the lowest batch height it saw each
owned nullifier at, and the coordinator keeps that with the highest height
a scan proved covered. A pending spend is judged displaced only when an
input was seen spent at or below a covered height and none of its outputs
was observed; otherwise it stays pending for a pass that covers the spend.
The evidence is kept in memory, so after a restart such a row stays
pending rather than being failed on unproved evidence.

A displaced multi-note spend also released only the consumed note: its
other inputs stayed reserved with no record left to resolve them. Under
the same store lock the derivation now releases each reservation still
carrying the displaced activity, never another attempt's, and the pass
reads its balances after the derivation so they count the freed notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… every network read

The contract fetch and the recorded-anchor read could raise the network
version the SDK knows after the signing version was chosen, so the
purchase built and signed with the table it captured earlier. The
purchase now fetches the contract and the recorded anchor set first,
then checks the signing version, then reserves notes and selects their
witnesses locally against the anchor set already read: nothing after the
check asks the network, and a mismatch is refused with nothing reserved,
saved or recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Takes the scan-based displacement of pending spends out of this change:
the coordinator no longer keeps spend evidence, marks a pending spend
Failed when another spend of one of its inputs lands, or releases that
spend's other reservations, and the note scan no longer reports spend
heights. The coordinator's production code and sync.rs are back to the
base branch; a pending spend that another device on the same seed
displaced stays pending, as it did before, a known limitation of every
spend kind that is tracked separately.

A pending token purchase is confirmed when a scan finds its change once
it lands, and otherwise stays pending. The two tests that show it are
kept: a scan that finds the row's change confirms it, and the offline
round trip of a purchase built by the real builder confirms its row from
the fee bundle's zero-valued change. Docs, the app's copy, SH-24 and the
parity manifest now say a shielded sync confirms the purchase once it
lands, rather than promising the next sync resolves it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-transitions branch from 1b38910 to c216f16 Compare November 23, 2026 06:27
@github-actions

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 23, 2026
@QuantumExplorer
QuantumExplorer merged commit 3c911b8 into v5.1-dev Nov 23, 2026
17 of 19 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/swift-example-shielded-token-transitions branch November 23, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants