mirror of https://github.com/zcash/halo2.git
dev: Handle too-small `k` error in `CircuitLayout::render`
In most places within `CircuitLayout`, we are flexible on `k`. However, for tracking selectors we need to know the number of rows. We could change this, but given that we also want the number of rows to be accurate for rendering unusable rows, we can instead use this as an opportunity to inform the user that they will need to bump `k`.
This commit is contained in:
parent
eb88a2ebef
commit
64680a1a2d
|
@ -18,6 +18,8 @@ and this project adheres to Rust's notion of
|
||||||
- `Error::SynthesisError` is now `Error::Synthesis`.
|
- `Error::SynthesisError` is now `Error::Synthesis`.
|
||||||
- `Error::TranscriptError` is now `Error::Transcript`, and stores the
|
- `Error::TranscriptError` is now `Error::Transcript`, and stores the
|
||||||
underlying `io::Error`.
|
underlying `io::Error`.
|
||||||
|
- `halo2::dev::CircuitLayout::render` now takes `k` as a `u32`, matching the
|
||||||
|
regular parameter APIs.
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
- `halo2::arithmetic::BatchInvert` (use `ff::BatchInvert` instead).
|
- `halo2::arithmetic::BatchInvert` (use `ff::BatchInvert` instead).
|
||||||
|
|
|
@ -33,7 +33,8 @@ use crate::plonk::{
|
||||||
/// .unwrap();
|
/// .unwrap();
|
||||||
///
|
///
|
||||||
/// let circuit = MyCircuit::default();
|
/// let circuit = MyCircuit::default();
|
||||||
/// CircuitLayout::default().render(&circuit, &drawing_area).unwrap();
|
/// let k = 5; // Suitable size for MyCircuit
|
||||||
|
/// CircuitLayout::default().render(k, &circuit, &drawing_area).unwrap();
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct CircuitLayout {
|
pub struct CircuitLayout {
|
||||||
|
@ -84,7 +85,7 @@ impl CircuitLayout {
|
||||||
/// Renders the given circuit on the given drawing area.
|
/// Renders the given circuit on the given drawing area.
|
||||||
pub fn render<F: Field, ConcreteCircuit: Circuit<F>, DB: DrawingBackend>(
|
pub fn render<F: Field, ConcreteCircuit: Circuit<F>, DB: DrawingBackend>(
|
||||||
self,
|
self,
|
||||||
k: usize,
|
k: u32,
|
||||||
circuit: &ConcreteCircuit,
|
circuit: &ConcreteCircuit,
|
||||||
drawing_area: &DrawingArea<DB, Shift>,
|
drawing_area: &DrawingArea<DB, Shift>,
|
||||||
) -> Result<(), DrawingAreaErrorKind<DB::ErrorType>> {
|
) -> Result<(), DrawingAreaErrorKind<DB::ErrorType>> {
|
||||||
|
@ -95,7 +96,7 @@ impl CircuitLayout {
|
||||||
// Collect the layout details.
|
// Collect the layout details.
|
||||||
let mut cs = ConstraintSystem::default();
|
let mut cs = ConstraintSystem::default();
|
||||||
let config = ConcreteCircuit::configure(&mut cs);
|
let config = ConcreteCircuit::configure(&mut cs);
|
||||||
let mut layout = Layout::new(n, cs.num_selectors);
|
let mut layout = Layout::new(k, n, cs.num_selectors);
|
||||||
ConcreteCircuit::FloorPlanner::synthesize(
|
ConcreteCircuit::FloorPlanner::synthesize(
|
||||||
&mut layout,
|
&mut layout,
|
||||||
circuit,
|
circuit,
|
||||||
|
@ -336,6 +337,7 @@ struct Region {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Layout {
|
struct Layout {
|
||||||
|
k: u32,
|
||||||
regions: Vec<Region>,
|
regions: Vec<Region>,
|
||||||
current_region: Option<usize>,
|
current_region: Option<usize>,
|
||||||
total_rows: usize,
|
total_rows: usize,
|
||||||
|
@ -349,8 +351,9 @@ struct Layout {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Layout {
|
impl Layout {
|
||||||
fn new(n: usize, num_selectors: usize) -> Self {
|
fn new(k: u32, n: usize, num_selectors: usize) -> Self {
|
||||||
Layout {
|
Layout {
|
||||||
|
k,
|
||||||
regions: vec![],
|
regions: vec![],
|
||||||
current_region: None,
|
current_region: None,
|
||||||
total_rows: 0,
|
total_rows: 0,
|
||||||
|
@ -417,7 +420,12 @@ impl<F: Field> Assignment<F> for Layout {
|
||||||
A: FnOnce() -> AR,
|
A: FnOnce() -> AR,
|
||||||
AR: Into<String>,
|
AR: Into<String>,
|
||||||
{
|
{
|
||||||
self.selectors[selector.0][row] = true;
|
if let Some(cell) = self.selectors[selector.0].get_mut(row) {
|
||||||
|
*cell = true;
|
||||||
|
} else {
|
||||||
|
return Err(Error::not_enough_rows_available(self.k, row + 1));
|
||||||
|
}
|
||||||
|
|
||||||
self.update((*selector).into(), row);
|
self.update((*selector).into(), row);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue