-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4e9d03
commit 5c9fb36
Showing
3 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/// ! 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 field type holding values of columns for the component. These are the inputs to the | ||
/// constraints. It might be [BaseField] packed types, or even [SecureField], when evaluating | ||
/// the columns out of domain. | ||
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>; | ||
|
||
/// A field type representing the closure of `F` with multiplying by [SecureField]. Constraints | ||
/// usually get multiplied by [SecureField] values for security. | ||
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 value for the first interaction at offset 0. | ||
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<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; SECURE_EXTENSION_DEGREE]) -> Self::EF; | ||
} |
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