Skip to content

Commit

Permalink
chore: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Al-Kindi-0 committed Jan 30, 2025
1 parent d3c8210 commit 50936e5
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 411 deletions.
56 changes: 55 additions & 1 deletion air/src/air/coefficients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

use alloc::vec::Vec;

use math::FieldElement;
use crypto::{RandomCoin, RandomCoinError};
use math::{get_power_series, get_power_series_with_offset, FieldElement};

// CONSTRAINT COMPOSITION COEFFICIENTS
// ================================================================================================
Expand Down Expand Up @@ -110,3 +111,56 @@ pub struct DeepCompositionCoefficients<E: FieldElement> {
/// Lagrange kernel trace polynomial composition coefficient $\gamma$.
pub lagrange: Option<E>,
}

impl<E: FieldElement> DeepCompositionCoefficients<E> {
/// Generates the random values used in the construction of the DEEP polynomial when linear
/// batching is used.
pub fn draw_linear(
public_coin: &mut impl RandomCoin<BaseField = E::BaseField>,
trace_width: usize,
num_constraint_composition_columns: usize,
) -> Result<Self, RandomCoinError> {
let mut t_coefficients = Vec::new();
for _ in 0..trace_width {
t_coefficients.push(public_coin.draw()?);
}

let mut c_coefficients = Vec::new();
for _ in 0..num_constraint_composition_columns {
c_coefficients.push(public_coin.draw()?);
}

Ok(DeepCompositionCoefficients {
trace: t_coefficients,
constraints: c_coefficients,
lagrange: None,
})
}

/// Generates the random values used in the construction of the DEEP polynomial when algebraic
/// batching is used.
pub fn draw_algebraic(
public_coin: &mut impl RandomCoin<BaseField = E::BaseField>,
trace_width: usize,
num_constraint_composition_columns: usize,
) -> Result<Self, RandomCoinError> {
let mut t_coefficients = Vec::new();
let alpha: E = public_coin.draw()?;
t_coefficients.extend_from_slice(&get_power_series(alpha, trace_width));

let mut c_coefficients = Vec::new();

let alpha_pow_trace_width = alpha.exp((trace_width as u32).into());
c_coefficients.extend_from_slice(&get_power_series_with_offset(
alpha,
alpha_pow_trace_width,
num_constraint_composition_columns,
));

Ok(DeepCompositionCoefficients {
trace: t_coefficients,
constraints: c_coefficients,
lagrange: None,
})
}
}
70 changes: 11 additions & 59 deletions air/src/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
use alloc::{collections::BTreeMap, vec::Vec};

use crypto::{RandomCoin, RandomCoinError};
use math::{
fft, get_power_series, get_power_series_with_offset, ExtensibleField, ExtensionOf,
FieldElement, StarkField, ToElements,
};
use math::{fft, ExtensibleField, ExtensionOf, FieldElement, StarkField, ToElements};

use crate::{BatchingMethod, ProofOptions};

Expand Down Expand Up @@ -581,62 +578,17 @@ pub trait Air: Send + Sync {
E: FieldElement<BaseField = Self::BaseField>,
R: RandomCoin<BaseField = Self::BaseField>,
{
let mut t_coefficients = Vec::new();
match self.context().options.deep_poly_batching_method() {
BatchingMethod::Linear => {
for _ in 0..self.trace_info().width() {
t_coefficients.push(public_coin.draw()?);
}

let mut c_coefficients = Vec::new();
for _ in 0..self.context().num_constraint_composition_columns() {
c_coefficients.push(public_coin.draw()?);
}

let lagrange_cc = if self.context().has_lagrange_kernel_aux_column() {
Some(public_coin.draw()?)
} else {
None
};

Ok(DeepCompositionCoefficients {
trace: t_coefficients,
constraints: c_coefficients,
lagrange: lagrange_cc,
})
},
BatchingMethod::Algebraic => {
let mut t_coefficients = Vec::new();
let alpha: E = public_coin.draw()?;
t_coefficients
.extend_from_slice(&get_power_series(alpha, self.trace_info().width()));

let mut c_coefficients = Vec::new();

let alpha_pow_trace_width = alpha.exp(((self.trace_info().width()) as u32).into());
c_coefficients.extend_from_slice(&get_power_series_with_offset(
alpha,
alpha_pow_trace_width,
self.context().num_constraint_composition_columns(),
));

let lagrange_cc = if self.context().has_lagrange_kernel_aux_column() {
Some(
*c_coefficients
.last()
.expect("there should be at least one constraint coefficient")
* alpha,
)
} else {
None
};

Ok(DeepCompositionCoefficients {
trace: t_coefficients,
constraints: c_coefficients,
lagrange: lagrange_cc,
})
},
BatchingMethod::Linear => DeepCompositionCoefficients::draw_linear(
public_coin,
self.trace_info().width(),
self.context().num_constraint_composition_columns(),
),
BatchingMethod::Algebraic => DeepCompositionCoefficients::draw_algebraic(
public_coin,
self.trace_info().width(),
self.context().num_constraint_composition_columns(),
),
}
}
}
1 change: 1 addition & 0 deletions math/src/field/f128/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ fn mul() {
assert_eq!(BaseElement::new(m - 2), t * BaseElement::from(2u8));
assert_eq!(BaseElement::new(m - 4), t * BaseElement::from(4u8));

#[allow(clippy::manual_div_ceil)]
let t = (m + 1) / 2;
assert_eq!(BaseElement::ONE, BaseElement::new(t) * BaseElement::from(2u8));

Expand Down
1 change: 1 addition & 0 deletions math/src/field/f62/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn mul() {
assert_eq!(BaseElement::new(m - 2), t * BaseElement::from(2u8));
assert_eq!(BaseElement::new(m - 4), t * BaseElement::from(4u8));

#[allow(clippy::manual_div_ceil)]
let t = (m + 1) / 2;
assert_eq!(BaseElement::ONE, BaseElement::new(t) * BaseElement::from(2u8));
}
Expand Down
1 change: 1 addition & 0 deletions math/src/field/f64/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn mul() {
assert_eq!(BaseElement::new(m - 2), t * BaseElement::from(2u8));
assert_eq!(BaseElement::new(m - 4), t * BaseElement::from(4u8));

#[allow(clippy::manual_div_ceil)]
let t = (m + 1) / 2;
assert_eq!(BaseElement::ONE, BaseElement::new(t) * BaseElement::from(2u8));
}
Expand Down
3 changes: 0 additions & 3 deletions winterfell/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,3 @@ pub use prover::{
TraceTableFragment, TransitionConstraintDegree,
};
pub use verifier::{verify, AcceptableOptions, ByteWriter, VerifierError};

#[cfg(test)]
mod tests;
Loading

0 comments on commit 50936e5

Please sign in to comment.