fix(bbs): eliminate data race in f2192 curve cache#84
Open
EvanYan1024 wants to merge 1 commit into
Open
Conversation
adecaro
previously approved these changes
Jul 8, 2026
adecaro
left a comment
Member
There was a problem hiding this comment.
LGTM. Thanks much @EvanYan1024 🙏
Member
|
Hi @EvanYan1024 , please, check the CI. Thanks 🙏 |
f2192 lazily populated a package-level map with no synchronization, so concurrent first-use calls (e.g. Verify and AuditNymEid, both through FrFromOKM) raced on the map, failing -race builds and risking a fatal concurrent map access. Precompute the entry for every registered curve at package init and treat the map as read-only afterwards; a curve not in ml.Curves falls back to computing the value without caching. Signed-off-by: Evan <evanyan@sign.global>
4171e18 to
c4b7923
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.
Fixes #83
f2192()cached the constant 2^192 per curve in a package-level map that was lazily populated with no synchronization; concurrent first-use calls raced on it (race report in #83).This precomputes the entry for every curve in
ml.Curvesat package init and treats the map as read-only afterwards, so lookups stay lock-free. A curve outside the registry falls back to computing the value without caching, which keeps the map read-only.The new
TestFrFromOKMConcurrentexercises concurrent first-use lookups for every curve: it reliably reports the race under-raceon the previous implementation and passes with this change.go build ./...andgo test -race ./bbs/...pass locally.