Skip to content

Commit

Permalink
[#1793] Implement EC ADD circuit + witness generation
Browse files Browse the repository at this point in the history
Squash
  • Loading branch information
volhovm committed Mar 21, 2024
1 parent b8977ae commit 413cdcd
Show file tree
Hide file tree
Showing 10 changed files with 870 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions msm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ ark-bn254.workspace = true
ark-serialize.workspace = true
o1-utils.workspace = true
kimchi.workspace = true
itertools.workspace = true
poly-commitment.workspace = true
groupmap.workspace = true
mina-curves.workspace = true
mina-poseidon.workspace = true
num-bigint.workspace = true
num-integer.workspace = true
num-traits.workspace = true
rmp-serde.workspace = true
serde_json.workspace = true
serde.workspace = true
Expand Down
4 changes: 4 additions & 0 deletions msm/src/fec/columns.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use crate::N_LIMBS;

/// Number of columns in the FEC circuits.
pub const FEC_N_COLUMNS: usize = 34 * N_LIMBS + 42 * N_LIMBS; // 42 LIMBS is for debugging
54 changes: 54 additions & 0 deletions msm/src/fec/constraint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use crate::{columns::Column, expr::E, fec::interpreter::FECInterpreterEnv};
use ark_ff::PrimeField;
use kimchi::circuits::{
expr::{ConstantExpr, ConstantTerm, Expr, ExprInner, Variable},
gate::CurrOrNext,
};

/// Contains constraints for just one row.
pub struct ConstraintBuilderEnv<F> {
pub constraints: Vec<E<F>>,
}

impl<F: PrimeField> FECInterpreterEnv<F> for ConstraintBuilderEnv<F> {
type Variable = E<F>;

fn empty() -> Self {
ConstraintBuilderEnv {
constraints: vec![],
}
}

fn assert_zero(&mut self, cst: Self::Variable) {
self.constraints.push(cst)
}

fn copy(&mut self, x: &Self::Variable, position: Column) -> Self::Variable {
let y = Expr::Atom(ExprInner::Cell(Variable {
col: position,
row: CurrOrNext::Curr,
}));
self.constraints.push(y.clone() - x.clone());
y
}

fn constant(value: F) -> Self::Variable {
let cst_expr_inner = ConstantExpr::from(ConstantTerm::Literal(value));
Expr::Atom(ExprInner::Constant(cst_expr_inner))
}

fn read_column(&self, ix: Column) -> Self::Variable {
Expr::Atom(ExprInner::Cell(Variable {
col: ix,
row: CurrOrNext::Curr,
}))
}

fn range_check_abs1(&mut self, _value: &Self::Variable) {
// FIXME unimplemented
}

fn range_check_15bit(&mut self, _value: &Self::Variable) {
// FIXME unimplemented
}
}
Loading

0 comments on commit 413cdcd

Please sign in to comment.