Skip to content

Commit

Permalink
verifier: evaluate lagrange transition constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
plafer committed Feb 16, 2024
1 parent 450ecf1 commit 2d20d30
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
17 changes: 13 additions & 4 deletions air/src/air/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub use coefficients::{
mod divisor;
pub use divisor::ConstraintDivisor;

use self::transition::LagrangeKernelTransitionConstraints;

#[cfg(test)]
mod tests;

Expand Down Expand Up @@ -289,17 +291,17 @@ pub trait Air: Send + Sync {
/// lagrange_kernel_evaluations: c(z), c(gz), c(g^2z), ...
fn evaluate_lagrange_kernel_transition<F, E>(
&self,
lagrange_kernel_column_evaluations: &[E],
lagrange_kernel_column_frame: &[E],
aux_rand_elements: &AuxTraceRandElements<E>,
result: &mut [E],
) where
F: FieldElement<BaseField = Self::BaseField>,
E: FieldElement<BaseField = Self::BaseField> + ExtensionOf<F>,
{
assert_eq!(lagrange_kernel_column_evaluations.len(), result.len());
assert_eq!(lagrange_kernel_column_frame.len(), result.len());

let v = lagrange_kernel_column_evaluations.len();
let c = lagrange_kernel_column_evaluations;
let v = lagrange_kernel_column_frame.len();
let c = lagrange_kernel_column_frame;
let r = aux_rand_elements.get_segment_elements(0);

for k in 1..v + 1 {
Expand Down Expand Up @@ -371,6 +373,13 @@ pub trait Air: Send + Sync {
TransitionConstraints::new(self.context(), composition_coefficients)
}

fn get_lagrange_kernel_transition_constraints<E: FieldElement<BaseField = Self::BaseField>>(
&self,
lagrange_constraint_coefficients: Vec<E>,
) -> LagrangeKernelTransitionConstraints<E> {
LagrangeKernelTransitionConstraints::new(self.context(), lagrange_constraint_coefficients)
}

/// Convert assertions returned from [get_assertions()](Air::get_assertions) and
/// [get_aux_assertions()](Air::get_aux_assertions) methods into boundary constraints.
///
Expand Down
2 changes: 1 addition & 1 deletion verifier/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl<E: FieldElement> TraceOodFrame<E> {
/// TODO: Make this clearer
/// Returns the Lagrange kernel evaluation constraints c(z), c(gz), c(g^2z), c(g^4z), ...
/// This should log(trace_length).
pub fn lagrange_kernel_constraints_evaluations(&self) -> Option<&[E]> {
pub fn lagrange_kernel_column_frame(&self) -> Option<&[E]> {
if self.num_lagrange_kernel_constraints_evaluations == 0 {
None
} else {
Expand Down
19 changes: 17 additions & 2 deletions verifier/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn evaluate_constraints<A: Air, E: FieldElement<BaseField = A::BaseField>>(
composition_coefficients: ConstraintCompositionCoefficients<E>,
main_trace_frame: &EvaluationFrame<E>,
aux_trace_frame: &Option<EvaluationFrame<E>>,
lagrange_kernel_evaluations: Option<&[E]>,
lagrange_kernel_column_frame: Option<&[E]>,
aux_rand_elements: AuxTraceRandElements<E>,
x: E,
) -> E {
Expand Down Expand Up @@ -63,7 +63,20 @@ pub fn evaluate_constraints<A: Air, E: FieldElement<BaseField = A::BaseField>>(

// 2 ----- evaluate Lagrange kernel transition constraints ------------------------------------

// TODO
if let Some(lagrange_kernel_column_frame) = lagrange_kernel_column_frame {
let mut lagrange_t_evaluations = E::zeroed_vector(lagrange_kernel_column_frame.len());
air.evaluate_lagrange_kernel_transition(
lagrange_kernel_column_frame,
&aux_rand_elements,
&mut lagrange_t_evaluations,
);

let lagrange_t_constraints = air.get_lagrange_kernel_transition_constraints(
composition_coefficients.lagrange_kernel_transition,
);

result += lagrange_t_constraints.combine_evaluations::<E>(&lagrange_t_evaluations, x);
}

// 3 ----- evaluate boundary constraints ------------------------------------------------------

Expand All @@ -87,5 +100,7 @@ pub fn evaluate_constraints<A: Air, E: FieldElement<BaseField = A::BaseField>>(
}
}

// TODO: Evaluate lagrange kernel boundary constraint

result
}
4 changes: 2 additions & 2 deletions verifier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ where
let ood_trace_frame = channel.read_ood_trace_frame();
let ood_main_trace_frame = ood_trace_frame.main_frame();
let ood_aux_trace_frame = ood_trace_frame.aux_frame();
let ood_lagrange_kernel_evaluations = ood_trace_frame.lagrange_kernel_constraints_evaluations();
let ood_lagrange_kernel_column_frame = ood_trace_frame.lagrange_kernel_column_frame();
let ood_constraint_evaluation_1 = evaluate_constraints(
&air,
constraint_coeffs,
&ood_main_trace_frame,
&ood_aux_trace_frame,
ood_lagrange_kernel_evaluations,
ood_lagrange_kernel_column_frame,
aux_trace_rand_elements,
z,
);
Expand Down

0 comments on commit 2d20d30

Please sign in to comment.