Skip to content

Commit

Permalink
Eval framework
Browse files Browse the repository at this point in the history
  • Loading branch information
spapinistarkware committed Jul 9, 2024
1 parent 126d63f commit 55d0ff0
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
58 changes: 58 additions & 0 deletions crates/prover/src/builder/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/// ! 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::FieldExpOps;

/// A trait for evaluating expressions at some point or row.
pub trait EvalAtRow {
/// The base field type.
type F: FieldExpOps
+ Copy
+ Debug
+ AddAssign<Self::F>
+ AddAssign<BaseField>
+ Add<Self::F, Output = Self::F>
+ Sub<Self::F, Output = Self::F>
+ Mul<BaseField, Output = Self::F>
+ Add<SecureField, Output = Self::EF>
+ Mul<SecureField, Output = Self::EF>
+ From<BaseField>;

/// The extension field type.
type EF: One
+ Copy
+ Debug
+ Zero
+ Add<SecureField, Output = Self::EF>
+ Sub<SecureField, Output = Self::EF>
+ Mul<SecureField, Output = Self::EF>
+ Add<Self::F, Output = Self::EF>
+ Mul<Self::F, Output = Self::EF>
+ Sub<Self::EF, Output = Self::EF>
+ Mul<Self::EF, Output = Self::EF>;

/// Returns the next mask.
fn next_mask(&mut self) -> Self::F {
self.next_interaction_mask(0, [0])[0]
}

/// Returns the next mask for the given interaction.
fn next_interaction_mask<const N: usize>(
&mut self,
interaction: usize,
offsets: [isize; N],
) -> [Self::F; N];

/// Adds a constraint to the component.
fn add_constraint<G>(&mut self, constraint: G)
where
Self::EF: Mul<G, Output = Self::EF>;

/// Combines 4 base field values into a single extension field value.
fn combine_ef(values: [Self::F; 4]) -> Self::EF;
}
6 changes: 6 additions & 0 deletions crates/prover/src/core/backend/simd/m31.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ impl From<[BaseField; N_LANES]> for PackedM31 {
}
}

impl From<BaseField> for PackedM31 {
fn from(v: BaseField) -> Self {
Self::broadcast(v)
}
}

impl Distribution<PackedM31> for Standard {
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> PackedM31 {
PackedM31::from_array(rng.gen())
Expand Down
1 change: 1 addition & 0 deletions crates/prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
assert_matches,
portable_simd
)]
pub mod builder;
pub mod core;
pub mod examples;
pub mod hash_functions;
Expand Down

0 comments on commit 55d0ff0

Please sign in to comment.