plonk_wasm/lib.rs
1//! The Marlin_plonk_stubs crate exports some functionalities
2//! and structures from the following the Rust crates to OCaml:
3//!
4//! * [Marlin](https://github.com/o1-labs/marlin),
5//! a PLONK implementation.
6//! * [Arkworks](http://arkworks.rs/),
7//! a math library that Marlin builds on top of.
8//!
9
10use wasm_bindgen::prelude::*;
11
12mod wasm_flat_vector;
13mod wasm_vector;
14
15#[wasm_bindgen]
16extern "C" {
17 pub fn alert(s: &str);
18}
19
20#[wasm_bindgen]
21extern "C" {
22 #[wasm_bindgen(js_namespace = console)]
23 fn log(s: &str);
24}
25
26// produces a warning, but can be useful
27// macro_rules! console_log {
28// ($($t:tt)*) => (crate::log(&format_args!($($t)*).to_string()))
29// }
30
31#[wasm_bindgen]
32pub fn console_log(s: &str) {
33 log(s);
34}
35
36#[wasm_bindgen]
37pub fn create_zero_u32_ptr() -> *mut u32 {
38 Box::into_raw(std::boxed::Box::new(0))
39}
40
41/// Free a pointer. This method is exported in the WebAssembly module to be used
42/// on the JavaScript side, see `web-backend.js`.
43///
44/// # Safety
45///
46/// See
47/// `<https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref>`
48#[wasm_bindgen]
49pub unsafe fn free_u32_ptr(ptr: *mut u32) {
50 let _drop_me = unsafe { std::boxed::Box::from_raw(ptr) };
51}
52
53/// Set the value of a pointer. This method is exported in the WebAssembly
54/// module to be used on the JavaScript side, see `web-backend.js`.
55///
56/// # Safety
57///
58/// See
59/// `<https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref>`
60#[wasm_bindgen]
61pub unsafe fn set_u32_ptr(ptr: *mut u32, arg: u32) {
62 // The rust docs explicitly forbid using this for cross-thread syncronization. Oh well, we
63 // don't have anything better. As long as it works in practice, we haven't upset the undefined
64 // behavior dragons.
65 unsafe {
66 core::ptr::write_volatile(ptr, arg);
67 }
68}
69
70/// This method is exported in the WebAssembly to be used on the JavaScript
71/// side, see `web-backend.js`.
72///
73/// # Safety
74///
75/// See
76/// `<https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref>`
77#[allow(unreachable_code)]
78#[wasm_bindgen]
79pub unsafe fn wait_until_non_zero(ptr: *const u32) -> u32 {
80 // The rust docs explicitly forbid using this for cross-thread syncronization. Oh well, we
81 // don't have anything better. As long as it works in practice, we haven't upset the undefined
82 // behavior dragons.
83 loop {
84 let contents = unsafe { core::ptr::read_volatile(ptr) };
85 if contents != 0 {
86 return contents;
87 }
88 }
89 unreachable!();
90}
91
92pub mod rayon;
93
94/// Arkworks types
95pub mod arkworks;
96
97/// Vectors
98pub mod gate_vector;
99
100pub mod poly_comm;
101/// Curves
102pub mod projective;
103
104/// SRS
105pub mod srs;
106
107/// Indexes
108pub mod pasta_fp_plonk_index;
109pub mod pasta_fq_plonk_index;
110
111/// Verifier indexes/keys
112pub mod plonk_verifier_index;
113
114/// Oracles
115pub mod oracles;
116
117/// Proofs
118pub mod plonk_proof;
119
120/// Poseidon
121pub mod poseidon;
122
123// exposes circuit for inspection
124pub mod circuit;
125
126pub mod wasm_ocaml_serde;