diff --git a/crates/prover/src/constraint_framework/mod.rs b/crates/prover/src/constraint_framework/mod.rs new file mode 100644 index 000000000..f68335b52 --- /dev/null +++ b/crates/prover/src/constraint_framework/mod.rs @@ -0,0 +1,61 @@ +/// ! This module contains helpers to express and use constraints for components. +use std::fmt::Debug; +use std::ops::{Add, AddAssign, Mul, Sub}; + +use num_traits::{One, Zero}; + +use crate::core::fields::m31::BaseField; +use crate::core::fields::qm31::SecureField; +use crate::core::fields::secure_column::SECURE_EXTENSION_DEGREE; +use crate::core::fields::FieldExpOps; + +/// A trait for evaluating expressions at some point or row. +pub trait EvalAtRow { + // TODO(spapini): Use a better trait for these, like 'Algebra' or something. + /// The base field type. + type F: FieldExpOps + + Copy + + Debug + + AddAssign + + AddAssign + + Add + + Sub + + Mul + + Add + + Mul + + From; + + /// The extension field type. + type EF: One + + Copy + + Debug + + Zero + + Add + + Sub + + Mul + + Add + + Mul + + Sub + + Mul; + + /// Returns the next mask value. + fn next_trace_mask(&mut self) -> Self::F { + let [mask_item] = self.next_interaction_mask(0, [0]); + mask_item + } + + /// Returns the mask values of the given offsets for the next column in the interaction. + fn next_interaction_mask( + &mut self, + interaction: usize, + offsets: [isize; N], + ) -> [Self::F; N]; + + /// Adds a constraint to the component. + fn add_constraint(&mut self, constraint: G) + where + Self::EF: Mul; + + /// Combines 4 base field values into a single extension field value. + fn combine_ef(values: [Self::F; SECURE_EXTENSION_DEGREE]) -> Self::EF; +} diff --git a/crates/prover/src/core/backend/simd/m31.rs b/crates/prover/src/core/backend/simd/m31.rs index 6ea2a7d65..efb664d23 100644 --- a/crates/prover/src/core/backend/simd/m31.rs +++ b/crates/prover/src/core/backend/simd/m31.rs @@ -253,6 +253,12 @@ impl From<[BaseField; N_LANES]> for PackedM31 { } } +impl From for PackedM31 { + fn from(v: BaseField) -> Self { + Self::broadcast(v) + } +} + impl Distribution for Standard { fn sample(&self, rng: &mut R) -> PackedM31 { PackedM31::from_array(rng.gen()) diff --git a/crates/prover/src/lib.rs b/crates/prover/src/lib.rs index 36ebc8b35..6c9ddaa02 100644 --- a/crates/prover/src/lib.rs +++ b/crates/prover/src/lib.rs @@ -12,6 +12,7 @@ assert_matches, portable_simd )] +pub mod constraint_framework; pub mod core; pub mod examples; pub mod math;