Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions plonk-wasm/src/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,33 @@ pub mod fp {
});
basis.iter().map(Into::into).collect()
}

/// Web-compatible version that returns pointer for worker communication
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both ways are web compatible, it just doesn't work with our current worker implementation. For clarity, I would change this comment to something that better reflects what it does: Calculates and returns a pointer to the lagrange basis

#[wasm_bindgen]
pub fn caml_fp_srs_get_lagrange_basis_ptr(
srs: &WasmFpSrs,
domain_size: i32,
) -> *mut WasmVector<WasmPolyComm> {
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<WasmPolyComm>,
) -> WasmVector<WasmPolyComm> {
// Reclaim ownership and extract data
let boxed = unsafe { Box::from_raw(ptr) };
*boxed // Return owned data, automatically cleans up Box
}
}

pub mod fq {
Expand Down Expand Up @@ -400,4 +427,31 @@ pub mod fq {
});
basis.iter().map(Into::into).collect()
}

/// Web-compatible version that returns pointer for worker communication
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

#[wasm_bindgen]
pub fn caml_fq_srs_get_lagrange_basis_ptr(
srs: &WasmFqSrs,
domain_size: i32,
) -> *mut WasmVector<WasmPolyComm> {
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<WasmPolyComm>,
) -> WasmVector<WasmPolyComm> {
// Reclaim ownership and extract data
let boxed = unsafe { Box::from_raw(ptr) };
*boxed // Return owned data, automatically cleans up Box
}
}
Loading