From 12f1a2f8be2173e1217ac659ffb7126ec62d1ff0 Mon Sep 17 00:00:00 2001 From: Alex Ozdemir Date: Thu, 26 Sep 2024 11:57:28 -0700 Subject: [PATCH] Better R1cs stats. --- examples/circ.rs | 18 +++++++++++++----- src/target/r1cs/mod.rs | 12 ++++++------ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/examples/circ.rs b/examples/circ.rs index d82e2ac8..3d57037b 100644 --- a/examples/circ.rs +++ b/examples/circ.rs @@ -44,7 +44,7 @@ use circ::target::r1cs::{ proof::{CommitProofSystem, ProofSystem}, }; #[cfg(feature = "r1cs")] -use circ::target::r1cs::{opt::reduce_linearities, trans::to_r1cs}; +use circ::target::r1cs::{opt::reduce_linearities, trans::to_r1cs, R1csStats}; #[cfg(feature = "smt")] use circ::target::smt::find_model; use circ_fields::FieldT; @@ -311,19 +311,26 @@ fn main() { trace!("IR: {}", circ::ir::term::text::serialize_computation(cs)); let mut r1cs = to_r1cs(cs, cfg()); if cfg().r1cs.profile { - println!("R1CS stats: {:#?}", r1cs.stats()); + println!("Pre-opt r1cs stats: {:#?}", r1cs.stats()); } println!("Running r1cs optimizations "); r1cs = reduce_linearities(r1cs, cfg()); - println!("Final R1cs size: {}", r1cs.constraints().len()); if cfg().r1cs.profile { - println!("R1CS stats: {:#?}", r1cs.stats()); + println!("Post-opt r1cs stats: {:#?}", r1cs.stats()); } + let n_constraints = r1cs.stats().n_constraints; + let n_vars = r1cs.stats().n_vars; + let n_entries = r1cs.stats().n_entries(); + let (prover_data, verifier_data) = r1cs.finalize(cs); + println!( - "Final R1cs rounds: {}", + "Final r1cs: {} constraints, {} variables, {} entries, {} rounds", + n_constraints, + n_vars, + n_entries, prover_data.precompute.stage_sizes().count() - 1 ); println!( @@ -331,6 +338,7 @@ fn main() { prover_data.precompute.num_steps(), prover_data.precompute.num_step_args() ); + match action { ProofAction::Count => (), #[cfg(feature = "bellman")] diff --git a/src/target/r1cs/mod.rs b/src/target/r1cs/mod.rs index 8e4c7a70..ba253f2c 100644 --- a/src/target/r1cs/mod.rs +++ b/src/target/r1cs/mod.rs @@ -443,12 +443,12 @@ impl R1cs { let s = &mut self.stats; s.n_constraints = self.constraints.len() as u32; for (a, b, c) in &self.constraints { - let n_a = a.monomials.len() + !a.constant.is_zero() as usize; - let n_b = b.monomials.len() + !b.constant.is_zero() as usize; - let n_c = c.monomials.len() + !c.constant.is_zero() as usize; - s.n_a_entries += n_a as u32; - s.n_b_entries += n_b as u32; - s.n_c_entries += n_c as u32; + let n_a = a.monomials.len() as u32 + !a.constant.is_zero() as u32; + let n_b = b.monomials.len() as u32 + !b.constant.is_zero() as u32; + let n_c = c.monomials.len() as u32 + !c.constant.is_zero() as u32; + s.n_a_entries += n_a; + s.n_b_entries += n_b; + s.n_c_entries += n_c; } } }