Skip to content
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

Use latest proof-systems/master in Mina #16405

Open
wants to merge 24 commits into
base: compatible
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4385e33
Deps/proof-systems: bump up
dannywillems Dec 9, 2024
e27eb17
Submodules/kimchi-vendors: remove temporarily
dannywillems Dec 9, 2024
ce13ec2
kimchi-bindings/wasm: simply reordering deps
dannywillems Dec 9, 2024
f671fae
Kimchi-bindings/stubs: reorganize deps in Cargo.toml
dannywillems Dec 9, 2024
60353ad
Kimchi-bindings/stubs: stop ordering to cargo to use vendored srcs
dannywillems Dec 9, 2024
75b29dc
Kimchi_bindings/wasm: match wasm-binding version with proof-systems
dannywillems Dec 9, 2024
e8014cc
Kimchi-bindings/stubs: enforce 80 characters per line
dannywillems Dec 9, 2024
dfdb0f8
Kimchi_bindings/stubs: make it compilable with latest proof-systems
dannywillems Dec 9, 2024
a1441a6
Kimchi-bindings/wasm: make clippy a bit happier
dannywillems Dec 9, 2024
fb7ac1e
Kimchi-bindings/stubs: make compilable with latest proof-systems
dannywillems Dec 9, 2024
6b98a9d
Kimchi-bindings/stubs: remove --offline parameters to build Rust
dannywillems Dec 9, 2024
5e3c507
Kimchi-bindings/stubs: update Cargo.lock
dannywillems Dec 9, 2024
02bcee2
kimchi-bindings/stubs: make clippy happier
dannywillems Dec 9, 2024
b1f0a26
kimchi-bindings/stubs: enforce 80 characters limit
dannywillems Dec 9, 2024
8255311
Deps/proof-systems: bump up
dannywillems Dec 9, 2024
3593766
Deps/proof-systems: bump up
dannywillems Dec 9, 2024
fe13da1
Kimchi-bindings/stubs: bring back ocaml_str with inherent cache
dannywillems Dec 9, 2024
5c838a5
Pickles: update scalars.ml, result of `dune build src/lib/pickles`
dannywillems Dec 9, 2024
1b76fed
Deps/proof-systems: bump up
dannywillems Dec 9, 2024
e696ce8
Kimchi-bindings/wasm: update Cargo.lock
dannywillems Dec 9, 2024
26a78dc
Kimchi-bindings/stubs: update Cargo.lock
dannywillems Dec 9, 2024
becb09c
Kimchi-bindings/wasm: downgrade wasm-bindgen to 0.2.87
dannywillems Dec 9, 2024
c1c89df
Deps/proof-systems: bump up
dannywillems Dec 9, 2024
2cc26fa
Cargo.toml: enforcing 80 characters limit
dannywillems Dec 9, 2024
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
5 changes: 1 addition & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
url = https://github.com/o1-labs/snarky
[submodule "src/lib/crypto/proof-systems"]
path = src/lib/crypto/proof-systems
url = https://github.com/o1-labs/proof-systems.git
[submodule "src/lib/crypto/kimchi_bindings/stubs/kimchi-stubs-vendors"]
path = src/lib/crypto/kimchi_bindings/stubs/kimchi-stubs-vendors
url = https://github.com/MinaProtocol/kimchi-stubs-vendors.git
url = https://github.com/o1-labs/proof-systems.git
8 changes: 1 addition & 7 deletions src/lib/crypto/kimchi_bindings/stubs/.cargo/config
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
[build]
rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]

[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "kimchi-stubs-vendors"
rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
27 changes: 15 additions & 12 deletions src/lib/crypto/kimchi_bindings/stubs/Cargo.lock

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

20 changes: 10 additions & 10 deletions src/lib/crypto/kimchi_bindings/stubs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,31 @@ crate-type = ["lib", "staticlib"]

[dependencies]
array-init = "2.0.0"
rmp-serde = "1.1.2"
libc = "0.2.62"
num-bigint = { version = "0.4.4", features = [ "rand", "serde" ] }
# ocaml-specific
ocaml = { version = "0.22.2", features = ["no-caml-startup"] }
ocaml-gen = "0.1.5"
once_cell = "1.10.0"
paste = "1.0.5"
rand = "0.8.5"
rayon = "1.5.0"
rmp-serde = "1.1.2"
serde = "1.0.130"
serde_json = "1.0.103"
sprs = { version = "0.11.0", features = ["multi_thread"] }
once_cell = "1.10.0"

# arkworks
ark-ff = { version = "0.4.2", features = ["parallel", "asm"] }
ark-serialize = "0.4.2"
ark-ec = { version = "0.4.2", features = ["parallel"] }
ark-ff = { version = "0.4.2", features = ["parallel", "asm"] }
ark-poly = { version = "0.4.2", features = ["parallel"] }
ark-serialize = "0.4.2"

# proof-systems
poly-commitment = { path = "../../proof-systems/poly-commitment", features = ["ocaml_types"] }
groupmap = { path = "../../proof-systems/groupmap" }
kimchi = { path = "../../proof-systems/kimchi", features = ["ocaml_types"] }
mina-curves = { path = "../../proof-systems/curves" }
o1-utils = { path = "../../proof-systems/utils" }
mina-poseidon = { path = "../../proof-systems/poseidon" }
kimchi = { path = "../../proof-systems/kimchi", features = ["ocaml_types"] }
o1-utils = { path = "../../proof-systems/utils" }
poly-commitment = { path = "../../proof-systems/poly-commitment", features = ["ocaml_types"] }

# ocaml-specific
ocaml = { version = "0.22.2", features = ["no-caml-startup"] }
ocaml-gen = "0.1.5"
4 changes: 2 additions & 2 deletions src/lib/crypto/kimchi_bindings/stubs/dune
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
(setenv
RUSTFLAGS
%{read:rustflags.sexp}
(run cargo build --release --offline)))
(run cargo build --release)))
(run
cp
%{read:../dune-build-root}/cargo_kimchi_stubs/release/libwires_15_stubs.a
Expand Down Expand Up @@ -161,7 +161,7 @@
(setenv
CARGO_TARGET_DIR
"%{read:../dune-build-root}/cargo_kimchi_bindgen"
(run cargo run %{targets} --offline))
(run cargo run %{targets}))
(run ocamlformat -i %{targets}))))

;; this is used by nix
Expand Down
Submodule kimchi-stubs-vendors deleted from 2201f3
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use crate::arkworks::CamlBigInteger256;
use crate::caml::caml_bytes_string::CamlBytesString;
use ark_ff::{FftField, Field, One, PrimeField, UniformRand, Zero};
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain as Domain};
use ark_serialize::{CanonicalSerialize, CanonicalDeserialize};
use mina_curves::pasta::fields::{fp::{Fp, FpParameters as Fp_params}, fft::FpParameters};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use mina_curves::pasta::fields::{
fft::FpParameters,
fp::{Fp, FpParameters as Fp_params},
};
use num_bigint::BigUint;
use rand::rngs::StdRng;
use std::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use crate::arkworks::CamlBigInteger256;
use crate::caml::caml_bytes_string::CamlBytesString;
use ark_ff::{FftField, Field, One, PrimeField, UniformRand, Zero};
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain as Domain};
use ark_serialize::{CanonicalSerialize, CanonicalDeserialize};
use mina_curves::pasta::{fields::{fq::FqParameters as Fq_params, fft::FpParameters}, Fq};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use mina_curves::pasta::{
fields::{fft::FpParameters, fq::FqParameters as Fq_params},
Fq,
};
use num_bigint::BigUint;
use rand::rngs::StdRng;
use std::{
Expand Down
18 changes: 10 additions & 8 deletions src/lib/crypto/kimchi_bindings/stubs/src/caml/caml_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ macro_rules! impl_caml_pointer {
}

extern "C" fn caml_pointer_compare(_: ocaml::Raw, _: ocaml::Raw) -> i32 {
// Always return equal. We can use this for sanity checks, and anything else using this
// would be broken anyway.
// Always return equal. We can use this for sanity checks, and
// anything else using this would be broken anyway.
0
}
}
Expand Down Expand Up @@ -49,12 +49,14 @@ macro_rules! impl_caml_pointer {
unsafe {
// Wholely unsafe, Batman!
// We would use [`get_mut_unchecked`] here, but it is nightly-only.
// Instead, we get coerce our constant pointer to a mutable pointer, in the knowledge
// that
// * all of our mutations called from OCaml are blocking, so we won't have multiple
// live mutable references live simultaneously, and
// * the underlying pointer is in the correct state to be mutable, since we can call
// [`get_mut_unchecked`] in nightly, or can call [`get_mut`] and unwrap if this is
// Instead, we get coerce our constant pointer to a mutable
// pointer, in the knowledge that
// * all of our mutations called from OCaml are blocking, so
// we won't have multiple live mutable references live
// simultaneously, and
// * the underlying pointer is in the correct state to be
// mutable, since we can call [`get_mut_unchecked`] in
// nightly, or can call [`get_mut`] and unwrap if this is
// the only live reference.
&mut *(((&*self.0) as *const Self::Target) as *mut Self::Target)
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/crypto/kimchi_bindings/stubs/src/field_vector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! We implement a custom type for field vectors in order to quickly build field vectors from the OCaml side and avoid large vector clones.
//! We implement a custom type for field vectors in order to quickly build field
//! vectors from the OCaml side and avoid large vector clones.

use paste::paste;

Expand Down
59 changes: 27 additions & 32 deletions src/lib/crypto/kimchi_bindings/stubs/src/lagrange_basis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use ark_ec::AffineRepr;
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain as D};
use cache::LagrangeCache;
use mina_curves::pasta::{Pallas, Vesta};
use poly_commitment::{commitment::CommitmentCurve, srs::SRS};
use poly_commitment::commitment::CommitmentCurve;
use poly_commitment::ipa::SRS;
use poly_commitment::SRS as _;
use std::env;

pub trait WithLagrangeBasis<G: AffineRepr> {
Expand Down Expand Up @@ -42,7 +44,6 @@ fn add_lagrange_basis_with_cache<G: CommitmentCurve, C: LagrangeCache<G>>(
}
if let Some(basis) = cache.load_lagrange_basis_from_cache(srs.g.len(), &domain) {
srs.lagrange_bases.get_or_generate(n, || basis);
return;
} else {
let basis = srs.get_lagrange_basis(domain);
cache.cache_lagrange_basis(srs.g.len(), &domain, basis);
Expand Down Expand Up @@ -81,7 +82,7 @@ mod cache {
&self,
srs_length: usize,
domain: &D<G::ScalarField>,
basis: &Vec<PolyComm<G>>,
basis: &[PolyComm<G>],
);
}

Expand All @@ -100,10 +101,9 @@ mod cache {
}
}

/*
The FileCache implementation uses a directory as a cache for the Lagrange basis hash map --
i.e every file corresponds to a Lagrange basis for a given G-basis and domain size.
*/
// The FileCache implementation uses a directory as a cache for the Lagrange
// basis hash map -- i.e every file corresponds to a Lagrange basis for a
// given G-basis and domain size.
impl<G: AffineRepr> LagrangeCache<G> for FileCache<G> {
type CacheKey = PathBuf;

Expand All @@ -115,7 +115,7 @@ mod cache {
self.cache_dir.clone().join(format!(
"lagrange_basis_{:}-{:}",
srs_length,
domain.size().to_string()
domain.size()
))
}

Expand All @@ -126,14 +126,13 @@ mod cache {
) -> Option<Vec<PolyComm<G>>> {
let cache_key = self.lagrange_basis_cache_key(srs_length, domain);
if Path::exists(&cache_key) {
let f = File::open(cache_key.clone()).expect(&format!(
"Missing lagrange basis cache file {:?}",
cache_key
));
let basis: Vec<PolyComm<G>> = rmp_serde::decode::from_read(f).expect(&format!(
"Error decoding lagrange cache file {:?}",
cache_key
));
let f = File::open(cache_key.clone()).unwrap_or_else(|_| {
panic!("Missing lagrange basis cache file {:?}", cache_key)
});
let basis: Vec<PolyComm<G>> =
rmp_serde::decode::from_read(f).unwrap_or_else(|_| {
panic!("Error decoding lagrange cache file {:?}", cache_key)
});
Some(basis)
} else {
None
Expand All @@ -144,26 +143,22 @@ mod cache {
&self,
srs_length: usize,
domain: &D<G::ScalarField>,
basis: &Vec<PolyComm<G>>,
basis: &[PolyComm<G>],
) {
let cache_key = self.lagrange_basis_cache_key(srs_length, domain);
if Path::exists(&cache_key) {
return;
} else {
let mut f = File::create(cache_key.clone()).expect(&format!(
"Error creating lagrabnge basis cache file {:?}",
cache_key
));
rmp_serde::encode::write(&mut f, basis).expect(&format!(
"Error encoding lagrange basis to file {:?}",
cache_key
));
if !Path::exists(&cache_key) {
let mut f = File::create(cache_key.clone()).unwrap_or_else(|_| {
panic!("Error creating lagrabnge basis cache file {:?}", cache_key)
});
rmp_serde::encode::write(&mut f, basis).unwrap_or_else(|_| {
panic!("Error encoding lagrange basis to file {:?}", cache_key)
});
}
}
}

// The following two caches are all that we need for mina tests. These will not be initialized unless they are
// explicitly called.
// The following two caches are all that we need for mina tests. These will
// not be initialized unless they are explicitly called.
static VESTA_FILE_CACHE: Lazy<FileCache<Vesta>> = Lazy::new(|| {
let cache_base_dir: String =
env::var("LAGRANGE_CACHE_DIR").expect("LAGRANGE_CACHE_DIR missing in env");
Expand All @@ -175,7 +170,7 @@ mod cache {
});

pub fn get_vesta_file_cache() -> &'static FileCache<Vesta> {
&*VESTA_FILE_CACHE
&VESTA_FILE_CACHE
}

static PALLAS_FILE_CACHE: Lazy<FileCache<Pallas>> = Lazy::new(|| {
Expand All @@ -189,6 +184,6 @@ mod cache {
});

pub fn get_pallas_file_cache() -> &'static FileCache<Pallas> {
&*PALLAS_FILE_CACHE
&PALLAS_FILE_CACHE
}
}
3 changes: 2 additions & 1 deletion src/lib/crypto/kimchi_bindings/stubs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ pub use {
CamlLookupCommitments, CamlProofWithPublic, CamlProverCommitments, CamlProverProof,
},
mina_poseidon::sponge::caml::CamlScalarChallenge,
poly_commitment::commitment::caml::{CamlOpeningProof, CamlPolyComm},
poly_commitment::commitment::caml::CamlPolyComm,
poly_commitment::ipa::caml::CamlOpeningProof,
};
11 changes: 6 additions & 5 deletions src/lib/crypto/kimchi_bindings/stubs/src/linearization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use kimchi::{
linearization::{constraints_expr, linearization_columns},
};

/// Converts the linearization of the kimchi circuit polynomial into a printable string.
/// Converts the linearization of the kimchi circuit polynomial into a printable
/// string.
pub fn linearization_strings<F: ark_ff::PrimeField>(
uses_custom_gates: bool,
) -> (String, Vec<(String, String)>)
where
num_bigint::BigUint: From<F::BigInt>,
where
num_bigint::BigUint: From<F::BigInt>,
{
let features = if uses_custom_gates {
None
Expand Down Expand Up @@ -44,8 +45,8 @@ pub fn linearization_strings<F: ark_ff::PrimeField>(
mut index_terms,
} = linearization.linearize(evaluated_cols).unwrap();

// HashMap deliberately uses an unstable order; here we sort to ensure that the output is
// consistent when printing.
// HashMap deliberately uses an unstable order; here we sort to ensure that
// the output is consistent when printing.
index_terms.sort_by(|(x, _), (y, _)| x.cmp(y));

let constant = constant_term.ocaml_str();
Expand Down
Loading