Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
CARGO_TERM_COLOR: always
# 30 MB of stack for Keccak tests
RUST_MIN_STACK: 31457280
CARGO_EXTRA_ARGS: "--workspace --exclude plonk_wasm --exclude saffron"

jobs:
run_mdbook:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ O1VM_MIPS_BIN_FILES = $(patsubst ${O1VM_MIPS_SOURCE_DIR}/%.asm,${O1VM_MIPS_BIN_D
# In addition to that, the version in the CI (see file
# .github/workflows/wasm.yml) should be changed accordingly.
NIGHTLY_RUST_VERSION = "nightly-2024-06-13"
WASM_RUSTFLAGS = "-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--max-memory=4294967296"
WASM_RUSTFLAGS = "-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296"
PLONK_WASM_NODEJS_OUTDIR ?= target/nodejs
PLONK_WASM_WEB_OUTDIR ?= target/web

Expand Down
4 changes: 4 additions & 0 deletions plonk-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ wasm-opt = false
rustflags = [
"-C",
"target-feature=+atomics,+bulk-memory",
"-C",
"link-arg=--no-check-features",
]

[target.wasm32-unknown-unknown]
rustflags = [
"-C",
"target-feature=+atomics,+bulk-memory",
"-C",
"link-arg=--no-check-features",
]
2 changes: 1 addition & 1 deletion plonk-wasm/src/arkworks/pasta_fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn caml_pasta_fp_domain_generator(log2_size: i32) -> WasmPastaFp {
#[wasm_bindgen]
pub fn caml_pasta_fp_to_bytes(x: WasmPastaFp) -> Vec<u8> {
let len = core::mem::size_of::<Fp>();
let mut str: Vec<u8> = vec![0; len];
let mut str: Vec<u8> = Vec::with_capacity(len);
str.resize(len, 0);
let str_as_fp: *mut Fp = str.as_mut_ptr().cast::<Fp>();
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion plonk-wasm/src/arkworks/pasta_fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn caml_pasta_fq_domain_generator(log2_size: i32) -> WasmPastaFq {
#[wasm_bindgen]
pub fn caml_pasta_fq_to_bytes(x: WasmPastaFq) -> Vec<u8> {
let len = core::mem::size_of::<Fq>();
let mut str: Vec<u8> = vec![0; len];
let mut str: Vec<u8> = Vec::with_capacity(len);
str.resize(len, 0);
let str_as_fq: *mut Fq = str.as_mut_ptr().cast::<Fq>();
unsafe {
Expand Down
27 changes: 3 additions & 24 deletions plonk-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,13 @@ pub fn create_zero_u32_ptr() -> *mut u32 {
Box::into_raw(std::boxed::Box::new(0))
}

/// Free a pointer. This method is exported in the WebAssembly module to be used
/// on the JavaScript side, see `web-backend.js`.
///
/// # Safety
///
/// See
/// `<https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref>`
#[wasm_bindgen]
pub unsafe fn free_u32_ptr(ptr: *mut u32) {
pub fn free_u32_ptr(ptr: *mut u32) {
let _drop_me = unsafe { std::boxed::Box::from_raw(ptr) };
}

/// Set the value of a pointer. This method is exported in the WebAssembly
/// module to be used on the JavaScript side, see `web-backend.js`.
///
/// # Safety
///
/// See
/// `<https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref>`
#[wasm_bindgen]
pub unsafe fn set_u32_ptr(ptr: *mut u32, arg: u32) {
pub fn set_u32_ptr(ptr: *mut u32, arg: u32) {
// The rust docs explicitly forbid using this for cross-thread syncronization. Oh well, we
// don't have anything better. As long as it works in practice, we haven't upset the undefined
// behavior dragons.
Expand All @@ -72,16 +58,9 @@ pub unsafe fn set_u32_ptr(ptr: *mut u32, arg: u32) {
}
}

/// This method is exported in the WebAssembly to be used on the JavaScript
/// side, see `web-backend.js`.
///
/// # Safety
///
/// See
/// `<https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref>`
#[allow(unreachable_code)]
#[wasm_bindgen]
pub unsafe fn wait_until_non_zero(ptr: *const u32) -> u32 {
pub fn wait_until_non_zero(ptr: *const u32) -> u32 {
// The rust docs explicitly forbid using this for cross-thread syncronization. Oh well, we
// don't have anything better. As long as it works in practice, we haven't upset the undefined
// behavior dragons.
Expand Down
3 changes: 1 addition & 2 deletions plonk-wasm/src/pasta_fp_plonk_index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ark_poly::EvaluationDomain;
use base64::{engine::general_purpose, Engine};
use kimchi::circuits::lookup::runtime_tables::RuntimeTableCfg;

use crate::{
Expand Down Expand Up @@ -271,7 +270,7 @@ pub fn caml_pasta_fp_plonk_index_write(
#[wasm_bindgen]
pub fn caml_pasta_fp_plonk_index_serialize(index: &WasmPastaFpPlonkIndex) -> String {
let serialized = rmp_serde::to_vec(&index.0).unwrap();
general_purpose::STANDARD.encode(serialized)
base64::encode(serialized)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: it would be better to rebase the branch and remove this "revert revert revert" change together with "revert revert" change earlier in the same PR to avoid confusion...

this looks quite innocent to me btw but we can keep it in the old base64 way for now for clarity.

Copy link
Member Author

Choose a reason for hiding this comment

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

this looks quite innocent to me btw but we can keep it in the old base64 way for now for clarity

Spoiler: it is not innocent.

}

// helpers
Expand Down
3 changes: 1 addition & 2 deletions plonk-wasm/src/pasta_fq_plonk_index.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use ark_poly::EvaluationDomain;
use base64::{engine::general_purpose, Engine};
use kimchi::circuits::lookup::runtime_tables::RuntimeTableCfg;

use crate::{
Expand Down Expand Up @@ -270,5 +269,5 @@ pub fn caml_pasta_fq_plonk_index_write(
#[wasm_bindgen]
pub fn caml_pasta_fq_plonk_index_serialize(index: &WasmPastaFqPlonkIndex) -> String {
let serialized = rmp_serde::to_vec(&index.0).unwrap();
general_purpose::STANDARD.encode(serialized)
base64::encode(serialized)
}
3 changes: 1 addition & 2 deletions plonk-wasm/src/plonk_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
};
use ark_ec::AffineRepr;
use ark_ff::One;
use base64::{engine::general_purpose, Engine};
use core::{array, convert::TryInto};
use groupmap::GroupMap;
use kimchi::{
Expand Down Expand Up @@ -619,7 +618,7 @@ macro_rules! impl_proof {
pub fn serialize(&self) -> String {
let (proof, _public_input) = self.into();
let serialized = rmp_serde::to_vec(&proof).unwrap();
general_purpose::STANDARD.encode(serialized)
base64::encode(serialized)
}
}

Expand Down
3 changes: 1 addition & 2 deletions plonk-wasm/src/plonk_verifier_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,6 @@ macro_rules! impl_verification_key {
#[wasm_bindgen]
impl [<Wasm $field_name:camel PlonkVerifierIndex>] {
#[wasm_bindgen(constructor)]
#[allow(clippy::too_many_arguments)]
pub fn new(
domain: &WasmDomain,
max_poly_size: i32,
Expand Down Expand Up @@ -643,7 +642,7 @@ macro_rules! impl_verification_key {
}
}

pub fn to_wasm(
pub fn to_wasm<'a>(
srs: &Arc<SRS<$G>>,
vi: DlogVerifierIndex<$G, OpeningProof<$G>>,
) -> WasmPlonkVerifierIndex {
Expand Down
8 changes: 1 addition & 7 deletions plonk-wasm/src/srs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,8 @@ macro_rules! impl_srs {
Box::into_raw(boxed_comm)
}

/// Reads the lagrange commitments from a raw pointer.
///
/// # Safety
///
/// This function is unsafe because it might dereference a
/// raw pointer.
#[wasm_bindgen]
pub unsafe fn [<$name:snake _lagrange_commitments_whole_domain_read_from_ptr>](
pub fn [<$name:snake _lagrange_commitments_whole_domain_read_from_ptr>](
ptr: *mut WasmVector<$WasmPolyComm>,
) -> WasmVector<$WasmPolyComm> {
// read the commitment at the pointers address, hack for the web
Expand Down
Loading