Skip to content

Commit 3486eb9

Browse files
committed
saffron-stubs: define caml_saffron_read_prove/verify
1 parent a70a7c8 commit 3486eb9

File tree

3 files changed

+66
-6
lines changed

3 files changed

+66
-6
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

saffron-stubs/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ edition = "2021"
1111
name = "saffron_stubs"
1212
# Important: do not ask to build a dynamic library.
1313
# On MacOS arm64, ocaml-rs.v0.2.2 causes build issues.
14-
# On the Mina side, a fake and empty dllkimchi_stubs.so file is used.
14+
# On the Saffron side, a fake and empty dllsaffron_stubs.so file is used.
1515
crate-type = ["lib", "staticlib"]
1616

1717
[dependencies]
18+
kimchi = { workspace = true, features = ["ocaml_types"] }
19+
kimchi-stubs.workspace = true
1820
libc.workspace = true
1921
ocaml = { workspace = true, features = ["no-caml-startup"] }
20-
ocaml-gen.workspace = true
22+
ocaml-gen.workspace = true
23+
poly-commitment.workspace = true
24+
rand.workspace = true
25+
saffron = { workspace = true, features = ["ocaml_types"] }

saffron-stubs/src/lib.rs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,57 @@
1-
/// Exposes the symbol caml_saffron_prove in the static library
2-
/// libsaffron_stubs.a.
1+
use kimchi::{circuits::domains::EvaluationDomains, groupmap::GroupMap};
2+
use kimchi_stubs::{
3+
arkworks::{CamlFp, CamlGVesta},
4+
srs::fp::CamlFpSrs,
5+
};
6+
use poly_commitment::SRS;
7+
use saffron::{
8+
read_proof::{self, caml::CamlReadProof, ReadProof},
9+
BaseField, Curve, ScalarField,
10+
};
11+
312
#[ocaml_gen::func]
413
#[ocaml::func]
5-
pub fn caml_saffron_prove() {
6-
unimplemented!("TODO")
14+
pub fn caml_saffron_read_prove(
15+
caml_srs: CamlFpSrs,
16+
caml_data: Vec<CamlFp>,
17+
caml_query: Vec<CamlFp>,
18+
caml_answer: Vec<CamlFp>,
19+
caml_data_comm: CamlGVesta,
20+
) -> CamlReadProof {
21+
let srs = caml_srs.0;
22+
let data: Vec<ScalarField> = caml_data.into_iter().map(|x| x.into()).collect();
23+
let query: Vec<ScalarField> = caml_query.into_iter().map(|x| x.into()).collect();
24+
let answer: Vec<ScalarField> = caml_answer.into_iter().map(|x| x.into()).collect();
25+
let data_comm: Curve = caml_data_comm.into();
26+
27+
let srs_size = srs.max_poly_size();
28+
let domain = EvaluationDomains::<ScalarField>::create(srs_size).unwrap();
29+
30+
let group_map = GroupMap::<BaseField>::setup();
31+
32+
let mut rng = rand::thread_rng();
33+
let read_proof = read_proof::prove(
34+
&srs, domain, &group_map, &mut rng, &data, &query, &answer, &data_comm,
35+
);
36+
read_proof.into()
37+
}
38+
39+
#[ocaml_gen::func]
40+
#[ocaml::func]
41+
pub fn caml_saffron_read_verify(
42+
caml_srs: CamlFpSrs,
43+
caml_data_comm: CamlGVesta,
44+
caml_proof: CamlReadProof,
45+
) -> bool {
46+
let srs = caml_srs.0;
47+
let data_comm: Curve = caml_data_comm.into();
48+
let proof: ReadProof = caml_proof.into();
49+
50+
let mut rng = rand::thread_rng();
51+
let srs_size = srs.max_poly_size();
52+
let domain = EvaluationDomains::<ScalarField>::create(srs_size).unwrap();
53+
54+
let group_map = GroupMap::<BaseField>::setup();
55+
56+
read_proof::verify(&srs, domain, &group_map, &mut rng, &data_comm, &proof)
757
}

0 commit comments

Comments
 (0)