Skip to content

fix: check a DashPay invitation claim against Platform before broadcasting it - #5536

Open
romchornyi wants to merge 18 commits into
v5.2-devfrom
feat/invitation-claim-preflight
Open

romchornyi wants to merge 18 commits into
v5.2-devfrom
feat/invitation-claim-preflight

Conversation

@romchornyi

@romchornyi romchornyi commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

Part of dashpay/dashwallet-ios#1224 (item 8): a DashPay invitation claim can end up on an identity the voucher did not fund, or burn the inviter's voucher for nothing.

Sdk::claim_invitation (moved into rs-sdk by #5471) broadcasts the claim without looking at Platform first. When one of the submitted keys is already registered to another identity (typically an identity this wallet registered before at the same index), Drive refuses the IdentityCreate with DuplicatedIdentityPublicKeyIdStateError (40207, or 10501 before protocol v11) and charges the voucher through PartiallyUseAssetLockAction (10M credits plus the fee) on every attempt. The inviter pays, and the invitee gets an opaque consensus error.

Hosts also cannot tell an invitation claimed by someone else from one their own earlier claim already used (a claim that landed while the app was killed). The pre-claim status only says "an identity exists".

What was done?

rs-sdk (platform/dashpay/invitation.rs)

  • A preflight runs after the funding proof is rebuilt and before anything is signed or broadcast. It fetches the identity at the invitation's derived id, and the identity under the hash of every submitted key, concurrently. Drive's v0/v1 check works the same way: it hashes every key against the unique-key index. The outcomes, none of which broadcast:
    • ClaimedByThisWallet { identity_id }: the invitation's identity holds the claim's master key (key 0). The preflight does not adopt or record it.
    • AlreadyClaimed { identity_id }: someone else's identity is there.
    • KeysAlreadyRegistered { identity_id }: another identity holds a submitted key.
    • NotReady: a lookup could not be verified yet (Error::is_quorum_source_unavailable). Any other lookup failure is Sdk.
    • Precedence: the invitation's identity first, whether the lookup by id or any key-hash lookup found it, whatever the other key hashes found. Lookups can reach different nodes. Then a taken key. Then a failed lookup, with NotReady preferred.
  • identity_holds_master_key is one predicate shared by the preflight and the claim status. It is a key-type and key-data match for ECDSA and BLS keys, which nobody else can forge, because Platform requires a signature for every such key added to an identity.
  • Backstop after the broadcast (when a node that lagged behind missed the identity): 40207/10501 become KeysAlreadyRegistered { identity_id: None, rejection }, which keeps Platform's refusal; the FFI reports it in consensus_code/consensus_kind beside code 63. Other refusals that charge the voucher (contract bounds and similar) are not mapped.
  • adopt_already_landed_claim still adopts an identity that carries exactly the submitted keys. Any other identity behind a consumed outpoint is now classified as ClaimedByThisWallet or AlreadyClaimed instead of the raw rejection.
  • preflight_keys_map refuses a key filed under another id's slot. Two keys with one id would otherwise be refused by Platform with 10501, which the backstop reads as "taken".
  • invitation_claim_status_with_identity also returns the claimed identity. invitation_claim_status returns the same status; a lookup the quorum source cannot verify yet is now NotReady (FFI 65, previously 99), as in the claim.

rs-platform-wallet

  • New PlatformWalletError variants: InvitationClaimedByThisWallet, InvitationAlreadyClaimed, InvitationKeysAlreadyRegistered, InvitationNotReady.
  • IdentityWallet::invitation_claim_status_for_identity(invitation, identity_index, resolve_master) returns the status plus claimed_by_this_wallet: Option<bool>:
    • an identity the wallet already records counts as ours, at any index;
    • otherwise the wallet's master key at identity_index decides;
    • the key is resolved only when the invitation was claimed, so a locked Keychain never turns an unclaimed invitation into "unknown".
  • claim_invitation reports AlreadyClaimed for an identity this wallet already records as InvitationClaimedByThisWallet.

rs-platform-wallet-ffi

  • Codes 63–66, recorded in ERROR_CODE_REGISTRY.md (61/62 are held by feat(platform-wallet): spend only final coins and report funds waiting on the network #5395/fix(platform-wallet): keep the cached identity in step with the chain around updates #5487):
    • ErrorInvitationKeysAlreadyRegistered (63) and ErrorInvitationClaimedByThisWallet (64), each with a JSON detail {"identityId": ...};
    • ErrorInvitationNotReady (65);
    • ErrorAssetLockNotChainLocked (66), which used to flatten to 99;
    • InvitationAlreadyClaimed maps to 24.
  • platform_wallet_invitation_claim_status_for_identity(wallet, resolver, identity_index, uri, out). It forwards to the wallet method and releases the wallet storage before the network calls and the resolver callback run. InvitationClaimStatusFFI gains a claimed_by_this_wallet tri-state (INVITATION_CLAIMED_BY_THIS_WALLET_NO/YES/UNKNOWN). The out-param is zeroed to UNKNOWN before any fallible work.

Swift / Kotlin

  • Swift: typed PlatformWalletError cases and PlatformWalletResultCode raw cases with their init(ffi:) arms. InvitationClaimStatus.claimedByThisWallet: Bool?. A new overload invitationClaimStatus(uri:identityIndex:storage:); the old invitationClaimStatus(uri:) is kept.
  • Kotlin: typed PlatformWallet.InvitationKeysAlreadyRegistered / InvitationClaimedByThisWallet / InvitationNotReady / AssetLockNotChainLocked (the last two retryable).
  • On code 64 both example apps continue with the identity the error names, as after a successful claim. They use it directly when the wallet already records it. Otherwise they load it the way they load any identity of the wallet (Swift loadIdentity(atIndex:), Kotlin discoverIdentities) and accept only that id. When it cannot be loaded, they show its id and point to the identity re-scan screen.
  • Parity: the JNI has no claim-status binding (it never had one for the old status either). This is recorded as a Kotlin gap in sdk-parity-manifest.json / PARITY_SUMMARY.md.

How Has This Been Tested?

  • cargo test -p dash-sdk -p platform-wallet -p platform-wallet-ffi --all-features: all green. New tests cover:
    • preflight outcomes and precedence: our claim found by id or only by a key hash, someone else's, taken keys, failed and unverifiable lookups;
    • that a refused preflight never reaches the submission;
    • Sdk::claim_invitation against a mock SDK. Our identity found by id ends the claim before anything is signed. So does a taken key found by the hash of the last submitted key. With nothing registered, the claim reaches the submission;
    • the 40207/10501 backstop, and a contract-bounds refusal that is not mapped;
    • adopt-arm classification;
    • lazy resolution of the master key (not resolved for an unclaimed invitation);
    • a recorded identity counted as ours, at another index;
    • the derived master key pinned by value against an independent BIP32 derivation (abandon…about, testnet, m/9'/1'/5'/0'/0'/0'/0');
    • FFI code pins, JSON details and the tri-state encoding.
  • cargo clippy -p dash-sdk -p platform-wallet -p platform-wallet-ffi --all-features --all-targets -- -D warnings: clean.
  • ./build_ios.sh --target sim (SwiftDashSDK with -warnings-as-errors, plus SwiftExampleApp). xcodebuild test -only-testing:SwiftDashSDKTests/ErrorHandlingTests: green.
  • ./gradlew :sdk:testDebugUnitTest (InvitationClaimErrorTest, DashSdkErrorTest, DpnsMarketplaceErrorTest) and :app:compileDebugKotlin: green.
  • python3 scripts/check_sdk_parity_manifest.py: OK.

Breaking Changes

No consensus change.

Host-visible behaviour changes:

  • A repeated claim after our own claim landed no longer succeeds by adopting the identity. It returns InvitationClaimedByThisWallet (64) and records nothing. The host loads the identity the way it loads any of its own, which also fetches its DPNS names; claim-side adoption recorded only the identity and its keys. Only a node that lags behind and lets the retry through still reaches the old adopt path.
  • AssetLockNotChainLocked now arrives as code 66 instead of 99.
  • ABI: InvitationClaimStatusFFI gains claimed_by_this_wallet: u8, so platform_wallet_invitation_claim_status writes a larger struct. The struct and the function exist only on v5.1-dev (no tag up to v5.0.0-rc.8 carries them), so no released binary uses the old layout and no _v2 entry point is added. Hosts rebuild against the generated header.
  • InvitationError gains variants, and preflight_keys_map refuses a key whose id differs from its map slot. InvitationError and the invitation variants of PlatformWalletError are also unreleased (absent from v5.0.0-rc.8).
  • Kotlin SDK: IdentityRegistration.loadIdentityAtIndex, a bridge to platform_wallet_load_identity_at_index, mirroring Swift loadIdentity(atIndex:).

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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · 28852e6

  • Bots — thepastaclaw requested changes — dismiss the review or push a fix, 4 threads unresolved — resolve them
  • Self-review — post /self-reviewed
  • Build failed
  • Approvals
    • files with no dedicated owner (docs/sdk/sdk-parity-manifest.json, packages/rs-unified-sdk-jni/src/identity.rs) — QuantumExplorer or shumkov
    • kotlin-sdk (packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/dashpay/ClaimInvitationSheet.kt, packages/kotlin-sdk/PARITY_SUMMARY.md, packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/errors/DashSdkError.kt and 4 more) — HashEngineering
    • rs-platform-wallet-ffi (packages/rs-platform-wallet-ffi/ERROR_CODE_REGISTRY.md, packages/rs-platform-wallet-ffi/src/error.rs, packages/rs-platform-wallet-ffi/src/invitation.rs) — HashEngineering or ZocoLini or llbartekll
    • rs-platform-wallet (packages/rs-platform-wallet/src/error.rs, packages/rs-platform-wallet/src/wallet/identity/network/identity_handle.rs, packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs and 1 more) — HashEngineering or ZocoLini or llbartekll
    • rust-sdk (packages/rs-sdk/src/mock/sdk.rs, packages/rs-sdk/src/platform/dashpay/invitation.rs, packages/rs-sdk/src/platform/dashpay/mod.rs) — lklimek or shumkov
    • swift-sdk — you own it

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.

Summary by CodeRabbit

  • New Features

    • Invitation claim status can indicate whether an invitation was claimed by the current wallet, with identity-specific checks available in Swift.
    • SDKs provide clearer outcomes for invitation claims, including when keys are already registered, a claim is not ready, or an asset lock is not yet confirmed on-chain.
    • Wallets can load an identity at a selected index.
  • Bug Fixes

    • Invitation claim flows in the example apps can recover from certain registration conflicts by checking for a matching identity, and provide guidance when a retry or rescan is needed.

…re broadcasting it

The claim used to broadcast blindly. When a submitted key was already
registered to another identity, Platform refused it with 40207/10501 and
charged the voucher on every attempt. Hosts also could not tell their own
landed claim from someone else's.

- rs-sdk: before signing, look up the identity at the invitation's id and
  under every submitted key hash, and return ClaimedByThisWallet /
  AlreadyClaimed / KeysAlreadyRegistered / NotReady without broadcasting.
  Map 40207/10501 after a broadcast to KeysAlreadyRegistered, and classify
  a consumed-outpoint refusal by whose identity is there. One shared
  identity_holds_master_key predicate.
- rs-platform-wallet: typed error variants; invitation_claim_status_for_identity
  with a claimed_by_this_wallet tri-state, resolving the master key only when
  the invitation was claimed; an identity the wallet already records counts
  as its own.
- FFI: codes 63-66 (JSON detail on 63/64), AlreadyClaimed -> 24, and
  platform_wallet_invitation_claim_status_for_identity.
- Swift/Kotlin mirrors, example-app message for 64, parity manifest gap for
  the missing Kotlin status binding.

Refs dashpay/dashwallet-ios#1224

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

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
Walkthrough

Invitation claims now check identity and key ownership before submission and report typed outcomes for claim conflicts. Wallet-aware claim status is available through the FFI and Swift SDK. The Kotlin SDK adds identity loading by index, and both example apps handle selected claim conflicts.

Changes: Invitation Claim Behavior

Layer / File(s) Summary
Claim preflight and classification
packages/rs-sdk/src/platform/dashpay/invitation.rs, packages/rs-sdk/src/platform/dashpay/mod.rs, packages/rs-sdk/src/mock/sdk.rs
The SDK checks the prospective identity and submitted key owners before submission. It classifies existing claims and duplicate-key refusals, and adds tests for preflight and consumed-claim outcomes.
Wallet ownership and status resolution
packages/rs-platform-wallet/src/error.rs, packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs, packages/rs-sdk/src/platform/dashpay/invitation.rs
The platform wallet determines whether a claimed identity belongs to the wallet and maps claim errors. The status query returns claim status with an optional ownership result.
FFI result codes and status API
packages/rs-platform-wallet-ffi/src/error.rs, packages/rs-platform-wallet-ffi/src/invitation.rs, packages/rs-platform-wallet-ffi/ERROR_CODE_REGISTRY.md
The FFI adds claim result codes and identity details, plus a tri-state ownership field and wallet-aware status call. Tests cover mappings and status values.
Swift and Kotlin error and status bindings
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/*, packages/swift-sdk/SwiftTests/SwiftDashSDKTests/ErrorHandlingTests.swift, packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/errors/DashSdkError.kt, packages/kotlin-sdk/sdk/src/test/kotlin/org/dashfoundation/dashsdk/errors/InvitationClaimErrorTest.kt, docs/sdk/sdk-parity-manifest.json, packages/kotlin-sdk/PARITY_SUMMARY.md
The SDKs map invitation result codes to typed errors. Swift adds wallet-aware claim status. The parity records list the capability and platform support.
Kotlin identity loading by index
packages/rs-unified-sdk-jni/src/identity.rs, packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/IdentityNative.kt, packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/identity/IdentityRegistration.kt, packages/kotlin-sdk/sdk/src/test/kotlin/org/dashfoundation/dashsdk/identity/IdentityLoadAtIndexTest.kt
The Kotlin SDK loads and records an identity at an index, returns its ID when present, and validates negative indexes.
Example-app claim recovery
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift, packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/dashpay/ClaimInvitationSheet.kt
The claim sheets check recorded or loaded identities for selected conflicts and display corresponding recovery guidance.

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ClaimInvitationSheet
  participant IdentityWallet
  participant Sdk
  participant DAPI
  ClaimInvitationSheet->>IdentityWallet: submit invitation claim
  IdentityWallet->>Sdk: run claim preflight
  Sdk->>DAPI: look up prospective identity and submitted key owners
  DAPI-->>Sdk: return lookup results
  Sdk->>DAPI: submit claim after successful preflight
  DAPI-->>Sdk: return claim result
  Sdk-->>IdentityWallet: return typed claim outcome
  IdentityWallet-->>ClaimInvitationSheet: return claim result
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers: thepastaclaw, shumkov, quantumexplorer

Merge Risk: Minimal · previous review 415f5

The invitation claim preflight and its typed error handling look ready to merge. One open question remains about example-app recovery in an unusual case. The app shows a recovery message there rather than failing, so it does not block the merge.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: checking a DashPay invitation claim against Platform before broadcasting it.
Docstring Coverage Passed Docstring coverage is 80.85% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 80.85% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 47 functions across 18 files.

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

@github-actions github-actions Bot added this to the v5.1.0 milestone Oct 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 1 thread unresolved — resolve it. 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 Oct 22, 2026
@thepastaclaw

thepastaclaw commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

⛔ Final review complete — 2 blocking finding(s) (commit 28852e6) · 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

The PR's preflight and typed error plumbing are generally sound, and the available Rust, Swift, Kotlin, and relevant JavaScript checks pass; PR Hygiene is still pending. One blocking classification bug remains for valid BLS master keys, while the mixed-key precedence, consensus-error preservation, lock scope, and protocol-version comments need correction.

🔴 1 blocking | 🟡 4 suggestion(s) | 💬 1 nitpick(s)

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — The substantial changes to Sdk::claim_invitation in packages/rs-sdk/src/platform/dashpay/invitation.rs alter key-ownership validation and the decision to broadcast a voucher-consuming identity creation, directly affecting key handling and funds movement.
  • 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.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/rs-sdk/src/platform/dashpay/invitation.rs`:
- [BLOCKING] packages/rs-sdk/src/platform/dashpay/invitation.rs:1077-1081: Recognize landed claims made with a BLS master key
  `preflight_keys_map` accepts any MASTER/AUTHENTICATION key, and identity-create signing and Platform validation support BLS12_381 keys with proof of possession. However, `identity_holds_master_key` returns false unless the submitted master key is ECDSA_SECP256K1. If a valid BLS-backed claim lands and its result is lost, a retry finds the invitation identity but classifies it as `AlreadyClaimed` instead of `ClaimedByThisWallet`; the same predicate also prevents the wallet-aware status path from recognizing that claim. This tells the caller that another party claimed the voucher and blocks the intended recovery classification.
- [SUGGESTION] packages/rs-sdk/src/platform/dashpay/invitation.rs:1129-1140: Check all key-hash results for the invitation identity before reporting taken keys
  When the lookup by invitation id is absent or fails, the loop returns the first successful key-hash identity. Because `join_all` preserves `key_hashes` order, a foreign identity found for an earlier hash can produce `KeysAlreadyRegistered` before a later hash identifies `prospective_identity_id`. The documented precedence requires the invitation identity to win regardless of submitted-key order, so retain the first foreign owner, continue scanning all results, and return the foreign-key outcome only after every successful result has been checked for the prospective identity.
- [SUGGESTION] packages/rs-sdk/src/platform/dashpay/invitation.rs:1184-1186: Correct the duplicate-key refusal version threshold
  The comment says Basic error 10501 applies before protocol v7, but the version tables select validation generation V5 for protocol v7 and V6 for protocol v10, both of which still return the Basic error. Validation generation V7 is first selected by protocol v11 and changes the result to State error 40207. The same incorrect threshold appears in the `preflight_keys_map` comment near line 757 and in the PR description. The behavior is unaffected, but the documentation gives future version-gated changes the wrong activation point.
- [SUGGESTION] packages/rs-sdk/src/platform/dashpay/invitation.rs:1194-1197: Preserve the consensus rejection when mapping taken keys
  `keys_taken_on_broadcast` converts the original `InvitationError::Sdk(error)` into `KeysAlreadyRegistered { identity_id: None }` and discards the consensus error. As a result, native callers lose the duplicate-key details, and the FFI conversion reports `consensus_code = 0` and `consensus_kind = None` even when Platform rejected the broadcast with 40207 or 10501. Preserve the original error as optional source metadata on this outcome and carry that metadata through the wallet and FFI conversions while retaining the typed invitation result code.

In `packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs:494-517: Do not hold the wallet-manager read guard during key derivation
  `claimant_master_public_key` keeps the `wallet_manager.read()` guard alive while deriving the keypair. The derivation is synchronous CPU work and does not need the manager lock for the master-key path, so it unnecessarily extends the critical section and can delay writers such as identity recording. Extract the required network and wallet-derived inputs before derivation, or otherwise scope the manager guard to the minimum access needed; retain the lock only where the resident-wallet derivation genuinely requires the wallet object.
- [NITPICK] packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs:491-500: Remove the redundant Unavailable match arm
  The early `matches!` check returns `Ok(None)` for `InvitationClaimantKey::Unavailable`, so the identical arm inside the following exhaustive match can never execute. Keep the exhaustive match arm and remove the separate early return, or remove the match arm and structure the branches so the case is handled only once.

- Recognize a landed claim whose master key is BLS: Platform signs BLS
  keys into an identity like ECDSA ones.
- Check every key-hash result for the invitation's identity before
  reporting a taken key, whatever order the keys were submitted in.
- Keep Platform's 40207/10501 refusal on KeysAlreadyRegistered and stamp
  its consensus code on FFI code 63.
- Classify an unverifiable claim-status lookup as NotReady, as the claim
  does.
- Release the wallet storage before the claim's network round, and the
  wallet-manager guard before deriving from a resolved master key.
- Correct the protocol version the duplicate-key refusal changed in (v11),
  narrow the wallet-internal claimant API to pub(crate), fix doc placement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Static verification of the complete diff at 7863d1f confirms that all six prior findings are fixed, with no remaining blockers identified. One nonblocking issue remains: Swift's new typed invitation error discards the consensus metadata preserved by Rust and FFI. Current CI shows successful JavaScript build/tests and Swift frozen-schema validation, while Rust workspace tests and Kotlin SDK build/tests remain pending; no local builds or tests were run.

🟡 1 suggestion(s)

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — The intricate changes to Sdk::claim_invitation in packages/rs-sdk/src/platform/dashpay/invitation.rs alter key-ownership validation and the decision to sign and broadcast voucher-funded identity creation, directly affecting key handling and voucher expenditure.
  • 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 final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletResult.swift`:
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletResult.swift:977-979: Preserve consensus metadata in Swift's typed invitation error
  A broadcast rejection for duplicate keys now retains Platform's original error through rs-sdk and rs-platform-wallet, and FFI returns code 63 alongside consensus metadata such as 40207/State or 10501/Basic. `init(result:)` reads that metadata, but this conversion constructs a case containing only `identityId`; the public `consensusError` getter consequently returns nil. Although the existing Swift adapter deliberately exposes consensus metadata only for catch-all errors, this new typed outcome drops information explicitly preserved by the Rust implementation, and the same rejection previously reached Swift through `.consensusRejection`. Claim safety is unaffected, but Swift callers lose the authoritative rejection code for diagnostics. Retain an optional `PlatformConsensusError` alongside the typed invitation case and expose it through `consensusError`, without replacing the invitation classification. Add conversion tests for both rejection codes and a preflight outcome without consensus metadata.

…tered

Code 63 refused after the broadcast now carries Platform's 40207/10501
consensus verdict; the typed Swift case keeps it beside the
classification and `consensusError` returns it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

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

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Reviewed the complete diff at 5be60e7 and independently verified all seven prior findings as fixed. One non-blocking correctness issue remains in wallet-aware status recognition for unrecorded BLS claims; the proposed non-unique-index blocker does not establish the claimed voucher-consuming failure. This was a static review: current CI passes Rust workspace tests, Kotlin tests, JS builds/tests, and the Swift frozen-schema check; Swift build/tests remain pending.

🟡 1 suggestion(s)

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large cross-language change that alters invitation claims involving voucher charging and identity key handling, including protocol-version-specific consensus error behavior in packages/rs-sdk/src/platform/dashpay/invitation.rs and packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs.
  • 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 final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs:530-537: Wallet-aware status reports BLS-owned invitation claims as not ours
  Both derivation branches produce an ECDSA key, and this construction always labels it ECDSA_SECP256K1. The claim API also accepts BLS master keys, so an earlier claim made with this wallet's BLS key can land without being recorded locally. When that identity has no matching ECDSA signing key, the new wallet-aware status returns Some(false), which reaches Swift as claimedByThisWallet == false, even though retrying the claim with the original BLS keys correctly returns ClaimedByThisWallet. The shared predicate's BLS support does not fix this because it never receives a BLS candidate here. Derive and compare the supported master-key types in the Rust owner, or return None when an unsupported derivation prevents a definitive ownership answer. Add a regression test for a landed, unrecorded BLS-backed claim.

@romchornyi

Copy link
Copy Markdown
Contributor Author

/skip-bots

@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 bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Oct 22, 2026
@romchornyi

Copy link
Copy Markdown
Contributor Author

/self-reviewed

@github-actions

Copy link
Copy Markdown
Contributor

Missing human approval. Automatic reviewer requests are paused and this PR is excluded from reviewers' queues. Merge, close, or draft another active PR by this author to free a review slot. Required human review can be satisfied without a slot; once all merge requirements are met, PR Hygiene passes.
Full checklist in the description.

@github-actions github-actions Bot added too-many-open-prs Beyond the author's 5 open PRs; waits for one to merge before a human is asked. and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 22, 2026
@llbartekll

Copy link
Copy Markdown
Contributor

Reviewed at 5be60e7c. I checked the preflight against Drive and it asks the same question Drive does:

  • validate_unique_identity_public_key_hashes_not_in_state (v0 and v1) checks every submitted key's hash against the unique-key index.
  • When that check fails, identity-create state validation v1 returns PartiallyUseAssetLockAction, charging unique_key_already_present plus the processing fee.
  • 40207 replaced 10501 at protocol v11 (DRIVE_ABCI_VALIDATION_VERSIONS_V7).

No blockers from me. CI is green and all bot threads are resolved.

Non-blocking:

  1. After code 64, nothing loads the identity in either example app. The message says "It appears once identities are refreshed", but both apps only discover identities from the manual "Search wallets for identities" screen. nextUnusedIdentityIndex() counts only recorded identities. So a retry after the app was killed picks the same index and gets 64 again, while before this PR that retry adopted the identity and recorded it. Suggestion: on 64, load the identity from identityId (or run discovery) in the example apps, or at least tell the user where to look. The same holds for 63 when the key owner is this wallet's own unrecorded identity.
    Question: the preflight has already shown that the identity holds the master key at identity_index. Why not record it at the wallet layer, as the adopt path did, and fetch its names separately? Is dashwallet-ios ready to handle 64 there?

  2. No test covers how claim_invitation wires in the preflight. The preflight decisions are well covered through the seams, and claim_unless_refused proves that a refused preflight never submits. But nothing checks that Sdk::claim_invitation passes prospective_identity_id, keys_map[0] and every key hash into preflight_claim, or that it submits through claim_unless_refused. A refactor that broadcasts first, or fetches the wrong id, would still pass. A mock-SDK test of claim_invitation would pin the actual fix: the lookup by id or by PublicKeyHash returns an identity, and nothing is broadcast.

  3. ABI note: InvitationClaimStatusFFI gains claimed_by_this_wallet: u8, so platform_wallet_invitation_claim_status now writes a larger struct. That is fine for hosts that rebuild against the generated header, but it is worth a line under Breaking Changes next to codes 64 and 66.

  4. Nit: in adopt_already_landed_claim, submitted_keys.get(&0) cannot be None, because preflight_keys_map and claim_invitation both require key 0. The None => Err(InvitationError::Sdk(error)) arm is unreachable.

A trade-off to be aware of, not a request: the preflight fails closed. A lookup failure that is not a quorum error (InvitationError::Sdk) now stops a claim that would have been broadcast before. Given what the voucher costs, that looks right.

llbartekll
llbartekll previously approved these changes Oct 23, 2026

@llbartekll llbartekll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Non-blocking notes in #5536 (comment)

…on code 64

- Test `Sdk::claim_invitation` against a mock SDK: our identity found by
  id and a taken key found by the last key's hash both end the claim
  before signing; with nothing registered it reaches the signer.
  `MockDashPlatformSdk::expect_request` (test-only) answers the Core
  funding-transaction request.
- `adopt_already_landed_claim` takes the master key from its caller,
  dropping an arm that could not be reached.
- Both example apps continue with the identity a code 64 names: the one
  the wallet records, or the one loaded from Platform when its id
  matches; otherwise they show its id and point to the re-scan screen.

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

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in b96690e:

  1. Code 64 in the example apps. On 64 both apps now continue with the identity the error names, as after a successful claim. They use it directly when the wallet already records it. Otherwise they load it the way they load any identity of the wallet (Swift loadIdentity(atIndex:), Kotlin discoverIdentities) and accept only that id. When it cannot be loaded, they show its id and point to the re-scan screen. A retry after the app was killed therefore ends with the identity loaded, not with 64 again.
    Why not record it at the wallet layer: claim-side adoption recorded only the identity and its keys. Loading it the way the host loads any of its own identities also fetches its DPNS names, which is what dashwallet-ios needs. The dashwallet-ios side handles 64 that way in the app PR that follows this one. The adopt path stays for a node that lags behind, where the broadcast is the only signal we get.
  2. Wiring test. Added claim_through_the_sdk tests that run Sdk::claim_invitation against a mock SDK. Our identity found by id, and a taken key found by the hash of the last submitted key, both end the claim before anything is signed. With nothing registered, the claim reaches the signer. Turning the preflight into a no-op makes the first two tests fail with the signer's error.
  3. ABI note. Added under Breaking Changes.
  4. Unreachable arm. Removed. adopt_already_landed_claim now takes the master key from its caller.

On fail-closed: agreed, that is intended, given what the voucher costs.

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 1 thread unresolved — resolve it. 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 removed the ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. label Nov 13, 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

Updated after discussion: 1 finding(s) of this review were settled in the inline threads; 1 blocking finding(s) still stand.

  • ✅ Withdrawn: 🔴 Recover a wallet-owned claim after an ownerless duplicate-key refusal

The current head correctly implements proof-backed preflight and typed recovery outcomes, but the example-app invitation flow still bypasses the shared registration-slot coordinator and cannot reliably recover claims that landed at an older HD index. The Rust backstop also loses the opportunity to recover a wallet-owned claim when broadcast returns an ownerless duplicate-key refusal, while the preflight can issue unbounded concurrent lookups for caller-supplied keys. CI has no failed code checks, but workspace, JavaScript, and wasm checks remain pending.

🔴 2 1 blocking

Follow-up candidates (optional) (2)

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: Retry recovery can select a different HD index than the landed invitation claim
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift:241-257

When a claim lands while the app is unavailable before its identity row is recorded, nextUnusedIdentityIndex() uses only locally recorded identities and chooses one past the current maximum. If the landed claim used index 0 while a higher identity at index 1 is already recorded, a retry chooses index 2 and loadIdentity(atIndex:) probes the wrong slot. The Rust preflight then sees the invitation identity but compares it with index-2 keys, reports a generic already-claimed result instead of wallet ownership, and the host has no way to record the identity at index 0. Kotlin has the same assumption in its nextUnusedIdentityIndex and identityAt(..., identityIndex) recovery path. Preserve the original index or discover the claimed identity across candidate wallet indexes before classifying the recovery.

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

🟡 Suggestion: Bound concurrent per-key preflight lookups
packages/rs-sdk/src/platform/dashpay/invitation.rs:1141-1144

The preflight passes every submitted key hash to join_all, retaining and starting all lookup futures before any result can short-circuit the decision. The FFI accepts a caller-supplied key count without a claim-specific bound, and the transition-size rejection occurs only after these lookups, so an oversized key map can initiate thousands of proof/DAPI requests and retain all responses. Apply the applicable claim key-count/size limit before network work and use bounded concurrency for the remaining hashes; using a set for deduplication would also avoid the current linear Vec::contains scan.

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This large, intricate change alters invitation claim preflight and backstop behavior around voucher charging, identity ownership, and cryptographic key registration in packages/rs-sdk/src/platform/dashpay/invitation.rs and related wallet/FFI paths.
  • 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)
  • Code unchanged since the last final review (415f5b01): 2 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 2 confirmed; 2 new suggestion(s) listed as follow-up candidates, not posted inline
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); 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/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift:203-218: Invitation claims do not reserve the identity slot used by normal registration
  The invitation flow computes `identityIndex` and immediately derives and persists keys without calling `walletManager.registrationCoordinator.startRegistration(...)`. Normal identity creation reserves the same `(walletId, identityIndex)` through that coordinator, so a normal registration can select the slot after this flow computes it, or both flows can select it concurrently while deriving the same HD keys. Whichever submission lands first makes the other fail on duplicate public-key hashes; because the two flows use different funding sources, the losing registration can consume its funding and leave persisted key state for a slot that was never successfully registered. Kotlin has the same race: it snapshots coordinator-held indices before choosing the slot but does not reserve the selected invitation slot.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: A claim can compute the same next-unused identity index as a concurrent normal registration because it derives and persists its keys before calling any RegistrationCoordinator reservation. Both flows can therefore derive the same HD keys; whichever identity submission loses to the duplicate-key check can consume its separate funding and leave persisted private-key state for an unregistered slot._

In `packages/rs-sdk/src/platform/dashpay/invitation.rs`:
- [BLOCKING → WITHDRAWN in discussion; do not fix] packages/rs-sdk/src/platform/dashpay/invitation.rs:1225-1233: Recover a wallet-owned claim after an ownerless duplicate-key refusal
  `keys_taken_on_broadcast` converts every duplicate-key consensus refusal into `KeysAlreadyRegistered { identity_id: None, rejection: Some(error) }`. The call is made around the entire submission future, while `adopt_already_landed_claim` only handles an asset-lock-consumed refusal, so an ownerless 40207/10501 returned by a node that already accepted the same claim never triggers a lookup of the prospective identity. In that race, a wallet-owned landed identity is exposed to FFI as code 63 with no identity id, and both example hosts rethrow it; the user cannot recover the landed identity and another retry can repeat the chargeable path. Resolve the prospective identity and compare its master key in the Rust claim path, preserving the original rejection when the recovery lookup is unavailable or does not match.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: After the preflight observes no claim, a claim can land on one node while the submission is handled by another node that rejects the same keys with 40207/10501. Because the duplicate-key mapping wraps the entire submission and adopt_already_landed_claim only recognizes an asset-lock-consumed rejection, the wallet-owned identity is returned as KeysAlreadyRegistered with identity_id None and code 63; the example hosts rethrow it, so the user cannot recover the landed identity and a retry can repeat the chargeable path._

@@ -218,14 +218,66 @@ struct ClaimInvitationSheet: View {
network: network

@thepastaclaw thepastaclaw Nov 13, 2026 •

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.

⏭️ Deferred (maintainer decision; not blocking) at f312d906; see the replies below.

🔴 Blocking: Invitation claims do not reserve the identity slot used by normal registration

The invitation flow computes identityIndex and immediately derives and persists keys without calling walletManager.registrationCoordinator.startRegistration(...). Normal identity creation reserves the same (walletId, identityIndex) through that coordinator, so a normal registration can select the slot after this flow computes it, or both flows can select it concurrently while deriving the same HD keys. Whichever submission lands first makes the other fail on duplicate public-key hashes; because the two flows use different funding sources, the losing registration can consume its funding and leave persisted key state for a slot that was never successfully registered. Kotlin has the same race: it snapshots coordinator-held indices before choosing the slot but does not reserve the selected invitation slot.

Raised on code unchanged since the last review, and confirmed by an independent pass: A claim can compute the same next-unused identity index as a concurrent normal registration because it derives and persists its keys before calling any RegistrationCoordinator reservation. Both flows can therefore derive the same HD keys; whichever identity submission loses to the duplicate-key check can consume its separate funding and leave persisted private-key state for an unregistered slot.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in ef70fa6. The Swift claim sheet now treats slots held by registrationCoordinator as used when it picks the index, the way the Kotlin sheet already does. So a claim no longer takes the slot of a normal registration that is still in flight.

The other direction, a normal registration picking the slot of a claim in flight, is not new in this PR. The slot choice and key pre-persist are the same on v5.2-dev. Closing it means giving invitation claims their own kind of coordinator-held registration in both example apps, which is beyond this PR's scope. Within this PR, the preflight already stops the claim before broadcast once the other registration has landed, because a taken key hash returns KeysAlreadyRegistered with its owner.

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.

Still applies (re-reviewed at ef70fa6c): Excluding coordinator-held normal-registration slots only closes the direction where the normal registration reserved the slot first. The claim still publishes no reservation before deriving and persisting keys, so a normal registration can begin after the claim's snapshot and race it; the later preflight cannot prevent the separately funded loser from submitting.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Swift: fixed in 7415d59. As soon as the claim picks its index, it marks the identity-registration slot used, before deriving keys. This is the same isUsed reservation that CreateIdentityView reads in usedIdentityIndices and canSubmit, so a normal registration started while the claim is in flight skips that slot. Combined with ef70fa6, both directions are now covered.

Kotlin: deferred to #5917. CreateIdentityScreen takes a free-typed index that starts at 0 and checks no taken index at all, so the claim has nothing to reserve against. That gap predates this PR and belongs to the registration form, not to invitations.

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.

Still applies (re-reviewed at 7415d593): The new marker does not provide a complete reservation: the selector ignores persisted isUsed, the helper can silently no-op beyond lookahead and is not synchronously persisted, and Kotlin has no equivalent reservation. A coordinator-held normal-registration entry only covers one direction; the claim must acquire a shared lease before key derivation so both flows cannot capture the same slot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In f312d90 the reservation is now saved as soon as it is set. The rest of this finding is deferred to #5917, which I widened to cover both example apps: a durable shared slot lease that the registration picker and the claim sheets acquire before deriving keys, that records its holder and that covers slots past the lookahead.

The claim's own selector does not read isUsed, and that is deliberate. A retry after a lost result has to return to its own slot, where the landed claim's keys are, so the preflight can recognize the claim as this wallet's (64). Reading the marker would move the retry to the next index, where the comparison fails and the claim is reported as someone else's. A reservation that tells the holders apart needs the lease from #5917.

Deferring to #5917.

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.

Deferred (re-reviewed at f312d906): The current head persists the Swift marker and accounts for coordinator-held normal registrations, but it still lacks the durable shared lease covering Kotlin, both registration directions, and slots beyond the lookahead. As discussed on the thread, that broader lifecycle fix is tracked in #5917 and is intentionally deferred.

@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 13, 2026
…stration when claiming an invitation

The claim sheet picked one past the highest recorded identity index, so a
normal registration still in flight for that slot (no identity row yet)
could be given the same index and the same HD keys. The Kotlin sheet
already counts the coordinator's slots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

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.

@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

The current head passes the completed Rust workspace and Swift SDK checks; JS and wasm checks remain queued, with no failed code checks reported. One blocking cross-flow identity-index race remains: the Swift change excludes slots already held by normal registration, but the invitation claim still does not reserve its selected slot before deriving and persisting keys.

🔴 1 blocking

Still open from earlier rounds (1)

  • 🔴 Blocking: Invitation claims do not reserve the identity slot used by normal registration — packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift:203-208 (thread)
Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, intricate cross-language change to invitation claiming that affects voucher-funded state transitions, identity key handling, cryptographic key matching, and consensus error interpretation in packages/rs-sdk/src/platform/dashpay/invitation.rs.
  • 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.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); 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/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift:203-208: Invitation claims do not reserve the identity slot used by normal registration
  (carried; thread: https://github.com/dashpay/platform/pull/5536#discussion_r4562834096)

…before deriving its keys

The claim now marks its identity-registration slot used as soon as it
picks the index, the same reservation CreateIdentityView reads, so a
normal registration started while the claim is in flight skips that slot
instead of deriving the same keys.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

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.

@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

The SDK, wallet, FFI, and host recovery changes are otherwise coherent, and the available Rust, Swift, Kotlin, and JS checks succeeded; several broader checks were skipped and review hygiene remains pending. One blocking identity-slot race remains: the Swift reservation is neither durable nor consulted by its selector, while Kotlin has no claim reservation and its normal registration accepts a free-typed index, allowing separately funded operations to derive and submit the same keys.

🔴 1 blocking

Still open from earlier rounds (1)

  • 🔴 Blocking: Invitation claims do not reserve the identity slot used by normal registration — packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift:349-369 (thread)
Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This large, cross-language change alters invitation claiming, voucher-funded identity creation, key handling, protocol-versioned consensus error mapping, concurrent Platform lookups, and FFI-visible behavior in rs-sdk, platform-wallet, and mobile SDKs.
  • 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 final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); 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/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/DashPay/ClaimInvitationSheet.swift:349-369: Invitation claims do not reserve the identity slot used by normal registration
  (carried; thread: https://github.com/dashpay/platform/pull/5536#discussion_r4562834096)
Out-of-scope follow-up suggestions (2)

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.

  • Return an unknown result for unrecorded BLS-backed invitation claims — The wallet-aware invitation status still derives and compares only the ECDSA claimant key, so an unrecorded claim made with this wallet's BLS master key can be reported as Some(false) rather than unknown or owned. Current mobile hosts cannot produce this path, and the required wallet-layer fix is already tracked separately.
  • Contain panics at platform-wallet FFI worker boundaries — The new Swift-facing status export inherits block_on_worker's panic-propagating behavior at an extern "C" boundary. This is a crate-wide issue shared by the existing invitation exports rather than a claim-specific regression, and the required shared fix is already tracked.

…at once

The isUsed marker was left to SwiftData's autosave, so an app exit during
the claim could lose it. The claim's own selector still ignores the
marker on purpose: a retry after a lost result must return to the same
slot to be recognized as this wallet's claim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

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.

@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

The invitation preflight and recovery paths are coherent, but duplicate public-key data is still allowed through the SDK and can reach Platform, where the asset-lock voucher is partially consumed before the structural rejection. The released FFI claim path also changes AssetLockNotChainLocked from the existing unknown code 99 to code 66 without using the repository's breaking-title convention or documenting compatibility behavior for mixed old/new hosts. CI has no failed code check; Kotlin and Swift checks passed, while Rust workspace tests remain in progress.

🔴 1 blocking

Follow-up candidates (optional) (1)

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

🟡 Suggestion: Document the released FFI error-code compatibility change
packages/rs-platform-wallet-ffi/src/error.rs:1252-1257

This mapping changes PlatformWalletError::AssetLockNotChainLocked from the ErrorUnknown sentinel 99 used by the released invitation-claim FFI to the new public code 66. The registry and native mirrors define 66 consistently, but an old host paired with the new library will not recognize it, while a new host paired with an old library will continue to receive 99. Either preserve 99 for the existing entry point and expose the typed result through a versioned surface, or make the release boundary explicitly breaking by using the repository's fix! title convention and documenting the mixed-version compatibility behavior in the release metadata.

source: gpt-6.1-sol (phase2-reviewer: platform-versioning)

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — The large, intricate change modifies invitation claim broadcasting, voucher charging behavior, identity key handling, and cross-platform error classification in packages/rs-sdk/src/platform/dashpay/invitation.rs and related wallet layers.
  • 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 final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Code unchanged since the last final review (7415d593): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed; 1 new suggestion(s) listed as follow-up candidates, not posted inline
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); 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-sdk/src/platform/dashpay/invitation.rs`:
- [BLOCKING] packages/rs-sdk/src/platform/dashpay/invitation.rs:737-771: Duplicate public-key data is not rejected before the invitation claim is broadcast
  `preflight_keys_map` validates the key map shape, key 0, and map-slot/key-ID correspondence, but it never rejects two keys with identical public-key data. `claim_key_hashes` only deduplicates hashes to avoid repeated lookups; it is not a validation check. The canonical identity-create structural validation rejects duplicate key data with `DuplicatedIdentityPublicKeyBasicError` (10500), and the asset-lock identity-create path creates a `PartiallyUseAssetLockAction` for this structural failure. As a result, a malformed invitation claim can still be signed and broadcast, consume part of the voucher, and return a generic refusal because `keys_taken_on_broadcast` handles only duplicate key-ID errors 40207 and 10501. Reject duplicate key data before signing, preferably by reusing or exposing the canonical DPP validation invariant.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: A caller can provide distinct map entries, such as IDs 0 and 1, with identical public-key data. If the corresponding key hash is not already registered, preflight succeeds and the claim is broadcast; Platform then rejects the identity creation with `DuplicatedIdentityPublicKeyBasicError` (10500) after creating a `PartiallyUseAssetLockAction`, consuming the voucher penalty. `keys_taken_on_broadcast` only maps duplicate key-ID errors 40207/10501, so this reaches the caller as a generic SDK error._

Comment on lines 757 to +771
))
}
}
// The transition carries each key's own id, not its map position, so a
// key filed under another slot is refused: the map's keys are then no
// longer a promise that the ids are unique. Two keys sharing an id would
// be refused by Platform with 10501, the code a key registered elsewhere
// also got before protocol v11, which the claim reads as
// `KeysAlreadyRegistered`.
if let Some((slot, key)) = keys_map.iter().find(|(slot, key)| key.id() != **slot) {
return Err(InvitationError::Invalid(format!(
"keys_map entry {slot} holds key id {}",
key.id()
)));
}

@thepastaclaw thepastaclaw Nov 13, 2026 •

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.

✅ Resolved at e5deb4a5; see the replies below.

🔴 Blocking: Duplicate public-key data is not rejected before the invitation claim is broadcast

preflight_keys_map validates the key map shape, key 0, and map-slot/key-ID correspondence, but it never rejects two keys with identical public-key data. claim_key_hashes only deduplicates hashes to avoid repeated lookups; it is not a validation check. The canonical identity-create structural validation rejects duplicate key data with DuplicatedIdentityPublicKeyBasicError (10500), and the asset-lock identity-create path creates a PartiallyUseAssetLockAction for this structural failure. As a result, a malformed invitation claim can still be signed and broadcast, consume part of the voucher, and return a generic refusal because keys_taken_on_broadcast handles only duplicate key-ID errors 40207 and 10501. Reject duplicate key data before signing, preferably by reusing or exposing the canonical DPP validation invariant.

Raised on code unchanged since the last review, and confirmed by an independent pass: A caller can provide distinct map entries, such as IDs 0 and 1, with identical public-key data. If the corresponding key hash is not already registered, preflight succeeds and the claim is broadcast; Platform then rejects the identity creation with DuplicatedIdentityPublicKeyBasicError (10500) after creating a PartiallyUseAssetLockAction, consuming the voucher penalty. keys_taken_on_broadcast only maps duplicate key-ID errors 40207/10501, so this reaches the caller as a generic SDK error.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in e5deb4a. Before anything is signed, claim_invitation now runs DPP's own IdentityPublicKeyInCreation::validate_identity_public_keys_structure (identity create, the SDK's platform version) on the claim keys. Any error it returns refuses the claim as Invalid. The check reuses the canonical invariant instead of copying it, so it covers duplicate key data (10500) and the other structural refusals Platform makes after charging the voucher: key count, master-key count and security levels. Test: should_refuse_keys_platform_refuses_structurally.

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.

Resolved (re-reviewed at e5deb4a5): The new call to DPP's IdentityPublicKeyInCreation::validate_identity_public_keys_structure now rejects duplicate key data and the other covered chargeable structural failures before signing or broadcasting. The focused structural-refusal test also covers this path.

…idation refuses

Duplicate key data, too many keys, a wrong master-key count or a
disallowed security level reached Platform, which refuses them only after
charging part of the voucher. The claim now runs the identity-create
structural validation from DPP on its keys before anything is signed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

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.

@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

The new structural validation correctly reuses DPP's canonical identity-create validator before signing, but it selects that validator from the SDK's potentially stale protocol version before any authenticated Platform request. A fresh auto-detected mainnet or testnet SDK can therefore accept a claim under v13 rules that v14 rejects after charging the voucher; the relevant CI checks are green, but this is an in-scope blocking security issue.

🔴 1 blocking

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This large cross-layer change alters invitation identity claims involving voucher funds, key registration and matching, and broadcast/backstop behavior in packages/rs-sdk/src/platform/dashpay/invitation.rs and the platform-wallet/FFI paths.
  • 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.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); 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-sdk/src/platform/dashpay/invitation.rs`:
- [BLOCKING] packages/rs-sdk/src/platform/dashpay/invitation.rs:983-984: Use the verified network protocol version for claim-key validation
  `validate_claim_keys_structure` runs with `self.version()` before `claim_invitation` makes any Platform request. An auto-detected SDK starts at the per-network minimum version, which is v13 for mainnet and testnet, and only ratchets upward after authenticated response metadata is accepted. Protocol v14 selects DPP structural-validation generation v1 while v13 selects generation v0; v1 newly rejects cases such as a master key carrying an expiry or budget and malformed hash-key data. A caller can therefore submit such a key set while the SDK still reports v13, pass the local preflight, sign and broadcast the claim, and have the v14 identity-create path reject it after applying the voucher-consuming asset-lock action. Obtain a verified target version before this validation, or fail closed when the current protocol version cannot be established.

Comment on lines +983 to +984
preflight_keys_map(&keys_map)?;
validate_claim_keys_structure(&keys_map, self.version())?;

@thepastaclaw thepastaclaw Nov 13, 2026 •

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.

✅ Resolved at f160a3c5; see the replies below.

🔴 Blocking: Use the verified network protocol version for claim-key validation

validate_claim_keys_structure runs with self.version() before claim_invitation makes any Platform request. An auto-detected SDK starts at the per-network minimum version, which is v13 for mainnet and testnet, and only ratchets upward after authenticated response metadata is accepted. Protocol v14 selects DPP structural-validation generation v1 while v13 selects generation v0; v1 newly rejects cases such as a master key carrying an expiry or budget and malformed hash-key data. A caller can therefore submit such a key set while the SDK still reports v13, pass the local preflight, sign and broadcast the claim, and have the v14 identity-create path reject it after applying the voucher-consuming asset-lock action. Obtain a verified target version before this validation, or fail closed when the current protocol version cannot be established.

source: gpt-6.1-sol (phase2-reviewer: security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a489bff. The structural check now runs inside the submission step, after the preflight and before anything is signed. The preflight only lets the claim through when every lookup returned (the identity at the invitation id and each key hash). Each lookup is proved, and accept_verified_metadata raises the SDK's version to the protocol version the network signed. So the keys are checked under the generation Platform will apply, not under the per-network minimum an auto-detected SDK starts with. If a lookup fails, the preflight returns an error and nothing is broadcast. Test: claim_through_the_sdk::should_refuse_structurally_invalid_keys_before_signing (it fails when the check is removed).

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.

Still applies (re-reviewed at a489bffa): The new placement fixes the unpinned auto-detection case, but self.version() remains unchanged for an explicitly pinned SDK after newer metadata is verified. The claim still needs to validate against the known verified version or refuse when that version is unavailable or unsupported.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 8a78a87. The keys are now judged by claim_keys_platform_version: the newer of the SDK's operation version and the version the network signed in a verified answer (protocol_version_info().verified_version, which ordinary proved queries record on a pinned SDK too). The check still runs after the preflight, whose lookups are all proved. The claim is refused before signing when no verified answer showed the network's version, or when that version is newer than this build has rules for.

Tests: claim_through_the_sdk::should_judge_keys_by_the_networks_version_on_a_pinned_sdk pins the SDK to v13 and gives it a master key with a budget, which v13's structural validation accepts and the latest refuses. With the network verified at the latest the claim is refused before signing; with the network at v13 it reaches the signer. It fails when the check goes back to self.version(). should_refuse_when_the_networks_version_was_not_verified and the unit test should_judge_claim_keys_by_the_networks_verified_version cover the refusals.

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.

Resolved (re-reviewed at f160a3c5): Thanks — claim-key validation now uses the newer of the SDK operation version and the verified network version, and fails closed when the required network version is unavailable or unsupported.

…rsion

The structural key check ran before any Platform request, at the version
an SDK starts with (the network minimum), so keys a newer generation
refuses could still be broadcast and charged. It now runs after the
preflight: its proved lookups raise the SDK's version to the one the
network signed, and nothing is signed before the check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 15, 2026 •

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.

@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

The latest head correctly moves canonical claim-key validation after the proof-verified preflight, but explicitly pinned SDKs can still validate against a stale local protocol generation. The claim bookkeeping also mutates wallet state by wallet ID alone after an asynchronous network operation, allowing a replacement wallet generation to receive the original claim. CI reports the relevant Rust, Swift, Kotlin, JavaScript, and WASM checks successful; functional suites were skipped and PR Hygiene remains pending.

🔴 2 blocking | 🟡 2 suggestion(s)

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

🔴 Blocking: Commit invitation-claim state only to the originating wallet generation
packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs:588-591

The claim releases the wallet manager while the network claim runs, then reacquires it and calls get_wallet_info_mut(&self.wallet_id) without checking self.generation. If the wallet is removed and recreated under the same ID while the claim is in flight, the successful claim's identity and key breadcrumbs are written into the replacement wallet. The existing current_wallet_info_mut helper compares the stored generation specifically to prevent stale handles from mutating replacement state; use that generation-checked path (or hold the generation lifecycle guard across the operation) and treat a stale generation as a non-mutating failure. The ownership lookup in claim_refusal/holds_identity must also be generation-aware so a replacement wallet cannot cause a stale claim to be classified as belonging to it.

Raised on code unchanged since the last review, and confirmed by an independent pass: A claim started through a generation G1 handle can finish after G1 is removed and a replacement wallet G2 is registered under the same ID; the post-claim get_wallet_info_mut(&self.wallet_id) then adds G1's newly claimed identity and key breadcrumbs to G2, corrupting the replacement wallet's local ownership state. The same race lets claim_refusal and invitation_claimed_by_this_wallet_resolving inspect G2 and misclassify a stale claim as belonging to the replacement wallet.

source: gpt-6.1-sol (phase2-reviewer: architecture-layering)

Still open from earlier rounds (1)

  • 🔴 Blocking: Use the verified network protocol version for claim-key validation — packages/rs-sdk/src/platform/dashpay/invitation.rs:1017-1022 (thread)
Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This large, intricate change modifies invitation claim authorization, cryptographic key handling, voucher-funded identity creation, protocol-version-specific rejection mapping, and Rust FFI error reporting in rs-sdk and platform-wallet layers.
  • 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)
  • Code unchanged since the last final review (e5deb4a5): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); 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/identity/network/invitation.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs:588-591: Commit invitation-claim state only to the originating wallet generation
  The claim releases the wallet manager while the network claim runs, then reacquires it and calls `get_wallet_info_mut(&self.wallet_id)` without checking `self.generation`. If the wallet is removed and recreated under the same ID while the claim is in flight, the successful claim's identity and key breadcrumbs are written into the replacement wallet. The existing `current_wallet_info_mut` helper compares the stored generation specifically to prevent stale handles from mutating replacement state; use that generation-checked path (or hold the generation lifecycle guard across the operation) and treat a stale generation as a non-mutating failure. The ownership lookup in `claim_refusal`/`holds_identity` must also be generation-aware so a replacement wallet cannot cause a stale claim to be classified as belonging to it.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: A claim started through a generation G1 handle can finish after G1 is removed and a replacement wallet G2 is registered under the same ID; the post-claim `get_wallet_info_mut(&self.wallet_id)` then adds G1's newly claimed identity and key breadcrumbs to G2, corrupting the replacement wallet's local ownership state. The same race lets `claim_refusal` and `invitation_claimed_by_this_wallet_resolving` inspect G2 and misclassify a stale claim as belonging to the replacement wallet._

In `packages/rs-sdk/src/platform/dashpay/invitation.rs`:
- [SUGGESTION] packages/rs-sdk/src/platform/dashpay/invitation.rs:1172-1175: Bound the per-key preflight lookup fan-out
  `preflight_claim` creates one concurrent fetch future for every submitted key before `validate_claim_keys_structure` checks the canonical identity-create limits. The public SDK accepts an arbitrarily large `BTreeMap`, so malformed or buggy input can trigger an unbounded number of concurrent DAPI requests and retry tasks before the claim is rejected locally. Preserve the version-sensitive structural check after verified metadata, but reject a version-independent oversized map before fan-out or use bounded concurrency for the key-hash lookups.
- [SUGGESTION] packages/rs-sdk/src/platform/dashpay/invitation.rs:3790-3804: Test the protocol-version-sensitive structural validation
  `should_refuse_structurally_invalid_keys_before_signing` uses duplicate public-key data, which is rejected by the older structural-validation generation as well as the newer one. The test therefore does not prove that the preflight ratchets an auto-detected SDK before validation, nor would it necessarily fail if the structural check moved back before the preflight. Add a regression using a key shape accepted by generation 0 but rejected by generation 1, such as a v1 key-limit or malformed hash-key case, and assert that a mock initially below the target version receives a verified target-version response and refuses before the signer is invoked.
- [BLOCKING] packages/rs-sdk/src/platform/dashpay/invitation.rs:1017-1022: Use the verified network protocol version for claim-key validation
  (carried; thread: https://github.com/dashpay/platform/pull/5536#discussion_r4569442074)

Comment on lines +1172 to +1175
let (claimed, by_hash) = futures::future::join(
fetch_by_id(),
futures::future::join_all(key_hashes.iter().map(|hash| fetch_by_hash(*hash))),
)

@thepastaclaw thepastaclaw Nov 15, 2026 •

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.

✅ Resolved at f160a3c5; see the replies below.

🟡 Suggestion: Bound the per-key preflight lookup fan-out

preflight_claim creates one concurrent fetch future for every submitted key before validate_claim_keys_structure checks the canonical identity-create limits. The public SDK accepts an arbitrarily large BTreeMap, so malformed or buggy input can trigger an unbounded number of concurrent DAPI requests and retry tasks before the claim is rejected locally. Preserve the version-sensitive structural check after verified metadata, but reject a version-independent oversized map before fan-out or use bounded concurrency for the key-hash lookups.

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 8a78a87: preflight_keys_map now refuses a keys map larger than the largest max_public_keys_in_creation of any protocol version this build knows, before any lookup starts. The version-sensitive structural check still runs after the verified preflight. Test: should_refuse_more_keys_than_any_version_allows_before_the_lookups.

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.

Resolved (re-reviewed at f160a3c5): Thanks — preflight_keys_map now rejects maps larger than the maximum supported identity-creation limit before constructing any lookup futures, with boundary coverage.

Comment on lines +3790 to +3804
/// data) pass the preflight lookups but stop before anything is signed.
#[tokio::test]
async fn should_refuse_structurally_invalid_keys_before_signing() {
use dpp::identity::identity_public_key::accessors::v0::{
IdentityPublicKeyGettersV0, IdentityPublicKeySettersV0,
};

let mut keys = claim_keys();
let master_data = keys[&0].data().clone();
keys.get_mut(&1).expect("key 1").set_data(master_data);
let (result, _) = claim_with_keys(keys, |_| None, |_, _| None).await;
assert!(
matches!(&result, Err(InvitationError::Invalid(_))),
"got {result:?}"
);

@thepastaclaw thepastaclaw Nov 15, 2026 •

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.

✅ Resolved at f160a3c5; see the replies below.

🟡 Suggestion: Test the protocol-version-sensitive structural validation

should_refuse_structurally_invalid_keys_before_signing uses duplicate public-key data, which is rejected by the older structural-validation generation as well as the newer one. The test therefore does not prove that the preflight ratchets an auto-detected SDK before validation, nor would it necessarily fail if the structural check moved back before the preflight. Add a regression using a key shape accepted by generation 0 but rejected by generation 1, such as a v1 key-limit or malformed hash-key case, and assert that a mock initially below the target version receives a verified target-version response and refuses before the signer is invoked.

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 8a78a87: should_judge_keys_by_the_networks_version_on_a_pinned_sdk uses a master key with a budget (accepted by generation 0, refused by generation 1), on an SDK pinned to v13 with the network verified at the latest version. It refuses before the signer is called, reaches the signer when the network is at v13, and fails if the check goes back to self.version(). The duplicate-data test now also asserts the structural refusal's message, so it can't pass on another refusal.

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.

Resolved (re-reviewed at f160a3c5): Thanks — the new pinned-SDK regression uses a key shape accepted by the older validation generation and rejected by the newer one, verifies the network version, and confirms signing is not reached.

romchornyi and others added 2 commits November 15, 2026 23:57
…col version

A pinned SDK keeps its operation version after a verified answer shows a
newer network, so the structural check of the claim's keys could run under
older rules than Platform applies. The keys are now judged by the newer of
the SDK's version and the network's verified one; the claim is refused before
signing when no verified answer showed it, or when this build has no rules
for it. A keys map larger than any known version allows is refused before
the per-key lookups start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on that started it

A claim runs without the wallet manager's lock, so its wallet can be removed
and re-created under the same id before it ends. The claim now records the
new identity only through the generation-checked `current_wallet_info_mut`,
and reads whether an identity is this wallet's (refusal classification,
claim status, the claimant's master key) only from the handle's own
generation.

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

Copy link
Copy Markdown
Contributor Author

Re the blocker not shown inline, "Commit invitation-claim state only to the originating wallet generation" (rs-platform-wallet/.../invitation.rs): fixed in f160a3c. The post-claim bookkeeping now writes only through current_wallet_info_mut. If the wallet was removed or re-created while the claim ran, it writes nothing and logs that. Platform already accepted the identity, so the claim still returns it. holds_identity (used by claim_refusal and the claim status), the resident-keys check and the claimant master-key derivation now read through a new current_wallet_and_info, the read counterpart of the generation-checked helpers. Test: should_not_read_a_replacement_wallets_identities_through_a_stale_handle. Through a stale handle, a replacement's identity stays "claimed by someone else" and the status is unknown; the replacement's own handle still recognizes it. The test fails without the generation check.

@github-actions

github-actions Bot commented Nov 15, 2026 •

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.

@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

The invitation preflight, verified-version validation, consensus metadata propagation, and direct claim bookkeeping are correctly implemented at this head. One blocking wallet-lifecycle race remains: the direct ClaimedByThisWallet refusal path can invoke generation-unsafe identity recovery, allowing a stale handle to persist fetched identity state into a replacement wallet generation; CI evidence is otherwise green for the relevant Rust, Swift, Kotlin, and JavaScript checks.

🔴 1 blocking

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, intricate cross-language change to invitation claiming that alters funds-charging behavior and key/identity validation in rs-sdk and platform-wallet, notably in Sdk::claim_invitation and related preflight/backstop logic.
  • 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.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); 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/identity/network/invitation.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs:433-440: Generation-check direct claimed-by-this-wallet refusals before recovery
  `Sdk::claim_invitation` can return `InvitationError::ClaimedByThisWallet` directly from the preflight, but `claim_refusal` applies the generation-aware `holds_identity` check only to `InvitationError::AlreadyClaimed`; the direct result falls through to `error.into()` and becomes code 64 unconditionally. Swift and Kotlin then invoke `loadIdentityAtIndex` through the retained `IdentityWallet` handle. That loader's asynchronous recovery path writes through `wm.get_wallet_info_mut(&self.wallet_id)` in `loading.rs:247-289` and again for DPNS enrichment in `loading.rs:298-305`, checking only the wallet id and not `self.generation`. If generation A receives the direct code-64 result and the wallet is removed and recreated under the same id while the recovery fetch is in flight, generation A can persist the fetched identity, key breadcrumbs, or DPNS state into generation B. Make the recovery operation generation-checked for both writes, and ensure direct `ClaimedByThisWallet` handling cannot proceed with a stale originating handle. Add a regression that uses the direct `ClaimedByThisWallet` result across wallet removal and same-id recreation.

Comment on lines +433 to +440
async fn claim_refusal(&self, error: InvitationError) -> PlatformWalletError {
match error {
InvitationError::AlreadyClaimed { identity_id }
if self.holds_identity(&identity_id).await =>
{
PlatformWalletError::InvitationClaimedByThisWallet { identity_id }
}
error => error.into(),

@thepastaclaw thepastaclaw Nov 15, 2026 •

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.

✅ Resolved at 28852e6e; see the replies below.

🔴 Blocking: Generation-check direct claimed-by-this-wallet refusals before recovery

Sdk::claim_invitation can return InvitationError::ClaimedByThisWallet directly from the preflight, but claim_refusal applies the generation-aware holds_identity check only to InvitationError::AlreadyClaimed; the direct result falls through to error.into() and becomes code 64 unconditionally. Swift and Kotlin then invoke loadIdentityAtIndex through the retained IdentityWallet handle. That loader's asynchronous recovery path writes through wm.get_wallet_info_mut(&self.wallet_id) in loading.rs:247-289 and again for DPNS enrichment in loading.rs:298-305, checking only the wallet id and not self.generation. If generation A receives the direct code-64 result and the wallet is removed and recreated under the same id while the recovery fetch is in flight, generation A can persist the fetched identity, key breadcrumbs, or DPNS state into generation B. Make the recovery operation generation-checked for both writes, and ensure direct ClaimedByThisWallet handling cannot proceed with a stale originating handle. Add a regression that uses the direct ClaimedByThisWallet result across wallet removal and same-id recreation.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 28852e6. claim_refusal reports this wallet's claim (direct ClaimedByThisWallet from the SDK, or AlreadyClaimed of an identity this wallet records) only while the handle's wallet is still current. A stale handle gets WalletNotFound, so the host is not sent to load the identity through it. The loader's two writes in load_identity_by_index_inner (the identity with its key breadcrumbs, then the DPNS names) now go through the generation-checked current_wallet_info_mut, so a load that finishes after the wallet was replaced writes nothing and fails as not found. Regression: should_not_read_a_replacement_wallets_identities_through_a_stale_handle now also sends a direct ClaimedByThisWallet across removal and same-id re-creation: WalletNotFound through the stale handle, InvitationClaimedByThisWallet through the replacement's.

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.

Resolved (re-reviewed at 28852e6e): The current head generation-checks direct ClaimedByThisWallet results before the host can start recovery, and both loader writes use the generation-aware helper. The added regression covers removal followed by same-id recreation.

… the handle's wallet generation

The SDK's own "claimed by this wallet" reached the host without a generation
check, and the host then loads that identity through the same handle, whose
loader wrote the fetched identity and its DPNS names by wallet id alone. A
claim refusal now reports this wallet's claim only while the handle's wallet
is still current (else WalletNotFound), and the loader's two writes go
through the generation-checked `current_wallet_info_mut`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 15, 2026 •

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.

@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

The invitation preflight and wallet-generation bookkeeping fixes are substantially correct, but identity recovery still has two stale-generation publication paths in rs-platform-wallet: an empty lookup can be returned successfully from a replacement wallet, and a DPNS-enrichment failure can return an old identity as successful. These are blocking because the host interprets both results as belonging to the selected wallet. CI reports Rust workspace, Swift, Kotlin, and JS checks successful; wallet-specific Rust tests are skipped.

A pattern across this PR's review rounds

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

1. No shared generation-scoped claim operation (2 new in this round, 4 earlier finding(s))

IdentityWallet and the two example-app registration flows do not have one durable, generation-scoped operation for (wallet_id, identity_index, invitation). The claim releases manager state for network and resolver work, while ordinary registration can choose the same slot; later patches check the generation at selected writes and branches, but empty-load and DPNS-error paths still publish stale results, while lost-result recovery still has to infer ownership from Platform. These are variants of the missing reservation and lifecycle fence, not isolated errors.

Already tracked: #5917

In this round: Reject stale wallet generations before returning an empty identity load; Fence the identity-load result after DPNS enrichment fails

2. Validation is patched around preflight fan-out (4 earlier finding(s))

Sdk::claim_invitation has no single gate that validates the complete identity-create key set under the network's verified rules before starting per-key ownership queries. Shape checks happen first, protocol-version knowledge arrives through preflight responses, and structural validation is then layered into the submission path; duplicate-data, version, fan-out, and regression-test findings keep exposing holes around that ordering. The component is growing by patching the preflight rather than enforcing a stable pre-broadcast contract.

Suggested decision (redesign the component): Redesign the invitation claim pipeline, spanning Sdk::claim_invitation, IdentityWallet, and the app adapters, as one operation with a verified-version and complete-key-validation gate, a durable shared identity-slot lease, and one generation-checked final publication path. Land that replacement instead of adding more branch-local guards; if the slot-lease and lifecycle primitive is not ready, remove or gate the invitation recovery flow that depends on it.

If a later review again finds new blockers from these causes, it will ask for that decision and pause automatic re-review until it is made.

🔴 2 blocking

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

🔴 Blocking: Reject stale wallet generations before returning an empty identity load
packages/rs-platform-wallet/src/wallet/identity/network/loading.rs:187-218

The initial read uses wm.get_wallet(&self.wallet_id) rather than the generation-aware current_wallet_and_info, so a handle from generation A can query a same-id replacement generation B. When that query returns Ok(None), line 218 returns successfully without checking self.generation. Swift and Kotlin then interpret the result as a valid lookup with no identity and direct the user to rescan, even though the handle's wallet state is stale and the lookup result is indeterminate. Use the generation-aware lookup for the initial wallet/network read and re-check the generation before returning Ok(None); add a regression that removes and recreates the wallet between the claim refusal and the recovery call.

source: gpt-6.1-sol (phase2-reviewer: general)

🔴 Blocking: Fence the identity-load result after DPNS enrichment fails
packages/rs-platform-wallet/src/wallet/identity/network/loading.rs:302-311

The first persistence phase is generation-checked, and the successful DPNS path is also checked, but the Err(e) branch only logs the DPNS failure and then returns Ok(Some(identity)). If generation A is removed and replaced while fetch_owned_dpns_names is in flight, the stale handle can therefore report generation A's identity as successfully loaded even though generation B was never populated. The generation check belongs in rs-platform-wallet: fail closed on this stale-generation error path, or hold the lifecycle guard through final publication; add a regression covering replacement during a failed DPNS fetch.

source: gpt-6.1-sol (phase2-reviewer: architecture-layering)

Review provenance

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

  • Triage: critical by gpt-6.1-sol (effort low) — This large cross-language change alters invitation claim broadcasting, asset-lock spending behavior, identity key handling, and protocol-version-dependent consensus error mapping in rs-sdk and platform-wallet.
  • 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.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — platform-versioning (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); 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 shared generation-scoped claim operation; Validation is patched around preflight fan-out. When you fix the findings below, fix the cause, not only the reported case. The review suggests (redesign the component): Redesign the invitation claim pipeline, spanning Sdk::claim_invitation, IdentityWallet, and the app adapters, as one operation with a verified-version and complete-key-validation gate, a durable shared identity-slot lease, and one generation-checked final publication path. Land that replacement instead of adding more branch-local guards; if the slot-lease and lifecycle primitive is not ready, remove or gate the invitation recovery flow that depends on it. 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/identity/network/loading.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/loading.rs:187-218: Reject stale wallet generations before returning an empty identity load
  The initial read uses `wm.get_wallet(&self.wallet_id)` rather than the generation-aware `current_wallet_and_info`, so a handle from generation A can query a same-id replacement generation B. When that query returns `Ok(None)`, line 218 returns successfully without checking `self.generation`. Swift and Kotlin then interpret the result as a valid lookup with no identity and direct the user to rescan, even though the handle's wallet state is stale and the lookup result is indeterminate. Use the generation-aware lookup for the initial wallet/network read and re-check the generation before returning `Ok(None)`; add a regression that removes and recreates the wallet between the claim refusal and the recovery call.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/loading.rs:302-311: Fence the identity-load result after DPNS enrichment fails
  The first persistence phase is generation-checked, and the successful DPNS path is also checked, but the `Err(e)` branch only logs the DPNS failure and then returns `Ok(Some(identity))`. If generation A is removed and replaced while `fetch_owned_dpns_names` is in flight, the stale handle can therefore report generation A's identity as successfully loaded even though generation B was never populated. The generation check belongs in `rs-platform-wallet`: fail closed on this stale-generation error path, or hold the lifecycle guard through final publication; add a regression covering replacement during a failed DPNS fetch.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants