From 985bd371ff68772034a356c775eac6783955e320 Mon Sep 17 00:00:00 2001 From: Maciej Skrzypkowski Date: Tue, 19 Mar 2024 11:44:09 +0100 Subject: [PATCH 1/4] Changed += to = in FieldVar double_in_place --- src/fields/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fields/mod.rs b/src/fields/mod.rs index bced7ffd..db787e70 100644 --- a/src/fields/mod.rs +++ b/src/fields/mod.rs @@ -116,7 +116,7 @@ pub trait FieldVar: /// Sets `self = self + self`. fn double_in_place(&mut self) -> Result<&mut Self, SynthesisError> { - *self += self.double()?; + *self = self.double()?; Ok(self) } From 294e89d2bbbc4fea2ae93c4a9ef6722884fbc336 Mon Sep 17 00:00:00 2001 From: Maciej Skrzypkowski Date: Thu, 21 Mar 2024 15:01:53 +0100 Subject: [PATCH 2/4] Unit test for FieldVar::double_in_place --- tests/arithmetic_tests.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/arithmetic_tests.rs b/tests/arithmetic_tests.rs index 83d72828..33dc1977 100644 --- a/tests/arithmetic_tests.rs +++ b/tests/arithmetic_tests.rs @@ -118,6 +118,29 @@ fn multiplication_test( ); } +fn doubling_test( + cs: ConstraintSystemRef, + rng: &mut R, +) { + let mut a_native = TargetF::rand(rng); + let mut a = + EmulatedFpVar::::new_witness(ark_relations::ns!(cs, "alloc a"), || { + Ok(a_native) + }) + .unwrap(); + + a.double_in_place().unwrap(); + a_native.double_in_place(); + let a_actual = a.value().unwrap(); + + assert!( + a_actual.eq(&a_native), + "a_actual = {:?}, a_native = {:?}", + a_actual.into_bigint().as_ref(), + a_native.into_bigint().as_ref() + ); +} + fn equality_test( cs: ConstraintSystemRef, rng: &mut R, @@ -592,6 +615,12 @@ macro_rules! nonnative_test { $test_target_field, $test_base_field ); + nonnative_test_individual!( + doubling_test, + $test_name, + $test_target_field, + $test_base_field + ); nonnative_test_individual!( equality_test, $test_name, From 9bf0df85ee38b6e9b65a15b2aa08dd02721d218b Mon Sep 17 00:00:00 2001 From: Maciej Skrzypkowski Date: Thu, 11 Apr 2024 13:51:08 +0200 Subject: [PATCH 3/4] removing unused imports --- src/alloc.rs | 1 - src/boolean/and.rs | 1 - src/boolean/cmp.rs | 1 - src/boolean/convert.rs | 2 +- src/boolean/eq.rs | 12 +----------- src/boolean/mod.rs | 2 -- src/boolean/or.rs | 1 - src/boolean/select.rs | 7 +------ src/boolean/test_utils.rs | 2 +- src/convert.rs | 1 - src/eq.rs | 2 +- src/fields/cubic_extension.rs | 7 +------ src/fields/emulated_fp/allocated_field_var.rs | 7 +------ src/fields/emulated_fp/allocated_mul_result.rs | 2 +- src/fields/emulated_fp/field_var.rs | 9 +-------- src/fields/emulated_fp/reduce.rs | 2 +- src/fields/fp/cmp.rs | 7 +------ src/fields/fp/mod.rs | 8 +------- src/fields/mod.rs | 1 - src/fields/quadratic_extension.rs | 7 +------ src/groups/curves/short_weierstrass/bls12/mod.rs | 8 +------- src/groups/curves/short_weierstrass/mnt4/mod.rs | 4 +--- src/groups/curves/short_weierstrass/mnt6/mod.rs | 4 +--- src/groups/curves/short_weierstrass/mod.rs | 2 +- .../curves/short_weierstrass/non_zero_affine.rs | 3 +-- src/groups/curves/twisted_edwards/mod.rs | 8 +------- src/groups/mod.rs | 6 +----- src/pairing/mod.rs | 2 +- src/poly/domain/mod.rs | 6 +----- .../univariate/lagrange_interpolator.rs | 1 - src/poly/evaluations/univariate/mod.rs | 5 +---- src/poly/polynomial/univariate/dense.rs | 3 +-- src/r1cs_var.rs | 1 - src/select.rs | 1 - src/uint/add/saturating.rs | 12 +----------- src/uint/add/wrapping.rs | 12 +----------- src/uint/and.rs | 10 +--------- src/uint/cmp.rs | 8 +------- src/uint/convert.rs | 7 +------ src/uint/eq.rs | 15 +-------------- src/uint/not.rs | 10 +--------- src/uint/or.rs | 1 - src/uint/rotate.rs | 8 +------- src/uint/select.rs | 8 +------- src/uint/shl.rs | 1 - src/uint/shr.rs | 1 - src/uint/test_utils.rs | 2 +- src/uint/xor.rs | 10 +--------- src/uint8.rs | 7 ++----- 49 files changed, 37 insertions(+), 211 deletions(-) diff --git a/src/alloc.rs b/src/alloc.rs index ccce47f5..2c6def7c 100644 --- a/src/alloc.rs +++ b/src/alloc.rs @@ -1,4 +1,3 @@ -use crate::Vec; use ark_ff::Field; use ark_relations::r1cs::{Namespace, SynthesisError}; use core::borrow::Borrow; diff --git a/src/boolean/and.rs b/src/boolean/and.rs index 20251f3f..0006e3a3 100644 --- a/src/boolean/and.rs +++ b/src/boolean/and.rs @@ -193,7 +193,6 @@ mod tests { use crate::{ alloc::{AllocVar, AllocationMode}, boolean::test_utils::run_binary_exhaustive, - prelude::EqGadget, R1CSVar, }; use ark_relations::r1cs::ConstraintSystem; diff --git a/src/boolean/cmp.rs b/src/boolean/cmp.rs index 744279a0..3adb075f 100644 --- a/src/boolean/cmp.rs +++ b/src/boolean/cmp.rs @@ -1,7 +1,6 @@ use crate::cmp::CmpGadget; use super::*; -use ark_ff::PrimeField; impl CmpGadget for Boolean { fn is_ge(&self, other: &Self) -> Result, SynthesisError> { diff --git a/src/boolean/convert.rs b/src/boolean/convert.rs index d4ce1518..3a53e89b 100644 --- a/src/boolean/convert.rs +++ b/src/boolean/convert.rs @@ -1,5 +1,5 @@ use super::*; -use crate::convert::{ToBytesGadget, ToConstraintFieldGadget}; +use crate::convert::ToConstraintFieldGadget; impl ToBytesGadget for Boolean { /// Outputs `1u8` if `self` is true, and `0u8` otherwise. diff --git a/src/boolean/eq.rs b/src/boolean/eq.rs index 43bc7da2..d914e2fd 100644 --- a/src/boolean/eq.rs +++ b/src/boolean/eq.rs @@ -1,8 +1,3 @@ -use ark_relations::r1cs::SynthesisError; - -use crate::boolean::Boolean; -use crate::eq::EqGadget; - use super::*; impl EqGadget for Boolean { @@ -83,12 +78,7 @@ impl EqGadget for Boolean { #[cfg(test)] mod tests { use super::*; - use crate::{ - alloc::{AllocVar, AllocationMode}, - boolean::test_utils::{run_binary_exhaustive, run_unary_exhaustive}, - prelude::EqGadget, - R1CSVar, - }; + use crate::boolean::test_utils::{run_binary_exhaustive, run_unary_exhaustive}; use ark_test_curves::bls12_381::Fr; #[test] diff --git a/src/boolean/mod.rs b/src/boolean/mod.rs index e4fab85c..fbfaa481 100644 --- a/src/boolean/mod.rs +++ b/src/boolean/mod.rs @@ -201,8 +201,6 @@ impl AllocVar for Boolean { #[cfg(test)] mod test { - use super::Boolean; - use crate::convert::ToBytesGadget; use crate::prelude::*; use ark_ff::{ AdditiveGroup, BitIteratorBE, BitIteratorLE, Field, One, PrimeField, UniformRand, diff --git a/src/boolean/or.rs b/src/boolean/or.rs index 8f8b41c1..c6cac8dc 100644 --- a/src/boolean/or.rs +++ b/src/boolean/or.rs @@ -152,7 +152,6 @@ mod tests { use crate::{ alloc::{AllocVar, AllocationMode}, boolean::test_utils::run_binary_exhaustive, - prelude::EqGadget, R1CSVar, }; use ark_test_curves::bls12_381::Fr; diff --git a/src/boolean/select.rs b/src/boolean/select.rs index 78eb0448..a3bbf2fb 100644 --- a/src/boolean/select.rs +++ b/src/boolean/select.rs @@ -94,12 +94,7 @@ impl CondSelectGadget for Boolean { #[cfg(test)] mod tests { use super::*; - use crate::{ - alloc::{AllocVar, AllocationMode}, - boolean::test_utils::run_binary_exhaustive, - prelude::EqGadget, - R1CSVar, - }; + use crate::boolean::test_utils::run_binary_exhaustive; use ark_test_curves::bls12_381::Fr; #[test] diff --git a/src/boolean/test_utils.rs b/src/boolean/test_utils.rs index 9577e82d..41cbdc89 100644 --- a/src/boolean/test_utils.rs +++ b/src/boolean/test_utils.rs @@ -1,7 +1,7 @@ use crate::test_utils; use super::*; -use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; +use ark_relations::r1cs::ConstraintSystem; pub(crate) fn test_unary_op( a: bool, diff --git a/src/convert.rs b/src/convert.rs index 41f87a3f..a300c449 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -1,6 +1,5 @@ use ark_ff::Field; use ark_relations::r1cs::SynthesisError; -use ark_std::vec::Vec; use crate::{boolean::Boolean, uint8::UInt8}; diff --git a/src/eq.rs b/src/eq.rs index 1692edc9..c79b311a 100644 --- a/src/eq.rs +++ b/src/eq.rs @@ -1,4 +1,4 @@ -use crate::{prelude::*, Vec}; +use crate::prelude::*; use ark_ff::{Field, PrimeField}; use ark_relations::r1cs::SynthesisError; diff --git a/src/fields/cubic_extension.rs b/src/fields/cubic_extension.rs index d0b64a71..9eff3f39 100644 --- a/src/fields/cubic_extension.rs +++ b/src/fields/cubic_extension.rs @@ -5,12 +5,7 @@ use ark_ff::{ use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use core::{borrow::Borrow, marker::PhantomData}; -use crate::{ - convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, - fields::{fp::FpVar, FieldOpsBounds, FieldVar}, - prelude::*, - Vec, -}; +use crate::{convert::ToConstraintFieldGadget, fields::fp::FpVar, prelude::*}; /// This struct is the `R1CS` equivalent of the cubic extension field type /// in `ark-ff`, i.e. `ark_ff::CubicExtField`. diff --git a/src/fields/emulated_fp/allocated_field_var.rs b/src/fields/emulated_fp/allocated_field_var.rs index 6905fe37..56258fea 100644 --- a/src/fields/emulated_fp/allocated_field_var.rs +++ b/src/fields/emulated_fp/allocated_field_var.rs @@ -3,11 +3,7 @@ use super::{ reduce::{bigint_to_basefield, limbs_to_bigint, Reducer}, AllocatedMulResultVar, }; -use crate::{ - convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, - fields::fp::FpVar, - prelude::*, -}; +use crate::{convert::ToConstraintFieldGadget, fields::fp::FpVar, prelude::*}; use ark_ff::{BigInteger, PrimeField}; use ark_relations::{ ns, @@ -20,7 +16,6 @@ use ark_std::{ cmp::{max, min}, marker::PhantomData, vec, - vec::Vec, }; /// The allocated version of `EmulatedFpVar` (introduced below) diff --git a/src/fields/emulated_fp/allocated_mul_result.rs b/src/fields/emulated_fp/allocated_mul_result.rs index 458f6223..18b4263a 100644 --- a/src/fields/emulated_fp/allocated_mul_result.rs +++ b/src/fields/emulated_fp/allocated_mul_result.rs @@ -9,7 +9,7 @@ use ark_relations::{ ns, r1cs::{ConstraintSystemRef, OptimizationGoal, Result as R1CSResult}, }; -use ark_std::{marker::PhantomData, vec::Vec}; +use ark_std::marker::PhantomData; use num_bigint::BigUint; /// The allocated form of `MulResultVar` (introduced below) diff --git a/src/fields/emulated_fp/field_var.rs b/src/fields/emulated_fp/field_var.rs index b8ad9052..88e0e4a8 100644 --- a/src/fields/emulated_fp/field_var.rs +++ b/src/fields/emulated_fp/field_var.rs @@ -1,17 +1,10 @@ use super::{params::OptimizationType, AllocatedEmulatedFpVar, MulResultVar}; -use crate::{ - boolean::Boolean, - convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, - fields::{fp::FpVar, FieldVar}, - prelude::*, - R1CSVar, -}; +use crate::{convert::ToConstraintFieldGadget, fields::fp::FpVar, prelude::*}; use ark_ff::{BigInteger, PrimeField}; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, Result as R1CSResult, SynthesisError}; use ark_std::{ borrow::Borrow, hash::{Hash, Hasher}, - vec::Vec, }; /// A gadget for representing non-native (`TargetF`) field elements over the diff --git a/src/fields/emulated_fp/reduce.rs b/src/fields/emulated_fp/reduce.rs index d3cd0c28..d02c8618 100644 --- a/src/fields/emulated_fp/reduce.rs +++ b/src/fields/emulated_fp/reduce.rs @@ -11,7 +11,7 @@ use ark_relations::{ ns, r1cs::{ConstraintSystemRef, Result as R1CSResult}, }; -use ark_std::{cmp::min, marker::PhantomData, vec, vec::Vec}; +use ark_std::{cmp::min, marker::PhantomData, vec}; use num_bigint::BigUint; use num_integer::Integer; diff --git a/src/fields/fp/cmp.rs b/src/fields/fp/cmp.rs index f3304e4a..3a3743af 100644 --- a/src/fields/fp/cmp.rs +++ b/src/fields/fp/cmp.rs @@ -1,9 +1,4 @@ -use crate::{ - boolean::Boolean, - convert::ToBitsGadget, - fields::{fp::FpVar, FieldVar}, - prelude::*, -}; +use crate::{fields::fp::FpVar, prelude::*}; use ark_ff::PrimeField; use ark_relations::r1cs::{SynthesisError, Variable}; use core::cmp::Ordering; diff --git a/src/fields/fp/mod.rs b/src/fields/fp/mod.rs index bc35c81b..d23ad3c2 100644 --- a/src/fields/fp/mod.rs +++ b/src/fields/fp/mod.rs @@ -5,13 +5,7 @@ use ark_relations::r1cs::{ use core::borrow::Borrow; -use crate::{ - boolean::AllocatedBool, - convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, - fields::{FieldOpsBounds, FieldVar}, - prelude::*, - Assignment, Vec, -}; +use crate::{boolean::AllocatedBool, convert::ToConstraintFieldGadget, prelude::*, Assignment}; use ark_std::iter::Sum; mod cmp; diff --git a/src/fields/mod.rs b/src/fields/mod.rs index db787e70..241fefb9 100644 --- a/src/fields/mod.rs +++ b/src/fields/mod.rs @@ -5,7 +5,6 @@ use core::{ ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}, }; -use crate::convert::{ToBitsGadget, ToBytesGadget}; use crate::prelude::*; /// This module contains a generic implementation of cubic extension field diff --git a/src/fields/quadratic_extension.rs b/src/fields/quadratic_extension.rs index a38f47c1..daf4567d 100644 --- a/src/fields/quadratic_extension.rs +++ b/src/fields/quadratic_extension.rs @@ -5,12 +5,7 @@ use ark_ff::{ use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use core::{borrow::Borrow, marker::PhantomData}; -use crate::{ - convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, - fields::{fp::FpVar, FieldOpsBounds, FieldVar}, - prelude::*, - Vec, -}; +use crate::{convert::ToConstraintFieldGadget, fields::fp::FpVar, prelude::*}; /// This struct is the `R1CS` equivalent of the quadratic extension field type /// in `ark-ff`, i.e. `ark_ff::QuadExtField`. diff --git a/src/groups/curves/short_weierstrass/bls12/mod.rs b/src/groups/curves/short_weierstrass/bls12/mod.rs index deb6b19a..0ba262c1 100644 --- a/src/groups/curves/short_weierstrass/bls12/mod.rs +++ b/src/groups/curves/short_weierstrass/bls12/mod.rs @@ -2,14 +2,8 @@ use ark_ec::{ bls12::{Bls12Config, G1Prepared, G2Prepared, TwistType}, short_weierstrass::Affine as GroupAffine, }; -use ark_ff::{BitIteratorBE, Field, One}; -use ark_relations::r1cs::{Namespace, SynthesisError}; -use crate::{ - fields::{fp::FpVar, fp2::Fp2Var, FieldVar}, - groups::curves::short_weierstrass::*, - Vec, -}; +use crate::{fields::fp2::Fp2Var, groups::curves::short_weierstrass::*}; use core::fmt::Debug; /// Represents a projective point in G1. diff --git a/src/groups/curves/short_weierstrass/mnt4/mod.rs b/src/groups/curves/short_weierstrass/mnt4/mod.rs index 3b960c82..d4c4e6ef 100644 --- a/src/groups/curves/short_weierstrass/mnt4/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt4/mod.rs @@ -6,12 +6,10 @@ use ark_ff::Field; use ark_relations::r1cs::{Namespace, SynthesisError}; use crate::{ - convert::ToBytesGadget, - fields::{fp::FpVar, fp2::Fp2Var, FieldVar}, + fields::{fp::FpVar, fp2::Fp2Var}, groups::curves::short_weierstrass::ProjectiveVar, pairing::mnt4::PairingVar, prelude::*, - Vec, }; use core::borrow::Borrow; diff --git a/src/groups/curves/short_weierstrass/mnt6/mod.rs b/src/groups/curves/short_weierstrass/mnt6/mod.rs index 3fdf923d..59038418 100644 --- a/src/groups/curves/short_weierstrass/mnt6/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt6/mod.rs @@ -6,12 +6,10 @@ use ark_ff::Field; use ark_relations::r1cs::{Namespace, SynthesisError}; use crate::{ - convert::ToBytesGadget, - fields::{fp::FpVar, fp3::Fp3Var, FieldVar}, + fields::{fp::FpVar, fp3::Fp3Var}, groups::curves::short_weierstrass::ProjectiveVar, pairing::mnt6::PairingVar, prelude::*, - Vec, }; use core::borrow::Borrow; diff --git a/src/groups/curves/short_weierstrass/mod.rs b/src/groups/curves/short_weierstrass/mod.rs index d18f7209..145a4f4b 100644 --- a/src/groups/curves/short_weierstrass/mod.rs +++ b/src/groups/curves/short_weierstrass/mod.rs @@ -8,7 +8,7 @@ use ark_std::{borrow::Borrow, marker::PhantomData, ops::Mul}; use non_zero_affine::NonZeroAffineVar; use crate::{ - convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, + convert::ToConstraintFieldGadget, fields::{emulated_fp::EmulatedFpVar, fp::FpVar}, prelude::*, Vec, diff --git a/src/groups/curves/short_weierstrass/non_zero_affine.rs b/src/groups/curves/short_weierstrass/non_zero_affine.rs index 7b894348..180e9b91 100644 --- a/src/groups/curves/short_weierstrass/non_zero_affine.rs +++ b/src/groups/curves/short_weierstrass/non_zero_affine.rs @@ -1,5 +1,4 @@ use super::*; -use ark_ff::AdditiveGroup; use ark_std::ops::Add; /// An affine representation of a prime order curve point that is guaranteed @@ -239,7 +238,7 @@ mod test_non_zero_affine { }; use ark_ec::{models::short_weierstrass::SWCurveConfig, CurveGroup}; use ark_relations::r1cs::ConstraintSystem; - use ark_std::{vec::Vec, One}; + use ark_std::One; use ark_test_curves::bls12_381::{g1::Config as G1Config, Fq}; #[test] diff --git a/src/groups/curves/twisted_edwards/mod.rs b/src/groups/curves/twisted_edwards/mod.rs index 82095bfd..ca6cab42 100644 --- a/src/groups/curves/twisted_edwards/mod.rs +++ b/src/groups/curves/twisted_edwards/mod.rs @@ -8,12 +8,7 @@ use ark_ec::{ use ark_ff::{BitIteratorBE, Field, One, PrimeField, Zero}; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; -use crate::{ - convert::{ToBitsGadget, ToBytesGadget, ToConstraintFieldGadget}, - fields::emulated_fp::EmulatedFpVar, - prelude::*, - Vec, -}; +use crate::{convert::ToConstraintFieldGadget, fields::emulated_fp::EmulatedFpVar, prelude::*}; use crate::fields::fp::FpVar; use ark_std::{borrow::Borrow, marker::PhantomData, ops::Mul}; @@ -44,7 +39,6 @@ where mod montgomery_affine_impl { use super::*; use ark_ec::twisted_edwards::MontgomeryAffine as GroupAffine; - use ark_ff::Field; use core::ops::Add; impl R1CSVar> for MontgomeryAffineVar diff --git a/src/groups/mod.rs b/src/groups/mod.rs index 08edbd57..444cdf18 100644 --- a/src/groups/mod.rs +++ b/src/groups/mod.rs @@ -1,8 +1,4 @@ -use crate::{ - convert::{ToBitsGadget, ToBytesGadget}, - fields::emulated_fp::EmulatedFpVar, - prelude::*, -}; +use crate::{fields::emulated_fp::EmulatedFpVar, prelude::*}; use ark_ff::PrimeField; use ark_relations::r1cs::{Namespace, SynthesisError}; use core::ops::{Add, AddAssign, Mul, MulAssign, Sub, SubAssign}; diff --git a/src/pairing/mod.rs b/src/pairing/mod.rs index ab081fb8..dbdb6483 100644 --- a/src/pairing/mod.rs +++ b/src/pairing/mod.rs @@ -1,4 +1,4 @@ -use crate::{convert::ToBytesGadget, prelude::*}; +use crate::prelude::*; use ark_ec::pairing::Pairing; use ark_relations::r1cs::SynthesisError; use core::fmt::Debug; diff --git a/src/poly/domain/mod.rs b/src/poly/domain/mod.rs index ebb72127..d0108d38 100644 --- a/src/poly/domain/mod.rs +++ b/src/poly/domain/mod.rs @@ -5,7 +5,6 @@ use crate::{ }; use ark_ff::PrimeField; use ark_relations::r1cs::SynthesisError; -use ark_std::vec::Vec; pub mod vanishing_poly; @@ -129,10 +128,7 @@ mod tests { use ark_relations::r1cs::ConstraintSystem; use ark_std::{rand::Rng, test_rng}; - use crate::{ - alloc::AllocVar, convert::ToBitsGadget, fields::fp::FpVar, poly::domain::Radix2DomainVar, - R1CSVar, - }; + use crate::{fields::fp::FpVar, poly::domain::Radix2DomainVar}; fn test_query_coset_template() { const COSET_DIM: u64 = 7; diff --git a/src/poly/evaluations/univariate/lagrange_interpolator.rs b/src/poly/evaluations/univariate/lagrange_interpolator.rs index 252f3d55..3acc1321 100644 --- a/src/poly/evaluations/univariate/lagrange_interpolator.rs +++ b/src/poly/evaluations/univariate/lagrange_interpolator.rs @@ -1,6 +1,5 @@ use crate::poly::domain::vanishing_poly::VanishingPolynomial; use ark_ff::{batch_inversion_and_mul, PrimeField}; -use ark_std::vec::Vec; /// Struct describing Lagrange interpolation for a multiplicative coset I, /// with |I| a power of 2. /// TODO: Pull in lagrange poly explanation from libiop diff --git a/src/poly/evaluations/univariate/mod.rs b/src/poly/evaluations/univariate/mod.rs index c05cc092..ce06646d 100644 --- a/src/poly/evaluations/univariate/mod.rs +++ b/src/poly/evaluations/univariate/mod.rs @@ -12,10 +12,7 @@ use crate::{ }; use ark_ff::{batch_inversion, PrimeField}; use ark_relations::r1cs::SynthesisError; -use ark_std::{ - ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}, - vec::Vec, -}; +use ark_std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; #[derive(Clone)] /// Stores a UV polynomial in evaluation form. diff --git a/src/poly/polynomial/univariate/dense.rs b/src/poly/polynomial/univariate/dense.rs index 53488963..3bc4ec3c 100644 --- a/src/poly/polynomial/univariate/dense.rs +++ b/src/poly/polynomial/univariate/dense.rs @@ -2,7 +2,6 @@ use ark_ff::PrimeField; use ark_relations::r1cs::SynthesisError; use crate::fields::{fp::FpVar, FieldVar}; -use ark_std::vec::Vec; /// Stores a polynomial in coefficient form, where coeffcient is represented by /// a list of `Fpvar`. @@ -47,7 +46,7 @@ mod tests { }; use ark_poly::{polynomial::univariate::DensePolynomial, DenseUVPolynomial, Polynomial}; use ark_relations::r1cs::ConstraintSystem; - use ark_std::{test_rng, vec::Vec, UniformRand}; + use ark_std::{test_rng, UniformRand}; use ark_test_curves::bls12_381::Fr; #[test] diff --git a/src/r1cs_var.rs b/src/r1cs_var.rs index f99e9b2d..dcbe5c9a 100644 --- a/src/r1cs_var.rs +++ b/src/r1cs_var.rs @@ -1,6 +1,5 @@ use ark_ff::Field; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; -use ark_std::vec::Vec; /// This trait describes some core functionality that is common to high-level /// variables, such as `Boolean`s, `FieldVar`s, `GroupVar`s, etc. diff --git a/src/select.rs b/src/select.rs index 528fc90d..ced0415b 100644 --- a/src/select.rs +++ b/src/select.rs @@ -1,7 +1,6 @@ use crate::prelude::*; use ark_ff::Field; use ark_relations::r1cs::SynthesisError; -use ark_std::vec::Vec; /// Generates constraints for selecting between one of two values. pub trait CondSelectGadget: Sized + Clone { /// If `cond == &Boolean::TRUE`, then this returns `true_value`; else, diff --git a/src/uint/add/saturating.rs b/src/uint/add/saturating.rs index 62c393eb..2739fab6 100644 --- a/src/uint/add/saturating.rs +++ b/src/uint/add/saturating.rs @@ -1,8 +1,4 @@ -use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; - use crate::uint::*; -use crate::{boolean::Boolean, R1CSVar}; impl UInt { /// Compute `*self = self.wrapping_add(other)`. @@ -56,13 +52,7 @@ impl UInt { #[cfg(test)] mod tests { use super::*; - use crate::{ - alloc::{AllocVar, AllocationMode}, - prelude::EqGadget, - uint::test_utils::{run_binary_exhaustive, run_binary_random}, - R1CSVar, - }; - use ark_ff::PrimeField; + use crate::uint::test_utils::{run_binary_exhaustive, run_binary_random}; use ark_test_curves::bls12_381::Fr; fn uint_saturating_add( diff --git a/src/uint/add/wrapping.rs b/src/uint/add/wrapping.rs index 5dfe4496..86aeb539 100644 --- a/src/uint/add/wrapping.rs +++ b/src/uint/add/wrapping.rs @@ -1,8 +1,4 @@ -use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; - use crate::uint::*; -use crate::R1CSVar; impl UInt { /// Compute `*self = self.wrapping_add(other)`. @@ -45,13 +41,7 @@ impl UInt { #[cfg(test)] mod tests { use super::*; - use crate::{ - alloc::{AllocVar, AllocationMode}, - prelude::EqGadget, - uint::test_utils::{run_binary_exhaustive, run_binary_random}, - R1CSVar, - }; - use ark_ff::PrimeField; + use crate::uint::test_utils::{run_binary_exhaustive, run_binary_random}; use ark_test_curves::bls12_381::Fr; fn uint_wrapping_add( diff --git a/src/uint/and.rs b/src/uint/and.rs index cfe711a2..8740d2c5 100644 --- a/src/uint/and.rs +++ b/src/uint/and.rs @@ -1,5 +1,3 @@ -use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; use ark_std::{ops::BitAnd, ops::BitAndAssign}; use super::*; @@ -256,13 +254,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitAndAssign<&'a T> for UInt( diff --git a/src/uint/cmp.rs b/src/uint/cmp.rs index 5a01b169..d980d47f 100644 --- a/src/uint/cmp.rs +++ b/src/uint/cmp.rs @@ -19,13 +19,7 @@ impl> CmpGadget for UInt #[cfg(test)] mod tests { use super::*; - use crate::{ - alloc::{AllocVar, AllocationMode}, - prelude::EqGadget, - uint::test_utils::{run_binary_exhaustive, run_binary_random}, - R1CSVar, - }; - use ark_ff::PrimeField; + use crate::uint::test_utils::{run_binary_exhaustive, run_binary_random}; use ark_test_curves::bls12_381::Fr; fn uint_gt>( diff --git a/src/uint/convert.rs b/src/uint/convert.rs index 242c3ad8..b031de65 100644 --- a/src/uint/convert.rs +++ b/src/uint/convert.rs @@ -174,12 +174,7 @@ impl ToBytesGadget #[cfg(test)] mod tests { use super::*; - use crate::{ - prelude::EqGadget, - uint::test_utils::{run_unary_exhaustive, run_unary_random}, - R1CSVar, - }; - use ark_ff::PrimeField; + use crate::uint::test_utils::{run_unary_exhaustive, run_unary_random}; use ark_test_curves::bls12_381::Fr; fn uint_to_bytes_le( diff --git a/src/uint/eq.rs b/src/uint/eq.rs index 1b7c386f..5bafba93 100644 --- a/src/uint/eq.rs +++ b/src/uint/eq.rs @@ -1,10 +1,3 @@ -use ark_ff::PrimeField; -use ark_relations::r1cs::SynthesisError; -use ark_std::vec::Vec; - -use crate::boolean::Boolean; -use crate::eq::EqGadget; - use super::*; impl EqGadget @@ -68,13 +61,7 @@ impl EqGadget #[cfg(test)] mod tests { use super::*; - use crate::{ - alloc::{AllocVar, AllocationMode}, - prelude::EqGadget, - uint::test_utils::{run_binary_exhaustive, run_binary_random}, - R1CSVar, - }; - use ark_ff::PrimeField; + use crate::uint::test_utils::{run_binary_exhaustive, run_binary_random}; use ark_test_curves::bls12_381::Fr; fn uint_eq( diff --git a/src/uint/not.rs b/src/uint/not.rs index 8457f2ec..1547200a 100644 --- a/src/uint/not.rs +++ b/src/uint/not.rs @@ -1,5 +1,3 @@ -use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; use ark_std::ops::Not; use super::*; @@ -81,13 +79,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> Not for UInt { #[cfg(test)] mod tests { use super::*; - use crate::{ - alloc::{AllocVar, AllocationMode}, - prelude::EqGadget, - uint::test_utils::{run_unary_exhaustive, run_unary_random}, - R1CSVar, - }; - use ark_ff::PrimeField; + use crate::uint::test_utils::{run_unary_exhaustive, run_unary_random}; use ark_test_curves::bls12_381::Fr; fn uint_not( diff --git a/src/uint/or.rs b/src/uint/or.rs index 0ca124ec..e0a7dc74 100644 --- a/src/uint/or.rs +++ b/src/uint/or.rs @@ -175,7 +175,6 @@ mod tests { uint::test_utils::{run_binary_exhaustive_both, run_binary_random_both}, R1CSVar, }; - use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; fn uint_or( diff --git a/src/uint/rotate.rs b/src/uint/rotate.rs index 62cd39f3..9498d292 100644 --- a/src/uint/rotate.rs +++ b/src/uint/rotate.rs @@ -111,13 +111,7 @@ impl UInt { #[cfg(test)] mod tests { use super::*; - use crate::{ - alloc::{AllocVar, AllocationMode}, - prelude::EqGadget, - uint::test_utils::{run_unary_exhaustive, run_unary_random}, - R1CSVar, - }; - use ark_ff::PrimeField; + use crate::uint::test_utils::{run_unary_exhaustive, run_unary_random}; use ark_test_curves::bls12_381::Fr; fn uint_rotate_left( diff --git a/src/uint/select.rs b/src/uint/select.rs index 6c061fe2..a44f2a15 100644 --- a/src/uint/select.rs +++ b/src/uint/select.rs @@ -1,5 +1,4 @@ use super::*; -use crate::select::CondSelectGadget; impl CondSelectGadget for UInt @@ -34,12 +33,7 @@ impl CondSelectGadget( diff --git a/src/uint/shl.rs b/src/uint/shl.rs index 4382ce64..f52937de 100644 --- a/src/uint/shl.rs +++ b/src/uint/shl.rs @@ -102,7 +102,6 @@ mod tests { uint::test_utils::{run_binary_exhaustive_native_only, run_binary_random_native_only}, R1CSVar, }; - use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; fn uint_shl( diff --git a/src/uint/shr.rs b/src/uint/shr.rs index 7368a3fb..56194afe 100644 --- a/src/uint/shr.rs +++ b/src/uint/shr.rs @@ -102,7 +102,6 @@ mod tests { uint::test_utils::{run_binary_exhaustive_native_only, run_binary_random_native_only}, R1CSVar, }; - use ark_ff::PrimeField; use ark_test_curves::bls12_381::Fr; fn uint_shr( diff --git a/src/uint/test_utils.rs b/src/uint/test_utils.rs index 4987a2a7..97bf64bd 100644 --- a/src/uint/test_utils.rs +++ b/src/uint/test_utils.rs @@ -1,4 +1,4 @@ -use ark_relations::r1cs::{ConstraintSystem, SynthesisError}; +use ark_relations::r1cs::ConstraintSystem; use std::ops::RangeInclusive; use crate::test_utils::{self, modes}; diff --git a/src/uint/xor.rs b/src/uint/xor.rs index 56546ba7..2fb3368d 100644 --- a/src/uint/xor.rs +++ b/src/uint/xor.rs @@ -1,5 +1,3 @@ -use ark_ff::Field; -use ark_relations::r1cs::SynthesisError; use ark_std::{ops::BitXor, ops::BitXorAssign}; use super::*; @@ -168,13 +166,7 @@ impl<'a, const N: usize, T: PrimUInt, F: Field> BitXorAssign<&'a T> for UInt( diff --git a/src/uint8.rs b/src/uint8.rs index 1f952de4..e6b1124b 100644 --- a/src/uint8.rs +++ b/src/uint8.rs @@ -3,10 +3,9 @@ use ark_ff::{Field, PrimeField, ToConstraintField}; use ark_relations::r1cs::{Namespace, SynthesisError}; use crate::{ - convert::{ToBitsGadget, ToConstraintFieldGadget}, + convert::ToConstraintFieldGadget, fields::fp::{AllocatedFp, FpVar}, prelude::*, - Vec, }; pub type UInt8 = super::uint::UInt<8, u8, F>; @@ -95,15 +94,13 @@ impl ToConstraintFieldGadget for Vec Date: Thu, 25 Apr 2024 15:17:36 +0200 Subject: [PATCH 4/4] brought back Vec imports --- src/alloc.rs | 1 + src/convert.rs | 1 + src/eq.rs | 1 + src/fields/cubic_extension.rs | 1 + src/fields/emulated_fp/allocated_field_var.rs | 1 + src/fields/emulated_fp/allocated_mul_result.rs | 2 +- src/fields/emulated_fp/field_var.rs | 1 + src/fields/emulated_fp/reduce.rs | 2 +- src/fields/fp/mod.rs | 2 +- src/fields/quadratic_extension.rs | 1 + src/groups/curves/short_weierstrass/mnt4/mod.rs | 1 + src/groups/curves/short_weierstrass/mnt6/mod.rs | 1 + src/groups/curves/twisted_edwards/mod.rs | 2 +- src/poly/domain/mod.rs | 1 + src/poly/evaluations/univariate/lagrange_interpolator.rs | 1 + src/poly/evaluations/univariate/mod.rs | 5 ++++- src/poly/polynomial/univariate/dense.rs | 1 + src/r1cs_var.rs | 1 + src/select.rs | 1 + src/uint8.rs | 2 +- 20 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/alloc.rs b/src/alloc.rs index 2c6def7c..e81f5236 100644 --- a/src/alloc.rs +++ b/src/alloc.rs @@ -1,5 +1,6 @@ use ark_ff::Field; use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_std::vec::Vec; use core::borrow::Borrow; /// Describes the mode that a variable should be allocated in within diff --git a/src/convert.rs b/src/convert.rs index a300c449..41f87a3f 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -1,5 +1,6 @@ use ark_ff::Field; use ark_relations::r1cs::SynthesisError; +use ark_std::vec::Vec; use crate::{boolean::Boolean, uint8::UInt8}; diff --git a/src/eq.rs b/src/eq.rs index c79b311a..de45e4f3 100644 --- a/src/eq.rs +++ b/src/eq.rs @@ -1,6 +1,7 @@ use crate::prelude::*; use ark_ff::{Field, PrimeField}; use ark_relations::r1cs::SynthesisError; +use ark_std::vec::Vec; /// Specifies how to generate constraints that check for equality for two /// variables of type `Self`. diff --git a/src/fields/cubic_extension.rs b/src/fields/cubic_extension.rs index 9eff3f39..306cd115 100644 --- a/src/fields/cubic_extension.rs +++ b/src/fields/cubic_extension.rs @@ -3,6 +3,7 @@ use ark_ff::{ CubicExtConfig, Zero, }; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use ark_std::vec::Vec; use core::{borrow::Borrow, marker::PhantomData}; use crate::{convert::ToConstraintFieldGadget, fields::fp::FpVar, prelude::*}; diff --git a/src/fields/emulated_fp/allocated_field_var.rs b/src/fields/emulated_fp/allocated_field_var.rs index 56258fea..a84fd197 100644 --- a/src/fields/emulated_fp/allocated_field_var.rs +++ b/src/fields/emulated_fp/allocated_field_var.rs @@ -16,6 +16,7 @@ use ark_std::{ cmp::{max, min}, marker::PhantomData, vec, + vec::Vec, }; /// The allocated version of `EmulatedFpVar` (introduced below) diff --git a/src/fields/emulated_fp/allocated_mul_result.rs b/src/fields/emulated_fp/allocated_mul_result.rs index 18b4263a..458f6223 100644 --- a/src/fields/emulated_fp/allocated_mul_result.rs +++ b/src/fields/emulated_fp/allocated_mul_result.rs @@ -9,7 +9,7 @@ use ark_relations::{ ns, r1cs::{ConstraintSystemRef, OptimizationGoal, Result as R1CSResult}, }; -use ark_std::marker::PhantomData; +use ark_std::{marker::PhantomData, vec::Vec}; use num_bigint::BigUint; /// The allocated form of `MulResultVar` (introduced below) diff --git a/src/fields/emulated_fp/field_var.rs b/src/fields/emulated_fp/field_var.rs index 88e0e4a8..517bfee4 100644 --- a/src/fields/emulated_fp/field_var.rs +++ b/src/fields/emulated_fp/field_var.rs @@ -5,6 +5,7 @@ use ark_relations::r1cs::{ConstraintSystemRef, Namespace, Result as R1CSResult, use ark_std::{ borrow::Borrow, hash::{Hash, Hasher}, + vec::Vec, }; /// A gadget for representing non-native (`TargetF`) field elements over the diff --git a/src/fields/emulated_fp/reduce.rs b/src/fields/emulated_fp/reduce.rs index d02c8618..d3cd0c28 100644 --- a/src/fields/emulated_fp/reduce.rs +++ b/src/fields/emulated_fp/reduce.rs @@ -11,7 +11,7 @@ use ark_relations::{ ns, r1cs::{ConstraintSystemRef, Result as R1CSResult}, }; -use ark_std::{cmp::min, marker::PhantomData, vec}; +use ark_std::{cmp::min, marker::PhantomData, vec, vec::Vec}; use num_bigint::BigUint; use num_integer::Integer; diff --git a/src/fields/fp/mod.rs b/src/fields/fp/mod.rs index d23ad3c2..b943d6d2 100644 --- a/src/fields/fp/mod.rs +++ b/src/fields/fp/mod.rs @@ -6,7 +6,7 @@ use ark_relations::r1cs::{ use core::borrow::Borrow; use crate::{boolean::AllocatedBool, convert::ToConstraintFieldGadget, prelude::*, Assignment}; -use ark_std::iter::Sum; +use ark_std::{iter::Sum, vec::Vec}; mod cmp; diff --git a/src/fields/quadratic_extension.rs b/src/fields/quadratic_extension.rs index daf4567d..dbbd362d 100644 --- a/src/fields/quadratic_extension.rs +++ b/src/fields/quadratic_extension.rs @@ -3,6 +3,7 @@ use ark_ff::{ Zero, }; use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; +use ark_std::vec::Vec; use core::{borrow::Borrow, marker::PhantomData}; use crate::{convert::ToConstraintFieldGadget, fields::fp::FpVar, prelude::*}; diff --git a/src/groups/curves/short_weierstrass/mnt4/mod.rs b/src/groups/curves/short_weierstrass/mnt4/mod.rs index d4c4e6ef..b1682898 100644 --- a/src/groups/curves/short_weierstrass/mnt4/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt4/mod.rs @@ -4,6 +4,7 @@ use ark_ec::mnt4::{ }; use ark_ff::Field; use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_std::vec::Vec; use crate::{ fields::{fp::FpVar, fp2::Fp2Var}, diff --git a/src/groups/curves/short_weierstrass/mnt6/mod.rs b/src/groups/curves/short_weierstrass/mnt6/mod.rs index 59038418..ff33a5f1 100644 --- a/src/groups/curves/short_weierstrass/mnt6/mod.rs +++ b/src/groups/curves/short_weierstrass/mnt6/mod.rs @@ -4,6 +4,7 @@ use ark_ec::mnt6::{ }; use ark_ff::Field; use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_std::vec::Vec; use crate::{ fields::{fp::FpVar, fp3::Fp3Var}, diff --git a/src/groups/curves/twisted_edwards/mod.rs b/src/groups/curves/twisted_edwards/mod.rs index ca6cab42..5427c8b4 100644 --- a/src/groups/curves/twisted_edwards/mod.rs +++ b/src/groups/curves/twisted_edwards/mod.rs @@ -11,7 +11,7 @@ use ark_relations::r1cs::{ConstraintSystemRef, Namespace, SynthesisError}; use crate::{convert::ToConstraintFieldGadget, fields::emulated_fp::EmulatedFpVar, prelude::*}; use crate::fields::fp::FpVar; -use ark_std::{borrow::Borrow, marker::PhantomData, ops::Mul}; +use ark_std::{borrow::Borrow, marker::PhantomData, ops::Mul, vec::Vec}; type BasePrimeField

= <

::BaseField as Field>::BasePrimeField; diff --git a/src/poly/domain/mod.rs b/src/poly/domain/mod.rs index d0108d38..5586b867 100644 --- a/src/poly/domain/mod.rs +++ b/src/poly/domain/mod.rs @@ -5,6 +5,7 @@ use crate::{ }; use ark_ff::PrimeField; use ark_relations::r1cs::SynthesisError; +use ark_std::vec::Vec; pub mod vanishing_poly; diff --git a/src/poly/evaluations/univariate/lagrange_interpolator.rs b/src/poly/evaluations/univariate/lagrange_interpolator.rs index 3acc1321..252f3d55 100644 --- a/src/poly/evaluations/univariate/lagrange_interpolator.rs +++ b/src/poly/evaluations/univariate/lagrange_interpolator.rs @@ -1,5 +1,6 @@ use crate::poly::domain::vanishing_poly::VanishingPolynomial; use ark_ff::{batch_inversion_and_mul, PrimeField}; +use ark_std::vec::Vec; /// Struct describing Lagrange interpolation for a multiplicative coset I, /// with |I| a power of 2. /// TODO: Pull in lagrange poly explanation from libiop diff --git a/src/poly/evaluations/univariate/mod.rs b/src/poly/evaluations/univariate/mod.rs index ce06646d..c05cc092 100644 --- a/src/poly/evaluations/univariate/mod.rs +++ b/src/poly/evaluations/univariate/mod.rs @@ -12,7 +12,10 @@ use crate::{ }; use ark_ff::{batch_inversion, PrimeField}; use ark_relations::r1cs::SynthesisError; -use ark_std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; +use ark_std::{ + ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}, + vec::Vec, +}; #[derive(Clone)] /// Stores a UV polynomial in evaluation form. diff --git a/src/poly/polynomial/univariate/dense.rs b/src/poly/polynomial/univariate/dense.rs index 3bc4ec3c..a7c6b9e2 100644 --- a/src/poly/polynomial/univariate/dense.rs +++ b/src/poly/polynomial/univariate/dense.rs @@ -1,5 +1,6 @@ use ark_ff::PrimeField; use ark_relations::r1cs::SynthesisError; +use ark_std::vec::Vec; use crate::fields::{fp::FpVar, FieldVar}; diff --git a/src/r1cs_var.rs b/src/r1cs_var.rs index dcbe5c9a..f99e9b2d 100644 --- a/src/r1cs_var.rs +++ b/src/r1cs_var.rs @@ -1,5 +1,6 @@ use ark_ff::Field; use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError}; +use ark_std::vec::Vec; /// This trait describes some core functionality that is common to high-level /// variables, such as `Boolean`s, `FieldVar`s, `GroupVar`s, etc. diff --git a/src/select.rs b/src/select.rs index ced0415b..528fc90d 100644 --- a/src/select.rs +++ b/src/select.rs @@ -1,6 +1,7 @@ use crate::prelude::*; use ark_ff::Field; use ark_relations::r1cs::SynthesisError; +use ark_std::vec::Vec; /// Generates constraints for selecting between one of two values. pub trait CondSelectGadget: Sized + Clone { /// If `cond == &Boolean::TRUE`, then this returns `true_value`; else, diff --git a/src/uint8.rs b/src/uint8.rs index e6b1124b..69f65923 100644 --- a/src/uint8.rs +++ b/src/uint8.rs @@ -1,6 +1,6 @@ use ark_ff::{Field, PrimeField, ToConstraintField}; - use ark_relations::r1cs::{Namespace, SynthesisError}; +use ark_std::vec::Vec; use crate::{ convert::ToConstraintFieldGadget,