diff --git a/felt/src/bigint_felt.rs b/felt/src/bigint_felt.rs index 93a49301bb..253aa47f32 100644 --- a/felt/src/bigint_felt.rs +++ b/felt/src/bigint_felt.rs @@ -25,14 +25,13 @@ lazy_static! { } #[derive(Eq, Hash, PartialEq, PartialOrd, Ord, Clone, Deserialize, Default, Serialize)] -//pub struct FeltBigInt(BigUint); -pub struct FeltBigInt { +pub(crate) struct FeltBigInt { val: BigUint, } macro_rules! from_integer { ($type:ty) => { - impl From<$type> for FeltBigInt { + impl From<$type> for FeltBigInt { fn from(value: $type) -> Self { Self { val: value @@ -46,7 +45,7 @@ macro_rules! from_integer { macro_rules! from_unsigned { ($type:ty) => { - impl From<$type> for FeltBigInt { + impl From<$type> for FeltBigInt { fn from(value: $type) -> Self { Self { val: value.into() } } @@ -70,24 +69,24 @@ from_unsigned!(usize); impl From for FeltBigInt { fn from(value: BigUint) -> Self { - if value > *CAIRO_PRIME { - Self { - val: value.mod_floor(&CAIRO_PRIME), - } - } else { - Self { val: value } + Self { + val: match value { + _ if value > *CAIRO_PRIME => value.mod_floor(&CAIRO_PRIME), + _ if value == *CAIRO_PRIME => BigUint::zero(), + _ => value, + }, } } } impl From<&BigUint> for FeltBigInt { fn from(value: &BigUint) -> Self { - if value > &*CAIRO_PRIME { - Self { - val: value.mod_floor(&CAIRO_PRIME), - } - } else { - Self { val: value.clone() } + Self { + val: match value { + _ if value > &*CAIRO_PRIME => value.mod_floor(&CAIRO_PRIME), + _ if value == &*CAIRO_PRIME => BigUint::zero(), + _ => value.clone(), + }, } } } @@ -125,12 +124,18 @@ impl From<&BigInt> for FeltBigInt { } } -impl FeltOps for FeltBigInt { - fn new>(value: T) -> Self { +impl FeltOps for FeltBigInt { + fn new>>( + value: T, + ) -> FeltBigInt { value.into() } - fn modpow(&self, exponent: &FeltBigInt, modulus: &FeltBigInt) -> Self { + fn modpow( + &self, + exponent: &FeltBigInt, + modulus: &FeltBigInt, + ) -> FeltBigInt { FeltBigInt { val: self.val.modpow(&exponent.val, &modulus.val), } @@ -148,16 +153,15 @@ impl FeltOps for FeltBigInt { self.val.to_bytes_be() } - fn parse_bytes(buf: &[u8], radix: u32) -> Option { - //BigUint::parse_bytes(buf, radix).map(FeltBigInt::new) + fn parse_bytes(buf: &[u8], radix: u32) -> Option> { match BigUint::parse_bytes(buf, radix) { Some(parsed) => Some(FeltBigInt::new(parsed)), None => BigInt::parse_bytes(buf, radix).map(FeltBigInt::new), } } - fn from_bytes_be(bytes: &[u8]) -> Self { - Self::new(BigUint::from_bytes_be(bytes)) + fn from_bytes_be(bytes: &[u8]) -> FeltBigInt { + FeltBigInt::::new(BigUint::from_bytes_be(bytes)) } fn to_str_radix(&self, radix: u32) -> String { @@ -176,7 +180,7 @@ impl FeltOps for FeltBigInt { self.val.clone() } - fn sqrt(&self) -> Self { + fn sqrt(&self) -> FeltBigInt { FeltBigInt { val: self.val.sqrt(), } @@ -391,16 +395,16 @@ impl<'a, const PH: u128, const PL: u128> SubAssign<&'a FeltBigInt> for F } } -impl Sub> for usize { - type Output = FeltBigInt; - fn sub(self, rhs: FeltBigInt) -> Self::Output { +impl Sub> for usize { + type Output = FeltBigInt; + fn sub(self, rhs: FeltBigInt) -> Self::Output { self - &rhs } } -impl Sub<&FeltBigInt> for usize { - type Output = FeltBigInt; - fn sub(self, rhs: &FeltBigInt) -> Self::Output { +impl Sub<&FeltBigInt> for usize { + type Output = FeltBigInt; + fn sub(self, rhs: &FeltBigInt) -> Self::Output { match (rhs.val).to_usize() { Some(num) => { if num > self { @@ -517,19 +521,15 @@ impl<'a, const PH: u128, const PL: u128> Div> for &'a FeltBig impl Rem for FeltBigInt { type Output = Self; - fn rem(self, rhs: Self) -> Self { - FeltBigInt { - val: self.val % rhs.val, - } + fn rem(self, _rhs: Self) -> Self { + FeltBigInt::zero() } } impl<'a, const PH: u128, const PL: u128> Rem<&'a FeltBigInt> for FeltBigInt { type Output = Self; - fn rem(self, rhs: &'a FeltBigInt) -> Self::Output { - FeltBigInt { - val: self.val % &rhs.val, - } + fn rem(self, _rhs: &'a FeltBigInt) -> Self::Output { + FeltBigInt::zero() } } @@ -571,29 +571,30 @@ impl Bounded for FeltBigInt { } } -impl Num for FeltBigInt { +impl Num for FeltBigInt { type FromStrRadixErr = ParseFeltError; fn from_str_radix(string: &str, radix: u32) -> Result { match BigUint::from_str_radix(string, radix) { - Ok(num) => Ok(FeltBigInt::new(num)), + Ok(num) => Ok(FeltBigInt::::new(num)), Err(_) => Err(ParseFeltError), } } } -impl Integer for FeltBigInt { +impl Integer for FeltBigInt { fn div_floor(&self, other: &Self) -> Self { FeltBigInt { - val: self.val.div_floor(&other.val), + val: &self.val / &other.val, } } fn div_rem(&self, other: &Self) -> (Self, Self) { - div_rem(self, other) + let (d, m) = self.val.div_mod_floor(&other.val); + (FeltBigInt { val: d }, FeltBigInt { val: m }) } fn divides(&self, other: &Self) -> bool { - self.val.divides(&other.val) + self.val.is_multiple_of(&other.val) } fn gcd(&self, other: &Self) -> Self { @@ -606,8 +607,8 @@ impl Integer for FeltBigInt { self.val.is_even() } - fn is_multiple_of(&self, other: &Self) -> bool { - self.val.is_multiple_of(&other.val) + fn is_multiple_of(&self, _other: &Self) -> bool { + true } fn is_odd(&self) -> bool { @@ -615,7 +616,7 @@ impl Integer for FeltBigInt { } fn lcm(&self, other: &Self) -> Self { - Self::new(self.val.lcm(&other.val)) + Self::new(std::cmp::max(&self.val, &other.val)) } fn mod_floor(&self, other: &Self) -> Self { @@ -625,7 +626,7 @@ impl Integer for FeltBigInt { } } -impl Signed for FeltBigInt { +impl Signed for FeltBigInt { fn abs(&self) -> Self { if self.is_negative() { self.neg() @@ -766,14 +767,6 @@ impl<'a, const PH: u128, const PL: u128> BitXor for &'a FeltBigInt { } } -pub fn div_rem( - x: &FeltBigInt, - y: &FeltBigInt, -) -> (FeltBigInt, FeltBigInt) { - let (d, m) = x.val.div_mod_floor(&y.val); - (FeltBigInt { val: d }, FeltBigInt { val: m }) -} - impl ToPrimitive for FeltBigInt { fn to_u64(&self) -> Option { self.val.to_u64() @@ -820,21 +813,6 @@ impl fmt::Display for ParseFeltError { } } -#[macro_export] -macro_rules! felt_str { - ($val: expr) => { - >::new( - num_bigint::BigInt::parse_bytes($val.as_bytes(), 10_u32).expect("Couldn't parse bytes"), - ) - }; - ($val: expr, $opt: expr) => { - >::new( - num_bigint::BigInt::parse_bytes($val.as_bytes(), $opt as u32) - .expect("Couldn't parse bytes"), - ) - }; -} - #[cfg(test)] mod tests { use super::*; diff --git a/felt/src/lib.rs b/felt/src/lib.rs index f2c4835bc3..72cc5120fb 100644 --- a/felt/src/lib.rs +++ b/felt/src/lib.rs @@ -4,9 +4,10 @@ use bigint_felt::FeltBigInt; use num_bigint::{BigInt, BigUint, U64Digits}; use num_integer::Integer; use num_traits::{Bounded, FromPrimitive, Num, One, Pow, Signed, ToPrimitive, Zero}; +use serde::{Deserialize, Serialize}; use std::{ convert::Into, - fmt::{Debug, Display}, + fmt, iter::Sum, ops::{ Add, AddAssign, BitAnd, BitOr, BitXor, Div, Mul, MulAssign, Neg, Rem, Shl, Shr, ShrAssign, @@ -18,18 +19,17 @@ pub const PRIME_STR: &str = "0x8000000000000110000000000000000000000000000000000 pub const FIELD_HIGH: u128 = (1 << 123) + (17 << 64); pub const FIELD_LOW: u128 = 1; -pub type Felt = FeltBigInt; - -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct ParseFeltError; - -pub trait FeltOps { - fn new>>(value: T) -> Self; - fn modpow(&self, exponent: &FeltBigInt, modulus: &FeltBigInt) -> Self; +pub(crate) trait FeltOps { + fn new>>(value: T) -> Self; + fn modpow( + &self, + exponent: &FeltBigInt, + modulus: &FeltBigInt, + ) -> Self; fn iter_u64_digits(&self) -> U64Digits; fn to_signed_bytes_le(&self) -> Vec; fn to_bytes_be(&self) -> Vec; - fn parse_bytes(buf: &[u8], radix: u32) -> Option>; + fn parse_bytes(buf: &[u8], radix: u32) -> Option>; fn from_bytes_be(bytes: &[u8]) -> Self; fn to_str_radix(&self, radix: u32) -> String; fn to_bigint(&self) -> BigInt; @@ -38,15 +38,641 @@ pub trait FeltOps { fn bits(&self) -> u64; } +#[macro_export] +macro_rules! felt_str { + ($val: expr) => { + felt::Felt::parse_bytes($val.as_bytes(), 10_u32).expect("Couldn't parse bytes") + }; + ($val: expr, $opt: expr) => { + felt::Felt::parse_bytes($val.as_bytes(), $opt as u32).expect("Couldn't parse bytes") + }; +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct ParseFeltError; + +#[derive(Eq, Hash, PartialEq, PartialOrd, Ord, Clone, Deserialize, Default, Serialize)] +pub struct Felt { + value: FeltBigInt, +} + +macro_rules! from_num { + ($type:ty) => { + impl From<$type> for Felt { + fn from(value: $type) -> Self { + Self { + value: value.into(), + } + } + } + }; +} + +from_num!(i8); +from_num!(i16); +from_num!(i32); +from_num!(i64); +from_num!(i128); +from_num!(isize); +from_num!(u8); +from_num!(u16); +from_num!(u32); +from_num!(u64); +from_num!(u128); +from_num!(usize); +from_num!(BigInt); +from_num!(&BigInt); +from_num!(BigUint); +from_num!(&BigUint); + +impl Felt { + pub fn new>(value: T) -> Self { + value.into() + } + pub fn modpow(&self, exponent: &Felt, modulus: &Felt) -> Self { + Self { + value: self.value.modpow(&exponent.value, &modulus.value), + } + } + pub fn iter_u64_digits(&self) -> U64Digits { + self.value.iter_u64_digits() + } + pub fn to_signed_bytes_le(&self) -> Vec { + self.value.to_signed_bytes_le() + } + pub fn to_bytes_be(&self) -> Vec { + self.value.to_bytes_be() + } + pub fn parse_bytes(buf: &[u8], radix: u32) -> Option { + Some(Self { + value: FeltBigInt::parse_bytes(buf, radix)?, + }) + } + pub fn from_bytes_be(bytes: &[u8]) -> Self { + Self { + value: FeltBigInt::from_bytes_be(bytes), + } + } + pub fn to_str_radix(&self, radix: u32) -> String { + self.value.to_str_radix(radix) + } + pub fn to_bigint(&self) -> BigInt { + self.value.to_bigint() + } + pub fn to_biguint(&self) -> BigUint { + self.value.to_biguint() + } + pub fn sqrt(&self) -> Self { + Self { + value: self.value.sqrt(), + } + } + pub fn bits(&self) -> u64 { + self.value.bits() + } +} + +impl Add for Felt { + type Output = Self; + fn add(self, rhs: Self) -> Self { + Self { + value: self.value + rhs.value, + } + } +} + +impl<'a> Add for &'a Felt { + type Output = Felt; + fn add(self, rhs: Self) -> Self::Output { + Self::Output { + value: &self.value + &rhs.value, + } + } +} + +impl<'a> Add<&'a Felt> for Felt { + type Output = Self; + fn add(self, rhs: &Self) -> Self::Output { + Self::Output { + value: self.value + &rhs.value, + } + } +} + +impl Add for Felt { + type Output = Self; + fn add(self, rhs: u32) -> Self { + Self { + value: self.value + rhs, + } + } +} + +impl Add for Felt { + type Output = Self; + fn add(self, rhs: usize) -> Self { + Self { + value: self.value + rhs, + } + } +} + +impl<'a> Add for &'a Felt { + type Output = Felt; + fn add(self, rhs: usize) -> Self::Output { + Self::Output { + value: &self.value + rhs, + } + } +} + +impl AddAssign for Felt { + fn add_assign(&mut self, rhs: Self) { + self.value += rhs.value; + } +} + +impl<'a> AddAssign<&'a Felt> for Felt { + fn add_assign(&mut self, rhs: &Self) { + self.value += &rhs.value; + } +} + +impl Sum for Felt { + fn sum>(iter: I) -> Self { + iter.fold(Felt::zero(), |mut acc, x| { + acc += x; + acc + }) + } +} + +impl Neg for Felt { + type Output = Self; + fn neg(self) -> Self { + Self { + value: self.value.neg(), + } + } +} + +impl<'a> Neg for &'a Felt { + type Output = Felt; + fn neg(self) -> Self::Output { + Self::Output { + value: (&self.value).neg(), + } + } +} + +impl Sub for Felt { + type Output = Self; + fn sub(self, rhs: Self) -> Self { + Self { + value: self.value - rhs.value, + } + } +} + +impl<'a> Sub for &'a Felt { + type Output = Felt; + fn sub(self, rhs: Self) -> Self::Output { + Self::Output { + value: &self.value - &rhs.value, + } + } +} + +impl<'a> Sub<&'a Felt> for Felt { + type Output = Self; + fn sub(self, rhs: &Self) -> Self { + Self { + value: self.value - &rhs.value, + } + } +} + +impl Sub<&Felt> for usize { + type Output = Felt; + fn sub(self, rhs: &Self::Output) -> Self::Output { + Self::Output { + value: self - &rhs.value, + } + } +} + +impl SubAssign for Felt { + fn sub_assign(&mut self, rhs: Self) { + self.value -= rhs.value + } +} + +impl<'a> SubAssign<&'a Felt> for Felt { + fn sub_assign(&mut self, rhs: &Self) { + self.value -= &rhs.value; + } +} + +impl Sub for Felt { + type Output = Self; + fn sub(self, rhs: u32) -> Self { + Self { + value: self.value - rhs, + } + } +} + +impl<'a> Sub for &'a Felt { + type Output = Felt; + fn sub(self, rhs: u32) -> Self::Output { + Self::Output { + value: &self.value - rhs, + } + } +} + +impl Sub for Felt { + type Output = Self; + fn sub(self, rhs: usize) -> Self { + Self { + value: self.value - rhs, + } + } +} + +impl Mul for Felt { + type Output = Self; + fn mul(self, rhs: Self) -> Self { + Self { + value: self.value * rhs.value, + } + } +} + +impl<'a> Mul for &'a Felt { + type Output = Felt; + fn mul(self, rhs: Self) -> Self::Output { + Self::Output { + value: &self.value * &rhs.value, + } + } +} + +impl<'a> Mul<&'a Felt> for Felt { + type Output = Self; + fn mul(self, rhs: &Self) -> Self { + Self { + value: self.value * &rhs.value, + } + } +} + +impl<'a> MulAssign<&'a Felt> for Felt { + fn mul_assign(&mut self, rhs: &Self) { + self.value *= &rhs.value; + } +} + +impl Pow for Felt { + type Output = Self; + fn pow(self, rhs: u32) -> Self { + Self { + value: self.value.pow(rhs), + } + } +} + +impl<'a> Pow for &'a Felt { + type Output = Felt; + fn pow(self, rhs: u32) -> Self::Output { + Self::Output { + value: (&self.value).pow(rhs), + } + } +} + +impl Div for Felt { + type Output = Self; + fn div(self, rhs: Self) -> Self { + Self { + value: self.value / rhs.value, + } + } +} + +impl<'a> Div for &'a Felt { + type Output = Felt; + fn div(self, rhs: Self) -> Self::Output { + Self::Output { + value: &self.value / &rhs.value, + } + } +} + +impl<'a> Div for &'a Felt { + type Output = Felt; + fn div(self, rhs: Self::Output) -> Self::Output { + Self::Output { + value: &self.value / rhs.value, + } + } +} + +impl Rem for Felt { + type Output = Self; + fn rem(self, rhs: Self) -> Self { + Self { + value: self.value % rhs.value, + } + } +} + +impl<'a> Rem<&'a Felt> for Felt { + type Output = Self; + fn rem(self, rhs: &Self) -> Self { + Self { + value: self.value % &rhs.value, + } + } +} + +impl Zero for Felt { + fn zero() -> Self { + Self { + value: FeltBigInt::zero(), + } + } + + fn is_zero(&self) -> bool { + self.value.is_zero() + } +} + +impl One for Felt { + fn one() -> Self { + Self { + value: FeltBigInt::one(), + } + } + + fn is_one(&self) -> bool { + self.value.is_one() + } +} + +impl Bounded for Felt { + fn min_value() -> Self { + Self { + value: FeltBigInt::min_value(), + } + } + + fn max_value() -> Self { + Self { + value: FeltBigInt::max_value(), + } + } +} + +impl Num for Felt { + type FromStrRadixErr = ParseFeltError; + fn from_str_radix(string: &str, radix: u32) -> Result { + Ok(Self { + value: FeltBigInt::from_str_radix(string, radix)?, + }) + } +} + +impl Integer for Felt { + fn div_floor(&self, rhs: &Self) -> Self { + Self { + value: self.value.div_floor(&rhs.value), + } + } + + fn div_rem(&self, other: &Self) -> (Self, Self) { + let (div, rem) = self.value.div_rem(&other.value); + (Self { value: div }, Self { value: rem }) + } + + fn divides(&self, other: &Self) -> bool { + self.value.divides(&other.value) + } + + fn gcd(&self, other: &Self) -> Self { + Self { + value: self.value.gcd(&other.value), + } + } + + fn is_even(&self) -> bool { + self.value.is_even() + } + + fn is_multiple_of(&self, other: &Self) -> bool { + self.value.is_multiple_of(&other.value) + } + + fn is_odd(&self) -> bool { + self.value.is_odd() + } + + fn lcm(&self, other: &Self) -> Self { + Self { + value: self.value.lcm(&other.value), + } + } + + fn mod_floor(&self, rhs: &Self) -> Self { + Self { + value: self.value.mod_floor(&rhs.value), + } + } +} + +impl Signed for Felt { + fn abs(&self) -> Self { + Self { + value: self.value.abs(), + } + } + + fn abs_sub(&self, other: &Self) -> Self { + Self { + value: self.value.abs_sub(&other.value), + } + } + + fn signum(&self) -> Self { + Self { + value: self.value.signum(), + } + } + + fn is_positive(&self) -> bool { + self.value.is_positive() + } + + fn is_negative(&self) -> bool { + self.value.is_negative() + } +} + +impl Shl for Felt { + type Output = Self; + fn shl(self, rhs: u32) -> Self { + Self { + value: self.value << rhs, + } + } +} + +impl<'a> Shl for &'a Felt { + type Output = Felt; + fn shl(self, rhs: u32) -> Self::Output { + Self::Output { + value: &self.value << rhs, + } + } +} + +impl Shl for Felt { + type Output = Self; + fn shl(self, rhs: usize) -> Self { + Self { + value: self.value << rhs, + } + } +} + +impl<'a> Shl for &'a Felt { + type Output = Felt; + fn shl(self, rhs: usize) -> Self::Output { + Self::Output { + value: &self.value << rhs, + } + } +} + +impl Shr for Felt { + type Output = Self; + fn shr(self, rhs: u32) -> Self { + Self { + value: self.value >> rhs, + } + } +} + +impl<'a> Shr for &'a Felt { + type Output = Felt; + fn shr(self, rhs: u32) -> Self::Output { + Self::Output { + value: &self.value >> rhs, + } + } +} + +impl ShrAssign for Felt { + fn shr_assign(&mut self, rhs: usize) { + self.value >>= rhs + } +} + +impl<'a> BitAnd for &'a Felt { + type Output = Felt; + fn bitand(self, rhs: Self) -> Self::Output { + Self::Output { + value: &self.value & &rhs.value, + } + } +} + +impl<'a> BitAnd<&'a Felt> for Felt { + type Output = Self; + fn bitand(self, rhs: &Self) -> Self { + Self { + value: self.value & &rhs.value, + } + } +} + +impl<'a> BitAnd for &'a Felt { + type Output = Felt; + fn bitand(self, rhs: Self::Output) -> Self::Output { + Self::Output { + value: &self.value & rhs.value, + } + } +} + +impl<'a> BitOr for &'a Felt { + type Output = Felt; + fn bitor(self, rhs: Self) -> Self::Output { + Self::Output { + value: &self.value | &rhs.value, + } + } +} + +impl<'a> BitXor for &'a Felt { + type Output = Felt; + fn bitxor(self, rhs: Self) -> Self::Output { + Self::Output { + value: &self.value ^ &rhs.value, + } + } +} + +impl ToPrimitive for Felt { + fn to_u64(&self) -> Option { + self.value.to_u64() + } + + fn to_i64(&self) -> Option { + self.value.to_i64() + } +} + +impl FromPrimitive for Felt { + fn from_u64(n: u64) -> Option { + FeltBigInt::from_u64(n).map(|n| Self { value: n }) + } + + fn from_i64(n: i64) -> Option { + FeltBigInt::from_i64(n).map(|n| Self { value: n }) + } +} + +impl fmt::Display for Felt { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", self.value) + } +} + +impl fmt::Debug for Felt { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.value) + } +} + +macro_rules! assert_felt_methods { + ($type:ty) => { + const _: () = { + fn assert_felt_ops() {} + fn assertion() { + assert_felt_ops::<$type>(); + } + }; + }; +} + macro_rules! assert_felt_impl { ($type:ty) => { const _: () = { - fn assert_felt_ops>() {} fn assert_add() {} fn assert_add_ref<'a, T: Add<&'a $type>>() {} fn assert_add_u32>() {} fn assert_add_usize>() {} - fn assert_add_ref_usize>() {} fn assert_add_assign() {} fn assert_add_assign_ref<'a, T: AddAssign<&'a $type>>() {} fn assert_sum>() {} @@ -75,26 +701,24 @@ macro_rules! assert_felt_impl { fn assert_shl_usize>() {} fn assert_shr_u32>() {} fn assert_shr_assign_usize>() {} - fn assert_bitand_ref() {} - fn assert_bitand<'a, T: BitAnd<&'a $type>>() {} + fn assert_bitand() {} + fn assert_bitand_ref<'a, T: BitAnd<&'a $type>>() {} fn assert_ref_bitand>() {} fn assert_bitor() {} fn assert_bitxor() {} fn assert_from_primitive() {} fn assert_to_primitive() {} - fn assert_display() {} - fn assert_debug() {} + fn assert_display() {} + fn assert_debug() {} - // RFC 2056 #[allow(dead_code)] fn assert_all() { - assert_felt_ops::<$type>(); assert_add::<$type>(); assert_add::<&$type>(); assert_add_ref::<$type>(); assert_add_u32::<$type>(); assert_add_usize::<$type>(); - assert_add_ref_usize::<&$type>(); + assert_add_usize::<&$type>(); assert_add_assign::<$type>(); assert_add_assign_ref::<$type>(); assert_sum::<$type>(); @@ -132,8 +756,8 @@ macro_rules! assert_felt_impl { assert_shr_u32::<$type>(); assert_shr_u32::<&$type>(); assert_shr_assign_usize::<$type>(); - assert_bitand_ref::<&$type>(); - assert_bitand::<$type>(); + assert_bitand::<&$type>(); + assert_bitand_ref::<$type>(); assert_ref_bitand::<&$type>(); assert_bitor::<&$type>(); assert_bitxor::<&$type>(); @@ -146,6 +770,8 @@ macro_rules! assert_felt_impl { }; } +assert_felt_methods!(FeltBigInt); +assert_felt_impl!(FeltBigInt); assert_felt_impl!(Felt); #[cfg(test)] @@ -166,9 +792,9 @@ mod test { // Property-based test that ensures, for 100 felt values that are randomly generated each time tests are run, that the negative of a felt doesn't fall outside the range [0, p]. fn neg_in_range(ref x in "(0|[1-9][0-9]*)") { let x = &Felt::parse_bytes(x.as_bytes(), 10).unwrap(); - let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); let neg = -x; let as_uint = &neg.to_biguint(); + let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); prop_assert!(as_uint < p); } @@ -225,8 +851,8 @@ mod test { fn div_is_mul_inv(ref x in "(0|[1-9][0-9]*)", ref y in "[1-9][0-9]*") { let x = &Felt::parse_bytes(x.as_bytes(), 10).unwrap(); let y = &Felt::parse_bytes(y.as_bytes(), 10).unwrap(); - prop_assume!(!y.is_zero()); let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); + prop_assume!(!y.is_zero()); let q = x / y; let as_uint = &q.to_biguint(); @@ -238,9 +864,9 @@ mod test { // Property-based test that ensures, for 100 {value}s that are randomly generated each time tests are run, that performing a bit shift to the left by {shift_amount} of bits (between 0 and 999) returns a result that is inside of the range [0, p]. fn shift_left_in_range(ref value in "(0|[1-9][0-9]*)", ref shift_amount in "[0-9]{1,3}"){ let value = Felt::parse_bytes(value.as_bytes(), 10).unwrap(); - let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); let shift_amount:u32 = shift_amount.parse::().unwrap(); let result = (value << shift_amount).to_biguint(); + let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); prop_assert!(&result < p); } @@ -248,9 +874,9 @@ mod test { // Property-based test that ensures, for 100 {value}s that are randomly generated each time tests are run, that performing a bit shift to the right by {shift_amount} of bits (between 0 and 999) returns a result that is inside of the range [0, p]. fn shift_right_in_range(ref value in "(0|[1-9][0-9]*)", ref shift_amount in "[0-9]{1,3}"){ let value = Felt::parse_bytes(value.as_bytes(), 10).unwrap(); - let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); let shift_amount:u32 = shift_amount.parse::().unwrap(); let result = (value >> shift_amount).to_biguint(); + let p = &BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); prop_assert!(&result < p); } @@ -259,11 +885,10 @@ mod test { // "With assignment" means that the result of the operation is autommatically assigned to the variable value, replacing its previous content. fn shift_right_assign_in_range(ref value in "(0|[1-9][0-9]*)", ref shift_amount in "[0-9]{1,3}"){ let mut value = Felt::parse_bytes(value.as_bytes(), 10).unwrap(); - let p = FeltBigInt::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); let shift_amount:usize = shift_amount.parse::().unwrap(); + let p = BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); value >>= shift_amount; - value.to_biguint(); - prop_assert!(value < p); + prop_assert!(value.to_biguint() < p); } #[test] @@ -271,10 +896,10 @@ mod test { fn bitand_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)"){ let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); let y = Felt::parse_bytes(y.as_bytes(), 10).unwrap(); - let p = FeltBigInt::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); + let p = BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); let result = &x & &y; result.to_biguint(); - prop_assert!(result < p); + prop_assert!(result.to_biguint() < p); } #[test] @@ -282,11 +907,9 @@ mod test { fn bitor_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)"){ let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); let y = Felt::parse_bytes(y.as_bytes(), 10).unwrap(); - let p = FeltBigInt::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); + let p = BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); let result = &x | &y; - println!("x: {}, y: {}, result: {}", x, y, result); - result.to_biguint(); - prop_assert!(result < p); + prop_assert!(result.to_biguint() < p); } #[test] @@ -294,11 +917,9 @@ mod test { fn bitxor_in_range(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)"){ let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); let y = Felt::parse_bytes(y.as_bytes(), 10).unwrap(); - let p = FeltBigInt::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); + let p = BigUint::parse_bytes(PRIME_STR[2..].as_bytes(), 16).unwrap(); let result = &x ^ &y; - println!("x: {}, y: {}, result: {}", x, y, result); - result.to_biguint(); - prop_assert!(result < p); + prop_assert!(result.to_biguint() < p); } #[test] @@ -312,5 +933,24 @@ mod test { let as_uint = &result.to_biguint(); prop_assert!(as_uint < p, "{}", as_uint); } + + #[test] + // Property test to check that lcm(x, y) works. Since we're operating in a prime field, lcm + // will just be the smaller number. + fn lcm_doesnt_panic(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") { + let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); + let y = Felt::parse_bytes(y.as_bytes(), 10).unwrap(); + let lcm = x.lcm(&y); + prop_assert!(lcm == std::cmp::max(x, y)) + } + + #[test] + // Property test to check that is_multiple_of(x, y) works. Since we're operating in a prime field, is_multiple_of + // will always be true + fn is_multiple_of_doesnt_panic(ref x in "(0|[1-9][0-9]*)", ref y in "(0|[1-9][0-9]*)") { + let x = Felt::parse_bytes(x.as_bytes(), 10).unwrap(); + let y = Felt::parse_bytes(y.as_bytes(), 10).unwrap(); + assert!(x.is_multiple_of(&y)); + } } } diff --git a/src/cairo_run.rs b/src/cairo_run.rs index ec0e8ff922..c80456d1bb 100644 --- a/src/cairo_run.rs +++ b/src/cairo_run.rs @@ -10,7 +10,7 @@ use crate::{ vm_core::VirtualMachine, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use std::{ fs::File, io::{self, BufWriter, Error, ErrorKind, Write}, @@ -141,7 +141,6 @@ mod tests { }, utils::test_utils::*, }; - use felt::FeltOps; use std::io::Read; fn run_test_program( diff --git a/src/hint_processor/builtin_hint_processor/blake2s_utils.rs b/src/hint_processor/builtin_hint_processor/blake2s_utils.rs index 861c2c543e..681e7f64db 100644 --- a/src/hint_processor/builtin_hint_processor/blake2s_utils.rs +++ b/src/hint_processor/builtin_hint_processor/blake2s_utils.rs @@ -14,7 +14,7 @@ use crate::{ vm_core::VirtualMachine, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_traits::ToPrimitive; use std::{borrow::Cow, collections::HashMap}; diff --git a/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs b/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs index c217cce10e..bf83fa45b8 100644 --- a/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs +++ b/src/hint_processor/builtin_hint_processor/builtin_hint_processor_definition.rs @@ -461,7 +461,6 @@ mod tests { vm_memory::memory::Memory, }, }; - use felt::FeltOps; use num_traits::{One, Zero}; use std::any::Any; diff --git a/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs b/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs index 866679e936..4cb0d3435c 100644 --- a/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs +++ b/src/hint_processor/builtin_hint_processor/cairo_keccak/keccak_hints.rs @@ -12,7 +12,7 @@ use crate::{ vm_core::VirtualMachine, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_traits::{ToPrimitive, Zero}; use std::{borrow::Cow, collections::HashMap, ops::Add}; diff --git a/src/hint_processor/builtin_hint_processor/find_element_hint.rs b/src/hint_processor/builtin_hint_processor/find_element_hint.rs index 26767adf1a..c3fe3ab836 100644 --- a/src/hint_processor/builtin_hint_processor/find_element_hint.rs +++ b/src/hint_processor/builtin_hint_processor/find_element_hint.rs @@ -14,7 +14,7 @@ use crate::{ vm_core::VirtualMachine, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_traits::{Signed, ToPrimitive}; use std::collections::HashMap; diff --git a/src/hint_processor/builtin_hint_processor/hint_utils.rs b/src/hint_processor/builtin_hint_processor/hint_utils.rs index 811a5473a2..2617a1c15f 100644 --- a/src/hint_processor/builtin_hint_processor/hint_utils.rs +++ b/src/hint_processor/builtin_hint_processor/hint_utils.rs @@ -116,8 +116,6 @@ pub fn get_reference_from_var_name<'a>( #[cfg(test)] mod tests { - use felt::FeltOps; - use super::*; use crate::{ hint_processor::hint_processor_definition::HintReference, diff --git a/src/hint_processor/builtin_hint_processor/keccak_utils.rs b/src/hint_processor/builtin_hint_processor/keccak_utils.rs index c62b8ad242..ce1b7f14c8 100644 --- a/src/hint_processor/builtin_hint_processor/keccak_utils.rs +++ b/src/hint_processor/builtin_hint_processor/keccak_utils.rs @@ -15,7 +15,7 @@ use crate::{ vm_core::VirtualMachine, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_traits::{One, Signed, ToPrimitive}; use sha3::{Digest, Keccak256}; use std::{cmp, collections::HashMap, ops::Shl}; diff --git a/src/hint_processor/builtin_hint_processor/math_utils.rs b/src/hint_processor/builtin_hint_processor/math_utils.rs index 45b70e922b..043232c0ca 100644 --- a/src/hint_processor/builtin_hint_processor/math_utils.rs +++ b/src/hint_processor/builtin_hint_processor/math_utils.rs @@ -15,7 +15,7 @@ use crate::{ vm_core::VirtualMachine, }, }; -use felt::{Felt, FeltOps, PRIME_STR}; +use felt::{Felt, PRIME_STR}; use num_bigint::BigUint; use num_integer::Integer; use num_traits::One; diff --git a/src/hint_processor/builtin_hint_processor/memcpy_hint_utils.rs b/src/hint_processor/builtin_hint_processor/memcpy_hint_utils.rs index 17a0025107..2d0f48640f 100644 --- a/src/hint_processor/builtin_hint_processor/memcpy_hint_utils.rs +++ b/src/hint_processor/builtin_hint_processor/memcpy_hint_utils.rs @@ -82,7 +82,6 @@ mod tests { vm_memory::memory::Memory, }, }; - use felt::FeltOps; #[test] fn get_integer_from_var_name_valid() { diff --git a/src/hint_processor/builtin_hint_processor/memset_utils.rs b/src/hint_processor/builtin_hint_processor/memset_utils.rs index b1384d6867..0f0c6d78ea 100644 --- a/src/hint_processor/builtin_hint_processor/memset_utils.rs +++ b/src/hint_processor/builtin_hint_processor/memset_utils.rs @@ -9,7 +9,7 @@ use crate::{ types::exec_scope::ExecutionScopes, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_traits::Signed; use std::{any::Any, collections::HashMap}; diff --git a/src/hint_processor/builtin_hint_processor/pow_utils.rs b/src/hint_processor/builtin_hint_processor/pow_utils.rs index d1a955457c..e1eddd54c4 100644 --- a/src/hint_processor/builtin_hint_processor/pow_utils.rs +++ b/src/hint_processor/builtin_hint_processor/pow_utils.rs @@ -8,7 +8,7 @@ use crate::{ serde::deserialize_program::ApTracking, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_integer::Integer; use std::collections::HashMap; diff --git a/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs b/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs index 5da03e4f39..d729956299 100644 --- a/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs +++ b/src/hint_processor/builtin_hint_processor/secp/bigint_utils.rs @@ -13,7 +13,7 @@ use crate::{ vm_core::VirtualMachine, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use std::collections::HashMap; /* Implements hint: diff --git a/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs b/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs index 73df75bd87..a6d0025a1e 100644 --- a/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs +++ b/src/hint_processor/builtin_hint_processor/secp/ec_utils.rs @@ -13,7 +13,7 @@ use crate::{ types::exec_scope::ExecutionScopes, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_bigint::BigInt; use num_integer::Integer; use num_traits::{One, Zero}; diff --git a/src/hint_processor/builtin_hint_processor/secp/field_utils.rs b/src/hint_processor/builtin_hint_processor/secp/field_utils.rs index e1806ddd8f..792de16c30 100644 --- a/src/hint_processor/builtin_hint_processor/secp/field_utils.rs +++ b/src/hint_processor/builtin_hint_processor/secp/field_utils.rs @@ -12,7 +12,7 @@ use crate::{ types::exec_scope::ExecutionScopes, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_bigint::BigInt; use num_integer::Integer; use num_traits::{One, Zero}; @@ -175,7 +175,6 @@ mod tests { vm_memory::memory::Memory, }, }; - use felt::FeltOps; use std::any::Any; #[test] diff --git a/src/hint_processor/builtin_hint_processor/secp/secp_utils.rs b/src/hint_processor/builtin_hint_processor/secp/secp_utils.rs index ce8cc27f36..6806b1f8d9 100644 --- a/src/hint_processor/builtin_hint_processor/secp/secp_utils.rs +++ b/src/hint_processor/builtin_hint_processor/secp/secp_utils.rs @@ -7,7 +7,7 @@ use crate::{ types::relocatable::Relocatable, vm::{errors::hint_errors::HintError, vm_core::VirtualMachine}, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_bigint::BigInt; use num_traits::Zero; use std::collections::HashMap; @@ -93,7 +93,7 @@ pub fn pack_from_relocatable(rel: Relocatable, vm: &VirtualMachine) -> Result #[cfg(test)] mod tests { use super::*; - use felt::FeltOps; #[test] fn is_call_instruction_true() { diff --git a/src/types/program.rs b/src/types/program.rs index ba01369b09..bde566ae94 100644 --- a/src/types/program.rs +++ b/src/types/program.rs @@ -112,7 +112,7 @@ mod tests { use super::*; use crate::serde::deserialize_program::{ApTracking, FlowTrackingData}; use crate::utils::test_utils::mayberelocatable; - use felt::{felt_str, FeltOps}; + use felt::felt_str; use num_traits::Zero; #[test] diff --git a/src/types/relocatable.rs b/src/types/relocatable.rs index e0de80057e..618003ccac 100644 --- a/src/types/relocatable.rs +++ b/src/types/relocatable.rs @@ -2,7 +2,7 @@ use crate::{ relocatable, vm::errors::{memory_errors::MemoryError, vm_errors::VirtualMachineError}, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_traits::{FromPrimitive, ToPrimitive, Zero}; use serde::{Deserialize, Serialize}; use std::{ diff --git a/src/utils.rs b/src/utils.rs index 0c164289ed..8bbc2347a6 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -183,10 +183,7 @@ pub mod test_utils { MaybeRelocatable::from(($val1, $val2)) }; ($val1 : expr) => { - MaybeRelocatable::from(>::new($val1 as i128)) + MaybeRelocatable::from(felt::Felt::new($val1 as i128)) }; } pub(crate) use mayberelocatable; @@ -531,7 +528,7 @@ mod test { vm_core::VirtualMachine, vm_memory::memory::Memory, }, }; - use felt::{Felt, FeltOps}; + use felt::Felt; use num_traits::One; use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc}; diff --git a/src/vm/context/run_context.rs b/src/vm/context/run_context.rs index 61fd7b9e00..91b2a78934 100644 --- a/src/vm/context/run_context.rs +++ b/src/vm/context/run_context.rs @@ -110,7 +110,7 @@ mod tests { use crate::types::instruction::{ApUpdate, FpUpdate, Opcode, PcUpdate, Res}; use crate::utils::test_utils::mayberelocatable; use crate::vm::errors::memory_errors::MemoryError; - use felt::{Felt, FeltOps}; + use felt::Felt; #[test] fn compute_dst_addr_for_ap_register() { diff --git a/src/vm/decoding/decoder.rs b/src/vm/decoding/decoder.rs index 064f42cea6..1f7188ac2f 100644 --- a/src/vm/decoding/decoder.rs +++ b/src/vm/decoding/decoder.rs @@ -146,7 +146,6 @@ fn decode_offset(offset: i64) -> isize { #[cfg(test)] mod decoder_test { use super::*; - use felt::FeltOps; #[test] fn invalid_op1_reg() { diff --git a/src/vm/runners/builtin_runner/bitwise.rs b/src/vm/runners/builtin_runner/bitwise.rs index de012d8c4d..4b4db3a800 100644 --- a/src/vm/runners/builtin_runner/bitwise.rs +++ b/src/vm/runners/builtin_runner/bitwise.rs @@ -12,7 +12,6 @@ use crate::{ vm_memory::{memory::Memory, memory_segments::MemorySegmentManager}, }, }; -use felt::FeltOps; use num_integer::div_ceil; #[derive(Debug, Clone)] @@ -222,7 +221,7 @@ mod tests { hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor, types::program::Program, utils::test_utils::*, vm::runners::cairo_runner::CairoRunner, }; - use felt::{Felt, FeltOps}; + use felt::Felt; #[test] fn get_used_instances() { diff --git a/src/vm/runners/builtin_runner/ec_op.rs b/src/vm/runners/builtin_runner/ec_op.rs index 996b016bb4..a8974af712 100644 --- a/src/vm/runners/builtin_runner/ec_op.rs +++ b/src/vm/runners/builtin_runner/ec_op.rs @@ -8,7 +8,7 @@ use crate::vm::errors::runner_errors::RunnerError; use crate::vm::vm_core::VirtualMachine; use crate::vm::vm_memory::memory::Memory; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_bigint::{BigInt, ToBigInt}; use num_integer::{div_ceil, Integer}; use num_traits::{Num, One, Pow, Zero}; diff --git a/src/vm/runners/builtin_runner/hash.rs b/src/vm/runners/builtin_runner/hash.rs index 788b827de0..7a008b7742 100644 --- a/src/vm/runners/builtin_runner/hash.rs +++ b/src/vm/runners/builtin_runner/hash.rs @@ -10,7 +10,7 @@ use crate::vm::errors::runner_errors::RunnerError; use crate::vm::vm_core::VirtualMachine; use crate::vm::vm_memory::memory::Memory; use crate::vm::vm_memory::memory_segments::MemorySegmentManager; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_integer::{div_ceil, Integer}; use starknet_crypto::{pedersen_hash, FieldElement}; diff --git a/src/vm/runners/builtin_runner/keccak.rs b/src/vm/runners/builtin_runner/keccak.rs index acec5ee9d9..9a0523254e 100644 --- a/src/vm/runners/builtin_runner/keccak.rs +++ b/src/vm/runners/builtin_runner/keccak.rs @@ -265,7 +265,6 @@ mod tests { runners::builtin_runner::BuiltinRunner, vm_core::VirtualMachine, }; - use felt::FeltOps; use std::path::Path; #[test] diff --git a/src/vm/runners/builtin_runner/range_check.rs b/src/vm/runners/builtin_runner/range_check.rs index a7c1190e41..60d7d36573 100644 --- a/src/vm/runners/builtin_runner/range_check.rs +++ b/src/vm/runners/builtin_runner/range_check.rs @@ -13,7 +13,7 @@ use crate::{ }, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_integer::Integer; use num_traits::{One, ToPrimitive, Zero}; use std::{ diff --git a/src/vm/runners/builtin_runner/signature.rs b/src/vm/runners/builtin_runner/signature.rs index 199f4dfce3..41baa2db09 100644 --- a/src/vm/runners/builtin_runner/signature.rs +++ b/src/vm/runners/builtin_runner/signature.rs @@ -13,7 +13,7 @@ use crate::{ }, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_integer::{div_ceil, Integer}; use num_traits::ToPrimitive; use starknet_crypto::{verify, FieldElement, Signature}; diff --git a/src/vm/runners/cairo_runner.rs b/src/vm/runners/cairo_runner.rs index 995054af37..ba795e6a7f 100644 --- a/src/vm/runners/cairo_runner.rs +++ b/src/vm/runners/cairo_runner.rs @@ -33,7 +33,7 @@ use crate::{ }, }, }; -use felt::{Felt, FeltOps}; +use felt::Felt; use num_integer::div_rem; use num_traits::Zero; use std::{ @@ -1140,7 +1140,7 @@ mod tests { utils::test_utils::*, vm::{trace::trace_entry::TraceEntry, vm_memory::memory::Memory}, }; - use felt::{felt_str, FeltOps}; + use felt::felt_str; use num_traits::One; use std::{ collections::{HashMap, HashSet}, diff --git a/src/vm/vm_core.rs b/src/vm/vm_core.rs index cb0be0aca5..fa212c50d8 100644 --- a/src/vm/vm_core.rs +++ b/src/vm/vm_core.rs @@ -999,7 +999,7 @@ mod tests { }, }; - use felt::{felt_str, FeltOps}; + use felt::felt_str; use std::{collections::HashSet, path::Path}; #[test] @@ -3736,10 +3736,10 @@ mod tests { #[test] fn gen_arg_bigint_prime() { let mut vm = vm!(); - let prime = felt_str!(&felt::PRIME_STR[2..], 16); + let prime = felt_str!(felt::PRIME_STR[2..], 16); let prime_maybe = MaybeRelocatable::from(prime); - assert_eq!(vm.gen_arg(&prime_maybe), Ok(mayberelocatable!(0)),); + assert_eq!(vm.gen_arg(&prime_maybe), Ok(mayberelocatable!(0))); } /// Test that the call to .gen_arg() with a Vec writes its diff --git a/src/vm/vm_memory/memory.rs b/src/vm/vm_memory/memory.rs index 47ca1e407f..af0fe1d114 100644 --- a/src/vm/vm_memory/memory.rs +++ b/src/vm/vm_memory/memory.rs @@ -375,7 +375,7 @@ mod memory_tests { vm_memory::memory_segments::MemorySegmentManager, }, }; - use felt::{felt_str, FeltOps}; + use felt::felt_str; use crate::vm::errors::memory_errors::MemoryError; diff --git a/src/vm/vm_memory/memory_segments.rs b/src/vm/vm_memory/memory_segments.rs index 1196d2d215..3b454135c8 100644 --- a/src/vm/vm_memory/memory_segments.rs +++ b/src/vm/vm_memory/memory_segments.rs @@ -256,7 +256,7 @@ mod tests { use super::*; use crate::vm::vm_core::VirtualMachine; use crate::{relocatable, utils::test_utils::*}; - use felt::{Felt, FeltOps}; + use felt::Felt; use num_traits::Num; use std::vec;