feat: add wasm32 single-thread fallback for threadpool#64
Open
URDJMK wants to merge 2 commits intofilecoin-project:masterfrom
Open
feat: add wasm32 single-thread fallback for threadpool#64URDJMK wants to merge 2 commits intofilecoin-project:masterfrom
URDJMK wants to merge 2 commits intofilecoin-project:masterfrom
Conversation
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.
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.
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 forwasm32-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 intonative(yastl Pool, multi-threaded) andwasm(WasmScope/WasmPool, single-threaded) modules via#[cfg(target_arch = "wasm32")]multiexp.rs: UseWasmScopeon wasm32 instead ofyastl::ScopeWasmPoolprovidesscoped()for fft.rs compatibilityWasmScopeprovidesexecute()matchingyastl::ScopeAPIWorkerAPI unchanged — downstream callers don't need modificationTesting
Tested with bellperson 0.26 compiled to wasm32-unknown-unknown via wasm-pack. Groth16 proof generation and verification confirmed working in Chrome browser.