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

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"mvpoly",
"o1vm",
"plonk-neon",
"plonk-napi",
"plonk-wasm",
"poly-commitment",
"poseidon",
Expand Down Expand Up @@ -61,6 +62,9 @@ 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-build = "2.1.0"
ocaml = { version = "0.22.2" }
ocaml-gen = { version = "1.0.0" }
once_cell = "=1.21.3"
Expand Down
43 changes: 43 additions & 0 deletions plonk-napi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[package]
name = "plonk-napi"
version = "0.1.0"
authors = ["[email protected]"]
description = "Node-API bindings for plonk proof systems"
repository = "https://github.com/MinaProtocol/mina"
license = "MIT/Apache-2.0"
edition = "2021"

[lib]
name = "plonk_napi"
crate-type = ["cdylib"] # to generate a dynamic library that is loadable by Node

[dependencies]
napi = { workspace = true, features = ["napi7"] }
napi-derive.workspace = true

# arkworks
ark-ec.workspace = true
ark-ff.workspace = true
ark-poly.workspace = true
ark-serialize.workspace = true
arkworks.workspace = true

# proof-systems
mina-curves = { path = "../curves" }
mina-poseidon = { path = "../poseidon" }
o1-utils = { path = "../utils" }

getrandom.workspace = true
libc.workspace = true
num-bigint.workspace = true
once_cell.workspace = true
paste.workspace = true
rand.workspace = true
rayon.workspace = true
rmp-serde.workspace = true
serde.workspace = true
serde_with.workspace = true
wasm-types.workspace = true

[build-dependencies]
napi-build.workspace = true
3 changes: 3 additions & 0 deletions plonk-napi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
napi_build::setup();
}
6 changes: 6 additions & 0 deletions plonk-napi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mod poseidon;

pub use poseidon::{
caml_pasta_fp_poseidon_block_cipher,
caml_pasta_fq_poseidon_block_cipher,
};
56 changes: 56 additions & 0 deletions plonk-napi/src/poseidon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use arkworks::{WasmPastaFp, WasmPastaFq};
use mina_curves::pasta::{Fp, Fq};
use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, permutation::poseidon_block_cipher};
use napi::bindgen_prelude::*;
use napi_derive::napi;
use wasm_types::{FlatVector, FlatVectorElem};

// fp

#[napi]
pub fn caml_pasta_fp_poseidon_block_cipher(state: Uint8Array) -> Result<Uint8Array> {
println!("from native rust");

let mut state_vec: Vec<Fp> = FlatVector::<WasmPastaFp>::from_bytes(state.to_vec())
.into_iter()
.map(Into::into)
.collect();

poseidon_block_cipher::<Fp, PlonkSpongeConstantsKimchi>(
mina_poseidon::pasta::fp_kimchi::static_params(),
&mut state_vec,
);

let res: Vec<u8> = state_vec
.into_iter()
.map(WasmPastaFp)
.flat_map(FlatVectorElem::flatten)
.collect();

Ok(Uint8Array::from(res))
}

// fq

#[napi]
pub fn caml_pasta_fq_poseidon_block_cipher(state: Uint8Array) -> Result<Uint8Array> {
println!("from native rust");

let mut state_vec: Vec<Fq> = FlatVector::<WasmPastaFq>::from_bytes(state.to_vec())
.into_iter()
.map(Into::into)
.collect();

poseidon_block_cipher::<Fq, PlonkSpongeConstantsKimchi>(
mina_poseidon::pasta::fq_kimchi::static_params(),
&mut state_vec,
);

let res: Vec<u8> = state_vec
.into_iter()
.map(WasmPastaFq)
.flat_map(FlatVectorElem::flatten)
.collect();

Ok(Uint8Array::from(res))
}
Loading