Skip to content

feat(swift-example-app)!: send tokens within a token shielded pool (type 26) - #6132

Merged
QuantumExplorer merged 25 commits into
v5.1-devfrom
feat/swift-example-shielded-token-spend
Nov 23, 2026
Merged

QuantumExplorer merged 25 commits into
v5.1-devfrom
feat/swift-example-shielded-token-spend

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

A wallet can now send tokens it holds in a token's shielded pool to another Orchard address in that pool. This is a TokenShieldedTransferWithShieldedFee, state transition type 26. The tokens never leave the pool. The fee is paid from the wallet's credit shielded pool notes, and no identity is involved.

Before: the wallet could see its tokens in a token shielded pool (#6116) but could not spend them.

After:

  • Each token row on the Shielded Tokens screen has a Send button.
  • The form takes a recipient (pasted, or "My Address") and an amount in the token's smallest units.
  • On submit it shows one of:
    • "Submitted, pending until the next shielded sync";
    • "may have gone through, do not retry";
    • Rust's refusal.
  • Tokens held by a spend in flight show as Pending: N until a sync settles them.

It builds on #6116 (merged), which added the token pool scan. The token unshield to an identity (type 27) is stacked on this PR in #6133.

Issue being fixed or feature implemented

Test plan row SH-26 was blocked on the wallet tracking token pool notes. #6116 added that tracking.

What was done?

rs-sdk

  • token_shielded_transfer_with_shielded_fee_requirement() (protocol 14) is registered in the broadcast gate, so a broadcast or redrive of type 26 is refused locally before activation.

rs-platform-wallet

operations::token_shielded_transfer does the whole transfer in Rust.

Admission:

  • The wallet's generation guard and the coordinator's operation guard are held through settlement, so a Clear waits for the transfer.
  • The shielded config lock is also held through settlement, after checking the wallet is still bound to this coordinator. A bind or an added account waits for the transfer, so a rebind cannot drop the account whose notes it holds.

Refusals before any note is reserved:

  • the amount;
  • the protocol requirement;
  • a token whose verified configuration has no shielded pool;
  • the anchor sets of both pools are read before the next check;
  • a signing version that differs from the network's: the SDK's version must equal the network's, because PV15 binds the fee bundle.

Token notes:

  • token_pool::reserve_token_notes reserves the account's unspent, unreserved token notes covering the amount, largest first.
  • How many notes fit one transition is sized with Orchard's Proof::expected_proof_size.
  • A shortfall is refused with TokenShieldedInsufficientBalance, and nothing stays reserved.

Fee notes:

  • Credit pool notes for the fee are reserved for the token bundle's action count (fee kind ShieldedFeeKind::TokenShieldedTransfer).
  • When they cannot pay, the token notes are released.

Merkle paths:

  • token_pool::spend_paths builds the token pool's tree in memory from the leaves the scan kept.
  • The root must be in the token pool's recorded anchor set. Otherwise the transfer is refused with ShieldedNoRecordedAnchor, and a sync fixes it.

Build and broadcast:

  • DPP's existing builder builds the transition at the checked version.
  • After proving, both pools' anchor sets are read again. A token or fee anchor pruned meanwhile, or a network version change, refuses the transfer before anything is saved or sent.
  • The activity row is keyed by the fee bundle's credit pool change, like the type 28 purchase.
  • The token reservation is re-keyed to the row's id, noting whether the transfer was signed at a version that binds its token bundle to its fee bundle (token_bundle_binds_fee_bundle). Then the record is saved and the transition broadcast with redrive. Saving the record also marks the token hold saved, in the same transaction.

What the proof binds:

  • Type 26's proof shows every token nullifier spent. Another spend of the same notes would show the same, so the proof does not bind this transfer.
  • An accepted transfer therefore stays pending (ShieldedTokenSpendOutcome::Submitted):
    • the token pool scan marks its token notes spent and finds the change;
    • the credit pool scan confirms the row from the fee change and marks the fee notes spent.

Scan evidence the settlement relies on:

  • Before the credit note scan marks any note spent (which can drop a saved spend's record), it durably keeps the highest height its batches were proven at (ShieldedStore::note_spend_scan_height). It does this before it saves or records anything else in the pass.
  • A token pool scan's recorded note count, height and protocol version only rise, so a page answered by a node a block behind cannot lower them. A pass counts the pool complete only when it reaches the highest note count a page has proved.

Reservation lifetime and settlement:

  • Reservations are kept in new reserved_by, signed_bound, record_saved and fee_anchor_pruned columns, added in place when missing.
  • After each pass's token scan, the coordinator judges the reservations that neither a spend in flight here nor a saved record holds. It only judges:
    • pools that pass counted complete;
    • pools whose scan reached the highest height a credit pool scan has kept;
    • accounts registered now whose saved records all read.
  • How a hold is settled (settle_orphaned_token_hold):
    • never saved: never sent. The row is marked Failed and the notes released.
    • some held notes spent and some not: its bundle spends them all at once, so another spend used some. It did not land and can no longer, at any version. Failed and released.
    • signed at 15 (bound): it cannot land without its own fee bundle, so its notes are released. It is marked Failed when its fee anchor was pruned, or when none of its notes are spent. Otherwise it landed, and its row is left for the scan that confirms it.
    • signed at 14 (unbound), all held notes spent: it may have been delivered with another fee bundle, so the spent notes are released and nothing is concluded.
    • signed at 14, no held note spent: marked Failed and released only once the pool's own scan is proven at 15. It can no longer land, and was unspent at that scan, so it never did. Until then the notes stay held, even when another device spent its fee note.
  • Nothing is inferred from what a scan did not see. A wallet whose damaged recovery row did not load is not judged; Clear resets that flag.
  • A pool cannot be unwatched while any of the wallet's notes there are held, spent or not (TokenShieldedPoolSpendPending).
  • Known limits, tracked separately:

Other changes:

  • ShieldedTokenPoolBalance gains reserved_balance, and balance excludes reserved notes. Its pool_note_count and scanned_height are now the highest proven values, not the last page's.
  • New activity kind TokenShieldedTransfer (tag 11).
  • Saved recovery records accept type 26.
  • New entry points PlatformWallet::shielded_token_transfer and ShieldedTokenPurchaser::transfer. The latter requests the follow-up sync.

rs-platform-wallet-ffi, Swift SDK, SwiftExampleApp

  • The FFI export only marshals:
    • it decodes the raw 43-byte recipient;
    • resolves the seed through the mnemonic resolver;
    • calls the purchaser, and maps the outcome and errors as the purchase does.
  • The balances row gains reserved_balance. Persisted activity tag 11 is decoded.
  • The Swift wrapper is admitted as a native operation, so shutdown waits for it. The app adds the Send form, the Pending line, and the "Token Transfer" label for tag 11, with amounts in smallest units and a "Transfer amount" label for every status. No SwiftData @Model change.
  • TEST_PLAN SH-26 is updated, and the parity manifest gains shielded.token_shielded_transfer.

New public interfaces

C FFI

PlatformWalletFFIResult platform_wallet_manager_shielded_token_transfer(
    Handle handle, const uint8_t *wallet_id_bytes,
    MnemonicResolverHandle *mnemonic_resolver_handle, uint32_t account,
    const uint8_t *data_contract_id, uint16_t token_contract_position,
    const uint8_t *recipient_raw_43, uint64_t amount);
  • Success means accepted and pending. An unconfirmed result maps as for the purchase, and a bad recipient address returns ErrorInvalidParameter.
  • ShieldedTokenPoolBalanceFFI gains uint64_t reserved_balance after unspent_note_count. feat(swift-example-app): show a wallet's tokens in token shielded pools #6116 is not released, so nothing depends on the old layout. Its pool_note_count and scanned_height are now documented as the highest proven values.
  • Unwatching a pool while any of the wallet's notes there are held returns an error instead of succeeding.

Swift

  • shieldedTokenTransfer(walletId:resolver:account:dataContractId:tokenContractPosition:recipientRaw43:amount:) async throws
  • ShieldedTokenPoolBalance.reservedBalance. Its public initializer takes reservedBalance: UInt64 = 0, so existing callers compile unchanged.

Rust (platform-wallet)

  • PlatformWallet::shielded_token_transfer, ShieldedTokenPurchaser::transfer, ShieldedTokenSpendOutcome::Submitted
  • ShieldedTokenPoolBalance::reserved_balance
  • PlatformWalletError::TokenShieldedInsufficientBalance { token_id, available, required }: a transfer the account's unreserved token notes cannot cover.
  • PlatformWalletError::TokenShieldedPoolSpendPending { token_id }: unwatch refused because some of the wallet's notes in that pool are held. Watching it again would otherwise offer them to another spend, or lose the link the sync settles a pending spend by.
  • ShieldedStore::note_spend_scan_height(&mut self, height: u64): a new trait method with a default no-op, called by the note sync before it marks notes spent. The file store keeps the height; other stores keep nothing.
  • ShieldedFeeKind::TokenShieldedTransfer, TokenPoolSpendNoteLimits, token_pool_spend_token_actions, compute_token_shielded_transfer_fee
  • ShieldedActivityKind::TokenShieldedTransfer (tag 11)
  • TokenPoolChunk::protocol_version: a public field on the struct a TokenPoolNoteSource returns, so an implementation outside the crate must set it.
  • feat(swift-example-app)!: unshield tokens from a token shielded pool to an identity (type 27) #6133 generalizes the fee kind and limits for type 27.

Rust (dash-sdk)

  • token_shielded_transfer_with_shielded_fee_requirement()

Persisted state

  • On shielded_token_pool_notes, added in place: reserved_by BLOB, signed_bound INTEGER NOT NULL DEFAULT 0, record_saved INTEGER NOT NULL DEFAULT 0, fee_anchor_pruned INTEGER NOT NULL DEFAULT 0, and the partial index shielded_token_pool_notes_by_reservation (wallet_id, account_index, reserved_by) WHERE reserved_by IS NOT NULL.
  • shielded_token_pool_scans.scanned_protocol_version INTEGER, added in place. A scan recorded before it existed binds nothing until the next scan writes it. The row's count, height and version are now only raised.
  • New table shielded_token_pool_sweep (id, credit_height), one row: the highest credit scan height kept, by the note sync before it marks notes spent and by the sweep. Clear empties it.
  • Activity tag 11 in the existing kindTag column.

App accessibility identifiers

  • shieldedTokens.sendButton, shieldedTokens.pendingBalance
  • shieldedTokenSend.form, .recipient, .pasteButton, .ownAddressButton, .amount, .submit, .result, .error, .close

Source compatibility: ShieldedFeeKind, ShieldedActivityKind and PlatformWalletError are public and not #[non_exhaustive]. Rust code that matches them exhaustively must add the new variants, and code that builds a TokenPoolChunk must set its new field, hence the !. The new ShieldedStore method has a default, so existing store implementations compile unchanged.

How Has This Been Tested?

  • cargo test -p platform-wallet --features shielded --lib -- shielded::: 435 passed. The new ones cover:
    • reservation largest first, kept out of the balance, then released;
    • refusals that reserve nothing: too few tokens, too many notes;
    • the sweep judges only orphaned reservations in scanned pools, of registered accounts, once the token scan reached the credit scan's height;
    • a later credit scan answered from a lower height, or a pass with no pool completed, does not lower that height; only the token scan advancing releases the hold;
    • the note sync keeps its highest batch height (not its last) before a fee note seen spent drops the record, across a reopen; when that write fails, nothing is marked spent and the record stays;
    • a page behind a larger one does not count the token pool complete, and keeps the larger count and height;
    • settlement across signing era, how the record went (never saved, fee anchor pruned, fee note spent), how many of two held notes are spent (none, one, both), and the pool scan's version, with the SDK at 15 throughout (15 cases); records are saved through arm_redrive and their removal checked;
    • the real re-key keeps the signing era the sweep reads, and the signing-era helper is bound only from protocol 15;
    • a credit height kept before a pass answered one block below, with the token scan catching up;
    • a transfer signed at 15 whose held note another spend used keeps the pool watched, then settles Failed once its fee anchor is pruned;
    • unwatch is refused while notes are held, including notes another spend used;
    • Merkle paths lead to the returned root, and a note past the kept leaves has none;
    • a zero transfer is refused before any request;
    • a token shortfall leaves nothing held;
    • token notes are released when the fee cannot be paid;
    • both reservations are released when the transfer fails before its broadcast.
  • should_bound_a_token_shielded_transfer...: the size limits and the fee match consensus.
  • cargo test -p dash-sdk --lib should_refuse_a_generic_broadcast: 4 passed, including the type 26 gate.
  • cargo test -p platform-wallet-ffi --features shielded --lib -- token_transfer shielded_token_pools: 17 passed, covering outcome and refusal mapping, null pointers, a bad recipient, and an unknown manager.
  • cargo clippy with CI's flags on platform-wallet and platform-wallet-ffi, and cargo fmt --all: clean on the latest commit.
  • packages/swift-sdk/build_ios.sh --target sim (release): BUILD SUCCEEDED, including SwiftExampleApp built with warnings as errors, before the last review rounds. The Swift changes since are one default argument value, one label string and two doc comments.

Not yet verified

  • No simulator run and no broadcast against a network. SH-26 says so.
  • No real-prover round trip of a type 26 build in the wallet crate. DPP's builder has its own tests.
  • The SwiftExampleAppTests target was not run.
  • No test drives a bind while a transfer holds the config lock; that needs a transfer running through PlatformWallet past proving.
  • This PR's form gives no fee number before sending. feat(swift-example-app)!: unshield tokens from a token shielded pool to an identity (type 27) #6133 adds a Rust fee preview that both forms will show.

Breaking Changes

Rust source only: new variants on the public ShieldedFeeKind, ShieldedActivityKind and PlatformWalletError enums, which are not #[non_exhaustive], and a new field on TokenPoolChunk. Nothing changes at the protocol, consensus, C ABI (additive; the unreleased row from #6116 grows) or SwiftData level.

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 · f07773b

  • 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
    • 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 and 1 more) — HashEngineering or ZocoLini or llbartekll or romchornyi
    • rs-platform-wallet (packages/rs-platform-wallet/src/error.rs, packages/rs-platform-wallet/src/manager/shielded_token_purchase.rs, packages/rs-platform-wallet/src/wallet/platform_wallet.rs and 11 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 4 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 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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 13 minutes.

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 91cac33 and f07773b.

Files selected for processing: 29

  • docs/sdk/sdk-parity-manifest.json
  • packages/kotlin-sdk/PARITY_SUMMARY.md
  • 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
  • packages/rs-platform-wallet-ffi/src/shielded_token_pools.rs
  • packages/rs-platform-wallet/src/error.rs
  • packages/rs-platform-wallet/src/manager/shielded_token_purchase.rs
  • packages/rs-platform-wallet/src/wallet/platform_wallet.rs
  • packages/rs-platform-wallet/src/wallet/shielded/activity.rs
  • packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs
  • packages/rs-platform-wallet/src/wallet/shielded/file_store.rs
  • packages/rs-platform-wallet/src/wallet/shielded/mod.rs
  • packages/rs-platform-wallet/src/wallet/shielded/note_selection.rs
  • packages/rs-platform-wallet/src/wallet/shielded/operations.rs
  • packages/rs-platform-wallet/src/wallet/shielded/store.rs
  • packages/rs-platform-wallet/src/wallet/shielded/sync.rs
  • packages/rs-platform-wallet/src/wallet/shielded/sync/cancel_tests.rs
  • packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs
  • packages/rs-platform-wallet/src/wallet/shielded/token_pool_tests.rs
  • packages/rs-sdk/src/platform/transition/broadcast.rs
  • packages/rs-sdk/src/sdk/protocol_gate_tests.rs
  • 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
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedTokenPoolsView.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/StorageModelListViews.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/StorageRecordDetailViews.swift
  • packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md
Walkthrough

The wallet now supports Type 26 shielded token transfers to Orchard addresses, with fees paid from credit-pool notes. Transfers reserve token notes while their status is unresolved. The Swift SDK and example app expose the send flow and display reserved balances and token-transfer activity.

Changes: Shielded Token Transfer

Layer / File(s) Summary
Reservations, fees, and protocol gates
packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs, packages/rs-platform-wallet/src/wallet/shielded/token_pool_tests.rs, packages/rs-platform-wallet/src/wallet/shielded/note_selection.rs, packages/rs-platform-wallet/src/error.rs, packages/rs-sdk/src/platform/transition/broadcast.rs, packages/rs-sdk/src/sdk/protocol_gate_tests.rs
Token-pool notes can be reserved and released, and balances separate spendable from reserved notes. Type 26 note limits and fees use transition action and size constraints. The SDK applies a protocol-version requirement to Type 26 broadcasts.
Transfer submission and settlement
packages/rs-platform-wallet/src/wallet/shielded/operations.rs, packages/rs-platform-wallet/src/wallet/shielded/activity.rs, packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs, packages/rs-platform-wallet/src/wallet/shielded/file_store.rs, packages/rs-platform-wallet/src/wallet/shielded/mod.rs
The transfer operation validates requirements, reserves token and fee notes, records and broadcasts the transition, and settles outcomes. Activity kind 11 identifies token transfers. Coordinator cleanup handles orphaned reservations and pending activity rows.
Wallet, FFI, and Swift API wiring
packages/rs-platform-wallet/src/wallet/platform_wallet.rs, packages/rs-platform-wallet/src/manager/shielded_token_purchase.rs, packages/rs-platform-wallet-ffi/src/shielded_send.rs, packages/rs-platform-wallet-ffi/src/shielded_token_pools.rs, packages/rs-platform-wallet-ffi/src/persistence.rs, packages/rs-platform-wallet-ffi/src/shielded_persistence.rs, packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift, packages/swift-sdk/Sources/SwiftDashSDK/Persistence/Models/PersistentShieldedActivity.swift
The wallet manager and FFI expose token transfers and map their outcomes. FFI balance rows include reserved balances, and persisted activity kind 11 restores as a token transfer. The Swift SDK validates transfer inputs and calls the FFI export.
Swift example-app send and activity display
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedTokenPoolsView.swift, packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedActivityView.swift, packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/StorageRecordDetailViews.swift, packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/StorageModelListViews.swift, packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md
The app adds a token send sheet, shows reserved balances as pending, and displays token-transfer amounts and details. The test plan marks SH-26 implemented.
SDK parity records
docs/sdk/sdk-parity-manifest.json, packages/kotlin-sdk/PARITY_SUMMARY.md
The parity records add the token shielded transfer capability. Swift is marked partial, and Kotlin is marked unsupported.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ShieldedTokenPoolsView
  participant PlatformWalletManager
  participant FFI
  participant ShieldedTokenPurchaser
  participant token_shielded_transfer
  participant NetworkShieldedCoordinator
  User->>ShieldedTokenPoolsView: submit recipient and amount
  ShieldedTokenPoolsView->>PlatformWalletManager: call shieldedTokenTransfer
  PlatformWalletManager->>FFI: submit Type 26 transfer
  FFI->>ShieldedTokenPurchaser: resolve purchaser and transfer
  ShieldedTokenPurchaser->>token_shielded_transfer: execute wallet transfer
  token_shielded_transfer-->>ShieldedTokenPurchaser: return spend outcome
  ShieldedTokenPurchaser->>NetworkShieldedCoordinator: request sync when outcome requires it
  FFI-->>PlatformWalletManager: return FFI result
  PlatformWalletManager-->>ShieldedTokenPoolsView: return result
Loading

Possibly related issues

Suggested reviewers: shumkov, llbartekll, romchornyi

Merge Risk: Moderate · previous review 91cac

Token transfers can show a wrong status or free their reserved tokens too early in rare sync and recovery orderings, which can leave a transfer stuck pending or let the same tokens be selected for a second send. Fix the sweep-floor persistence and the v14 hold-release rule before merging; the remaining items are lower-impact follow-ups.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names a feature the changeset implements: type 26 token transfers from a wallet's shielded token pool to an Orchard address, including the SwiftExampleApp Send form. The changeset is much br…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names a feature the changeset implements: type 26 token transfers from a wallet's shielded token pool to an Orchard address, including the SwiftExampleApp Send form. The changeset is much broader (Rust wallet reservation logic, FFI export, parity manifests, sweep settlement), but the title covers its primary user-facing change. The title is in conventional-commit form and flags a breaking change with '!', which matches the PR objectives noting Rust source compatibility breaks.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

@thepastaclaw

thepastaclaw commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress (commit 6bdac6a) · live progress

@QuantumExplorer
QuantumExplorer marked this pull request as ready for review November 23, 2026 10:03
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-spend branch from 53d823e to 6274695 Compare November 23, 2026 10:32
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from a24f75c to 465f275 Compare November 23, 2026 10:55
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-spend branch from 6274695 to 764dc02 Compare November 23, 2026 10:55
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from 465f275 to b8a127b Compare November 23, 2026 11:01
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-spend branch from 764dc02 to d4641ac Compare November 23, 2026 11:01
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from b8a127b to b281f45 Compare November 23, 2026 11:04
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-spend branch from d4641ac to 73d63a8 Compare November 23, 2026 11:04
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from b281f45 to 93285c3 Compare November 23, 2026 11:11
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-spend branch from 73d63a8 to 4fad076 Compare November 23, 2026 11:11
@QuantumExplorer QuantumExplorer added this to the v5.1.0 milestone Nov 23, 2026
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from 93285c3 to db53f05 Compare November 23, 2026 11:16
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-spend branch from 4fad076 to 6d9d794 Compare November 23, 2026 11:16
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from db53f05 to a7ab835 Compare November 23, 2026 12:22
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-spend branch from 6d9d794 to f47751a Compare November 23, 2026 12:22
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from a7ab835 to 3a766bf Compare November 23, 2026 12:24
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-spend branch from f47751a to 8b6d786 Compare November 23, 2026 12:24
Base automatically changed from feat/swift-example-shielded-token-notes to v5.1-dev November 23, 2026 12:30
QuantumExplorer and others added 2 commits November 23, 2026 19:31
… 26)

The wallet builds a TokenShieldedTransferWithShieldedFee from an
account's notes in a watched token pool, paying the fee from its credit
pool notes. Token notes are reserved in the token pool tables, largest
first and bounded by what fits one transition; their Merkle paths come
from the leaves the scan kept, and their root must be an anchor the
token pool records. An accepted transfer stays pending: its proof shows
its token nullifiers spent, which does not bind this transfer. A sync
pass releases the token notes of a spend that holds no saved record and
is not in flight. The SDK gates the transition at protocol version 14.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…he Shielded Tokens screen

FFI export platform_wallet_manager_shielded_token_transfer marshals a
type 26 transfer (raw 43-byte Orchard recipient) to the manager's
purchaser, which requests the follow-up sync itself. The balances row
gains reserved_balance. The Swift SDK wraps the transfer, and the
Shielded Tokens screen gets a Send form per token row, a Pending line
for reserved tokens, and a "Token Transfer" label for activity tag 11.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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-spend branch from 8b6d786 to 0011c08 Compare November 23, 2026 12:34
@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.

⚠️ DEGRADED — Final validation — Phase 1 + Phase 2

⚠️ DEGRADED review. The primary review models were unavailable (gpt-6.2-sol unavailable: All credentials for model gpt-6.2-sol are cooling down (last error: usage_limit_reached: The usage limit has been reache), so this review ran on stand-in models: gpt-5.6-luna → muse-spark-1.3-contributor, gpt-5.6-sol → muse-spark-1.3-contributor, gpt-5.6-terra → muse-spark-1.3-contributor, gpt-6-astra → muse-spark-1.3-contributor, gpt-6.1-sol → muse-spark-1.3-contributor, gpt-6.2-astra → muse-spark-1.3-contributor, gpt-6.2-sol → muse-spark-1.3-contributor. Both review phases and the independent verifiers still ran, but on weaker models, with Phase 1 capped at high effort. Treat the verdict as provisional; a full-strength re-review will run on the next push once the primary models are back.

Nothing blocks: no blocking finding stands on this head.

Adds type-26 token shielded-pool transfers end to end in rs-platform-wallet with FFI and SwiftExampleApp wiring. CI snapshot shows CodeRabbit and title checks passing with remaining checks queued or in progress and no failed code check attributable to this head.

🟡 3 suggestion(s)

Review provenance

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

  • Degraded mode: gpt-6.2-sol unavailable: All credentials for model gpt-6.2-sol are cooling down (last error: usage_limit_reached: The usage limit has been reache (detected by probe, since 2026-11-23T09:07:27Z); stand-ins gpt-5.6-luna → muse-spark-1.3-contributor, gpt-5.6-sol → muse-spark-1.3-contributor, gpt-5.6-terra → muse-spark-1.3-contributor, gpt-6-astra → muse-spark-1.3-contributor, gpt-6.1-sol → muse-spark-1.3-contributor, gpt-6.2-astra → muse-spark-1.3-contributor, gpt-6.2-sol → muse-spark-1.3-contributor; Phase 1 effort capped at high
  • Triage: critical by muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (effort low) — Large intricate change adding wallet funds-movement and note selection in operations::token_shielded_transfer with Orchard proofs and anchor checks.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — rust-quality (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 67% left, weekly 94% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh verifier: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — final-verifier; agent sol-verifier
  • Phase 2 reviewers: muse-spark-1.3-contributor (standing in for gpt-6.2-astra) — general (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-astra) — architecture-layering (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-astra) — ffi-engineer (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-astra) — platform-versioning (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-astra) — rust-quality (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for 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`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/operations.rs:2471-2518: Type-26 transfer settlement branches that hold or release token notes have no test
  Impact: A regression that releases a submitted transfer's token notes early or retires its record as failed would let the wallet double-spend or hide balances with CI staying green.
  The consequence is an untested double-spend guard: every new test in mod token_shielded_transfer_tests stops before the broadcast, while settle_token_pool_spend decides whether token notes stay held under the record id on Submitted, stay held on unconfirmed, or are released on definitive failure. The sibling type-28 purchase path has exactly this harness with purchase_token_with_outcome plus should_keep_a_purchase_pending_when_platform_answers_with_the_pool_balance and should_keep_an_unconfirmed_purchase_pending_and_report_it. Add the same two mock-driven cases for the transfer past build and prove: one where the affected-state wait answers success and asserts Submitted with the activity row pending and the token notes still reserved, and one where the broadcast fails unconfirmed and asserts both fee and token reservations are retained with a retryable result.

In `packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:874-893: Orphan sweep holds the reservation lock across SQLite writes
  Impact: Concurrent token spends block in reserve, rekey, or drop for the whole post-scan sweep instead of microseconds.
  The consequence is avoidable executor stalls: release_orphaned_reservations holds the process-wide IN_FLIGHT mutex guard for the entire SELECT plus per-marker UPDATE loop, so every thread needing in_flight waits on SQLite I/O. The guard is only needed for point-in-time membership. Snapshot it and drop the guard before touching SQLite.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:784-796: Token reservation loads and deserializes every pool note to pick a few
  Impact: Each transfer reads the account's full token-pool history including spent and reserved notes before discarding most of it, growing without bound as the pool accumulates history.
  The consequence is wasted I/O and allocation on every spend: reserve_token_notes calls notes() which SELECTs all rows for the wallet, account, and token and deserializes every note_data blob, then filters to unspent-and-unreserved in Rust. The predicate is already known to the query. Push the filter into SQL so a reservation reads only spendable notes.

@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 the waiting-self-review Waiting for the author to post /self-reviewed label 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 2 only (queue backlog)

Changes requested: 2 blockers

  • A delivered token payment can show as Failed when its last scan page is one block behind — packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:348-350 (new)
    Impact: A protocol-14 sender whose payment spans two token scan pages can see Failed after the recipient was paid, with a spent input temporarily shown as available.
  • A failed scan-height write can leave an outgoing note out of the host store after retry — packages/rs-platform-wallet/src/wallet/shielded/sync.rs:837-841 (new)
    Impact: A wallet syncing send history through a transient SQLite write failure can persist a cursor beyond an outgoing note that the host never received.

New on this head: This head distinguishes partially spent token holds from fully spent ones and persists the credit scan’s highest proof height before applying nullifiers that can retire a recovery record. No code checks had failed when checked; the Rust workspace and WASM tests, Kotlin emulator build and tests, JS and Docker builds, and PR Hygiene were still pending.

A pattern across this PR's review rounds

This is review round 7, and the PR has drawn 14 blocking findings so far. 9 of them share one underlying cause. They are listed with the other findings as usual; fixing the cause is likely to be cheaper than fixing each case.

1. No durable owner for the two-pool spend (2 new in this round, 7 earlier finding(s))

A spent fee note or a pruned fee anchor can remove PendingRedrive before the wallet knows what happened to the token transfer, leaving release_orphaned_token_reservations to reconstruct the outcome from flags on token notes and pool scan metadata. The new partly-spent check treats flags committed by different pages as one complete view, so a lagging final page can make a delivered payment look like a competing spend. The patch to preserve the credit scan height after the record is gone also adds a fallible SQLite write after sync_notes_from_stream has updated its outgoing-note deduplication index but before the host receives those notes.

Already tracked: #6108

In this round: A delivered token payment can show as Failed when its last scan page is one block behind; A failed scan-height write can leave an outgoing note out of the host store after retry

Suggested decision (redesign the component): Replace the type-26 orphan sweep as the settlement authority with a durable spend record in rs-platform-wallet that owns both pools' holds and survives the end of rebroadcast. Keep whether dispatch was possible, the signing version, the input nullifiers, and the token output commitments so the wallet can decide separately whether the inputs are safe to reuse and whether this payment landed, even after a restart or a scan with pages from different heights. Leave idle-anchor cleanup, host status-write retries, and account removal behavior in their existing follow-ups. Rust workspace and wasm32 tests, the Kotlin emulator job, and the JS, Drive, and RS-DAPI builds were still pending when checked.

🔴 2 blocking | 🟡 1 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); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The new funds-movement path in operations::token_shielded_transfer and note selection in token_pool::reserve_token_notes coordinate token and fee inputs, broadcast, and persistent settlement across two shielded pools.
  • Phase 1 reviewers: not run (skipped for throughput: 15 PRs queued, above the 10 limit)
  • New since the last final review (651a541b): 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
Several findings on this PR share an underlying cause (the review's "pattern" section): No durable owner for the two-pool spend. When you fix the findings below, fix the cause, not only the reported case. The review suggests (redesign the component): Replace the type-26 orphan sweep as the settlement authority with a durable spend record in `rs-platform-wallet` that owns both pools' holds and survives the end of rebroadcast. Keep whether dispatch was possible, the signing version, the input nullifiers, and the token output commitments so the wallet can decide separately whether the inputs are safe to reuse and whether this payment landed, even after a restart or a scan with pages from different heights. Leave idle-anchor cleanup, host status-write retries, and account removal behavior in their existing follow-ups. Rust workspace and wasm32 tests, the Kotlin emulator job, and the JS, Drive, and RS-DAPI builds were still pending when checked. If that decision is not yours to make, say so to the PR's author or maintainer.

These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:348-350: A delivered token payment can show as Failed when its last scan page is one block behind
  Impact: A protocol-14 sender whose payment spans two token scan pages can see Failed after the recipient was paid, with a spent input temporarily shown as available.
  The new `partly_spent` branch turns incomplete scan coverage into a failure verdict. A sender can submit a multi-input protocol-14 transfer, have another device spend its original fee note in a credit payment by H−1, and then have the token transfer land with a different fee bundle at H. A credit scan through H−1 can retire the recovery record without seeing the token transfer. If its token actions straddle a page boundary, `apply_chunk` commits the first input’s spent flag from a full page proved at H. The next request can go to a node at H−1: the SDK accepts one block of lag, and an aligned range beyond that block’s tree end has a valid empty proof. `apply_chunk` overwrites the pool’s count and height with that answer, and `scan_pool` treats the short page as complete. H−1 meets the credit floor, so the sweep marks the payment Failed and clears both holds. Catch-up marks the second input spent, but the original fee change will never arrive to correct the verdict. Persist the highest proved token-tree count alongside applied chunks and withhold settlement until the scanned prefix covers that count and satisfies the credit-height floor, including after interruption or restart. Test a full page at H, an empty page at H−1, and catch-up at H: the lagging pass must keep the hold, and neither pass should report Failed.

  _Confirmed by an independent pass: A wallet submits a multi-input transfer on protocol 14 and leaves it pending after an ambiguous broadcast; another device spends the original fee note by H−1, and the unbound token bundle lands with a different fee bundle at H. Shielded sync can retire the recovery record at H−1, mark one token input spent from a full page at H, then accept a valid empty page at H−1 when the remaining spend action is across the page boundary. The sweep marks the delivered payment Failed and releases the token hold; catching up cannot confirm the row because it is keyed to the original fee change, which never landed._
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:4402-4406: The restart test still passes if credit sync stops saving the spend height
  Impact: A regression in how credit sync records spend evidence could reopen spent token inputs after restart without failing this test.
  The reopen assertion checks that SQLite retains height 11, but the fixture supplies that value directly to `note_spend_scan_height` and calls `mark_spent` itself. The test would still pass if `sync_notes_from_stream` stopped writing the floor or used the lower terminal batch’s height instead of the maximum. Use the existing synthetic stream entry point to feed a batch at 11 containing the fee nullifier followed by a terminal batch at 10. Assert that the recovery record is gone, the reopened floor is still 11, and a token scan at 10 cannot release the hold.

In `packages/rs-platform-wallet/src/wallet/shielded/sync.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/sync.rs:837-841: A failed scan-height write can leave an outgoing note out of the host store after retry
  Impact: A wallet syncing send history through a transient SQLite write failure can persist a cursor beyond an outgoing note that the host never received.
  A successful retry can advance the host’s scan cursor without saving an outgoing note recovered on the failed pass. During normal shielded sync, `record_outgoing_note` inserts the commitment into the file-backed store’s in-memory deduplication set and adds the outgoing note to the changeset. If the new SQLite height write then fails, for example because the device is out of space, `?` discards that changeset before the coordinator calls the host persister. Once the write succeeds on a retry in the same process, the unchanged watermark causes the scan to recover the note again, but deduplication returns `false`, so only the advanced cursor reaches the host. If the note is before the chunk the cursor resumes from, restarting loses the only copy without rescanning it. This happens before any host persistence attempt, so retrying host writes in #6157 would not recover it. Move the height write immediately after the cancellation return, before saving receipts or recording outgoing notes, while keeping it before nullifier replay. Add a fail-once write test that verifies the retry emits the outgoing note.

  _Confirmed by an independent pass: During normal shielded sync, the wallet can recover an outgoing note and then hit a transient SQLite write failure, such as running out of disk space, in the new scan-height write. After space is freed, a retry in the same process can persist an advanced scan cursor without the outgoing note because the first pass already populated the in-memory deduplication set. If the note lies before the cursor's aligned resume point, normal sync after restart skips it and the persisted send history remains incomplete._

@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
…the largest tree seen

A page answered by a node a block behind proves a shorter tree. After a
full page proved the pool larger, such a page ended the scan as if it were
the pool's end, lowered the recorded height and count, and let the sweep
judge holds from a scan that missed a spend. The recorded count, height and
version now only rise, and a pass counts the pool complete only when it
reaches the highest count a page has proved.

The credit note sync keeps its highest batch height before it saves or
records anything else, so a failed write leaves nothing half recorded for a
retry to skip; a synthetic stream test checks the highest, not the last,
batch height is kept across a reopen.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 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 records the credit spend-observation height before saving ledger changes and requires a token scan to cover the largest proven tree before it can settle holds. In the latest CI check, the Kotlin emulator build and tests passed, no code checks were failing, and PR Hygiene and PastaClaw review were pending.

🟡 2 suggestion(s)

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

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 transfer in rs-platform-wallet/src/wallet/shielded/operations.rs moves shielded token funds and coordinates token and fee note selection, reservation, broadcast, and settlement across two pools.
  • 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 below 15% reserve: models 0% left), 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/token_pool.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:1448-1449: After a lagging page, the balance reports an earlier proof as the last page
  Impact: Rust, C, and Swift callers inspecting an incomplete scan can mistake an earlier page’s larger tree count and higher proof height for the final response or for completed coverage.
  The balance no longer tells callers what the final page proved. The new `MAX` updates deliberately preserve the larger count and higher height from an earlier page, even when the lagging final page leaves the pool out of `completed`. The Rust, C-facing, and Swift fields still describe values from the last chunk read. Keep the maxima and document them as the highest proven values retained for the pool, distinct from `scanned_note_count`, the contiguous prefix actually checked for the account. The reported height alone does not certify completion.

In `packages/rs-platform-wallet/src/wallet/shielded/sync/cancel_tests.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/sync/cancel_tests.rs:482-496: The restart test still passes if the recovery record is deleted before the height write
  Impact: A future reordering could let an interrupted sync lose the height needed to settle a pending transfer while this regression test stays green.
  The test verifies that the record is gone and the maximum height survives reopen, but only after a successful scan. Moving `note_spend_scan_height` below `apply_scanned_nullifier_spends` would still satisfy both assertions. The production order is correct on this head. Keep the success case and add a failure-path test that rejects the sweep-height write, runs the real scan, and verifies that the scan returns an error, the fee note is still unspent, and its recovery record is still present before retrying.

@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
…as the highest proven

The recorded count and height only rise, so the Rust, C and Swift fields
say so, and that neither certifies a scan reached the pool's end. A
failure-path test checks a failed spend-scan height write leaves the fee
note unspent and the saved spend's record in place.

Co-Authored-By: Claude Opus 5.5 <[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.

@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 documents the highest proven token-pool count and height separately from the prefix each account has scanned. It also adds a regression test that checks that a failed credit scan-height write leaves the fee note unspent and its recovery record intact. No code checks have failed; the Kotlin emulator build and tests, PR Hygiene, and the review check are still pending.

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

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 wallet's shielded/operations.rs and shielded/token_pool.rs implement an intricate funds-movement flow that selects and reserves token and fee notes, validates anchors before broadcast, and tracks pending spends through 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 (antigravity below 15% reserve: models 0% left), 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 (e8eb9d87): 1 finding(s) judged fixed earlier and raised again on unchanged lines kept settled
  • 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
…e-shielded-token-spend

# Conflicts:
#	docs/sdk/sdk-parity-manifest.json
#	packages/kotlin-sdk/PARITY_SUMMARY.md
@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
…e-shielded-token-spend

# Conflicts:
#	docs/sdk/sdk-parity-manifest.json
#	packages/kotlin-sdk/PARITY_SUMMARY.md
@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.

@QuantumExplorer
QuantumExplorer merged commit b378b16 into v5.1-dev Nov 23, 2026
16 of 18 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/swift-example-shielded-token-spend branch November 23, 2026 21:14
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