Skip to content

fix: remove session key auto-revoke, increase MAX_SESSION_KEYS#4

Merged
newtsjamie merged 1 commit into
mainfrom
fix/session-key-remove-auto-revoke
Mar 31, 2026
Merged

fix: remove session key auto-revoke, increase MAX_SESSION_KEYS#4
newtsjamie merged 1 commit into
mainfrom
fix/session-key-remove-auto-revoke

Conversation

@newtsjamie

@newtsjamie newtsjamie commented Mar 31, 2026

Copy link
Copy Markdown
Member

Summary

  • Removed auto-revoke loop from authorize_session_key() — now insert-only, producing zero nullifiers from existing notes
  • Increased MAX_SESSION_KEYS from 5 to 10 — provides headroom for orphaned notes between client-side cleanup cycles

Why

In Aztec's UTXO model, the get_notes + remove(each) loop produced nullifiers. When PXE had stale state or another TX was in the mempool, the same nullifiers appeared in two TXs → "Nullifier conflict" rejection. This is fundamental to the UTXO model and cannot be fixed with sync-and-retry.

Orphaned notes (from browser refresh losing the in-memory key) are now cleaned up by the client via revoke_session_key() on a best-effort basis before each new authorization.

Companion PR

Apertrue/web#24 — TypeScript changes (stale key tracking, simplified wallet flow)

Deployment

After merge: ./build.sh → recompile + AVM transpile + copy artifact to web app. Existing devnet accounts need redeployment (new bytecode = new contract class ID).

Test plan

  • nargo compile passes
  • Full build.sh pipeline succeeds (requires sandbox Docker container)
  • Session key authorization succeeds without nullifier conflicts
  • revoke_session_key still works for individual key revocation
  • is_valid_impl finds session key with up to 10 notes in storage

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features
    • Session key capacity increased from 5 to 10, enabling more concurrent session management.
    • Session key authorization behavior updated: existing keys are no longer automatically revoked. Manual revocation is now required for cleanup.

…ION_KEYS to 10

In Aztec's UTXO model, atomically revoking existing session key notes
and inserting a new one causes nullifier conflicts when the PXE has
stale state or a previous TX is still in the mempool. Two TXs cannot
consume the same note — this is fundamental, not a sync issue.

Changes:
- authorize_session_key is now insert-only (no get_notes + remove loop)
- MAX_SESSION_KEYS increased from 5 to 10 for orphaned note headroom
- Stale notes cleaned up via revoke_session_key (called from client
  on a best-effort basis before each new authorization)

Companion PR: Apertrue/web#24

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

coderabbitai Bot commented Mar 31, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The change increases MAX_SESSION_KEYS from 5 to 10 and modifies authorize_session_key behavior from auto-revocation (removing prior session key notes before inserting new ones) to insert-only operation, requiring explicit calls to revoke_session_key for cleanup.

Changes

Cohort / File(s) Summary
Session Key Management
webauthn_account/src/main.nr
Increased MAX_SESSION_KEYS constant from 5 to 10; refactored authorize_session_key from auto-revocation pattern to insert-only behavior; updated method documentation to reflect dependency on explicit revoke_session_key() calls for session key cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • Apertrue/web#23: Implements PXE sync and client-side retry logic to handle nullifier conflicts that result from the prior auto-revoke behavior in authorize_session_key, making this PR's shift to insert-only semantics directly relevant.

Poem

🐰 Ten keys now dance where five once stood,
No auto-clean, as one should;
Explicit revoke, a cleaner way,
The rabbit hops through change today! 🔑✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: removing session key auto-revoke and increasing MAX_SESSION_KEYS from 5 to 10.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/session-key-remove-auto-revoke

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
webauthn_account/src/main.nr (1)

186-209: ⚠️ Potential issue | 🟡 Minor

Potential edge case: session key lookup may fail if orphaned notes exceed limit.

The insert-only approach is sound for avoiding nullifier conflicts, but there's a correctness edge case: if orphaned notes accumulate beyond MAX_SESSION_KEYS (10), is_valid_impl may not find a valid session key in the returned note set, causing authentication to fail unexpectedly. Similarly, revoke_session_key might miss its target.

This relies on the companion PR's client-side cleanup being robust. Consider whether the client should track note count and proactively revoke stale keys before reaching the limit.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@webauthn_account/src/main.nr` around lines 186 - 209, authorize_session_key
currently unconditionally inserts a SessionKeyNote which can overflow the
MAX_SESSION_KEYS (10) slot window and make is_valid_impl / revoke_session_key
miss keys; update authorize_session_key to first read the existing notes at
self.storage.session_keys.at(owner), count them, and if count >=
MAX_SESSION_KEYS either (a) purge or revoke the oldest/stale notes by selecting
candidates using SessionKeyNote.expiry (and invoking revoke_session_key or the
storage removal API) before inserting, or (b) reject the new authorization with
a clear error/return so callers can retry cleanup; ensure the logic references
SessionKeyNote, MAX_SESSION_KEYS, authorize_session_key, is_valid_impl, and
revoke_session_key so behavior remains consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@webauthn_account/src/main.nr`:
- Around line 186-209: authorize_session_key currently unconditionally inserts a
SessionKeyNote which can overflow the MAX_SESSION_KEYS (10) slot window and make
is_valid_impl / revoke_session_key miss keys; update authorize_session_key to
first read the existing notes at self.storage.session_keys.at(owner), count
them, and if count >= MAX_SESSION_KEYS either (a) purge or revoke the
oldest/stale notes by selecting candidates using SessionKeyNote.expiry (and
invoking revoke_session_key or the storage removal API) before inserting, or (b)
reject the new authorization with a clear error/return so callers can retry
cleanup; ensure the logic references SessionKeyNote, MAX_SESSION_KEYS,
authorize_session_key, is_valid_impl, and revoke_session_key so behavior remains
consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 04a81f0d-adc1-4040-8ab0-bbda4013c8e4

📥 Commits

Reviewing files that changed from the base of the PR and between 6cea3ce and 8c07137.

📒 Files selected for processing (1)
  • webauthn_account/src/main.nr

@newtsjamie newtsjamie merged commit 5e65a28 into main Mar 31, 2026
18 checks passed
@newtsjamie newtsjamie deleted the fix/session-key-remove-auto-revoke branch April 5, 2026 13:04
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.

1 participant