fix(store): serialize key load-or-generate to close the exists-check race - #100
Merged
Conversation
0xHansLee
requested review from
barry-peng-story,
jdubpark,
lucas2brh,
stevemilk,
wo-o and
yingyangxu2026
as code owners
August 4, 2026 03:15
|
The fix is correct and well-scoped. Adding a store-wide 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
force-pushed
the
fix/serialize-key-load-or-generate
branch
from
August 4, 2026 03:26
215cde7 to
fcbe75c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two concurrent
LoadOrGenerate{Ed25519,Secp256k1}Keycalls 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 plainLoadSealed*read paths are untouched.Tests
TestLoadOrGenerateKeys_ConcurrentSameRound— 8 concurrent callers must observe the same key pair; passes under-race.issue: none