Skip to content

fix(wallet): grant no biometric allowance without a stored spending limit - #1356

Merged
ross-dash merged 1 commit into
developfrom
fix/unset-spending-limit
Nov 12, 2026
Merged

ross-dash merged 1 commit into
developfrom
fix/unset-spending-limit

Conversation

@ross-dash

Copy link
Copy Markdown
Contributor

Summary

  • A PIN entry now restores the biometric allowance only from a stored limit; with no stored limit there is no allowance, and a spend asks for the PIN.
  • A limit of 0 now resets the allowance to 0 on PIN entry instead of leaving the previous value.
  • The allowance rules (allowanceAfterPinEntry, biometricAllowanceCovers) are pure functions, covered by BiometricAllowanceTests.

Regular limits are unchanged: with a 0.5 DASH limit, a PIN entry restores 0.5 DASH, and the legacy UserDefaults limit migration works as before.

Test plan

  • BiometricAllowanceTests (7) and AuthenticationGateTests pass
  • check_test_target_membership.py passes

🤖 Generated with Claude Code

A PIN entry now restores the biometric allowance only from a stored
limit; with no stored limit there is no allowance and a spend asks for
the PIN. A limit of 0 now resets the allowance to 0 on PIN entry instead
of leaving the previous value. The allowance rules are pure functions
with unit tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ross-dash
ross-dash requested a review from romchornyi November 10, 2026 22:02
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Passed 1 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Pending This assessment has not completed. The check will be retried on the next pre-merge check run.
Passed Passed checks: 1 passed

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Share

@thepastaclaw

thepastaclaw commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit e2bbd84) · 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

Static verification of head e2bbd84 found no actionable in-scope code defects: the allowance check rejects an unset spending limit, and PIN verification resets absent or zero limits to zero allowance. Current CI reports passing simulator tests, target-membership validation, workflow lint, and accessibility checks; no local builds or tests were run. The only failed check is PR-title validation because auth is not an allowed scope; renaming the title to fix(wallet): … addresses that metadata-only failure.

Review provenance

Source: reviewer 1: glm-5.3-flash (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: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The diff makes a small, contained change to biometric allowance checks and PIN-entry resets with focused tests, rather than a large or intricate change to a critical surface.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 99% left, weekly 87% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort medium); agent phase2-reviewer

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

✅ no major · 1 untracked gap · 4 non-blocking recommendations · no blockers — reviewed at e2bbd84691

Level Verdict
1 · Idea ✅ valid Real hole: with no stored limit a PIN entry wrote UInt64.max as the allowance, so biometrics covered any amount. Failing closed is the right call.
2 · Architecture ✅ right layer The decision stays in AuthenticationService.
3 · Completeness 🟡 untracked gap Spend gates that pass no amount never consult the allowance (below).
4 · Code ✅ clean The hole is closed on both sides (refill writes 0; an existing -1 allowance with no limit is refused). No sentinel collision: only 0 / 0.1 / 0.5 / 1 / 5 DASH are ever stored. didAuthenticate is set before the reset. No lockout: the user leaves the state via the biometrics toggle, the Advanced Security slider or Reset to Default.

Untracked gap — please file an issue: several spend gates call AuthenticationGate.authenticate without spendAmount, so the biometric limit (including this PR's "no limit ⇒ PIN" rule and a limit of 0, which the UI describes as "PIN is always required") does not apply there; biometrics authorize any amount:

4 non-blocking recommendations
  1. The spend check now runs the legacy limit migration —
    return Self.biometricAllowanceCovers(amount: amount,
    — canUseBiometricAuthentication reads biometricSpendingLimit, which migrates SPEND_LIMIT_AMOUNT on read and rewrites .biometricAmountLeft to the full limit (
    guard PinStore.set(int64: Int64(bitPattern: limit), for: .biometricAmountLeft) else { return false }
    ). With a legacy UserDefaults limit and a Face-ID-only session, the allowance is read first (stale) and then refilled, so the next spend passes without a PIN. One-time and capped at the user's own limit; reading the limit without the migration side effect here would avoid it.
  2. Advanced Security misdescribes the "no stored limit" state — DWAdvancedSecurityModel treats UINT64_MAX as no confirmation needed, while spends now always ask for the PIN (the slider index is also NSNotFound, as on base). (partly verified)
  3. The root cause sits in the enable paths — DWBiometricAuthModel and SecurityMenuViewModel ignore the result of setBiometricSpendingLimitIfAuthenticated, which is how "biometrics on, no limit" arises; those users now silently lose biometric spending. Restoring the 0.5 DASH default on PIN entry when biometrics are enabled and no limit is stored would be the sturdier fix. (not verified)
  4. Tests cover only the two static helpers —
    func testPinEntryRestoresNoAllowanceWithoutStoredLimit() {
    — restoring the old if limit > 0 body in resetSpendingLimitsIfAuthenticated keeps all 7 green; a test through init(secureTime:userDefaults:) covering the instance wiring would pin it.
Review details

Layered review: idea → architecture → completeness → code. Level 4 ran the general correctness lane and a security/funds lane covering every reader and writer of .spendingLimit / .biometricAmountLeft, the legacy migration and upgrade states. The gap list and recommendations 1 and 4 were verified against the code.

🤖 Reviewed with Claude Code

@ross-dash ross-dash changed the title fix(auth): grant no biometric allowance without a stored spending limit fix(wallet): grant no biometric allowance without a stored spending limit Nov 11, 2026
@ross-dash

Copy link
Copy Markdown
Contributor Author

Filed #1381 for the spend confirmations that skip the limit.

@ross-dash
ross-dash merged commit a126c8b into develop Nov 12, 2026
7 of 8 checks passed
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.

3 participants