From f2bcfe4d77088e602e3a570cfc5dd77192b950fe Mon Sep 17 00:00:00 2001 From: mcarilli Date: Thu, 20 Jul 2023 19:44:13 -0600 Subject: [PATCH 1/2] quartic fails --- src/starks/example/mod.rs | 1 + tests/integration_tests.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/starks/example/mod.rs b/src/starks/example/mod.rs index 83bb526d..1c91ba1d 100644 --- a/src/starks/example/mod.rs +++ b/src/starks/example/mod.rs @@ -2,4 +2,5 @@ pub mod dummy_air; pub mod fibonacci_2_columns; pub mod fibonacci_rap; pub mod quadratic_air; +pub mod quartic_air; pub mod simple_fibonacci; diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 9b92b5a0..a4f1b4e5 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -23,6 +23,7 @@ use lambdaworks_stark::{ fibonacci_2_columns::{self, Fibonacci2ColsAIR}, fibonacci_rap::{fibonacci_rap_trace, FibonacciRAP, FibonacciRAPPublicInputs}, quadratic_air::{self, QuadraticAIR, QuadraticPublicInputs}, + quartic_air::{self, QuarticAIR, QuarticPublicInputs}, simple_fibonacci::{self, FibonacciAIR, FibonacciPublicInputs}, }, proof::options::{ProofOptions, SecurityLevel}, @@ -111,6 +112,28 @@ fn test_prove_quadratic() { )); } +#[test_log::test] +fn test_prove_quartic() { + let trace = quartic_air::quartic_trace(FE::from(3), 8); + + // let proof_options = ProofOptions::default_test_options(); + let proof_options = ProofOptions { + blowup_factor: 4, + fri_number_of_queries: 3, + coset_offset: 3, + grinding_factor: 1, + }; + + let pub_inputs = QuarticPublicInputs { a0: FE::from(3) }; + + let proof = prove::>(&trace, &pub_inputs, &proof_options).unwrap(); + assert!(verify::>( + &proof, + &pub_inputs, + &proof_options + )); +} + /// Loads the program in path, runs it with the Cairo VM, and makes a proof of it fn test_prove_cairo_program(file_path: &str, output_range: &Option>) { let proof_options = ProofOptions::default_test_options(); From c98a02efdc21d398fa45d24b2a7ccabd4ce96950 Mon Sep 17 00:00:00 2001 From: mcarilli Date: Thu, 20 Jul 2023 19:44:32 -0600 Subject: [PATCH 2/2] add file --- src/starks/example/quartic_air.rs | 125 ++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/starks/example/quartic_air.rs diff --git a/src/starks/example/quartic_air.rs b/src/starks/example/quartic_air.rs new file mode 100644 index 00000000..865fac73 --- /dev/null +++ b/src/starks/example/quartic_air.rs @@ -0,0 +1,125 @@ +use lambdaworks_crypto::fiat_shamir::transcript::Transcript; +use lambdaworks_math::field::{element::FieldElement, traits::IsFFTField}; + +use crate::starks::{ + constraints::boundary::{BoundaryConstraint, BoundaryConstraints}, + context::AirContext, + frame::Frame, + proof::options::ProofOptions, + trace::TraceTable, + traits::AIR, +}; + +#[derive(Clone)] +pub struct QuarticAIR +where + F: IsFFTField, +{ + context: AirContext, + trace_length: usize, + pub_inputs: QuarticPublicInputs, +} + +#[derive(Clone, Debug)] +pub struct QuarticPublicInputs +where + F: IsFFTField, +{ + pub a0: FieldElement, +} + +impl AIR for QuarticAIR +where + F: IsFFTField, +{ + type Field = F; + type RAPChallenges = (); + type PublicInputs = QuarticPublicInputs; + + fn new( + trace_length: usize, + pub_inputs: &Self::PublicInputs, + proof_options: &ProofOptions, + ) -> Self { + let context = AirContext { + proof_options: proof_options.clone(), + trace_columns: 1, + transition_degrees: vec![4], + transition_exemptions: vec![1], + transition_offsets: vec![0, 1], + num_transition_constraints: 1, + num_transition_exemptions: 1, + }; + + Self { + trace_length, + context, + pub_inputs: pub_inputs.clone(), + } + } + + fn build_auxiliary_trace( + &self, + _main_trace: &TraceTable, + _rap_challenges: &Self::RAPChallenges, + ) -> TraceTable { + TraceTable::empty() + } + + fn build_rap_challenges(&self, _transcript: &mut T) -> Self::RAPChallenges {} + + fn compute_transition( + &self, + frame: &Frame, + _rap_challenges: &Self::RAPChallenges, + ) -> Vec> { + let first_row = frame.get_row(0); + let second_row = frame.get_row(1); + + vec![&second_row[0] - &first_row[0] * &first_row[0] * &first_row[0] * &first_row[0]] + } + + fn number_auxiliary_rap_columns(&self) -> usize { + 0 + } + + fn boundary_constraints( + &self, + _rap_challenges: &Self::RAPChallenges, + ) -> BoundaryConstraints { + let a0 = BoundaryConstraint::new_simple(0, self.pub_inputs.a0.clone()); + + BoundaryConstraints::from_constraints(vec![a0]) + } + + fn context(&self) -> &AirContext { + &self.context + } + + fn composition_poly_degree_bound(&self) -> usize { + 4 * self.trace_length() + } + + fn trace_length(&self) -> usize { + self.trace_length + } + + fn pub_inputs(&self) -> &Self::PublicInputs { + &self.pub_inputs + } +} + +pub fn quartic_trace( + initial_value: FieldElement, + trace_length: usize, +) -> TraceTable { + let mut ret: Vec> = vec![]; + + ret.push(initial_value); + + for i in 1..(trace_length) { + ret.push(ret[i - 1].clone() * ret[i - 1].clone() * ret[i - 1].clone() * ret[i - 1].clone()); + } + + TraceTable::new_from_cols(&[ret]) +}