Skip to content

fix(dashpay): refuse a contract-group-bound key registration - #1139

Merged
romchornyi merged 1 commit into
developfrom
fix/dashconnect-contract-group-compat
Sep 20, 2026
Merged

romchornyi merged 1 commit into
developfrom
fix/dashconnect-contract-group-compat

Conversation

@romchornyi

@romchornyi romchornyi commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

dashpay/dashwallet-ios develop no longer compiles against current packages/swift-sdk on v4.2-dev.

ManagedPlatformWallet.ContractBounds gained a third case in dashpay/platform#4800 (5568dfa443) — contractGroup(id:), FFI kind 3 — while the DPP-layer ContractBounds that PlatformDashConnectDataSource.parse() maps it into still has two:

PlatformDashConnectDataSource.swift:246:33: error: switch must be exhaustive
note: add missing case: '.contractGroup(id: let id)'

The SDK-side gap is filed as dashpay/platform#4853. This PR is only the app-side refusal, split out of #1138 so a build can take it without the Bluetooth login feature.

What was done?

parse() refuses a key registration that carries a contract-group bound, rather than mapping it to something it is not.

There is no correct arm to add, and dropping the bound would be wrong twice over:

  • the bound decides which approved app a scanned key registration belongs to, so a key whose bound is erased names no single app;
  • the same value is rebuilt into the IdentityPubkey handed back to updateIdentity(...), so a silently weakened bound would mean signing a transition the dApp never asked for.

A key bound to a contract group is never one of the login keys this flow derives, so refusing is also the honest behaviour — the same conclusion the SDK's own PersistentPublicKey seam documents when it declines to project kind 3 as .singleContract.

The identity-key fixtures in PlatformDashConnectDataSourceTests gain the protocol-14 limit fields (totalBudget, expiresAt, both nil — dashpay/platform#4798) so the unit-test target builds against the same SDK.

How Has This Been Tested?

Against packages/swift-sdk on v4.2-dev at 72b58f6073, DashSDKFFI.xcframework rebuilt with ./build_ios.sh --target sim:

  • xcodebuild -workspace DashWallet.xcworkspace -scheme dashpay -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' ARCHS=arm64 build — BUILD SUCCEEDED (fails on develop without this change).
  • build-for-testing on the unit-test target — TEST BUILD SUCCEEDED (fails without the fixture change).

Not exercised at runtime: no dApp registers a contract-group-bound key today, so the refusal path has no live counterpart to try it against. The behaviour it replaces did not compile.

Breaking Changes

None for users. A key registration carrying a contract-group bound is now refused instead of failing to build; nothing in the shipped flows produces one.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Key registration transitions now reject unexpected contract-group bounds instead of processing them with incomplete data.
    • Improved handling of key registration data when contract-bound conversion fails.

`ManagedPlatformWallet.ContractBounds` grew a third case in the Swift SDK
(dashpay/platform#4800), and the DPP-layer `ContractBounds` that
`PlatformDashConnectDataSource.parse()` maps it into still has two, so the
file stopped compiling against current `v4.2-dev`:

    PlatformDashConnectDataSource.swift:246:33: error: switch must be exhaustive
    note: add missing case: '.contractGroup(id: let id)'

There is no correct arm to add. Dropping the bound would be wrong twice
over: the value decides which approved app a scanned key registration
belongs to, so a key whose bound is erased names no single app; and the
same value is rebuilt into the `IdentityPubkey` handed back to
`updateIdentity(...)`, so a silently weakened bound would mean signing a
transition the dApp never asked for. A key bound to a contract group is
never one of the login keys this flow derives, so refuse the transition
instead — the same conclusion the SDK's own persistence seam reaches, and
the reason dashpay/platform#4853 asks for the DPP-layer enum to model the
bound end to end.

The identity-key fixtures gain the protocol-14 limit fields
(dashpay/platform#4798) so the test target builds against the same SDK.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: bf4cc4f4-d02f-483a-95af-85b7b989c98a

📥 Commits

Reviewing files that changed from the base of the PR and between 65d6aa1 and 61c3208.

📒 Files selected for processing (2)
  • DashWallet/Sources/Models/DashConnect/PlatformDashConnectDataSource.swift
  • DashWalletTests/DashConnect/PlatformDashConnectDataSourceTests.swift

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The key-registration parser now rejects contract-group bounds instead of omitting them. The test helper now supplies the added totalBudget and expiresAt fields.

Changes

Key registration validation

Layer / File(s) Summary
Reject unsupported contract bounds
DashWallet/Sources/Models/DashConnect/PlatformDashConnectDataSource.swift, DashWalletTests/DashConnect/PlatformDashConnectDataSourceTests.swift
Key and contract-bound mapping now propagates errors. Contract-group bounds throw keyRegistrationUnexpectedMutation. The test helper initializes the added key-limit fields with nil values.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: jeanpierreroma

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
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: refusing key registrations with a contract-group bound.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit 61c3208) · triage: low

@thepastaclaw thepastaclaw 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.

Final validation — Phase 1 + Phase 2

Verified the supplied findings against head 61c3208 and the complete base-to-head diff. The throwing conversion rejects the entire registration before connection selection, key derivation, authorization, or identity-update submission; no blocking defect was identified. Both reviewers identified the same valid, non-blocking regression-test gap, consolidated below; this verification was static and did not independently establish build or runtime success.

🟡 1 suggestion(s)

Review provenance

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

  • Triage: low by gpt-6-astra (effort low) — The diff adds a straightforward rejection of an unsupported contract-bound enum case in PlatformWalletDashConnectStateTransitionParser.parse() and updates test fixture arguments, making it small and contained despite touching key-registration handling.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort high); agent phase1-reviewer, muse-spark-1.3-contributor — ffi-engineer (completed, effort high); agent phase1-reviewer, muse-spark-1.3-contributor — security-auditor (completed, effort high); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane failed), glm-5.3-flash (zai below 15% reserve: 5h 100% left, weekly 13% left)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort medium); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6-astra — security-auditor (completed, effort medium); 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 `DashWallet/Sources/Models/DashConnect/PlatformDashConnectDataSource.swift`:
- [SUGGESTION] DashWallet/Sources/Models/DashConnect/PlatformDashConnectDataSource.swift:254-266: Add a regression test for whole-transition contract-group refusal
  The new `.contractGroup` refusal branch has no regression coverage: the existing parser tests cover supported identity updates and token purchases, while this PR's fixture changes only supply the new optional key-limit fields. Use the existing injected `parseTransition` closure to return an identity update containing a supported key followed by a contract-group-bound key, then assert that `parse` throws `DashConnectPlatformError.keyRegistrationUnexpectedMutation`. This directly protects the security-relevant guarantee that the entire registration is rejected rather than returning a partial key list or silently weakening a bound, without requiring a live dApp.

Comment on lines +254 to 266
case .contractGroup:
// The wallet layer reports a contract-group bound since the
// SDK's #4800, and the DPP-layer `ContractBounds` this maps
// into has no case for it (dashpay/platform#4853). Dropping
// the bound is not an option here: the value decides which
// approved app a key registration belongs to, and it is also
// rebuilt into the `IdentityPubkey` handed back to
// `updateIdentity(...)`, so a silently weakened bound would
// mean signing a transition the dApp did not ask for. A key
// bound to a contract group is never one of the login keys
// this flow derives, so refuse the transition instead.
throw DashConnectPlatformError.keyRegistrationUnexpectedMutation
}

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.

🟡 Suggestion: Add a regression test for whole-transition contract-group refusal

The new .contractGroup refusal branch has no regression coverage: the existing parser tests cover supported identity updates and token purchases, while this PR's fixture changes only supply the new optional key-limit fields. Use the existing injected parseTransition closure to return an identity update containing a supported key followed by a contract-group-bound key, then assert that parse throws DashConnectPlatformError.keyRegistrationUnexpectedMutation. This directly protects the security-relevant guarantee that the entire registration is rejected rather than returning a partial key list or silently weakening a bound, without requiring a live dApp.

source: muse-spark-1.3-contributor (phase1-reviewer: general, ffi-engineer, security-auditor); gpt-6-astra (phase2-reviewer: general, ffi-engineer, security-auditor)

@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.

Approving. Verified against packages/swift-sdk at 72b58f6073: the switch in parse() was the only app-side match over ManagedPlatformWallet.ContractBounds (the other two sites switch the DPP enum, which #4853 leaves at two cases), refusing rather than dropping the bound is correct since it both selects the pending connection and is rebuilt into the IdentityPubkey for updateIdentity, and the IdentityPublicKeyInfo fixture change matches the no-default memberwise init from #4798 in the right order. Note for anyone building develop after this merges: ../platform must be ≥ 5568dfa443 with a rebuilt xcframework.

@romchornyi
romchornyi merged commit bd4b1b5 into develop Sep 20, 2026
4 checks passed
@romchornyi
romchornyi deleted the fix/dashconnect-contract-group-compat branch September 20, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants