Skip to content

Commit

Permalink
Merge pull request #1976 from o1-labs/dw/rc-lookup-constraints-serial…
Browse files Browse the repository at this point in the history
…ization

MSM: add rangecheck4 and rangecheck15 lookups in constraints
  • Loading branch information
dannywillems authored Mar 14, 2024
2 parents 626460f + 6a19eed commit c25763f
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions msm/src/serialization/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use kimchi::circuits::{

use crate::{columns::Column, expr::E, serialization::N_INTERMEDIATE_LIMBS, N_LIMBS};

use super::interpreter::InterpreterEnv;
use super::Lookup;
use super::{interpreter::InterpreterEnv, LookupTable};

pub struct Env<Fp> {
/// An indexed set of constraints.
Expand All @@ -15,13 +16,17 @@ pub struct Env<Fp> {
/// folding for instance.
pub constraints: Vec<(usize, Expr<ConstantExpr<Fp>, Column>)>,
pub constrain_index: usize,
pub rangecheck4_lookups: Vec<Lookup<E<Fp>>>,
pub rangecheck15_lookups: Vec<Lookup<E<Fp>>>,
}

impl<Fp: PrimeField> Env<Fp> {
pub fn create() -> Self {
Self {
constraints: vec![],
constrain_index: 0,
rangecheck4_lookups: vec![],
rangecheck15_lookups: vec![],
}
}
}
Expand Down Expand Up @@ -63,12 +68,22 @@ impl<F: PrimeField> InterpreterEnv<F> for Env<F> {
Column::X(3 + j)
}

fn range_check15(&mut self, _value: &Self::Variable) {
// TODO
fn range_check15(&mut self, value: &Self::Variable) {
let one = ConstantExpr::from(ConstantTerm::Literal(F::one()));
self.rangecheck15_lookups.push(Lookup {
table_id: LookupTable::RangeCheck15,
numerator: Expr::Atom(ExprInner::Constant(one)),
value: vec![value.clone()],
})
}

fn range_check4(&mut self, _value: &Self::Variable) {
// TODO
fn range_check4(&mut self, value: &Self::Variable) {
let one = ConstantExpr::from(ConstantTerm::Literal(F::one()));
self.rangecheck4_lookups.push(Lookup {
table_id: LookupTable::RangeCheck4,
numerator: Expr::Atom(ExprInner::Constant(one)),
value: vec![value.clone()],
})
}

fn constant(value: F) -> Self::Variable {
Expand Down

0 comments on commit c25763f

Please sign in to comment.