-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem
The WASM build currently uses wasm32-wasi instead of the preferred wasm32-freestanding target because the crypto module depends on C libraries that require libc.
Dependency Chain
wasm_mod → primitives_mod → crypto_mod → C libraries (bn254_wrapper.a, c-kzg-4844.a, blst.a) → libc
Current Workaround
- Using
wasm32-wasitarget which provides libc - Disabled C library features in WASM build via build options:
use_bn254 = falseuse_c_kzg = false
- BN254 and C-KZG precompiles are not available in WASM builds
Ideal Solution
To use wasm32-freestanding, we need to:
-
Option A: Compile C libraries to WASM
- Build bn254_wrapper, c-kzg-4844, and blst as WASM libraries
- May require significant porting work
-
Option B: Pure Zig implementations
- Rewrite BN254 pairing operations in pure Zig
- Rewrite KZG operations in pure Zig
- Would be more maintainable but requires cryptographic expertise
-
Option C: Conditional compilation
- Keep current approach but improve feature flags
- Make precompiles gracefully degrade when C libraries unavailable
- Document which features are unavailable in freestanding WASM
References
- See
build.zig:523-531for the TODO comment - WASM build configuration starts at line 533 in build.zig
Impact
- WASM bundle size is larger due to WASI libc overhead
- Requires WASI runtime support (wasmtime, wasmer, or browser polyfills)
- Cannot run in minimal WASM environments that don't support WASI
- Some precompiles (BN254, KZG) are disabled in WASM builds
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request