mirror of https://github.com/zcash/halo2.git
Use ranges to clarify bounds on cell assignment.
This commit is contained in:
parent
00b0b6c535
commit
bd29ebdb05
16
src/dev.rs
16
src/dev.rs
|
@ -3,6 +3,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
use std::ops::RangeTo;
|
||||
|
||||
use ff::Field;
|
||||
|
||||
|
@ -244,9 +245,8 @@ pub struct MockProver<F: Group + Field> {
|
|||
|
||||
permutation: permutation::keygen::Assembly,
|
||||
|
||||
// All rows including and above this one are off
|
||||
// limits due to blinding factors.
|
||||
upper_bound_cell_index: usize,
|
||||
// A range of available rows for assignment and copies.
|
||||
usable_rows: RangeTo<usize>,
|
||||
}
|
||||
|
||||
impl<F: Field + Group> Assignment<F> for MockProver<F> {
|
||||
|
@ -278,7 +278,7 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
|
|||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
{
|
||||
if row >= self.upper_bound_cell_index {
|
||||
if !self.usable_rows.contains(&row) {
|
||||
return Err(Error::BoundsFailure);
|
||||
}
|
||||
|
||||
|
@ -319,7 +319,7 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
|
|||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
{
|
||||
if row >= self.upper_bound_cell_index {
|
||||
if !self.usable_rows.contains(&row) {
|
||||
return Err(Error::BoundsFailure);
|
||||
}
|
||||
|
||||
|
@ -350,7 +350,7 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
|
|||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
{
|
||||
if row >= self.upper_bound_cell_index {
|
||||
if !self.usable_rows.contains(&row) {
|
||||
return Err(Error::BoundsFailure);
|
||||
}
|
||||
|
||||
|
@ -375,7 +375,7 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
|
|||
right_column: Column<Any>,
|
||||
right_row: usize,
|
||||
) -> Result<(), crate::plonk::Error> {
|
||||
if left_row >= self.upper_bound_cell_index || right_row >= self.upper_bound_cell_index {
|
||||
if !self.usable_rows.contains(&left_row) || !self.usable_rows.contains(&right_row) {
|
||||
return Err(Error::BoundsFailure);
|
||||
}
|
||||
|
||||
|
@ -428,7 +428,7 @@ impl<F: FieldExt> MockProver<F> {
|
|||
advice,
|
||||
instance,
|
||||
permutation,
|
||||
upper_bound_cell_index: n - (blinding_factors + 1),
|
||||
usable_rows: ..n - (blinding_factors + 1),
|
||||
};
|
||||
|
||||
ConcreteCircuit::FloorPlanner::synthesize(&mut prover, circuit, config)?;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#![allow(clippy::int_plus_one)]
|
||||
|
||||
use std::ops::RangeTo;
|
||||
|
||||
use ff::Field;
|
||||
use group::Curve;
|
||||
|
||||
|
@ -42,9 +44,8 @@ where
|
|||
struct Assembly<F: Field> {
|
||||
fixed: Vec<Polynomial<Assigned<F>, LagrangeCoeff>>,
|
||||
permutation: permutation::keygen::Assembly,
|
||||
// All rows including and above this one are off
|
||||
// limits due to blinding factors.
|
||||
upper_bound_cell_index: usize,
|
||||
// A range of available rows for assignment and copies.
|
||||
usable_rows: RangeTo<usize>,
|
||||
_marker: std::marker::PhantomData<F>,
|
||||
}
|
||||
|
||||
|
@ -71,7 +72,7 @@ impl<F: Field> Assignment<F> for Assembly<F> {
|
|||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
{
|
||||
if row >= self.upper_bound_cell_index {
|
||||
if !self.usable_rows.contains(&row) {
|
||||
return Err(Error::BoundsFailure);
|
||||
}
|
||||
// Selectors are just fixed columns.
|
||||
|
@ -117,7 +118,7 @@ impl<F: Field> Assignment<F> for Assembly<F> {
|
|||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
{
|
||||
if row >= self.upper_bound_cell_index {
|
||||
if !self.usable_rows.contains(&row) {
|
||||
return Err(Error::BoundsFailure);
|
||||
}
|
||||
|
||||
|
@ -137,8 +138,7 @@ impl<F: Field> Assignment<F> for Assembly<F> {
|
|||
right_column: Column<Any>,
|
||||
right_row: usize,
|
||||
) -> Result<(), Error> {
|
||||
// Check bounds first
|
||||
if left_row >= self.upper_bound_cell_index || right_row >= self.upper_bound_cell_index {
|
||||
if !self.usable_rows.contains(&left_row) || !self.usable_rows.contains(&right_row) {
|
||||
return Err(Error::BoundsFailure);
|
||||
}
|
||||
|
||||
|
@ -177,7 +177,7 @@ where
|
|||
let mut assembly: Assembly<C::Scalar> = Assembly {
|
||||
fixed: vec![domain.empty_lagrange_assigned(); cs.num_fixed_columns],
|
||||
permutation: permutation::keygen::Assembly::new(params.n as usize, &cs.permutation),
|
||||
upper_bound_cell_index: params.n as usize - (cs.blinding_factors() + 1),
|
||||
usable_rows: ..params.n as usize - (cs.blinding_factors() + 1),
|
||||
_marker: std::marker::PhantomData,
|
||||
};
|
||||
|
||||
|
@ -225,7 +225,7 @@ where
|
|||
let mut assembly: Assembly<C::Scalar> = Assembly {
|
||||
fixed: vec![vk.domain.empty_lagrange_assigned(); vk.cs.num_fixed_columns],
|
||||
permutation: permutation::keygen::Assembly::new(params.n as usize, &vk.cs.permutation),
|
||||
upper_bound_cell_index: params.n as usize - (vk.cs.blinding_factors() + 1),
|
||||
usable_rows: ..params.n as usize - (vk.cs.blinding_factors() + 1),
|
||||
_marker: std::marker::PhantomData,
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use ff::Field;
|
||||
use group::Curve;
|
||||
use std::iter;
|
||||
use std::ops::RangeTo;
|
||||
|
||||
use super::{
|
||||
circuit::{
|
||||
|
@ -128,7 +129,7 @@ pub fn create_proof<
|
|||
struct WitnessCollection<'a, F: Field> {
|
||||
pub advice: Vec<Polynomial<Assigned<F>, LagrangeCoeff>>,
|
||||
instances: &'a [&'a [F]],
|
||||
upper_bound_cell_index: usize,
|
||||
usable_rows: RangeTo<usize>,
|
||||
_marker: std::marker::PhantomData<F>,
|
||||
}
|
||||
|
||||
|
@ -185,7 +186,7 @@ pub fn create_proof<
|
|||
A: FnOnce() -> AR,
|
||||
AR: Into<String>,
|
||||
{
|
||||
if row >= self.upper_bound_cell_index {
|
||||
if !self.usable_rows.contains(&row) {
|
||||
return Err(Error::BoundsFailure);
|
||||
}
|
||||
|
||||
|
@ -241,6 +242,8 @@ pub fn create_proof<
|
|||
}
|
||||
}
|
||||
|
||||
let unusable_rows_start = params.n as usize - (meta.blinding_factors() + 1);
|
||||
|
||||
let mut witness = WitnessCollection {
|
||||
advice: vec![domain.empty_lagrange_assigned(); meta.num_advice_columns],
|
||||
instances,
|
||||
|
@ -248,7 +251,7 @@ pub fn create_proof<
|
|||
// cells that exist within inactive rows, which include some
|
||||
// number of blinding factors and an extra row for use in the
|
||||
// permutation argument.
|
||||
upper_bound_cell_index: params.n as usize - (meta.blinding_factors() + 1),
|
||||
usable_rows: ..unusable_rows_start,
|
||||
_marker: std::marker::PhantomData,
|
||||
};
|
||||
|
||||
|
@ -259,7 +262,7 @@ pub fn create_proof<
|
|||
|
||||
// Add blinding factors to advice columns
|
||||
for advice in &mut advice {
|
||||
for cell in &mut advice[witness.upper_bound_cell_index..] {
|
||||
for cell in &mut advice[unusable_rows_start..] {
|
||||
*cell = C::Scalar::rand();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue