use crate::components::prelude::*;
pub const N_TRACE_COLUMNS: usize = 1;
pub const LOG_SIZE: u32 = 8;
pub const RELATION_USES_PER_ROW: [RelationUse; 0] = [];
pub struct Eval {
pub claim: Claim,
pub common_lookup_elements: relations::CommonLookupElements,
}
#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize, CairoDeserialize)]
pub struct Claim {}
impl Claim {
pub fn log_sizes(&self) -> TreeVec<Vec<u32>> {
let trace_log_sizes = vec![LOG_SIZE; N_TRACE_COLUMNS];
let interaction_log_sizes = vec![LOG_SIZE; SECURE_EXTENSION_DEGREE];
TreeVec::new(vec![vec![], trace_log_sizes, interaction_log_sizes])
}
}
#[derive(Copy, Clone, Serialize, Deserialize, CairoSerialize, CairoDeserialize)]
pub struct InteractionClaim {
pub claimed_sum: SecureField,
}
pub type Component = FrameworkComponent<Eval>;
impl FrameworkEval for Eval {
fn log_size(&self) -> u32 {
LOG_SIZE
}
fn max_constraint_log_degree_bound(&self) -> u32 {
self.log_size() + 1
}
#[allow(unused_parens)]
#[allow(clippy::double_parens)]
#[allow(non_snake_case)]
fn evaluate<E: EvalAtRow>(&self, mut eval: E) -> E {
let M31_1420243005 = E::F::from(M31::from(1420243005));
let seq_8 = eval.get_preprocessed_column(PreProcessedColumnId {
id: "seq_8".to_owned(),
});
let multiplicity_0_col0 = eval.next_trace_mask();
eval.add_to_relation(RelationEntry::new(
&self.common_lookup_elements,
-E::EF::from(multiplicity_0_col0.clone()),
&[M31_1420243005.clone(), seq_8.clone()],
));
eval.finalize_logup_in_pairs();
eval
}
}
#[cfg(test)]
mod tests {
use num_traits::Zero;
use rand::rngs::SmallRng;
use rand::{Rng, SeedableRng};
use stwo::core::fields::qm31::QM31;
use stwo_constraint_framework::expr::ExprEvaluator;
use super::*;
use crate::components::constraints_regression_test_values::RANGE_CHECK_8;
#[test]
fn range_check_8_constraints_regression() {
let mut rng = SmallRng::seed_from_u64(0);
let eval = Eval {
claim: Claim {},
common_lookup_elements: relations::CommonLookupElements::dummy(),
};
let expr_eval = eval.evaluate(ExprEvaluator::new());
let assignment = expr_eval.random_assignment();
let mut sum = QM31::zero();
for c in expr_eval.constraints {
sum += c.assign(&assignment) * rng.gen::<QM31>();
}
RANGE_CHECK_8.assert_debug_eq(&sum);
}
}