-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor folders and Air Trait location (#25)
* Refactor * add is empty * Fmt commentary * Remove print * Enable test * Pelito refactor * Pelito refactor * Refactor folders * Refactor folders + Air Trait * Apply formatting --------- Co-authored-by: Mariano Nicolini <mariano.nicolini.91@gmail.com>
- Loading branch information
1 parent
b58c913
commit 3850002
Showing
18 changed files
with
123 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod air; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pub mod cairo; | ||
pub mod dummy_air; | ||
pub mod fibonacci_2_columns; | ||
pub mod fibonacci_f17; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,9 @@ | ||
use crate::prover::ProvingError; | ||
|
||
use self::{ | ||
constraints::boundary::BoundaryConstraints, | ||
context::{AirContext, ProofOptions}, | ||
frame::Frame, | ||
trace::TraceTable, | ||
}; | ||
use lambdaworks_crypto::fiat_shamir::transcript::Transcript; | ||
use lambdaworks_fft::roots_of_unity::get_powers_of_primitive_root_coset; | ||
use lambdaworks_math::{ | ||
field::{element::FieldElement, traits::IsFFTField}, | ||
polynomial::Polynomial, | ||
}; | ||
|
||
pub mod cairo_air; | ||
pub mod constraints; | ||
pub mod context; | ||
#[cfg(debug_assertions)] | ||
pub mod debug; | ||
pub mod example; | ||
pub mod frame; | ||
pub mod trace; | ||
|
||
pub trait AIR: Clone { | ||
type Field: IsFFTField; | ||
type RawTrace; | ||
type RAPChallenges; | ||
type PublicInput; | ||
|
||
fn build_main_trace( | ||
&self, | ||
raw_trace: &Self::RawTrace, | ||
public_input: &mut Self::PublicInput, | ||
) -> Result<TraceTable<Self::Field>, ProvingError>; | ||
|
||
fn build_auxiliary_trace( | ||
&self, | ||
main_trace: &TraceTable<Self::Field>, | ||
rap_challenges: &Self::RAPChallenges, | ||
public_input: &Self::PublicInput, | ||
) -> TraceTable<Self::Field>; | ||
|
||
fn build_rap_challenges<T: Transcript>(&self, transcript: &mut T) -> Self::RAPChallenges; | ||
|
||
fn number_auxiliary_rap_columns(&self) -> usize; | ||
|
||
fn composition_poly_degree_bound(&self) -> usize; | ||
|
||
fn compute_transition( | ||
&self, | ||
frame: &Frame<Self::Field>, | ||
rap_challenges: &Self::RAPChallenges, | ||
) -> Vec<FieldElement<Self::Field>>; | ||
fn boundary_constraints( | ||
&self, | ||
rap_challenges: &Self::RAPChallenges, | ||
public_input: &Self::PublicInput, | ||
) -> BoundaryConstraints<Self::Field>; | ||
fn transition_divisors(&self) -> Vec<Polynomial<FieldElement<Self::Field>>> { | ||
let trace_length = self.context().trace_length; | ||
let roots_of_unity_order = trace_length.trailing_zeros(); | ||
let roots_of_unity = get_powers_of_primitive_root_coset( | ||
roots_of_unity_order as u64, | ||
self.context().trace_length, | ||
&FieldElement::<Self::Field>::one(), | ||
) | ||
.unwrap(); | ||
|
||
let mut result = vec![]; | ||
let x_n = Polynomial::new_monomial(FieldElement::one(), trace_length); | ||
let x = Polynomial::new_monomial(FieldElement::one(), 1); | ||
for transition_idx in 0..self.context().num_transition_constraints { | ||
// X^(trace_length) - 1 | ||
let roots_of_unity_vanishing_polynomial = &x_n - FieldElement::one(); | ||
|
||
let mut exemptions_polynomial = Polynomial::new_monomial(FieldElement::one(), 0); | ||
|
||
for i in 0..self.context().transition_exemptions[transition_idx] { | ||
exemptions_polynomial = | ||
exemptions_polynomial * (&x - &roots_of_unity[roots_of_unity.len() - 1 - i]) | ||
} | ||
|
||
result.push(roots_of_unity_vanishing_polynomial / exemptions_polynomial); | ||
} | ||
|
||
result | ||
} | ||
fn context(&self) -> AirContext; | ||
fn options(&self) -> ProofOptions { | ||
self.context().options | ||
} | ||
|
||
fn blowup_factor(&self) -> u8 { | ||
self.options().blowup_factor | ||
} | ||
|
||
fn num_transition_constraints(&self) -> usize { | ||
self.context().num_transition_constraints | ||
} | ||
} | ||
pub mod traits; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
use lambdaworks_crypto::fiat_shamir::transcript::Transcript; | ||
use lambdaworks_math::{ | ||
field::{element::FieldElement, traits::IsFFTField}, | ||
polynomial::Polynomial, | ||
}; | ||
|
||
use crate::prover::ProvingError; | ||
|
||
use super::{ | ||
constraints::boundary::BoundaryConstraints, | ||
context::{AirContext, ProofOptions}, | ||
frame::Frame, | ||
trace::TraceTable, | ||
}; | ||
use crate::get_powers_of_primitive_root_coset; | ||
/// AIR is a representation of the Constraints | ||
pub trait AIR: Clone { | ||
type Field: IsFFTField; | ||
type RawTrace; | ||
type RAPChallenges; | ||
type PublicInput; | ||
|
||
fn build_main_trace( | ||
&self, | ||
raw_trace: &Self::RawTrace, | ||
public_input: &mut Self::PublicInput, | ||
) -> Result<TraceTable<Self::Field>, ProvingError>; | ||
|
||
fn build_auxiliary_trace( | ||
&self, | ||
main_trace: &TraceTable<Self::Field>, | ||
rap_challenges: &Self::RAPChallenges, | ||
public_input: &Self::PublicInput, | ||
) -> TraceTable<Self::Field>; | ||
|
||
fn build_rap_challenges<T: Transcript>(&self, transcript: &mut T) -> Self::RAPChallenges; | ||
|
||
fn number_auxiliary_rap_columns(&self) -> usize; | ||
|
||
fn composition_poly_degree_bound(&self) -> usize; | ||
|
||
fn compute_transition( | ||
&self, | ||
frame: &Frame<Self::Field>, | ||
rap_challenges: &Self::RAPChallenges, | ||
) -> Vec<FieldElement<Self::Field>>; | ||
|
||
fn boundary_constraints( | ||
&self, | ||
rap_challenges: &Self::RAPChallenges, | ||
public_input: &Self::PublicInput, | ||
) -> BoundaryConstraints<Self::Field>; | ||
|
||
fn transition_divisors(&self) -> Vec<Polynomial<FieldElement<Self::Field>>> { | ||
let trace_length = self.context().trace_length; | ||
let roots_of_unity_order = trace_length.trailing_zeros(); | ||
let roots_of_unity = get_powers_of_primitive_root_coset( | ||
roots_of_unity_order as u64, | ||
self.context().trace_length, | ||
&FieldElement::<Self::Field>::one(), | ||
) | ||
.unwrap(); | ||
|
||
let mut result = vec![]; | ||
let x_n = Polynomial::new_monomial(FieldElement::one(), trace_length); | ||
let x = Polynomial::new_monomial(FieldElement::one(), 1); | ||
for transition_idx in 0..self.context().num_transition_constraints { | ||
// X^(trace_length) - 1 | ||
let roots_of_unity_vanishing_polynomial = &x_n - FieldElement::one(); | ||
|
||
let mut exemptions_polynomial = Polynomial::new_monomial(FieldElement::one(), 0); | ||
|
||
for i in 0..self.context().transition_exemptions[transition_idx] { | ||
exemptions_polynomial = | ||
exemptions_polynomial * (&x - &roots_of_unity[roots_of_unity.len() - 1 - i]) | ||
} | ||
|
||
result.push(roots_of_unity_vanishing_polynomial / exemptions_polynomial); | ||
} | ||
|
||
result | ||
} | ||
fn context(&self) -> AirContext; | ||
|
||
fn options(&self) -> ProofOptions { | ||
self.context().options | ||
} | ||
|
||
fn blowup_factor(&self) -> u8 { | ||
self.options().blowup_factor | ||
} | ||
|
||
fn num_transition_constraints(&self) -> usize { | ||
self.context().num_transition_constraints | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters