Skip to content

Bindings draft for Saffron #3236

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ o1vm = { path = "./o1vm", version = "0.1.0" }
optimism = { path = "./optimism", version = "0.1.0" }
plonk_wasm = { path = "./plonk-wasm", version = "0.1.0" }
poly-commitment = { path = "./poly-commitment", version = "0.1.0" }
saffron = { path = "./poly-commitment", version = "0.1.0" }
saffron = { path = "./saffron", version = "0.1.0" }
signer = { path = "./signer", version = "0.1.0" }
turshi = { path = "./turshi", version = "0.1.0" }
utils = { path = "./utils", version = "0.1.0" }
Expand Down
1 change: 1 addition & 0 deletions kimchi-stubs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ mina-curves = { workspace = true }
mina-poseidon = { workspace = true }
o1-utils = { workspace = true }
poly-commitment = { workspace = true, features = ["ocaml_types"] }
saffron = { workspace = true, features = ["ocaml_types"] }
3 changes: 3 additions & 0 deletions kimchi-stubs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ pub mod pasta_fq_plonk_proof;
pub mod pasta_fp_poseidon;
pub mod pasta_fq_poseidon;

/// Safron
pub mod saffron_storage;

/// Linearization helpers
pub mod linearization;

Expand Down
74 changes: 74 additions & 0 deletions kimchi-stubs/src/saffron_storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// #[cfg(feature = "ocaml_types")]
pub mod caml {
use crate::field_vector::fp::CamlFpVector;
use mina_curves::pasta::Fp;
use saffron::{diff::Diff, storage::*};

#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
pub struct CamlData {
pub data: CamlFpVector,
}

// let x: Data<Fq> = Data { data: vec![Fq::one()] };
// let caml_x: CamlData<Fq> = x.into();

impl From<Data<Fp>> for CamlData {
fn from(data: Data<Fp>) -> Self {
Self {
data: CamlFpVector::create(data.data),
}
}
}

impl From<CamlData> for Data<Fp> {
fn from(caml_data: CamlData) -> Self {
Self {
data: caml_data.data.as_slice().into(),
}
}
}

#[derive(ocaml::IntoValue, ocaml::FromValue, ocaml_gen::Struct)]
pub struct CamlDiff {
pub region: ocaml::Uint,
pub addresses: Vec<ocaml::Uint>,
pub new_values: CamlFpVector,
}

impl From<CamlDiff> for Diff<Fp> {
fn from(caml_diff: CamlDiff) -> Self {
Self {
region: caml_diff.region as u64,
addresses: caml_diff.addresses.into_iter().map(|x| x as u64).collect(),
new_values: caml_diff.new_values.as_slice().into(),
}
}
}

#[ocaml_gen::func]
#[ocaml::func]
pub fn caml_init(path: String, data: CamlData) -> Result<(), ocaml::Error> {
match init(&path, &data.into()) {
Err(_) => ocaml::Error::failwith("Storage.caml_init: error in file initialisation"),
Ok(()) => Ok(()),
}
}

#[ocaml_gen::func]
#[ocaml::func]
pub fn caml_read(path: String) -> Result<CamlData, ocaml::Error> {
match read(&path) {
Err(e) => return Err(e.into()),
Ok(data) => Ok(data.into()),
}
}

#[ocaml_gen::func]
#[ocaml::func]
pub fn caml_update(path: String, diff: CamlDiff) -> Result<(), ocaml::Error> {
match update(&path, &diff.into()) {
Err(_) => ocaml::Error::failwith("Storage.caml_update: error in file initialisation"),
Ok(()) => Ok(()),
}
}
}
3 changes: 3 additions & 0 deletions saffron/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ kimchi.workspace = true
mina-curves.workspace = true
mina-poseidon.workspace = true
o1-utils.workspace = true
ocaml = { workspace = true, optional = true }
ocaml-gen = { workspace = true, optional = true }
poly-commitment.workspace = true
rand.workspace = true
rayon.workspace = true
Expand Down Expand Up @@ -66,3 +68,4 @@ harness = false

[features]
bench = []
ocaml_types = ["ocaml", "ocaml-gen"]
Loading