Skip to content

perf(evm-wallet): make PBKDF2 iterations configurable, speed up crypto tests#907

Merged
sirtimid merged 1 commit into
mainfrom
sirtimid/optimize-crypto-test-timing
Mar 31, 2026
Merged

perf(evm-wallet): make PBKDF2 iterations configurable, speed up crypto tests#907
sirtimid merged 1 commit into
mainfrom
sirtimid/optimize-crypto-test-timing

Conversation

@sirtimid

@sirtimid sirtimid commented Mar 31, 2026

Copy link
Copy Markdown
Member

Summary

The evm-wallet mnemonic encryption tests were taking ~250s combined (140s for mnemonic-crypto.test.ts, 110s for keyring-vat.test.ts) because they run PBKDF2 with 600,000 iterations — the production default — on every encrypt/decrypt call.

This PR adds an optional pbkdf2Iterations parameter to encryptMnemonic(), decryptMnemonic(), and keyring-vat's initialize() / unlock() methods. The parameter defaults to 600,000, so production behavior is unchanged. Tests now pass 1,000 iterations, reducing combined test time from ~250s to ~1.8s.

  • Add optional pbkdf2Iterations parameter to encryptMnemonic() and decryptMnemonic(), defaulting to DEFAULT_PBKDF2_ITERATIONS (600,000)
  • Thread the parameter through keyring-vat initialize() and unlock()
  • Update all crypto-related tests to pass TEST_PBKDF2_ITERATIONS (1,000)
  • Remove all 900_000ms test timeouts (no longer needed)

Test plan

All 36 tests across mnemonic-crypto.test.ts (8 tests) and keyring-vat.test.ts (28 tests) pass in ~1.8s total. The tests exercise the same encrypt/decrypt logic paths as before — only the iteration count differs, which doesn't affect correctness of AES-GCM encryption, key derivation structure, or error handling.

🤖 Generated with Claude Code


Note

Medium Risk
Introduces a new optional security parameter (pbkdf2Iterations) to mnemonic encryption/decryption and keyring unlock/initialize; production defaults are unchanged but callers could accidentally use too-low iteration counts if misconfigured.

Overview
Makes PBKDF2 iteration count configurable for mnemonic encryption by adding an optional pbkdf2Iterations parameter to encryptMnemonic/decryptMnemonic (defaulting to 600,000) and threading it through keyring vat initialize and unlock.

Speeds up test suite by updating mnemonic/keyring crypto tests to use TEST_PBKDF2_ITERATIONS = 1_000 and removing the long per-test timeouts while keeping the same behavioral assertions (roundtrip, wrong password, tampering, deterministic output).

Written by Cursor Bugbot for commit 1fa27e3. This will update automatically on new commits. Configure here.

Add optional `pbkdf2Iterations` parameter to `encryptMnemonic()` and
`decryptMnemonic()`, defaulting to the production value of 600,000.
Thread the parameter through `keyring-vat` initialize() and unlock().

Tests now pass 1,000 iterations instead of 600,000, reducing combined
test time from ~250s to ~1.8s (mnemonic-crypto: 140s → 0.15s,
keyring-vat: 110s → 1.6s).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sirtimid sirtimid requested a review from a team as a code owner March 31, 2026 11:58
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 78.15%
🟰 ±0%
8218 / 10515
🔵 Statements 77.96%
🟰 ±0%
8351 / 10711
🔵 Functions 75.54%
🟰 ±0%
1937 / 2564
🔵 Branches 76.6%
⬆️ +0.01%
3484 / 4548
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/evm-wallet-experiment/src/lib/mnemonic-crypto.ts 97.43%
🟰 ±0%
83.33%
⬆️ +8.33%
85.71%
🟰 ±0%
100%
🟰 ±0%
6
packages/evm-wallet-experiment/src/vats/keyring-vat.ts 88%
🟰 ±0%
82.85%
🟰 ±0%
100%
🟰 ±0%
87.87%
🟰 ±0%
137, 148, 196, 211, 216, 233, 237, 245, 250, 254, 272, 276
Generated in workflow #4120 for commit 1fa27e3 by the Vitest Coverage Report Action

@sirtimid sirtimid enabled auto-merge March 31, 2026 12:08

@rekmarks rekmarks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@sirtimid sirtimid added this pull request to the merge queue Mar 31, 2026
Merged via the queue into main with commit cb3fe0f Mar 31, 2026
32 checks passed
@sirtimid sirtimid deleted the sirtimid/optimize-crypto-test-timing branch March 31, 2026 22: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.

2 participants