Skip to content

Commit b29297c

Browse files
committed
fix(icicle): extend mutex scope to protect NTT domain operations
Fix race condition where the nttDomainMu mutex was released before ReleaseDomain() and InitDomain() operations completed, allowing concurrent threads to corrupt domain state. Issue: When multiple ProvingKey instances with different domain sizes are initialized concurrently, Thread A could begin InitDomain() while Thread B simultaneously calls ReleaseDomain(), causing undefined behavior in the ICICLE C++ backend. Solution: Use defer to hold the mutex for the entire critical section, including the async domain operations. This ensures atomic domain initialization and prevents interleaved domain management. Impact: - Prevents silent domain corruption that could lead to invalid proofs - Eliminates potential panics from concurrent domain operations - Critical for production environments with concurrent circuit initialization The mutex now protects: 1. Reading/updating nttDomainMaxByDevice map 2. ReleaseDomain() execution (if needed) 3. InitDomain() execution 4. Waiting for domain operations to complete
1 parent cd78741 commit b29297c

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

backend/accelerated/icicle/groth16/bls12-377/icicle.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/accelerated/icicle/groth16/bls12-381/icicle.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/accelerated/icicle/groth16/bn254/icicle.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/accelerated/icicle/groth16/bw6-761/icicle.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/accelerated/icicle/internal/generator/templates/groth16.icicle.go.tmpl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ func (pk *ProvingKey) setupDevicePointers(device *icicle_runtime.Device) error {
110110
needDomainRelease := false
111111

112112
nttDomainMu.Lock()
113+
defer nttDomainMu.Unlock()
114+
113115
currentMax := nttDomainMaxByDevice[device.Id]
114116
if requestedDomainSize > currentMax {
115117
needDomainRelease = currentMax != 0
116118
nttDomainMaxByDevice[device.Id] = requestedDomainSize
117119
}
118-
nttDomainMu.Unlock()
119120

120121
if needDomainRelease {
121122
releaseDomain := make(chan struct{})

0 commit comments

Comments
 (0)