Skip to content

Commit

Permalink
some linting errors RE base64 api
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Dec 14, 2024
1 parent 59a2df0 commit ae2f0ec
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 12 deletions.
3 changes: 1 addition & 2 deletions plonk-wasm/src/arkworks/pasta_fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +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 = std::mem::size_of::<Fp>();
let mut str: Vec<u8> = Vec::with_capacity(len);
str.resize(len, 0);
let mut str: Vec<u8> = vec![0; len];
let str_as_fp: *mut Fp = str.as_mut_ptr().cast::<Fp>();
unsafe {
*str_as_fp = x.0;
Expand Down
3 changes: 1 addition & 2 deletions plonk-wasm/src/arkworks/pasta_fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +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 = std::mem::size_of::<Fq>();
let mut str: Vec<u8> = Vec::with_capacity(len);
str.resize(len, 0);
let mut str: Vec<u8> = vec![0; len];
let str_as_fq: *mut Fq = str.as_mut_ptr().cast::<Fq>();
unsafe {
*str_as_fq = x.0;
Expand Down
12 changes: 9 additions & 3 deletions plonk-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ pub fn create_zero_u32_ptr() -> *mut u32 {
Box::into_raw(std::boxed::Box::new(0))
}

/// #Safety
/// The caller must ensure that the pointer is valid and that it is not dereferenced later
#[wasm_bindgen]
pub fn free_u32_ptr(ptr: *mut u32) {
pub unsafe fn free_u32_ptr(ptr: *mut u32) {
let _drop_me = unsafe { std::boxed::Box::from_raw(ptr) };
}

/// #Safety
/// The caller must ensure that the pointer is valid
#[wasm_bindgen]
pub fn set_u32_ptr(ptr: *mut u32, arg: u32) {
pub unsafe 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 @@ -58,9 +62,11 @@ pub fn set_u32_ptr(ptr: *mut u32, arg: u32) {
}
}

/// #Safety
/// The caller must ensure that the pointer is valid
#[allow(unreachable_code)]
#[wasm_bindgen]
pub fn wait_until_non_zero(ptr: *const u32) -> u32 {
pub unsafe 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
1 change: 1 addition & 0 deletions plonk-wasm/src/oracles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ macro_rules! impl_oracles {
}
}

#[allow(clippy::from_over_into)]
impl Into<RandomOracles<$F>> for WasmRandomOracles
{
fn into(self) -> RandomOracles<$F> {
Expand Down
3 changes: 2 additions & 1 deletion plonk-wasm/src/pasta_fp_plonk_index.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ark_poly::EvaluationDomain;
use base64::{engine::general_purpose, Engine as _};
use kimchi::circuits::lookup::runtime_tables::RuntimeTableCfg;

use crate::{
Expand Down Expand Up @@ -271,7 +272,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();
base64::encode(serialized)
general_purpose::STANDARD.encode(serialized)
}

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

use crate::{
Expand Down Expand Up @@ -270,5 +271,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();
base64::encode(serialized)
general_purpose::STANDARD.encode(serialized)
}
4 changes: 2 additions & 2 deletions plonk-wasm/src/plonk_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use array_init::array_init;
use kimchi::{circuits::wires::COLUMNS, verifier::Context};
use std::array;
// use std::path::Path;
use base64::{engine::general_purpose, Engine as _};
use groupmap::GroupMap;
use kimchi::{
proof::{
Expand All @@ -37,7 +38,6 @@ use poly_commitment::{
SRS as _,
};
use serde::{Deserialize, Serialize};

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(js_namespace = console)]
Expand Down Expand Up @@ -628,7 +628,7 @@ macro_rules! impl_proof {
pub fn serialize(&self) -> String {
let (proof, _public_input) = self.into();
let serialized = rmp_serde::to_vec(&proof).unwrap();
base64::encode(serialized)
general_purpose::STANDARD.encode(serialized)
}
}

Expand Down
3 changes: 2 additions & 1 deletion plonk-wasm/src/plonk_verifier_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ macro_rules! impl_verification_key {
}
type WasmPlonkVerifierIndex = [<Wasm $field_name:camel PlonkVerifierIndex>];

#[allow(clippy::too_many_arguments)]
#[wasm_bindgen]
impl [<Wasm $field_name:camel PlonkVerifierIndex>] {
#[wasm_bindgen(constructor)]
Expand Down Expand Up @@ -640,7 +641,7 @@ macro_rules! impl_verification_key {
}
}

pub fn to_wasm<'a>(
pub fn to_wasm(
srs: &Arc<SRS<$G>>,
vi: DlogVerifierIndex<$G, OpeningProof<$G>>,
) -> WasmPlonkVerifierIndex {
Expand Down

0 comments on commit ae2f0ec

Please sign in to comment.