Skip to content

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

Open
EvanYan1024 wants to merge 1 commit into
IBM:mainfrom
EvanYan1024:fix/f2192-data-race
Open

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

Conversation

@EvanYan1024

Copy link
Copy Markdown

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