From d9527c832888ffbd9231999b30a700ce3e572c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michele=20Orr=C3=B9?= Date: Fri, 15 Dec 2023 20:49:27 +0100 Subject: [PATCH] Fix #715 (#716) --- ff/src/biginteger/mod.rs | 6 +++--- ff/src/biginteger/tests.rs | 31 +++++++++++++++---------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/ff/src/biginteger/mod.rs b/ff/src/biginteger/mod.rs index 7aded310b..e7c07ac37 100644 --- a/ff/src/biginteger/mod.rs +++ b/ff/src/biginteger/mod.rs @@ -799,15 +799,15 @@ pub trait BigInteger: + Into + BitXorAssign + for<'a> BitXorAssign<&'a Self> - + BitXor + + BitXor + for<'a> BitXor<&'a Self, Output = Self> + BitAndAssign + for<'a> BitAndAssign<&'a Self> - + BitAnd + + BitAnd + for<'a> BitAnd<&'a Self, Output = Self> + BitOrAssign + for<'a> BitOrAssign<&'a Self> - + BitOr + + BitOr + for<'a> BitOr<&'a Self, Output = Self> { /// Number of 64-bit limbs representing `Self`. diff --git a/ff/src/biginteger/tests.rs b/ff/src/biginteger/tests.rs index cb355f48b..fd381efcf 100644 --- a/ff/src/biginteger/tests.rs +++ b/ff/src/biginteger/tests.rs @@ -1,5 +1,4 @@ -use crate::{biginteger::BigInteger, BigInt, UniformRand}; -use ark_std::rand::Rng; +use crate::{biginteger::BigInteger, UniformRand}; use num_bigint::BigUint; // Test elementary math operations for BigInteger. @@ -58,43 +57,43 @@ fn biginteger_bitwise_ops_test() { // Test XOR // a xor a = 0 - let a: BigInt<4> = UniformRand::rand(&mut rng); - assert_eq!(a ^ &a, BigInt::from(0_u64)); + let a = B::rand(&mut rng); + assert_eq!(a ^ &a, B::from(0_u64)); // Testing a xor b xor b - let a: BigInt<4> = UniformRand::rand(&mut rng); - let b: BigInt<4> = UniformRand::rand(&mut rng); + let a = B::rand(&mut rng); + let b = B::rand(&mut rng); let xor_ab = a ^ b; assert_eq!(xor_ab ^ b, a); // Test OR // a or a = a - let a = rng.gen::>(); + let a = B::rand(&mut rng); assert_eq!(a | &a, a); // Testing a or b or b - let a = rng.gen::>(); - let b = rng.gen::>(); + let a = B::rand(&mut rng); + let b = B::rand(&mut rng); let or_ab = a | b; assert_eq!(or_ab | &b, a | b); // Test AND // a and a = a - let a = rng.gen::>(); + let a = B::rand(&mut rng); assert_eq!(a & (&a), a); // Testing a and a and b. - let a = rng.gen::>(); - let b = rng.gen::>(); + let a = B::rand(&mut rng); + let b = B::rand(&mut rng); let b_clone = b.clone(); let and_ab = a & b; assert_eq!(and_ab & b_clone, a & b); // Testing De Morgan's law - let a = rng.gen::>(); - let b = rng.gen::>(); - let de_morgan_lhs = !(a | b); - let de_morgan_rhs = (!a) & (!b); + let a = 0x1234567890abcdef_u64; + let b = 0xfedcba0987654321_u64; + let de_morgan_lhs = B::from(!(a | b)); + let de_morgan_rhs = B::from(!a) & B::from(!b); assert_eq!(de_morgan_lhs, de_morgan_rhs); }