Skip to content

feat: add wasm32 single-thread fallback for threadpool#64

Open
URDJMK wants to merge 2 commits intofilecoin-project:masterfrom
URDJMK:feat/wasm32-single-thread-fallback
Open

feat: add wasm32 single-thread fallback for threadpool#64
URDJMK wants to merge 2 commits intofilecoin-project:masterfrom
URDJMK:feat/wasm32-single-thread-fallback

Conversation

@URDJMK
Copy link
Copy Markdown

@URDJMK URDJMK commented Apr 7, 2026

Summary

Add wasm32-unknown-unknown support to ec-gpu-gen's threadpool module.

On wasm32 targets, OS thread spawning (std::thread::spawn) panics because WASM does not support native threads. This PR adds a single-threaded fallback that executes all operations sequentially on the main thread when compiled for wasm32-unknown-unknown.

Motivation

bellperson uses ec-gpu-gen for multi-exponentiation and FFT operations. While bellperson itself compiles to WASM (blst has built-in wasm32 support), it panics at runtime when yastl::Pool::new() tries to spawn worker threads. This makes Groth16 proof generation in the browser impossible.

With this change, bellperson can generate Groth16 proofs in browser WASM — single-threaded but fully functional. This enables client-side ZK proof generation for privacy protocols without requiring a server-side prover.

Changes

  • threadpool.rs: Split into native (yastl Pool, multi-threaded) and wasm (WasmScope/WasmPool, single-threaded) modules via #[cfg(target_arch = "wasm32")]
  • multiexp.rs: Use WasmScope on wasm32 instead of yastl::Scope
  • WasmPool provides scoped() for fft.rs compatibility
  • WasmScope provides execute() matching yastl::Scope API
  • Worker API unchanged — downstream callers don't need modification

Testing

Tested with bellperson 0.26 compiled to wasm32-unknown-unknown via wasm-pack. Groth16 proof generation and verification confirmed working in Chrome browser.

URDJMK added 2 commits April 7, 2026 18:43
On wasm32 targets, OS thread spawning is not supported. This adds a
single-threaded fallback that executes all operations sequentially
on the main thread when compiled for wasm32-unknown-unknown.

Changes:
- threadpool.rs: split into native (yastl Pool) and wasm (WasmScope,
  WasmPool) modules, conditionally compiled via cfg(target_arch)
- multiexp.rs: use WasmScope on wasm32 instead of yastl::Scope
- WasmPool provides scoped() for fft.rs compatibility
- WasmScope provides execute() matching yastl::Scope API
- Worker API unchanged — callers don't need modification

This enables bellperson Groth16 proof generation in the browser
via WebAssembly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant