diff --git a/arrabiata/src/constraints.rs b/arrabiata/src/constraints.rs index d568fd6699..1bc542a4ca 100644 --- a/arrabiata/src/constraints.rs +++ b/arrabiata/src/constraints.rs @@ -5,6 +5,8 @@ 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, @@ -12,12 +14,12 @@ use kimchi::circuits::{ use log::debug; use num_bigint::BigInt; use o1_utils::FieldHelpers; +use poly_commitment::commitment::CommitmentCurve; #[derive(Clone, Debug)] pub struct Env { /// 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, @@ -26,9 +28,13 @@ pub struct Env { pub activated_gadget: Option, } -impl Env { - pub fn new(a: BigInt) -> Self { +impl Env +where + <::Params as CurveConfig>::BaseField: PrimeField, +{ + pub fn new() -> Self { // This check might not be useful + let a: BigInt = ::Params::COEFF_A.to_biguint().into(); assert!( a < C::ScalarField::modulus_biguint().into(), "a is too large" @@ -371,3 +377,12 @@ impl Env { constraints } } + +impl Default for Env +where + <::Params as CurveConfig>::BaseField: PrimeField, +{ + fn default() -> Self { + Self::new() + } +} diff --git a/arrabiata/tests/constraints.rs b/arrabiata/tests/constraints.rs index 72899b059a..abc523efa3 100644 --- a/arrabiata/tests/constraints.rs +++ b/arrabiata/tests/constraints.rs @@ -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::::new(BigInt::from(0_usize)); + let mut constraints_fp = constraints::Env::::new(); interpreter::run_ivc(&mut constraints_fp, instr); assert_eq!(constraints_fp.constraints.len(), exp_constraints); - let mut constraints_fq = constraints::Env::::new(BigInt::from(0_usize)); + let mut constraints_fq = constraints::Env::::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) { - let mut constraints_fp = constraints::Env::::new(BigInt::from(0_usize)); + let mut constraints_fp = constraints::Env::::new(); interpreter::run_ivc(&mut constraints_fp, instr); let mut actual_degrees: HashMap = HashMap::new(); @@ -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::::new(BigInt::from(0_usize)); + let mut constraints_fp = constraints::Env::::new(); interpreter::run_ivc(&mut constraints_fp, instr); let nb_columns = constraints_fp.idx_var; @@ -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::::new(BigInt::from(0_usize)); + let mut constraints_fp = constraints::Env::::new(); interpreter::run_ivc(&mut constraints_fp, instr); assert_eq!(constraints_fp.activated_gadget, Some(gadget)); @@ -103,7 +102,7 @@ fn test_gadget_elliptic_curve_addition() { #[test] fn test_ivc_total_number_of_constraints_ivc() { - let constraints_fp = constraints::Env::::new(BigInt::from(0_usize)); + let constraints_fp = constraints::Env::::new(); let constraints = constraints_fp.get_all_constraints_for_ivc(); assert_eq!(constraints.len(), 28); @@ -111,7 +110,7 @@ fn test_ivc_total_number_of_constraints_ivc() { #[test] fn test_degree_of_constraints_ivc() { - let constraints_fp = constraints::Env::::new(BigInt::from(0_usize)); + let constraints_fp = constraints::Env::::new(); let constraints = constraints_fp.get_all_constraints_for_ivc(); @@ -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::::new(BigInt::from(0_usize)); + let constraints_fp = constraints::Env::::new(); let constraints = constraints_fp.get_all_constraints_for_ivc(); let mut rng = o1_utils::tests::make_test_rng(None);