diff --git a/starky/src/constraint_consumer.rs b/starky/src/constraint_consumer.rs index 20f29192..c7a8bfea 100644 --- a/starky/src/constraint_consumer.rs +++ b/starky/src/constraint_consumer.rs @@ -17,19 +17,15 @@ pub struct ConstraintConsumer { /// The evaluation of the Lagrange basis polynomial which is nonzero at the point associated /// with the first trace row, and zero at other points in the subgroup. - lagrange_basis_first: P::Scalar, + lagrange_basis_first: P, /// The evaluation of the Lagrange basis polynomial which is nonzero at the point associated /// with the last trace row, and zero at other points in the subgroup. - lagrange_basis_last: P::Scalar, + lagrange_basis_last: P, } impl ConstraintConsumer

{ - pub fn new( - alpha: P::Scalar, - lagrange_basis_first: P::Scalar, - lagrange_basis_last: P::Scalar, - ) -> Self { + pub fn new(alpha: P::Scalar, lagrange_basis_first: P, lagrange_basis_last: P) -> Self { Self { alpha, constraint_acc: P::ZEROS, diff --git a/starky/src/julia_stark.rs b/starky/src/julia_stark.rs new file mode 100644 index 00000000..e8bca9fe --- /dev/null +++ b/starky/src/julia_stark.rs @@ -0,0 +1,91 @@ +use std::marker::PhantomData; + +use plonky2::field::extension_field::{Extendable, FieldExtension}; +use plonky2::field::packed_field::PackedField; +use plonky2::hash::hash_types::RichField; +use plonky2::plonk::circuit_builder::CircuitBuilder; + +use crate::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; +use crate::stark::Stark; +use crate::vars::{StarkEvaluationTargets, StarkEvaluationVars}; + +pub struct JuliaStark, const D: usize> { + c: F, + _phantom: PhantomData, +} + +impl, const D: usize> JuliaStark { + const NUM_COLUMNS: usize = 1; + const NUM_ROWS: usize = 1 << 10; + + fn new(c: F) -> Self { + Self { + c, + _phantom: PhantomData, + } + } + + fn generate_trace(&self) -> Vec<[F; Self::NUM_COLUMNS]> { + (0..Self::NUM_ROWS) + .scan([F::ZERO; Self::NUM_COLUMNS], |acc, _| { + let tmp = *acc; + acc[0] = acc[0] * acc[0] + self.c; + Some(tmp) + }) + .collect() + } +} + +impl, const D: usize> Stark for JuliaStark { + const COLUMNS: usize = Self::NUM_COLUMNS; + const PUBLIC_INPUTS: usize = 0; + + fn eval_packed_generic( + &self, + vars: StarkEvaluationVars, + yield_constr: &mut ConstraintConsumer

, + ) where + FE: FieldExtension, + P: PackedField, + { + yield_constr.one( + vars.next_values[0] + - vars.local_values[0] * vars.local_values[0] + - FE::from_basefield(self.c), + ); + } + + fn eval_ext_recursively( + &self, + builder: &mut CircuitBuilder, + vars: StarkEvaluationTargets, + yield_constr: &mut RecursiveConstraintConsumer, + ) { + todo!() + } +} + +#[cfg(test)] +mod tests { + use plonky2::field::field_types::Field; + use plonky2::field::goldilocks_field::GoldilocksField; + use plonky2::plonk::config::{GenericConfig, PoseidonGoldilocksConfig}; + use plonky2::util::timing::TimingTree; + + use crate::config::StarkConfig; + use crate::julia_stark::JuliaStark; + use crate::prover::prove; + + #[test] + fn test_julia_stark() { + const D: usize = 2; + type C = PoseidonGoldilocksConfig; + type F = >::F; + type S = JuliaStark; + + let config = StarkConfig::standard_fast_config(); + let stark = S::new(F::NEG_ONE); + let trace = stark.generate_trace(); + prove::(stark, config, trace, &mut TimingTree::default()); + } +} diff --git a/starky/src/lib.rs b/starky/src/lib.rs index be28a01e..72407511 100644 --- a/starky/src/lib.rs +++ b/starky/src/lib.rs @@ -12,3 +12,6 @@ pub mod proof; pub mod prover; pub mod stark; pub mod vars; + +#[cfg(test)] +pub mod julia_stark;