Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6aa05b1
cargo: add comment about cdylib
querolita Sep 11, 2025
d02ec83
napi: poseidon ffi
querolita Sep 22, 2025
18a2370
minor: rename variable to avoid confusion
querolita Sep 29, 2025
cd24f57
types: change output types of poseidon ffi to fix o1js tests
querolita Sep 30, 2025
2a07e99
dummy logs
Trivo25 Oct 8, 2025
9348803
Merge pull request #3343 from o1-labs/florian/napi-conversion-core
querolita Oct 9, 2025
9286836
re-implement `circuit.rs `
Trivo25 Oct 15, 2025
cf6b541
hack serialisation for now
Trivo25 Oct 15, 2025
534fb8e
Merge pull request #3345 from o1-labs/florian/napi-prover-json
querolita Oct 23, 2025
ba4289c
native prover build with proper types
bleepbloopsify Oct 27, 2025
bcc5eb6
add build info
bleepbloopsify Oct 28, 2025
c3c5807
types tbd
Trivo25 Oct 30, 2025
0c04446
base types and caml_pasta_fp_plonk_verifier_index_shifts
Trivo25 Oct 30, 2025
953bc32
simplify
Trivo25 Oct 30, 2025
ab2d728
pub(crate)
bleepbloopsify Oct 30, 2025
8922137
Merge pull request #3357 from o1-labs/leon/native-prover-build
bleepbloopsify Oct 30, 2025
a68221c
plonk_proof_poc and renaming some fns
bleepbloopsify Oct 30, 2025
6660854
add reporting
bleepbloopsify Oct 31, 2025
6098614
do not want this
bleepbloopsify Oct 31, 2025
98f069f
Merge pull request #3361 from o1-labs/leon/native/napi/proof-generati…
bleepbloopsify Nov 3, 2025
36a0212
pinning napi-rs fork
bleepbloopsify Nov 3, 2025
6b91352
Merge pull request #3360 from o1-labs/florian/verifier-index-napi
querolita Nov 4, 2025
1859dc8
Merge pull request #3362 from o1-labs/leon/native/napi/napi-rs-fork
querolita Nov 4, 2025
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
144 changes: 142 additions & 2 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 = { git = "https://github.com/o1-labs/napi-rs.git", rev = "023d1d4f31bd75e8ab55c95b5077a319b5208cdf", version = "3.3.0", default-features = false, features = ["napi7"] }
napi-derive = { git="https://github.com/o1-labs/napi-rs.git", rev = "023d1d4f31bd75e8ab55c95b5077a319b5208cdf", version = "3.3.0", features = ["type-def"] }
napi-build = "2.1.0"
ocaml = { version = "0.22.2" }
ocaml-gen = { version = "1.0.0" }
once_cell = "=1.21.3"
Expand Down
46 changes: 46 additions & 0 deletions plonk-napi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[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
kimchi.workspace = true
mina-curves = { path = "../curves" }
mina-poseidon = { path = "../poseidon" }
o1-utils = { path = "../utils" }
poly-commitment = { path = "../poly-commitment" }

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_json.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();
}
41 changes: 41 additions & 0 deletions plonk-napi/src/build_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::sync::atomic::{AtomicU64, Ordering};

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";

#[napi]
pub const BACKING: &str = "native";

static NATIVE_CALLS: AtomicU64 = AtomicU64::new(0);

#[napi]
pub fn get_native_calls() -> u64 {
NATIVE_CALLS.load(Ordering::Relaxed)
}

pub(crate) fn report_native_call() {
NATIVE_CALLS.fetch_add(1, Ordering::Relaxed);
}
38 changes: 38 additions & 0 deletions plonk-napi/src/circuit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use ark_ff::PrimeField;
use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate};
use mina_curves::pasta::Fp;
use napi::bindgen_prelude::*;
use napi_derive::napi;
use serde::Serialize;

use crate::{build_info::report_native_call, types::WasmPastaFpPlonkIndex};

#[derive(Serialize)]
struct Circuit<F>
where
F: PrimeField,
{
public_input_size: usize,
#[serde(bound = "CircuitGate<F>: Serialize")]
gates: Vec<CircuitGate<F>>,
}

impl<F> From<&ConstraintSystem<F>> for Circuit<F>
where
F: PrimeField,
{
fn from(cs: &ConstraintSystem<F>) -> Self {
Self {
public_input_size: cs.public,
gates: cs.gates.to_vec(),
}
}
}

#[napi(js_name = "prover_to_json")]
pub fn prover_to_json(prover_index: &External<WasmPastaFpPlonkIndex>) -> String {
report_native_call();

let circuit: Circuit<Fp> = prover_index.0.cs.as_ref().into();
serde_json::to_string(&circuit).expect("couldn't serialize constraints")
}
12 changes: 12 additions & 0 deletions plonk-napi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mod build_info;
mod circuit;
pub mod plonk_verifier_index;
mod poseidon;
mod prover_index;
mod types;

pub use poseidon::{caml_pasta_fp_poseidon_block_cipher, caml_pasta_fq_poseidon_block_cipher};

pub use circuit::prover_to_json;
pub use prover_index::{prover_index_from_bytes, prover_index_to_bytes};
pub use types::WasmPastaFpPlonkIndex;
Loading