From 9a08bb78c4746648795d7c18b73be1a62579faf4 Mon Sep 17 00:00:00 2001 From: ymekuria Date: Mon, 11 Aug 2025 00:58:11 -0700 Subject: [PATCH 1/3] Add Fp lagrange basis pointer functions for web compatibility - Add caml_fp_srs_get_lagrange_basis_ptr: Returns pointer for web worker communication - Add caml_fp_srs_get_lagrange_basis_read_from_ptr: Extracts data from pointer - Follows existing working pattern from lagrange_commitments_whole_domain functions - Enables zkProgram.compile() with cache writing in web environments - Part 1 of 2: Fp functions (Fq functions to follow) --- plonk-wasm/src/srs.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plonk-wasm/src/srs.rs b/plonk-wasm/src/srs.rs index 4a38717f76..322f2e31b3 100644 --- a/plonk-wasm/src/srs.rs +++ b/plonk-wasm/src/srs.rs @@ -320,6 +320,33 @@ pub mod fp { }); basis.iter().map(Into::into).collect() } + + /// Web-compatible version that returns pointer for worker communication + #[wasm_bindgen] + pub fn caml_fp_srs_get_lagrange_basis_ptr( + srs: &WasmFpSrs, + domain_size: i32, + ) -> *mut WasmVector { + let result = caml_fp_srs_get_lagrange_basis(srs, domain_size); + let boxed = Box::new(result); + Box::into_raw(boxed) + } + + /// Reads the lagrange basis from a raw pointer. + /// + /// # Safety + /// + /// This function is unsafe because it dereferences a raw pointer. + /// The pointer must be valid and point to a properly allocated WasmVector. + /// The pointer becomes invalid after this call (ownership transferred). + #[wasm_bindgen] + pub unsafe fn caml_fp_srs_get_lagrange_basis_read_from_ptr( + ptr: *mut WasmVector, + ) -> WasmVector { + // Reclaim ownership and extract data + let boxed = unsafe { Box::from_raw(ptr) }; + *boxed // Return owned data, automatically cleans up Box + } } pub mod fq { From 5c101eb942f18f67a8175c25af990282b020fcda Mon Sep 17 00:00:00 2001 From: ymekuria Date: Mon, 11 Aug 2025 00:58:57 -0700 Subject: [PATCH 2/3] Add Fq lagrange basis pointer functions for web compatibility - Add caml_fq_srs_get_lagrange_basis_ptr: Returns pointer for web worker communication - Add caml_fq_srs_get_lagrange_basis_read_from_ptr: Extracts data from pointer - Completes pair with Fp functions added in previous commit - Uses same proven pattern as existing lagrange_commitments_whole_domain functions - Part 2 of 2: Now both Fp and Fq are ready for web environments --- plonk-wasm/src/srs.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plonk-wasm/src/srs.rs b/plonk-wasm/src/srs.rs index 322f2e31b3..d271408c23 100644 --- a/plonk-wasm/src/srs.rs +++ b/plonk-wasm/src/srs.rs @@ -427,4 +427,31 @@ pub mod fq { }); basis.iter().map(Into::into).collect() } + + /// Web-compatible version that returns pointer for worker communication + #[wasm_bindgen] + pub fn caml_fq_srs_get_lagrange_basis_ptr( + srs: &WasmFqSrs, + domain_size: i32, + ) -> *mut WasmVector { + let result = caml_fq_srs_get_lagrange_basis(srs, domain_size); + let boxed = Box::new(result); + Box::into_raw(boxed) + } + + /// Reads the lagrange basis from a raw pointer. + /// + /// # Safety + /// + /// This function is unsafe because it dereferences a raw pointer. + /// The pointer must be valid and point to a properly allocated WasmVector. + /// The pointer becomes invalid after this call (ownership transferred). + #[wasm_bindgen] + pub unsafe fn caml_fq_srs_get_lagrange_basis_read_from_ptr( + ptr: *mut WasmVector, + ) -> WasmVector { + // Reclaim ownership and extract data + let boxed = unsafe { Box::from_raw(ptr) }; + *boxed // Return owned data, automatically cleans up Box + } } From 8bb8a7a1cefe06706ba24777385757b8a1982477 Mon Sep 17 00:00:00 2001 From: ymekuria Date: Mon, 15 Sep 2025 15:10:00 -0400 Subject: [PATCH 3/3] style(srs.rs): remove unnecessary whitespace to fix format error --- plonk-wasm/src/srs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plonk-wasm/src/srs.rs b/plonk-wasm/src/srs.rs index d271408c23..5a1c9a77c6 100644 --- a/plonk-wasm/src/srs.rs +++ b/plonk-wasm/src/srs.rs @@ -345,7 +345,7 @@ pub mod fp { ) -> WasmVector { // Reclaim ownership and extract data let boxed = unsafe { Box::from_raw(ptr) }; - *boxed // Return owned data, automatically cleans up Box + *boxed // Return owned data, automatically cleans up Box } } @@ -452,6 +452,6 @@ pub mod fq { ) -> WasmVector { // Reclaim ownership and extract data let boxed = unsafe { Box::from_raw(ptr) }; - *boxed // Return owned data, automatically cleans up Box + *boxed // Return owned data, automatically cleans up Box } }