Skip to content

Commit 6a197f6

Browse files
authored
Merge pull request #3262 from o1-labs/volhovm/fix-ci-benches
Fix failing mina benches in CI
2 parents 4436bd4 + 3b273fc commit 6a197f6

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

.github/workflows/benches-mina-prover-set-baseline.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
name: Bench mina circuits (set baseline master)
22

3+
# Runs on either pushes to master, or on manual call
4+
#
5+
# Please don't regenerate the data unless you REALLY know what you're doing, e.g. you had to regenerate
6+
# benchmark data and now the baselines changed.
37
on:
48
push:
59
branches:
610
- master
11+
pull_request:
12+
types: [labeled]
713

814
env:
915
OCAML_VERSION: "4.14"
@@ -12,6 +18,7 @@ env:
1218

1319
jobs:
1420
bench-set-baseline:
21+
if: github.event_name == 'push' || github.event.label.name == 'unsafe-benches-mina-reset-baseline'
1522
runs-on: ubuntu-latest
1623
name: Run benches
1724
steps:

kimchi-stubs/src/pasta_fp_plonk_proof.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ pub fn caml_pasta_fp_plonk_proof_create(
8484
// public input
8585
let public_input = witness[0][0..index.cs.public].to_vec();
8686

87+
if std::env::var("KIMCHI_PROVER_DUMP_ARGUMENTS").is_ok() {
88+
kimchi::bench::bench_arguments_dump_into_file(&index.cs, &witness, &runtime_tables, &prev);
89+
}
90+
8791
// NB: This method is designed only to be used by tests. However, since creating a new reference will cause `drop` to be called on it once we are done with it. Since `drop` calls `caml_shutdown` internally, we *really, really* do not want to do this, but we have no other way to get at the active runtime.
8892
// TODO: There's actually a way to get a handle to the runtime as a function argument. Switch
8993
// to doing this instead.

kimchi-stubs/src/pasta_fq_plonk_proof.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ pub fn caml_pasta_fq_plonk_proof_create(
7979
// public input
8080
let public_input = witness[0][0..index.cs.public].to_vec();
8181

82+
if std::env::var("KIMCHI_PROVER_DUMP_ARGUMENTS").is_ok() {
83+
kimchi::bench::bench_arguments_dump_into_file(&index.cs, &witness, &runtime_tables, &prev);
84+
}
85+
8286
// NB: This method is designed only to be used by tests. However, since
8387
// creating a new reference will cause `drop` to be called on it once we are
8488
// done with it. Since `drop` calls `caml_shutdown` internally, we *really,

kimchi/src/circuits/constraints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ where
234234
gates: Arc<Vec<CircuitGate<F>>>,
235235
zk_rows: u64,
236236
feature_flags: FeatureFlags,
237-
lazy_mode: bool,
238237
#[serde_as(as = "Vec<o1_utils::serialization::SerdeAs>")]
239238
sid: Vec<F>,
240239
#[serde_as(as = "[o1_utils::serialization::SerdeAs; PERMUTS]")]

kimchi/tests/test_constraints.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,43 @@ fn test_lookup_domain_size_computation() {
8686
assert_eq!(res.domain.d1.size, expected_domain_size);
8787
});
8888
}
89+
90+
#[test]
91+
fn test_constraint_system_serialization_deserialization() {
92+
let (next_start, range_check_gates_0) = CircuitGate::<Fp>::create_range_check(0); /* 1 range_check gate */
93+
let (next_start, range_check_gates_1) = CircuitGate::<Fp>::create_range_check(next_start); /* 1 range_check gate */
94+
let (next_start, xor_gates_0) = CircuitGate::<Fp>::create_xor_gadget(next_start, 3); /* 1 xor gate */
95+
let (next_start, xor_gates_1) = CircuitGate::<Fp>::create_xor_gadget(next_start, 3); /* 1 xor gate */
96+
let (_, ffm_gates) =
97+
CircuitGate::<Fp>::create_foreign_field_mul(next_start, &Fq::modulus_biguint()); /* 1 foreign field multiplication gate */
98+
let circuit_gates: Vec<CircuitGate<Fp>> = range_check_gates_0
99+
.into_iter()
100+
.chain(range_check_gates_1)
101+
.chain(xor_gates_0)
102+
.chain(xor_gates_1)
103+
.chain(ffm_gates)
104+
.collect(); /* 2 range check gates + 2 xor gates + 1 foreign field multiplication */
105+
106+
let (number_of_table_ids, size) = (10, 10);
107+
108+
let builder = ConstraintSystem::create(circuit_gates.clone());
109+
110+
let table_ids: Vec<i32> = (3..number_of_table_ids + 3).collect();
111+
let lookup_tables: Vec<LookupTable<Fp>> = table_ids
112+
.into_iter()
113+
.map(|id| {
114+
let indexes: Vec<u32> = (0..size).collect();
115+
let data: Vec<Fp> = indexes.into_iter().map(Fp::from).collect();
116+
LookupTable {
117+
id,
118+
data: vec![data],
119+
}
120+
})
121+
.collect();
122+
let cs = builder.lookup(lookup_tables).build().unwrap();
123+
124+
let bytes_cs: Vec<u8> = rmp_serde::to_vec(&cs).unwrap();
125+
126+
// Should not panic
127+
let _: ConstraintSystem<Fp> = rmp_serde::from_read(bytes_cs.as_slice()).unwrap();
128+
}

scripts/bench-criterion-mina-circuits.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
echo "Starting bench-criterion-mina-circuits.sh"
4+
35
set -ex
46

57
# Queries all test circuits from the cloud
@@ -25,6 +27,13 @@ for test_file in $(list_objects); do
2527
# The noise threshold is higher than default because our CI machines are not super precise
2628
REPORT_FILE=/tmp/criterion-result-$(date +%Y-%m-%d_%H-%M-%S).txt
2729
BENCH_PROOF_CREATION_MINA_INPUTS=$LOCAL_PATH cargo bench --bench proof_criterion_mina -- --noise-threshold 0.05 --baseline $BASELINE_NAME 2>&1 | tee $REPORT_FILE
30+
31+
BENCH_EXIT_STATUS=${PIPESTATUS[0]}
32+
if [ $BENCH_EXIT_STATUS -ne 0 ]; then
33+
echo "Cargo bench command failed with exit status $BENCH_EXIT_STATUS"
34+
exit $BENCH_EXIT_STATUS
35+
fi
36+
2837
# Fail if there is 'regressed' in the logs
2938
grep 'regressed' $REPORT_FILE && exit 1 || echo "No regressions detected, continuing..."
3039
else

0 commit comments

Comments
 (0)