1#![allow(non_local_definitions)]
13#![allow(unexpected_cfgs)]
14
15extern crate libc;
16
17#[macro_use]
19pub mod caml;
20
21pub mod arkworks;
23
24pub mod urs_utils; pub mod cache_error;
29
30pub mod field_vector;
32pub mod gate_vector;
33
34pub mod projective;
36
37pub mod srs;
39
40pub mod pasta_fp_plonk_index;
42pub mod pasta_fq_plonk_index;
43
44pub mod plonk_verifier_index;
46
47pub mod pasta_fp_plonk_verifier_index;
48pub mod pasta_fq_plonk_verifier_index;
49
50pub mod oracles;
52
53pub mod pasta_fp_plonk_proof;
55pub mod pasta_fq_plonk_proof;
56
57pub mod pasta_fp_poseidon;
59pub mod pasta_fq_poseidon;
60
61pub mod linearization;
63
64pub use {
66 kimchi::circuits::{
67 gate::{caml::CamlCircuitGate, CurrOrNext, GateType},
68 scalars::caml::CamlRandomOracles,
69 wires::caml::CamlWire,
70 },
71 kimchi::proof::caml::CamlProofEvaluations,
72 kimchi::prover::caml::{
73 CamlLookupCommitments, CamlProofWithPublic, CamlProverCommitments, CamlProverProof,
74 },
75 mina_poseidon::sponge::caml::CamlScalarChallenge,
76 poly_commitment::{commitment::caml::CamlPolyComm, ipa::caml::CamlOpeningProof},
77};
78
79fn prove_pool_cache() -> &'static std::sync::Mutex<
83 std::collections::HashMap<usize, Vec<std::sync::Arc<rayon::ThreadPool>>>,
84> {
85 static CACHE: std::sync::OnceLock<
86 std::sync::Mutex<std::collections::HashMap<usize, Vec<std::sync::Arc<rayon::ThreadPool>>>>,
87 > = std::sync::OnceLock::new();
88 CACHE.get_or_init(|| std::sync::Mutex::new(std::collections::HashMap::new()))
89}
90
91pub(crate) fn with_prove_pool<R: Send>(f: impl FnOnce() -> R + Send) -> R {
104 let n = match std::env::var("KIMCHI_PROVE_THREADS")
105 .ok()
106 .and_then(|s| s.parse::<usize>().ok())
107 {
108 Some(n) if n >= 1 => n,
109 _ => return f(),
110 };
111 let pool = {
112 let mut cache = prove_pool_cache().lock().unwrap();
113 cache
114 .get_mut(&n)
115 .and_then(|free| free.pop())
116 .unwrap_or_else(|| {
117 std::sync::Arc::new(
118 rayon::ThreadPoolBuilder::new()
119 .num_threads(n)
120 .build()
121 .expect("KIMCHI_PROVE_THREADS thread pool"),
122 )
123 })
124 };
125 let result = pool.install(f);
126 let cap = std::env::var("KIMCHI_PROVE_POOL_CAP")
131 .ok()
132 .and_then(|s| s.parse::<usize>().ok())
133 .unwrap_or(2);
134 {
135 let mut cache = prove_pool_cache().lock().unwrap();
136 let free = cache.entry(n).or_default();
137 if free.len() < cap {
138 free.push(pool);
139 }
140 }
141 result
142}