mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Make getters for column index() and column_type()
This commit is contained in:
parent
0519a522aa
commit
766caf9214
4 changed files with 44 additions and 31 deletions
|
|
@ -13,8 +13,18 @@ pub trait ColumnType: 'static + Sized {}
|
|||
/// A column with an index and type
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct Column<C: ColumnType> {
|
||||
pub(crate) index: usize,
|
||||
pub(crate) column_type: C,
|
||||
index: usize,
|
||||
column_type: C,
|
||||
}
|
||||
|
||||
impl<C: ColumnType> Column<C> {
|
||||
pub(crate) fn index(&self) -> usize {
|
||||
self.index
|
||||
}
|
||||
|
||||
pub(crate) fn column_type(&self) -> &C {
|
||||
&self.column_type
|
||||
}
|
||||
}
|
||||
|
||||
/// An advice column
|
||||
|
|
@ -48,7 +58,7 @@ impl ColumnType for Any {}
|
|||
impl From<Column<Advice>> for Column<Any> {
|
||||
fn from(advice: Column<Advice>) -> Column<Any> {
|
||||
Column {
|
||||
index: advice.index,
|
||||
index: advice.index(),
|
||||
column_type: Any::Advice,
|
||||
}
|
||||
}
|
||||
|
|
@ -57,7 +67,7 @@ impl From<Column<Advice>> for Column<Any> {
|
|||
impl From<Column<Fixed>> for Column<Any> {
|
||||
fn from(advice: Column<Fixed>) -> Column<Any> {
|
||||
Column {
|
||||
index: advice.index,
|
||||
index: advice.index(),
|
||||
column_type: Any::Fixed,
|
||||
}
|
||||
}
|
||||
|
|
@ -66,7 +76,7 @@ impl From<Column<Fixed>> for Column<Any> {
|
|||
impl From<Column<Aux>> for Column<Any> {
|
||||
fn from(advice: Column<Aux>) -> Column<Any> {
|
||||
Column {
|
||||
index: advice.index,
|
||||
index: advice.index(),
|
||||
column_type: Any::Aux,
|
||||
}
|
||||
}
|
||||
|
|
@ -76,10 +86,10 @@ impl TryFrom<Column<Any>> for Column<Advice> {
|
|||
type Error = &'static str;
|
||||
|
||||
fn try_from(any: Column<Any>) -> Result<Self, Self::Error> {
|
||||
match any.column_type {
|
||||
match any.column_type() {
|
||||
Any::Advice => {
|
||||
return Ok(Column {
|
||||
index: any.index,
|
||||
index: any.index(),
|
||||
column_type: Advice,
|
||||
})
|
||||
}
|
||||
|
|
@ -92,10 +102,10 @@ impl TryFrom<Column<Any>> for Column<Fixed> {
|
|||
type Error = &'static str;
|
||||
|
||||
fn try_from(any: Column<Any>) -> Result<Self, Self::Error> {
|
||||
match any.column_type {
|
||||
match any.column_type() {
|
||||
Any::Fixed => {
|
||||
return Ok(Column {
|
||||
index: any.index,
|
||||
index: any.index(),
|
||||
column_type: Fixed,
|
||||
})
|
||||
}
|
||||
|
|
@ -108,10 +118,10 @@ impl TryFrom<Column<Any>> for Column<Aux> {
|
|||
type Error = &'static str;
|
||||
|
||||
fn try_from(any: Column<Any>) -> Result<Self, Self::Error> {
|
||||
match any.column_type {
|
||||
match any.column_type() {
|
||||
Any::Aux => {
|
||||
return Ok(Column {
|
||||
index: any.index,
|
||||
index: any.index(),
|
||||
column_type: Aux,
|
||||
})
|
||||
}
|
||||
|
|
@ -427,7 +437,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
}
|
||||
|
||||
fn query_any_index(&mut self, column: Column<Any>, at: i32) -> usize {
|
||||
let index = match column.column_type {
|
||||
let index = match column.column_type() {
|
||||
Any::Advice => self.query_advice_index(Column::<Advice>::try_from(column).unwrap(), at),
|
||||
Any::Fixed => self.query_fixed_index(Column::<Fixed>::try_from(column).unwrap(), at),
|
||||
Any::Aux => self.query_aux_index(Column::<Aux>::try_from(column).unwrap(), at),
|
||||
|
|
@ -438,7 +448,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
|
||||
/// Query an Any column at a relative position
|
||||
pub fn query_any(&mut self, column: Column<Any>, at: i32) -> Expression<F> {
|
||||
match column.column_type {
|
||||
match column.column_type() {
|
||||
Any::Advice => Expression::Advice(
|
||||
self.query_advice_index(Column::<Advice>::try_from(column).unwrap(), at),
|
||||
),
|
||||
|
|
@ -485,7 +495,7 @@ impl<F: Field> ConstraintSystem<F> {
|
|||
}
|
||||
|
||||
pub(crate) fn get_any_query_index(&self, column: Column<Any>, at: i32) -> usize {
|
||||
let index = match column.column_type {
|
||||
let index = match column.column_type() {
|
||||
Any::Advice => {
|
||||
self.get_advice_query_index(Column::<Advice>::try_from(column).unwrap(), at)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ where
|
|||
) -> Result<(), Error> {
|
||||
*self
|
||||
.fixed
|
||||
.get_mut(column.index)
|
||||
.get_mut(column.index())
|
||||
.and_then(|v| v.get_mut(row))
|
||||
.ok_or(Error::BoundsFailure)? = to()?;
|
||||
|
||||
|
|
@ -230,7 +230,7 @@ where
|
|||
.fixed_queries
|
||||
.iter()
|
||||
.map(|&(column, at)| {
|
||||
let poly = fixed_polys[column.index].clone();
|
||||
let poly = fixed_polys[column.index()].clone();
|
||||
domain.coeff_to_extended(poly, at)
|
||||
})
|
||||
.collect();
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
) -> Result<(), Error> {
|
||||
*self
|
||||
.advice
|
||||
.get_mut(column.index)
|
||||
.get_mut(column.index())
|
||||
.and_then(|v| v.get_mut(row))
|
||||
.ok_or(Error::BoundsFailure)? = to()?;
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
.aux_queries
|
||||
.iter()
|
||||
.map(|&(column, at)| {
|
||||
let poly = aux_polys[column.index].clone();
|
||||
let poly = aux_polys[column.index()].clone();
|
||||
domain.coeff_to_extended(poly, at)
|
||||
})
|
||||
.collect();
|
||||
|
|
@ -157,7 +157,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
.advice_queries
|
||||
.iter()
|
||||
.map(|&(column, at)| {
|
||||
let poly = advice_polys[column.index].clone();
|
||||
let poly = advice_polys[column.index()].clone();
|
||||
domain.coeff_to_extended(poly, at)
|
||||
})
|
||||
.collect();
|
||||
|
|
@ -192,7 +192,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
parallelize(&mut modified_advice, |modified_advice, start| {
|
||||
for ((modified_advice, advice_value), permuted_advice_value) in modified_advice
|
||||
.iter_mut()
|
||||
.zip(witness.advice[column.index][start..].iter())
|
||||
.zip(witness.advice[column.index()][start..].iter())
|
||||
.zip(permuted_column_values[start..].iter())
|
||||
{
|
||||
*modified_advice *= &(x_0 * permuted_advice_value + &x_1 + advice_value);
|
||||
|
|
@ -226,7 +226,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
let mut deltaomega = deltaomega * &omega.pow_vartime(&[start as u64, 0, 0, 0]);
|
||||
for (modified_advice, advice_value) in modified_advice
|
||||
.iter_mut()
|
||||
.zip(witness.advice[column.index][start..].iter())
|
||||
.zip(witness.advice[column.index()][start..].iter())
|
||||
{
|
||||
// Multiply by p_j(\omega^i) + \delta^j \omega^i \beta
|
||||
*modified_advice *= &(deltaomega * &x_0 + &x_1 + advice_value);
|
||||
|
|
@ -395,7 +395,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
.advice_queries
|
||||
.iter()
|
||||
.map(|&(column, at)| {
|
||||
eval_polynomial(&advice_polys[column.index], domain.rotate_omega(x_3, at))
|
||||
eval_polynomial(&advice_polys[column.index()], domain.rotate_omega(x_3, at))
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
@ -403,7 +403,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
.aux_queries
|
||||
.iter()
|
||||
.map(|&(column, at)| {
|
||||
eval_polynomial(&aux_polys[column.index], domain.rotate_omega(x_3, at))
|
||||
eval_polynomial(&aux_polys[column.index()], domain.rotate_omega(x_3, at))
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
@ -411,7 +411,10 @@ impl<C: CurveAffine> Proof<C> {
|
|||
.fixed_queries
|
||||
.iter()
|
||||
.map(|&(column, at)| {
|
||||
eval_polynomial(&pk.fixed_polys[column.index], domain.rotate_omega(x_3, at))
|
||||
eval_polynomial(
|
||||
&pk.fixed_polys[column.index()],
|
||||
domain.rotate_omega(x_3, at),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
|
@ -469,8 +472,8 @@ impl<C: CurveAffine> Proof<C> {
|
|||
|
||||
instances.push(ProverQuery {
|
||||
point,
|
||||
poly: &advice_polys[column.index],
|
||||
blind: advice_blinds[column.index],
|
||||
poly: &advice_polys[column.index()],
|
||||
blind: advice_blinds[column.index()],
|
||||
eval: advice_evals[query_index],
|
||||
});
|
||||
}
|
||||
|
|
@ -480,7 +483,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
|
||||
instances.push(ProverQuery {
|
||||
point,
|
||||
poly: &aux_polys[column.index],
|
||||
poly: &aux_polys[column.index()],
|
||||
blind: Blind::default(),
|
||||
eval: aux_evals[query_index],
|
||||
});
|
||||
|
|
@ -491,7 +494,7 @@ impl<C: CurveAffine> Proof<C> {
|
|||
|
||||
instances.push(ProverQuery {
|
||||
point,
|
||||
poly: &pk.fixed_polys[column.index],
|
||||
poly: &pk.fixed_polys[column.index()],
|
||||
blind: Blind::default(),
|
||||
eval: fixed_evals[query_index],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ impl<'a, C: CurveAffine> Proof<C> {
|
|||
let point = vk.domain.rotate_omega(x_3, at);
|
||||
queries.push(VerifierQuery {
|
||||
point,
|
||||
commitment: &self.advice_commitments[column.index],
|
||||
commitment: &self.advice_commitments[column.index()],
|
||||
eval: self.advice_evals[query_index],
|
||||
});
|
||||
}
|
||||
|
|
@ -102,7 +102,7 @@ impl<'a, C: CurveAffine> Proof<C> {
|
|||
let point = vk.domain.rotate_omega(x_3, at);
|
||||
queries.push(VerifierQuery {
|
||||
point,
|
||||
commitment: &aux_commitments[column.index],
|
||||
commitment: &aux_commitments[column.index()],
|
||||
eval: self.aux_evals[query_index],
|
||||
});
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ impl<'a, C: CurveAffine> Proof<C> {
|
|||
let point = vk.domain.rotate_omega(x_3, at);
|
||||
queries.push(VerifierQuery {
|
||||
point,
|
||||
commitment: &vk.fixed_commitments[column.index],
|
||||
commitment: &vk.fixed_commitments[column.index()],
|
||||
eval: self.fixed_evals[query_index],
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue