Skip to content

fix(bbs): eliminate data race in f2192 curve cache - #84

Merged
adecaro merged 1 commit into
IBM:mainfrom
EvanYan1024:fix/f2192-data-race
Jul 9, 2026
Merged

fix(bbs): eliminate data race in f2192 curve cache#84
adecaro merged 1 commit into
IBM:mainfrom
EvanYan1024:fix/f2192-data-race

Conversation

@EvanYan1024

Copy link
Copy Markdown
Contributor

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.Curves at 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 TestFrFromOKMConcurrent exercises concurrent first-use lookups for every curve: it reliably reports the race under -race on the previous implementation and passes with this change. go build ./... and go test -race ./bbs/... pass locally.

adecaro
adecaro previously approved these changes Jul 8, 2026

@adecaro adecaro 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. Thanks much @EvanYan1024 🙏

@adecaro

adecaro commented Jul 8, 2026

Copy link
Copy Markdown
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>
@EvanYan1024
EvanYan1024 force-pushed the fix/f2192-data-race branch from c4b7923 to 6a151bd Compare July 9, 2026 01:36
@EvanYan1024

Copy link
Copy Markdown
Contributor Author

Hi @EvanYan1024 , please, check the CI. Thanks 🙏

fixed

@adecaro
adecaro self-requested a review July 9, 2026 03:58

@adecaro adecaro 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

@adecaro
adecaro merged commit bb7ed95 into IBM:main Jul 9, 2026
3 checks passed
@EvanYan1024
EvanYan1024 deleted the fix/f2192-data-race branch July 9, 2026 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Data race in bbs.f2192() curve cache (unsynchronized map, potential fatal concurrent map access)

2 participants