Skip to content
Open
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
103 changes: 85 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ libflate = "2"
log = "0.4.20"
num-bigint = { version = "0.4.4", features = ["rand", "serde"] }
num-integer = "0.1.45"
napi = { version = "2.16.8", default-features = false, features = ["napi7"] }
napi-derive = "2.16.8"
napi = { version = "3.3.0", default-features = false, features = ["napi7"] }
napi-derive = { version = "3.3.0", features = ["type-def"] }
napi-build = "2.1.0"
ocaml = { version = "0.22.2" }
ocaml-gen = { version = "1.0.0" }
Expand Down
25 changes: 25 additions & 0 deletions plonk-napi/src/build_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use napi_derive::napi;

#[cfg(target_os = "windows")]
#[napi]
pub const OS_NAME: &str = "Windows";

#[cfg(target_os = "linux")]
#[napi]
pub const OS_NAME: &str = "Linux";

#[cfg(target_os = "macos")]
#[napi]
pub const OS_NAME: &str = "macOS";

#[cfg(target_arch = "x86_64")]
#[napi]
pub const ARCH_NAME: &str = "x86_64";

#[cfg(target_arch = "arm")]
#[napi]
pub const ARCH_NAME: &str = "ARM";

#[cfg(target_arch = "aarch64")]
#[napi]
pub const ARCH_NAME: &str = "AArch64";
2 changes: 1 addition & 1 deletion plonk-napi/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
}

#[napi]
pub fn prover_to_json(prover_index: External<WasmPastaFpPlonkIndex>) -> String {
pub fn prover_to_json(prover_index: &External<WasmPastaFpPlonkIndex>) -> String {
let circuit: Circuit<Fp> = prover_index.0.cs.as_ref().into();
serde_json::to_string(&circuit).expect("couldn't serialize constraints")
}
5 changes: 4 additions & 1 deletion plonk-napi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
mod circuit;
mod poseidon;
mod types;
mod prover_index;
mod build_info;

pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_block_cipher};

pub use circuit::prover_to_json;
pub use types::{prover_index_from_bytes, prover_index_to_bytes, WasmPastaFpPlonkIndex};
pub use prover_index::{prover_index_from_bytes, prover_index_to_bytes};
pub use types::WasmPastaFpPlonkIndex;
21 changes: 21 additions & 0 deletions plonk-napi/src/prover_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use napi::bindgen_prelude::*;
use napi_derive::napi;

use crate::types::WasmPastaFpPlonkIndex;

// TOOD: remove incl all dependencies when no longer needed and we only pass napi objects around
#[napi]
pub fn prover_index_from_bytes(bytes: Uint8Array) -> Result<External<WasmPastaFpPlonkIndex>> {
let index = WasmPastaFpPlonkIndex::deserialize_inner(bytes.as_ref())
.map_err(|e| Error::new(Status::InvalidArg, e))?;
Ok(External::new(index))
}

// TOOD: remove incl all dependencies when no longer needed and we only pass napi objects around
#[napi]
pub fn prover_index_to_bytes(index: &External<WasmPastaFpPlonkIndex>) -> Result<Uint8Array> {
let bytes = index
.serialize_inner()
.map_err(|e| Error::new(Status::GenericFailure, e))?;
Ok(Uint8Array::from(bytes))
}
26 changes: 4 additions & 22 deletions plonk-napi/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use kimchi::{linearization::expr_linearization, prover_index::ProverIndex};
use mina_curves::pasta::{Vesta as GAffine, VestaParameters};
use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge};
use napi::bindgen_prelude::{Error, External, Result as NapiResult, Status, Uint8Array};
use napi_derive::napi;

use poly_commitment::ipa::{OpeningProof, SRS};
use serde::{Deserialize, Serialize};
use std::{io::Cursor, sync::Arc};
Expand All @@ -18,7 +17,7 @@ struct SerializedProverIndex {

// TOOD: remove incl all dependencies when no longer needed and we only pass napi objects around
impl WasmPastaFpPlonkIndex {
fn serialize_inner(&self) -> Result<Vec<u8>, String> {
pub fn serialize_inner(&self) -> Result<Vec<u8>, String> {
let prover_index = rmp_serde::to_vec(self.0.as_ref()).map_err(|e| e.to_string())?;

let mut srs = Vec::new();
Expand All @@ -32,7 +31,7 @@ impl WasmPastaFpPlonkIndex {
rmp_serde::to_vec(&serialized).map_err(|e| e.to_string())
}

fn deserialize_inner(bytes: &[u8]) -> Result<Self, String> {
pub fn deserialize_inner(bytes: &[u8]) -> Result<Self, String> {
let serialized: SerializedProverIndex =
rmp_serde::from_slice(bytes).map_err(|e| e.to_string())?;

Expand All @@ -59,21 +58,4 @@ impl WasmPastaFpPlonkIndex {

Ok(WasmPastaFpPlonkIndex(Box::new(index)))
}
}

// TOOD: remove incl all dependencies when no longer needed and we only pass napi objects around
#[napi]
pub fn prover_index_from_bytes(bytes: Uint8Array) -> NapiResult<External<WasmPastaFpPlonkIndex>> {
let index = WasmPastaFpPlonkIndex::deserialize_inner(bytes.as_ref())
.map_err(|e| Error::new(Status::InvalidArg, e))?;
Ok(External::new(index))
}

// TOOD: remove incl all dependencies when no longer needed and we only pass napi objects around
#[napi]
pub fn prover_index_to_bytes(index: External<WasmPastaFpPlonkIndex>) -> NapiResult<Uint8Array> {
let bytes = index
.serialize_inner()
.map_err(|e| Error::new(Status::GenericFailure, e))?;
Ok(Uint8Array::from(bytes))
}
}
Loading