Skip to content

Commit 04b03e6

Browse files
authored
Merge branch 'master' into brian/o1js-test
2 parents 85e3822 + 15139e4 commit 04b03e6

33 files changed

+939
-331
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ spmc = "=0.3.0"
8585
strum = "0.26.1"
8686
strum_macros = "0.26.1"
8787
thiserror = { version = "2", default-features = false }
88+
tikv-jemalloc-ctl = { version = "0.5" }
89+
tikv-jemallocator = { version = "0.5" }
8890
tinytemplate = "1.1"
8991
wasm-bindgen = "=0.2.89"
9092
wasm-bindgen-test = ">=0.3.0"

book/src/specs/kimchi.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ These pre-computations are optimizations, in the context of normal proofs, but t
17121712
pub struct ProverIndex<G: KimchiCurve, OpeningProof: OpenProof<G>> {
17131713
/// constraints system polynomials
17141714
#[serde(bound = "ConstraintSystem<G::ScalarField>: Serialize + DeserializeOwned")]
1715-
pub cs: ConstraintSystem<G::ScalarField>,
1715+
pub cs: Arc<ConstraintSystem<G::ScalarField>>,
17161716

17171717
/// The symbolic linearization of our circuit, which can compile to concrete types once certain values are learned in the protocol.
17181718
#[serde(skip)]
@@ -1732,7 +1732,7 @@ pub struct ProverIndex<G: KimchiCurve, OpeningProof: OpenProof<G>> {
17321732
pub max_poly_size: usize,
17331733

17341734
#[serde(bound = "ColumnEvaluations<G::ScalarField>: Serialize + DeserializeOwned")]
1735-
pub column_evaluations: ColumnEvaluations<G::ScalarField>,
1735+
pub column_evaluations: Arc<LazyCache<ColumnEvaluations<G::ScalarField>>>,
17361736

17371737
/// The verifier index corresponding to this prover index
17381738
#[serde(skip)]
@@ -1798,7 +1798,7 @@ pub struct VerifierIndex<G: KimchiCurve, OpeningProof: OpenProof<G>> {
17981798
/// coefficient commitment array
17991799
#[serde(bound = "PolyComm<G>: Serialize + DeserializeOwned")]
18001800
pub coefficients_comm: [PolyComm<G>; COLUMNS],
1801-
/// coefficient commitment array
1801+
/// generic gate commitment array
18021802
#[serde(bound = "PolyComm<G>: Serialize + DeserializeOwned")]
18031803
pub generic_comm: PolyComm<G>,
18041804

kimchi-stubs/src/pasta_fp_plonk_index.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn caml_pasta_fp_plonk_index_create(
5757
runtime_tables: Vec<CamlRuntimeTableCfg<CamlFp>>,
5858
prev_challenges: ocaml::Int,
5959
srs: CamlFpSrs,
60+
lazy_mode: bool,
6061
) -> Result<CamlPastaFpPlonkIndex, ocaml::Error> {
6162
let gates: Vec<_> = gates
6263
.as_ref()
@@ -85,6 +86,7 @@ pub fn caml_pasta_fp_plonk_index_create(
8586
} else {
8687
Some(runtime_tables)
8788
})
89+
.lazy_mode(lazy_mode)
8890
.build()
8991
{
9092
Err(e) => return Err(e.into()),
@@ -97,7 +99,8 @@ pub fn caml_pasta_fp_plonk_index_create(
9799
srs.0.with_lagrange_basis(cs.domain.d1);
98100

99101
// create index
100-
let mut index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.clone());
102+
let mut index =
103+
ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.clone(), lazy_mode);
101104
// Compute and cache the verifier index digest
102105
index.compute_verifier_index_digest::<DefaultFqSponge<VestaParameters, PlonkSpongeConstantsKimchi>>();
103106

kimchi-stubs/src/pasta_fp_plonk_proof.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ pub fn caml_pasta_fp_plonk_proof_create_and_verify(
189189
#[ocaml::func]
190190
pub fn caml_pasta_fp_plonk_proof_example_with_lookup(
191191
srs: CamlFpSrs,
192+
lazy_mode: bool,
192193
) -> (
193194
CamlPastaFpPlonkIndex,
194195
CamlFp,
@@ -279,13 +280,14 @@ pub fn caml_pasta_fp_plonk_proof_example_with_lookup(
279280
.runtime(Some(runtime_tables_setup))
280281
.lookup(fixed_tables)
281282
.public(num_public_inputs)
283+
.lazy_mode(lazy_mode)
282284
.build()
283285
.unwrap();
284286

285287
srs.0.with_lagrange_basis(cs.domain.d1);
286288

287289
let (endo_q, _endo_r) = endos::<Pallas>();
288-
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0);
290+
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0, lazy_mode);
289291
let group_map = <Vesta as CommitmentCurve>::Map::setup();
290292
let public_input = witness[0][0];
291293
let proof = ProverProof::create_recursive::<EFqSponge, EFrSponge, _>(
@@ -312,6 +314,7 @@ pub fn caml_pasta_fp_plonk_proof_example_with_lookup(
312314
#[ocaml::func]
313315
pub fn caml_pasta_fp_plonk_proof_example_with_foreign_field_mul(
314316
srs: CamlFpSrs,
317+
lazy_mode: bool,
315318
) -> (
316319
CamlPastaFpPlonkIndex,
317320
CamlProofWithPublic<CamlGVesta, CamlFp>,
@@ -443,12 +446,15 @@ pub fn caml_pasta_fp_plonk_proof_example_with_foreign_field_mul(
443446
}
444447

445448
// Create constraint system
446-
let cs = ConstraintSystem::<Fp>::create(gates).build().unwrap();
449+
let cs = ConstraintSystem::<Fp>::create(gates)
450+
.lazy_mode(lazy_mode)
451+
.build()
452+
.unwrap();
447453

448454
srs.0.with_lagrange_basis(cs.domain.d1);
449455

450456
let (endo_q, _endo_r) = endos::<Pallas>();
451-
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0);
457+
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0, lazy_mode);
452458
let group_map = <Vesta as CommitmentCurve>::Map::setup();
453459
let proof = ProverProof::create_recursive::<EFqSponge, EFrSponge, _>(
454460
&group_map,
@@ -470,6 +476,7 @@ pub fn caml_pasta_fp_plonk_proof_example_with_foreign_field_mul(
470476
#[ocaml::func]
471477
pub fn caml_pasta_fp_plonk_proof_example_with_range_check(
472478
srs: CamlFpSrs,
479+
lazy_mode: bool,
473480
) -> (
474481
CamlPastaFpPlonkIndex,
475482
CamlProofWithPublic<CamlGVesta, CamlFp>,
@@ -511,12 +518,15 @@ pub fn caml_pasta_fp_plonk_proof_example_with_range_check(
511518
}
512519

513520
// Create constraint system
514-
let cs = ConstraintSystem::<Fp>::create(gates).build().unwrap();
521+
let cs = ConstraintSystem::<Fp>::create(gates)
522+
.lazy_mode(lazy_mode)
523+
.build()
524+
.unwrap();
515525

516526
srs.0.with_lagrange_basis(cs.domain.d1);
517527

518528
let (endo_q, _endo_r) = endos::<Pallas>();
519-
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0);
529+
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0, lazy_mode);
520530
let group_map = <Vesta as CommitmentCurve>::Map::setup();
521531
let proof = ProverProof::create_recursive::<EFqSponge, EFrSponge, _>(
522532
&group_map,
@@ -538,6 +548,7 @@ pub fn caml_pasta_fp_plonk_proof_example_with_range_check(
538548
#[ocaml::func]
539549
pub fn caml_pasta_fp_plonk_proof_example_with_range_check0(
540550
srs: CamlFpSrs,
551+
lazy_mode: bool,
541552
) -> (
542553
CamlPastaFpPlonkIndex,
543554
CamlProofWithPublic<CamlGVesta, CamlFp>,
@@ -583,12 +594,15 @@ pub fn caml_pasta_fp_plonk_proof_example_with_range_check0(
583594
};
584595

585596
// not sure if theres a smarter way instead of the double unwrap, but should be fine in the test
586-
let cs = ConstraintSystem::<Fp>::create(gates).build().unwrap();
597+
let cs = ConstraintSystem::<Fp>::create(gates)
598+
.lazy_mode(lazy_mode)
599+
.build()
600+
.unwrap();
587601

588602
srs.0.with_lagrange_basis(cs.domain.d1);
589603

590604
let (endo_q, _endo_r) = endos::<Pallas>();
591-
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0);
605+
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0, lazy_mode);
592606
let group_map = <Vesta as CommitmentCurve>::Map::setup();
593607
let proof = ProverProof::create_recursive::<EFqSponge, EFrSponge, _>(
594608
&group_map,
@@ -610,6 +624,7 @@ pub fn caml_pasta_fp_plonk_proof_example_with_range_check0(
610624
#[ocaml::func]
611625
pub fn caml_pasta_fp_plonk_proof_example_with_ffadd(
612626
srs: CamlFpSrs,
627+
lazy_mode: bool,
613628
) -> (
614629
CamlPastaFpPlonkIndex,
615630
CamlFp,
@@ -708,13 +723,14 @@ pub fn caml_pasta_fp_plonk_proof_example_with_ffadd(
708723
// be fine in the test
709724
let cs = ConstraintSystem::<Fp>::create(gates)
710725
.public(num_public_inputs)
726+
.lazy_mode(lazy_mode)
711727
.build()
712728
.unwrap();
713729

714730
srs.0.with_lagrange_basis(cs.domain.d1);
715731

716732
let (endo_q, _endo_r) = endos::<Pallas>();
717-
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0);
733+
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0, lazy_mode);
718734
let group_map = <Vesta as CommitmentCurve>::Map::setup();
719735
let public_input = witness[0][0];
720736
let proof = ProverProof::create_recursive::<EFqSponge, EFrSponge, _>(
@@ -738,6 +754,7 @@ pub fn caml_pasta_fp_plonk_proof_example_with_ffadd(
738754
#[ocaml::func]
739755
pub fn caml_pasta_fp_plonk_proof_example_with_xor(
740756
srs: CamlFpSrs,
757+
lazy_mode: bool,
741758
) -> (
742759
CamlPastaFpPlonkIndex,
743760
(CamlFp, CamlFp),
@@ -799,13 +816,14 @@ pub fn caml_pasta_fp_plonk_proof_example_with_xor(
799816
// be fine in the test
800817
let cs = ConstraintSystem::<Fp>::create(gates)
801818
.public(num_public_inputs)
819+
.lazy_mode(lazy_mode)
802820
.build()
803821
.unwrap();
804822

805823
srs.0.with_lagrange_basis(cs.domain.d1);
806824

807825
let (endo_q, _endo_r) = endos::<Pallas>();
808-
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0);
826+
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0, lazy_mode);
809827
let group_map = <Vesta as CommitmentCurve>::Map::setup();
810828
let public_input = (witness[0][0], witness[0][1]);
811829
let proof = ProverProof::create_recursive::<EFqSponge, EFrSponge, _>(
@@ -829,6 +847,7 @@ pub fn caml_pasta_fp_plonk_proof_example_with_xor(
829847
#[ocaml::func]
830848
pub fn caml_pasta_fp_plonk_proof_example_with_rot(
831849
srs: CamlFpSrs,
850+
lazy_mode: bool,
832851
) -> (
833852
CamlPastaFpPlonkIndex,
834853
(CamlFp, CamlFp),
@@ -893,13 +912,14 @@ pub fn caml_pasta_fp_plonk_proof_example_with_rot(
893912
// be fine in the test
894913
let cs = ConstraintSystem::<Fp>::create(gates)
895914
.public(num_public_inputs)
915+
.lazy_mode(lazy_mode)
896916
.build()
897917
.unwrap();
898918

899919
srs.0.with_lagrange_basis(cs.domain.d1);
900920

901921
let (endo_q, _endo_r) = endos::<Pallas>();
902-
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0);
922+
let index = ProverIndex::<Vesta, OpeningProof<Vesta>>::create(cs, endo_q, srs.0, lazy_mode);
903923
let group_map = <Vesta as CommitmentCurve>::Map::setup();
904924
let public_input = (witness[0][0], witness[0][1]);
905925
let proof = ProverProof::create_recursive::<EFqSponge, EFrSponge, _>(

kimchi-stubs/src/pasta_fq_plonk_index.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ pub fn caml_pasta_fq_plonk_index_create(
5757
runtime_tables: Vec<CamlRuntimeTableCfg<CamlFq>>,
5858
prev_challenges: ocaml::Int,
5959
srs: CamlFqSrs,
60+
lazy_mode: bool,
6061
) -> Result<CamlPastaFqPlonkIndex, ocaml::Error> {
6162
let gates: Vec<_> = gates
6263
.as_ref()
@@ -84,6 +85,7 @@ pub fn caml_pasta_fq_plonk_index_create(
8485
} else {
8586
Some(runtime_tables)
8687
})
88+
.lazy_mode(lazy_mode)
8789
.build()
8890
{
8991
Err(e) => return Err(e.into()),
@@ -96,7 +98,8 @@ pub fn caml_pasta_fq_plonk_index_create(
9698
srs.0.with_lagrange_basis(cs.domain.d1);
9799

98100
// create index
99-
let mut index = ProverIndex::<Pallas, OpeningProof<Pallas>>::create(cs, endo_q, srs.clone());
101+
let mut index =
102+
ProverIndex::<Pallas, OpeningProof<Pallas>>::create(cs, endo_q, srs.clone(), lazy_mode);
100103
// Compute and cache the verifier index digest
101104
index.compute_verifier_index_digest::<DefaultFqSponge<PallasParameters, PlonkSpongeConstantsKimchi>>();
102105

kimchi/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ license = "Apache-2.0"
1313
path = "src/lib.rs"
1414
bench = false # needed for criterion (https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options)
1515

16+
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
17+
tikv-jemalloc-ctl = { workspace = true }
18+
tikv-jemallocator = { workspace = true }
19+
1620
[dependencies]
1721
ark-bn254 = { workspace = true, optional = true }
1822
ark-ec.workspace = true

kimchi/src/bench.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ where
231231
let cs: ConstraintSystem<G::ScalarField> = rmp_serde::from_read(bytes_cs.as_slice()).unwrap();
232232

233233
let endo = cs.endo;
234-
let mut index: ProverIndex<G, OpeningProof<G>> = ProverIndex::create(cs, endo, srs.into());
234+
let mut index: ProverIndex<G, OpeningProof<G>> =
235+
ProverIndex::create(cs, endo, srs.into(), false);
235236
index.compute_verifier_index_digest::<BaseSponge>();
236237

237238
(index, witness, runtime_tables, prev)

0 commit comments

Comments
 (0)