From 15fe1c68f58b1b041f3ea148040fc020df17ca1e Mon Sep 17 00:00:00 2001 From: iquerejeta Date: Mon, 3 Feb 2025 11:01:52 +0100 Subject: [PATCH] Remove instance from cost model (use only nb_instances) --- examples/proof-size.rs | 2 +- src/dev/cost_model.rs | 63 ++++++++++-------------------------------- 2 files changed, 15 insertions(+), 50 deletions(-) diff --git a/examples/proof-size.rs b/examples/proof-size.rs index 88308eb3b..ba1a0dd8a 100644 --- a/examples/proof-size.rs +++ b/examples/proof-size.rs @@ -88,7 +88,7 @@ const K: u32 = 11; fn main() { let circuit = TestCircuit {}; - let model = from_circuit_to_circuit_model::<_, _, 32, 32>(Some(K), &circuit, vec![]); + let model = from_circuit_to_circuit_model::<_, _, 32, 32>(Some(K), &circuit, 10); println!( "Cost of circuit with 8 bit lookup table: \n{}", serde_json::to_string_pretty(&model).unwrap() diff --git a/src/dev/cost_model.rs b/src/dev/cost_model.rs index 08d22173a..c6e2f0223 100644 --- a/src/dev/cost_model.rs +++ b/src/dev/cost_model.rs @@ -19,7 +19,7 @@ use ff::{Field, FromUniformBytes}; use serde::Deserialize; use serde_derive::Serialize; -use super::{CellValue, InstanceValue, Region}; +use super::{CellValue, Region}; /// Options to build a circuit specification to measure the cost model of. #[derive(Debug)] @@ -234,9 +234,9 @@ pub fn from_circuit_to_circuit_model< >( k: Option, circuit: &C, - instances: Vec>, + nb_instances: usize, ) -> CircuitModel { - let options = from_circuit_to_cost_model_options(k, circuit, instances); + let options = from_circuit_to_cost_model_options(k, circuit, nb_instances); options.into_circuit_model::() } @@ -245,14 +245,13 @@ pub fn from_circuit_to_circuit_model< pub fn from_circuit_to_cost_model_options, C: Circuit>( k_upper_bound: Option, circuit: &C, - instances: Vec>, + nb_instances: usize, ) -> CostOptions { - let instance_len = instances.iter().map(Vec::len).max().unwrap_or(0); let prover = if let Some(k) = k_upper_bound { - DevAssembly::run(k, circuit, instances).unwrap() + DevAssembly::run(k, circuit).unwrap() } else { let k = k_from_circuit(circuit); - DevAssembly::run(k, circuit, instances).unwrap() + DevAssembly::run(k, circuit).unwrap() }; let cs = prover.cs; @@ -328,12 +327,12 @@ pub fn from_circuit_to_cost_model_options, let min_k = [ rows_count + cs.blinding_factors(), table_rows_count + cs.blinding_factors(), - instance_len, + nb_instances, ] .into_iter() .max() .unwrap(); - if min_k == instance_len { + if min_k == nb_instances { println!("WARNING: The dominant factor in your circuit's size is the number of public inputs, which causes the verifier to perform linear work."); } @@ -366,8 +365,6 @@ struct DevAssembly { fixed: Vec>>, // The advice cells in the circuit, arranged as [column][row]. _advice: Vec>>, - // The instance cells in the circuit, arranged as [column][row]. - instance: Vec>>, selectors: Vec>, @@ -387,7 +384,6 @@ impl + Ord> DevAssembly { pub fn run>( k: u32, circuit: &ConcreteCircuit, - instance: Vec>, ) -> Result { let n = 1 << k; @@ -406,28 +402,6 @@ impl + Ord> DevAssembly { k, ); - assert_eq!(instance.len(), cs.num_instance_columns); - - let instance = instance - .into_iter() - .map(|instance| { - assert!( - instance.len() <= n - (cs.blinding_factors() + 1), - "instance.len={}, n={}, cs.blinding_factors={}", - instance.len(), - n, - cs.blinding_factors() - ); - - let mut instance_values = vec![InstanceValue::Padding; n]; - for (idx, value) in instance.into_iter().enumerate() { - instance_values[idx] = InstanceValue::Assigned(value); - } - - instance_values - }) - .collect::>(); - // Fixed columns contain no blinding factors. let fixed = vec![vec![CellValue::Unassigned; n]; cs.num_fixed_columns]; let selectors = vec![vec![false; n]; cs.num_selectors]; @@ -466,7 +440,6 @@ impl + Ord> DevAssembly { current_region: None, fixed, _advice, - instance, selectors, _challenges, permutation, @@ -567,21 +540,13 @@ impl Assignment for DevAssembly { Ok(()) } - fn query_instance(&self, column: Column, row: usize) -> Result, Error> { - assert!( - self.usable_rows.contains(&row), - "row={}, usable_rows={:?}, k={}", - row, - self.usable_rows, - self.k, - ); + fn query_instance(&self, _column: Column, row: usize) -> Result, Error> { + if !self.usable_rows.contains(&row) { + return Err(Error::not_enough_rows_available(self.k)); + } - Ok(self - .instance - .get(column.index()) - .and_then(|column| column.get(row)) - .map(|v| circuit::Value::known(v.value())) - .expect("bound failure")) + // There is no instance in this context. + Ok(Value::unknown()) } fn assign_advice(