feat: Cache table when same identifier and improve permutation checks in `MockProver`

This commit is contained in:
han0110 2022-07-07 14:51:37 +08:00
parent f08632016f
commit 984105592c
1 changed files with 32 additions and 19 deletions

View File

@ -5,6 +5,7 @@ use std::collections::HashSet;
use std::fmt; use std::fmt;
use std::iter; use std::iter;
use std::ops::{Add, Mul, Neg, Range}; use std::ops::{Add, Mul, Neg, Range};
use std::time::{Duration, Instant};
use ff::Field; use ff::Field;
@ -701,6 +702,8 @@ impl<F: FieldExt> MockProver<F> {
}) })
}); });
let mut cached_table = Vec::new();
let mut cached_table_identifier = Vec::new();
// Check that all lookups exist in their respective tables. // Check that all lookups exist in their respective tables.
let lookup_errors = let lookup_errors =
self.cs self.cs
@ -760,9 +763,17 @@ impl<F: FieldExt> MockProver<F> {
.map(move |c| load(c, self.usable_rows.end - 1)) .map(move |c| load(c, self.usable_rows.end - 1))
.collect(); .collect();
let table_identifier = lookup
.table_expressions
.iter()
.map(Expression::identifier)
.collect::<Vec<_>>();
if table_identifier != cached_table_identifier {
cached_table_identifier = table_identifier;
// In the real prover, the lookup expressions are never enforced on // In the real prover, the lookup expressions are never enforced on
// unusable rows, due to the (1 - (l_last(X) + l_blind(X))) term. // unusable rows, due to the (1 - (l_last(X) + l_blind(X))) term.
let mut table: Vec<Vec<_>> = self cached_table = self
.usable_rows .usable_rows
.clone() .clone()
.filter_map(|table_row| { .filter_map(|table_row| {
@ -779,7 +790,9 @@ impl<F: FieldExt> MockProver<F> {
} }
}) })
.collect(); .collect();
table.sort_unstable(); cached_table.sort_unstable();
}
let table = &cached_table;
let mut inputs: Vec<(Vec<_>, usize)> = lookup_input_row_ids let mut inputs: Vec<(Vec<_>, usize)> = lookup_input_row_ids
.clone() .clone()