Skip to content
504 changes: 504 additions & 0 deletions plonk-napi/src/gate_vector.rs

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions plonk-napi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
mod circuit;
mod gate_vector;
mod pasta_fp_plonk_index;
mod pasta_fq_plonk_index;
mod poly_comm;
mod poseidon;
mod srs;
mod tables;
mod wrappers;
mod wasm_vector;
mod wrappers;

pub use circuit::prover_to_json;
pub use gate_vector::{
caml_pasta_fp_plonk_circuit_serialize, caml_pasta_fp_plonk_gate_vector_add,
caml_pasta_fp_plonk_gate_vector_create, caml_pasta_fp_plonk_gate_vector_digest,
caml_pasta_fp_plonk_gate_vector_from_bytes, caml_pasta_fp_plonk_gate_vector_get,
caml_pasta_fp_plonk_gate_vector_len, caml_pasta_fp_plonk_gate_vector_to_bytes,
caml_pasta_fp_plonk_gate_vector_wrap, caml_pasta_fq_plonk_circuit_serialize,
caml_pasta_fq_plonk_gate_vector_add, caml_pasta_fq_plonk_gate_vector_create,
caml_pasta_fq_plonk_gate_vector_digest, caml_pasta_fq_plonk_gate_vector_from_bytes,
caml_pasta_fq_plonk_gate_vector_get, caml_pasta_fq_plonk_gate_vector_len,
caml_pasta_fq_plonk_gate_vector_to_bytes, caml_pasta_fq_plonk_gate_vector_wrap,
NapiFpGate as WasmFpGate, NapiFpGateVector as WasmFpGateVector, NapiFqGate as WasmFqGate,
NapiFqGateVector as WasmFqGateVector,
};
pub use pasta_fp_plonk_index::{
prover_index_fp_from_bytes, prover_index_fp_to_bytes, WasmPastaFpPlonkIndex,
};
Expand All @@ -16,7 +31,13 @@ pub use pasta_fq_plonk_index::{
};
pub use poly_comm::{pallas::WasmFqPolyComm, vesta::WasmFpPolyComm};
pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_block_cipher};
pub use srs::{caml_fp_srs_from_bytes, caml_fp_srs_to_bytes, caml_fq_srs_from_bytes};
pub use srs::{
caml_fp_srs_from_bytes, caml_fp_srs_to_bytes, caml_fq_srs_from_bytes,
fp::NapiFpSrs as WasmFpSrs, fq::NapiFqSrs as WasmFqSrs,
};
pub use tables::{JsLookupTableFp, JsLookupTableFq, JsRuntimeTableCfgFp, JsRuntimeTableCfgFq};
pub use wasm_vector::{fp::WasmVecVecFp, fq::WasmVecVecFq};
pub use wrappers::{field::{WasmPastaFp, WasmPastaFq}, group::{WasmGPallas, WasmGVesta}};
pub use wrappers::{
field::{WasmPastaFp, WasmPastaFq},
group::{WasmGPallas, WasmGVesta},
};
6 changes: 3 additions & 3 deletions plonk-napi/src/pasta_fp_plonk_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use mina_curves::pasta::{Fp, Pallas as GAffineOther, Vesta as GAffine, VestaPara
use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge};
use napi::bindgen_prelude::{Error, External, Result as NapiResult, Status, Uint8Array};
use napi_derive::napi;
use plonk_wasm::gate_vector::shared::GateVector;
use crate::gate_vector::NapiFpGateVector;
use poly_commitment::ipa::{OpeningProof, SRS as IPA_SRS};
use poly_commitment::SRS;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -119,15 +119,15 @@ pub fn caml_pasta_fp_plonk_index_domain_d8_size(index: External<WasmPastaFpPlonk

#[napi]
pub fn caml_pasta_fp_plonk_index_create(
gates: External<GateVector<Fp>>,
gates: &NapiFpGateVector,
public_: i32,
lookup_tables: Vec<JsLookupTableFp>,
runtime_table_cfgs: Vec<JsRuntimeTableCfgFp>,
prev_challenges: i32,
srs: External<WasmSrs>,
lazy_mode: bool,
) -> Result<External<WasmPastaFpPlonkIndex>, Error> {
let gates: Vec<_> = gates.as_ref().as_slice().to_vec();
let gates: Vec<_> = gates.to_vec();

let runtime_cfgs: Vec<RuntimeTableCfg<Fp>> = runtime_table_cfgs
.into_iter()
Expand Down
6 changes: 3 additions & 3 deletions plonk-napi/src/pasta_fq_plonk_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use mina_curves::pasta::{Fq, Pallas as GAffine, PallasParameters, Vesta as GAffi
use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge};
use napi::bindgen_prelude::{Error, External, Result as NapiResult, Status, Uint8Array};
use napi_derive::napi;
use plonk_wasm::gate_vector::shared::GateVector;
use crate::gate_vector::NapiFqGateVector;
use poly_commitment::ipa::{OpeningProof, SRS as IPA_SRS};
use poly_commitment::SRS;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -113,7 +113,7 @@ pub fn caml_pasta_fq_plonk_index_domain_d8_size(index: External<WasmPastaFqPlonk

#[napi]
pub fn caml_pasta_fq_plonk_index_create(
gates: External<GateVector<Fq>>,
gates: &NapiFqGateVector,
public_: i32,
lookup_tables: Vec<JsLookupTableFq>,
runtime_table_cfgs: Vec<JsRuntimeTableCfgFq>,
Expand All @@ -123,7 +123,7 @@ pub fn caml_pasta_fq_plonk_index_create(
) -> Result<External<WasmPastaFqPlonkIndex>, Error> {
// TODO: check if and how we run rayon threads automatically in napi

let gates: Vec<_> = gates.as_ref().as_slice().to_vec();
let gates: Vec<_> = gates.to_vec();

let runtime_cfgs = runtime_table_cfgs
.into_iter()
Expand Down
11 changes: 11 additions & 0 deletions plonk-napi/src/poly_comm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::wasm_vector::WasmVector;
use napi::bindgen_prelude::{ClassInstance, FromNapiValue};
use napi_derive::napi;
use paste::paste;
use poly_commitment::commitment::PolyComm;
Expand Down Expand Up @@ -93,6 +94,16 @@ macro_rules! impl_poly_comm {
}
}
}

impl FromNapiValue for [<Wasm $field_name:camel PolyComm>] {
unsafe fn from_napi_value(
env: napi::sys::napi_env,
napi_val: napi::sys::napi_value,
) -> napi::Result<Self> {
let instance = <ClassInstance<[<Wasm $field_name:camel PolyComm>]> as FromNapiValue>::from_napi_value(env, napi_val)?;
Ok((*instance).clone())
}
}
}
};
}
Expand Down
Loading