diff --git a/Cargo.lock b/Cargo.lock index c22fbd7337..8f63de3ef9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2036,6 +2036,7 @@ dependencies = [ "rand", "rayon", "rmp-serde", + "saffron", "serde", "serde_json", ] @@ -3395,6 +3396,8 @@ dependencies = [ "mina-curves", "mina-poseidon", "o1-utils", + "ocaml", + "ocaml-gen", "once_cell", "poly-commitment", "proptest", diff --git a/Cargo.toml b/Cargo.toml index f184e7c219..fa6e7df285 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/kimchi-stubs/Cargo.toml b/kimchi-stubs/Cargo.toml index e5ae3d69a5..0aa9769e12 100644 --- a/kimchi-stubs/Cargo.toml +++ b/kimchi-stubs/Cargo.toml @@ -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"] } diff --git a/kimchi-stubs/src/lib.rs b/kimchi-stubs/src/lib.rs index 2654a255d0..d6c32ae0c0 100644 --- a/kimchi-stubs/src/lib.rs +++ b/kimchi-stubs/src/lib.rs @@ -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; diff --git a/kimchi-stubs/src/saffron_storage.rs b/kimchi-stubs/src/saffron_storage.rs new file mode 100644 index 0000000000..7e8feb3e62 --- /dev/null +++ b/kimchi-stubs/src/saffron_storage.rs @@ -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 = Data { data: vec![Fq::one()] }; + // let caml_x: CamlData = x.into(); + + impl From> for CamlData { + fn from(data: Data) -> Self { + Self { + data: CamlFpVector::create(data.data), + } + } + } + + impl From for Data { + 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, + pub new_values: CamlFpVector, + } + + impl From for Diff { + 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 { + 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(()), + } + } +} diff --git a/saffron/Cargo.toml b/saffron/Cargo.toml index cb2e8b05bd..53cbc22469 100644 --- a/saffron/Cargo.toml +++ b/saffron/Cargo.toml @@ -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 @@ -66,3 +68,4 @@ harness = false [features] bench = [] +ocaml_types = ["ocaml", "ocaml-gen"]