Remove Polynomial from backend interface

This commit is contained in:
Eduard S. 2024-01-09 11:58:51 +01:00
parent 1bc84caf30
commit 582d6d5dee
3 changed files with 41 additions and 31 deletions

View File

@ -1692,7 +1692,8 @@ pub struct PreprocessingV2<F: Field> {
pub(crate) permutation: permutation::keygen::Assembly,
// TODO(Edu): Replace this by Vec<Vec<F>>. Requires some methods of Polynomial to take Vec<F>
// instead
pub(crate) fixed: Vec<Polynomial<F, LagrangeCoeff>>,
// pub(crate) fixed: Vec<Polynomial<F, LagrangeCoeff>>,
pub(crate) fixed: Vec<Vec<F>>,
}
/// This is a description of a low level Plonkish compiled circuit. Contains the Constraint System
@ -1858,7 +1859,8 @@ impl<'a, F: Field, ConcreteCircuit: Circuit<F>> WitnessCalculator<'a, F, Concret
&mut self,
phase: u8,
challenges: &HashMap<usize, F>,
) -> Result<Vec<Option<Polynomial<Assigned<F>, LagrangeCoeff>>>, Error> {
// ) -> Result<Vec<Option<Polynomial<Assigned<F>, LagrangeCoeff>>>, Error> {
) -> Result<Vec<Option<Vec<Assigned<F>>>>, Error> {
if phase != self.next_phase {
return Err(Error::Other(format!(
"Expected phase {}, got {}",
@ -1874,7 +1876,7 @@ impl<'a, F: Field, ConcreteCircuit: Circuit<F>> WitnessCalculator<'a, F, Concret
let mut witness = WitnessCollection {
k: self.k,
current_phase,
advice: vec![Polynomial::new_empty(self.n, F::ZERO.into()); self.cs.num_advice_columns],
advice: vec![vec![Assigned::Zero; self.n]; self.cs.num_advice_columns],
instances: self.instances,
challenges,
// The prover will not be allowed to assign values to advice
@ -1974,11 +1976,8 @@ pub fn compile_circuit<F: Field, ConcreteCircuit: Circuit<F>>(
let selectors = std::mem::take(&mut assembly.selectors);
cs.directly_convert_selectors_to_fixed(selectors)
};
fixed.extend(
selector_polys
.into_iter()
.map(|poly| Polynomial::new_lagrange_from_vec(poly)),
);
let mut fixed: Vec<_> = fixed.into_iter().map(|p| p.values).collect();
fixed.extend(selector_polys.into_iter());
let cs2 = ConstraintSystemV2Backend {
num_fixed_columns: cs.num_fixed_columns,

View File

@ -231,7 +231,14 @@ where
.preprocessing
.fixed
.iter()
.map(|poly| params.commit_lagrange(poly, Blind::default()).to_affine())
.map(|poly| {
params
.commit_lagrange(
&Polynomial::new_lagrange_from_vec(poly.clone()),
Blind::default(),
)
.to_affine()
})
.collect();
Ok(VerifyingKey::from_parts(
@ -299,7 +306,10 @@ where
.preprocessing
.fixed
.iter()
.map(|poly| vk.domain.lagrange_to_coeff(poly.clone()))
.map(|poly| {
vk.domain
.lagrange_to_coeff(Polynomial::new_lagrange_from_vec(poly.clone()))
})
.collect();
let fixed_cosets = fixed_polys
@ -355,7 +365,13 @@ where
l0,
l_last,
l_active_row,
fixed_values: circuit.preprocessing.fixed.clone(),
fixed_values: circuit
.preprocessing
.fixed
.clone()
.into_iter()
.map(Polynomial::new_lagrange_from_vec)
.collect(),
fixed_polys,
fixed_cosets,
permutation: permutation_pk,

View File

@ -94,7 +94,8 @@ impl<
phase: u8,
// TODO: Turn this into Vec<Option<Vec<F>>>. Requires batch_invert_assigned to work with
// Vec<F>
witness: Vec<Option<Polynomial<Assigned<Scheme::Scalar>, LagrangeCoeff>>>,
// witness: Vec<Option<Polynomial<Assigned<Scheme::Scalar>, LagrangeCoeff>>>,
witness: Vec<Option<Vec<Assigned<Scheme::Scalar>>>>,
) -> Result<HashMap<usize, Scheme::Scalar>, Error>
where
Scheme::Scalar: WithSmallOrderMulGroup<3> + FromUniformBytes<64>,
@ -265,7 +266,8 @@ impl<
phase: u8,
// TODO: Turn this into Vec<Option<Vec<F>>>. Requires batch_invert_assigned to work with
// Vec<F>
witness: Vec<Vec<Option<Polynomial<Assigned<Scheme::Scalar>, LagrangeCoeff>>>>,
// witness: Vec<Vec<Option<Polynomial<Assigned<Scheme::Scalar>, LagrangeCoeff>>>>,
witness: Vec<Vec<Option<Vec<Assigned<Scheme::Scalar>>>>>,
) -> Result<HashMap<usize, Scheme::Scalar>, Error>
where
Scheme::Scalar: WithSmallOrderMulGroup<3> + FromUniformBytes<64>,
@ -304,11 +306,10 @@ impl<
})
.collect::<BTreeSet<_>>();
// TODO: Check that witness.len() is the expected number of advice columns.
if witness.len() != advice.len() {
return Err(Error::Other("witness.len() != advice.len()".to_string()));
}
for witness_circuit in witness.iter() {
for witness_circuit in &witness {
if witness_circuit.len() != meta.num_advice_columns {
return Err(Error::Other(format!(
"unexpected length in witness_circuitk. Got {}, expected {}",
@ -316,20 +317,8 @@ impl<
meta.num_advice_columns,
)));
}
for witness_column in witness_circuit.iter().flatten() {
if witness_column.len() != self.params.n() as usize {
return Err(Error::Other(format!(
"unexpected length in witness_column. Got {}, expected {}",
witness_column.len(),
self.params.n()
)));
}
}
}
// Check that all current_phase advice columns are Some, and their length is correct
for witness in &witness {
for (column_index, advice_column) in witness.iter().enumerate() {
// Check that all current_phase advice columns are Some, and their length is correct
for (column_index, advice_column) in witness_circuit.iter().enumerate() {
if column_indices.contains(&column_index) {
match advice_column {
None => {
@ -420,7 +409,13 @@ impl<
};
for (witness, advice) in witness.into_iter().zip(advice.iter_mut()) {
commit_phase_fn(advice, witness)?;
commit_phase_fn(
advice,
witness
.into_iter()
.map(|v| v.map(Polynomial::new_lagrange_from_vec))
.collect(),
)?;
}
for (index, phase) in meta.challenge_phase.iter().enumerate() {
@ -755,7 +750,7 @@ impl<
pub(crate) struct WitnessCollection<'a, F: Field> {
pub(crate) k: u32,
pub(crate) current_phase: sealed::Phase,
pub(crate) advice: Vec<Polynomial<Assigned<F>, LagrangeCoeff>>,
pub(crate) advice: Vec<Vec<Assigned<F>>>,
// pub(crate) unblinded_advice: HashSet<usize>,
pub(crate) challenges: &'a HashMap<usize, F>,
pub(crate) instances: &'a [&'a [F]],