Skip to content

Commit

Permalink
Arrabiata: get rid of the a parameter in the constraints env
Browse files Browse the repository at this point in the history
  • Loading branch information
dannywillems committed Oct 28, 2024
1 parent 9a56f7a commit a7524e7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
21 changes: 18 additions & 3 deletions arrabiata/src/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ use crate::{
interpreter::{self, Instruction, Side},
MAX_DEGREE, NUMBER_OF_COLUMNS, NUMBER_OF_PUBLIC_INPUTS,
};
use ark_ec::{short_weierstrass::SWCurveConfig, CurveConfig};
use ark_ff::PrimeField;
use kimchi::circuits::{
expr::{ConstantTerm::Literal, Expr, ExprInner, Operations, Variable},
gate::CurrOrNext,
};
use log::debug;
use num_bigint::BigInt;
use o1_utils::FieldHelpers;
use poly_commitment::commitment::CommitmentCurve;

#[derive(Clone, Debug)]
pub struct Env<C: ArrabiataCurve> {
/// The parameter a is the coefficients of the elliptic curve in affine
/// coordinates.
// FIXME: this is ugly. Let use the curve as a parameter. Only lazy for now.
pub a: BigInt,
pub idx_var: usize,
pub idx_var_next_row: usize,
Expand All @@ -26,9 +28,13 @@ pub struct Env<C: ArrabiataCurve> {
pub activated_gadget: Option<Gadget>,
}

impl<C: ArrabiataCurve> Env<C> {
pub fn new(a: BigInt) -> Self {
impl<C: ArrabiataCurve> Env<C>
where
<<C as CommitmentCurve>::Params as CurveConfig>::BaseField: PrimeField,
{
pub fn new() -> Self {
// This check might not be useful
let a: BigInt = <C as CommitmentCurve>::Params::COEFF_A.to_biguint().into();
assert!(
a < C::ScalarField::modulus_biguint().into(),
"a is too large"
Expand Down Expand Up @@ -371,3 +377,12 @@ impl<C: ArrabiataCurve> Env<C> {
constraints
}
}

impl<C: ArrabiataCurve> Default for Env<C>
where
<<C as CommitmentCurve>::Params as CurveConfig>::BaseField: PrimeField,
{
fn default() -> Self {
Self::new()
}
}
17 changes: 8 additions & 9 deletions arrabiata/tests/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ use arrabiata::{
};
use mina_curves::pasta::{curves::vesta::Vesta, fields::Fp, Pallas};
use mvpoly::{monomials::Sparse, MVPoly};
use num_bigint::BigInt;
use std::collections::HashMap;

fn helper_compute_constraints_gadget(instr: Instruction, exp_constraints: usize) {
let mut constraints_fp = constraints::Env::<Vesta>::new(BigInt::from(0_usize));
let mut constraints_fp = constraints::Env::<Vesta>::new();

interpreter::run_ivc(&mut constraints_fp, instr);
assert_eq!(constraints_fp.constraints.len(), exp_constraints);

let mut constraints_fq = constraints::Env::<Pallas>::new(BigInt::from(0_usize));
let mut constraints_fq = constraints::Env::<Pallas>::new();
interpreter::run_ivc(&mut constraints_fq, instr);
assert_eq!(constraints_fq.constraints.len(), exp_constraints);
}

fn helper_check_expected_degree_constraints(instr: Instruction, exp_degrees: HashMap<u64, usize>) {
let mut constraints_fp = constraints::Env::<Vesta>::new(BigInt::from(0_usize));
let mut constraints_fp = constraints::Env::<Vesta>::new();
interpreter::run_ivc(&mut constraints_fp, instr);

let mut actual_degrees: HashMap<u64, usize> = HashMap::new();
Expand Down Expand Up @@ -51,7 +50,7 @@ fn helper_gadget_number_of_columns_used(
exp_nb_columns: usize,
exp_nb_public_input: usize,
) {
let mut constraints_fp = constraints::Env::<Vesta>::new(BigInt::from(0_usize));
let mut constraints_fp = constraints::Env::<Vesta>::new();
interpreter::run_ivc(&mut constraints_fp, instr);

let nb_columns = constraints_fp.idx_var;
Expand All @@ -62,7 +61,7 @@ fn helper_gadget_number_of_columns_used(
}

fn helper_check_gadget_activated(instr: Instruction, gadget: Gadget) {
let mut constraints_fp = constraints::Env::<Vesta>::new(BigInt::from(0_usize));
let mut constraints_fp = constraints::Env::<Vesta>::new();
interpreter::run_ivc(&mut constraints_fp, instr);

assert_eq!(constraints_fp.activated_gadget, Some(gadget));
Expand Down Expand Up @@ -103,15 +102,15 @@ fn test_gadget_elliptic_curve_addition() {

#[test]
fn test_ivc_total_number_of_constraints_ivc() {
let constraints_fp = constraints::Env::<Vesta>::new(BigInt::from(0_usize));
let constraints_fp = constraints::Env::<Vesta>::new();

let constraints = constraints_fp.get_all_constraints_for_ivc();
assert_eq!(constraints.len(), 28);
}

#[test]
fn test_degree_of_constraints_ivc() {
let constraints_fp = constraints::Env::<Vesta>::new(BigInt::from(0_usize));
let constraints_fp = constraints::Env::<Vesta>::new();

let constraints = constraints_fp.get_all_constraints_for_ivc();

Expand Down Expand Up @@ -149,7 +148,7 @@ fn test_gadget_elliptic_curve_scaling() {
// It doesn't test anything in particular. It is mostly an "integration" test.
#[test]
fn test_integration_with_mvpoly_to_compute_cross_terms() {
let constraints_fp = constraints::Env::<Vesta>::new(BigInt::from(0_usize));
let constraints_fp = constraints::Env::<Vesta>::new();

let constraints = constraints_fp.get_all_constraints_for_ivc();
let mut rng = o1_utils::tests::make_test_rng(None);
Expand Down

0 comments on commit a7524e7

Please sign in to comment.