Merge pull request #448 from zcash/dev-fill-from-row

[dev] Implement `Assignment::fill_from_row()` for `MockProver`.
This commit is contained in:
str4d 2022-01-04 13:12:55 +00:00 committed by GitHub
commit f565883db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 7 deletions

View File

@ -553,14 +553,18 @@ impl<F: Field + Group> Assignment<F> for MockProver<F> {
fn fill_from_row( fn fill_from_row(
&mut self, &mut self,
_: Column<Fixed>, col: Column<Fixed>,
from_row: usize, from_row: usize,
_: Option<Assigned<F>>, to: Option<Assigned<F>>,
) -> Result<(), Error> { ) -> Result<(), Error> {
if !self.usable_rows.contains(&from_row) { if !self.usable_rows.contains(&from_row) {
return Err(Error::not_enough_rows_available(self.k)); return Err(Error::not_enough_rows_available(self.k));
} }
for row in self.usable_rows.clone().skip(from_row) {
self.assign_fixed(|| "", col, row, || to.ok_or(Error::Synthesis))?;
}
Ok(()) Ok(())
} }
@ -992,7 +996,10 @@ mod tests {
use super::{LookupFailure, MockProver, VerifyFailure}; use super::{LookupFailure, MockProver, VerifyFailure};
use crate::{ use crate::{
circuit::{Layouter, SimpleFloorPlanner}, circuit::{Layouter, SimpleFloorPlanner},
plonk::{Advice, Any, Circuit, Column, ConstraintSystem, Error, Selector, TableColumn}, plonk::{
Advice, Any, Circuit, Column, ConstraintSystem, Error, Expression, Selector,
TableColumn,
},
poly::Rotation, poly::Rotation,
}; };
@ -1095,8 +1102,10 @@ mod tests {
let q = cells.query_selector(q); let q = cells.query_selector(q);
// If q is enabled, a must be in the table. // If q is enabled, a must be in the table.
// Zero is in the table, which satisfies the disabled case. // When q is not enabled, lookup the default value instead.
vec![(q * a, table)] let not_q = Expression::Constant(Fp::one()) - q.clone();
let default = Expression::Constant(Fp::from(2));
vec![(q * a + not_q * default, table)]
}); });
FaultyCircuitConfig { a, q, table } FaultyCircuitConfig { a, q, table }
@ -1114,12 +1123,12 @@ mod tests {
layouter.assign_table( layouter.assign_table(
|| "Doubling table", || "Doubling table",
|mut table| { |mut table| {
(0..(1 << (K - 1))) (1..(1 << (K - 1)))
.map(|i| { .map(|i| {
table.assign_cell( table.assign_cell(
|| format!("table[{}] = {}", i, 2 * i), || format!("table[{}] = {}", i, 2 * i),
config.table, config.table,
i, i - 1,
|| Ok(Fp::from(2 * i as u64)), || Ok(Fp::from(2 * i as u64)),
) )
}) })