diff --git a/curves/curve-constraint-tests/src/lib.rs b/curves/curve-constraint-tests/src/lib.rs index b7d146ade..2607f8c85 100644 --- a/curves/curve-constraint-tests/src/lib.rs +++ b/curves/curve-constraint-tests/src/lib.rs @@ -195,7 +195,7 @@ pub mod fields { pub fn frobenius_tests(maxpower: usize) -> Result<(), SynthesisError> where F: Field, - ConstraintF: Field, + ConstraintF: PrimeField, AF: FieldVar, for<'a> &'a AF: FieldOpsBounds<'a, F, AF>, { @@ -231,7 +231,7 @@ pub mod curves { use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; use ark_std::{test_rng, vec::Vec, UniformRand}; - use ark_r1cs_std::prelude::*; + use ark_r1cs_std::{fields::emulated_fp::EmulatedFpVar, prelude::*}; pub fn group_test() -> Result<(), SynthesisError> where @@ -350,15 +350,29 @@ pub mod curves { let scalar_bits: Vec = BitIteratorLE::new(&scalar).collect(); input = Vec::new_witness(ark_relations::ns!(cs, "bits"), || Ok(scalar_bits)).unwrap(); + let scalar_var = EmulatedFpVar::new_variable( + ark_relations::ns!(cs, "scalar"), + || { + let scalar = scalar + .iter() + .flat_map(|b| b.to_le_bytes()) + .collect::>(); + Ok(C::ScalarField::from_le_bytes_mod_order(&scalar)) + }, + mode, + ) + .unwrap(); let result = a .scalar_mul_le(input.iter()) .expect(&format!("Mode: {:?}", mode)); + let mul_result = a.clone() * scalar_var; let result_val = result.value()?.into_affine(); assert_eq!( result_val, native_result, "gadget & native values are diff. after scalar mul {:?}", scalar, ); + assert_eq!(mul_result.value().unwrap().into_affine(), native_result); assert!(cs.is_satisfied().unwrap()); } @@ -521,10 +535,13 @@ pub mod pairing { AffineRepr, CurveGroup, }; use ark_ff::{BitIteratorLE, Field, PrimeField}; + use ark_r1cs_std::convert::ToBytesGadget; use ark_r1cs_std::prelude::*; use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; use ark_std::{test_rng, vec::Vec, UniformRand}; + type BasePrimeField

= <

::BaseField as Field>::BasePrimeField; + #[allow(dead_code)] pub fn bilinearity_test>() -> Result<(), SynthesisError> where @@ -538,7 +555,7 @@ pub mod pairing { AllocationMode::Constant, ]; for &mode in &modes { - let cs = ConstraintSystem::<::BaseField>::new_ref(); + let cs = ConstraintSystem::>::new_ref(); let mut rng = test_rng(); let a = E::G1::rand(&mut rng);