Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix number of rows #3

Merged
merged 4 commits into from
Apr 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions halo2_proofs/src/dev/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct CostOptions {

/// Minimum value of k needed to account for the circuit
pub min_k: usize,

/// Expanded rows count, which does not account for compression (where
/// multiple regions can use the same rows).
pub expanded_rows_count: usize,
Expand Down Expand Up @@ -139,7 +139,7 @@ impl Shuffle {

/// Information about how a gate (see plonk::circuit::Gate) is used in the
/// circuit.
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GateUsage {
/// The name of the gate.
pub name: String,
Expand Down Expand Up @@ -353,16 +353,25 @@ pub fn from_circuit_to_cost_model_options<F: Ord + Field + FromUniformBytes<64>,
let mut expanded_rows_count = 0;
let mut compressed_rows_count = 0;
for region in prover.regions {
if region.name.contains("table") { // Account for lookup tables separately
let (start, end) = region.rows.expect("region.rows should be known by now");
min_k = std::cmp::max(min_k, end - start);
} else {
let (start, end) = region.rows.expect("region.rows should be known by now");
expanded_rows_count = expanded_rows_count + ((end - start) + 1);
compressed_rows_count = std::cmp::max(compressed_rows_count, end + 1);
}
// If `region.rows == None`, then that region has no rows (e.g. just copy constraints)
if let Some((start, end)) = region.rows {
// A region is a _table region_ if all of its columns are `Fixed`
// columns (see that [`plonk::circuit::TableColumn` is a wrapper
// around `Column<Fixed>`]). All of a table region's rows are
// counted towards `table_rows_count.`
iquerejeta marked this conversation as resolved.
Show resolved Hide resolved
if region
.columns
.iter()
.all(|c| *c.column_type() == crate::plonk::Any::Fixed)
{
min_k = std::cmp::max(min_k, end - start);
} else {
expanded_rows_count += (end - start) + 1;
iquerejeta marked this conversation as resolved.
Show resolved Hide resolved
compressed_rows_count = std::cmp::max(compressed_rows_count, end + 1);
}

min_k = std::cmp::max(min_k, compressed_rows_count);
min_k = std::cmp::max(min_k, compressed_rows_count);
}
}
(expanded_rows_count, compressed_rows_count, min_k)
};
Expand Down Expand Up @@ -390,7 +399,6 @@ pub fn from_circuit_to_cost_model_options<F: Ord + Field + FromUniformBytes<64>,
})
.collect();


CostOptions {
advice,
instance,
Expand Down
Loading