Skip to content

fix(store): serialize key load-or-generate to close the exists-check race - #100

Merged
0xHansLee merged 1 commit into
mainfrom
fix/serialize-key-load-or-generate
Aug 7, 2026
Merged

fix(store): serialize key load-or-generate to close the exists-check race#100
0xHansLee merged 1 commit into
mainfrom
fix/serialize-key-load-or-generate

Conversation

@0xHansLee

Copy link
Copy Markdown
Collaborator

Problem

Two concurrent LoadOrGenerate{Ed25519,Secp256k1}Key calls for the same (round, code commitment) can both miss the file-exists check and generate different key pairs; the loser's sealed file silently replaces the key the winner already returned.

Fix

Guard both load-or-generate paths with a store-level mutex (keyMu). The lock is a leaf held only across the sealer file IO; the plain LoadSealed* read paths are untouched.

Tests

  • TestLoadOrGenerateKeys_ConcurrentSameRound — 8 concurrent callers must observe the same key pair; passes under -race.

issue: none

@jinn-agent

jinn-agent Bot commented Aug 4, 2026

Copy link
Copy Markdown

The fix is correct and well-scoped. Adding a store-wide sync.Mutex to serialize LoadOrGenerate* calls cleanly closes the check-then-act race without touching the read-only LoadSealed* paths. One minor test-robustness concern is noted below; no production-code issues were found.


Review iteration 2 · Commit fcbe75c · 2026-08-04T03:30:40Z

…race

Two concurrent LoadOrGenerate calls for the same round could both miss the
file-exists check and generate different key pairs, with the loser's sealed
file silently replacing the key the winner already returned. Guard both
load-or-generate paths with a store-level mutex.
@0xHansLee
0xHansLee force-pushed the fix/serialize-key-load-or-generate branch from 215cde7 to fcbe75c Compare August 4, 2026 03:26
@0xHansLee
0xHansLee merged commit 897eb49 into main Aug 7, 2026
13 checks passed
@0xHansLee
0xHansLee deleted the fix/serialize-key-load-or-generate branch August 7, 2026 06:47
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