Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger committed Apr 4, 2024
1 parent 08b0e78 commit ea23995
Showing 1 changed file with 1 addition and 150 deletions.
151 changes: 1 addition & 150 deletions crates/starknet-types-core/src/felt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl Felt {
]);

/// Creates a new [Felt] from the raw internal representation.
/// See [UnsignedInteger] to understand how it works under the hood.
/// See [UnisgnedInteger] to understand how it works under the hood.
pub const fn from_raw(val: [u64; 4]) -> Self {
Self(FieldElement::<Stark252PrimeField>::const_from_raw(
UnsignedInteger::from_limbs(val),
Expand Down Expand Up @@ -952,48 +952,6 @@ mod arithmetic {
base
}
}

impl ops::BitAnd for Felt {
type Output = Self;

fn bitand(self, rhs: Self) -> Self {
Self::from_raw((self.0.to_raw() & rhs.0.to_raw()).limbs)
}
}

impl ops::BitAndAssign for Felt {
fn bitand_assign(&mut self, rhs: Self) {
*self = Self::from_raw((self.0.to_raw() & rhs.0.to_raw()).limbs);
}
}

impl ops::BitOr for Felt {
type Output = Self;

fn bitor(self, rhs: Self) -> Self {
Self::from_raw((self.0.to_raw() | rhs.0.to_raw()).limbs)
}
}

impl ops::BitOrAssign for Felt {
fn bitor_assign(&mut self, rhs: Self) {
*self = Self::from_raw((self.0.to_raw() | rhs.0.to_raw()).limbs);
}
}

impl ops::BitXor for Felt {
type Output = Self;

fn bitxor(self, rhs: Self) -> Self {
Self::from_raw((self.0.to_raw() ^ rhs.0.to_raw()).limbs)
}
}

impl ops::BitXorAssign for Felt {
fn bitxor_assign(&mut self, rhs: Self) {
*self = Self::from_raw((self.0.to_raw() ^ rhs.0.to_raw()).limbs);
}
}
}

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -1327,112 +1285,6 @@ mod test {
prop_assert!(x + y <= Felt::MAX);
}

#[test]
fn bit_and(x in any::<Felt>(), y in any::<Felt>()){
let x_raw = x.to_raw();
let y_raw = y.to_raw();

prop_assert_eq!(
x & y,
Felt::from_raw([
x_raw[0] & y_raw[0],
x_raw[1] & y_raw[1],
x_raw[2] & y_raw[2],
x_raw[3] & y_raw[3],
])
);
}

#[test]
fn bit_and_assign(x in any::<Felt>(), y in any::<Felt>()){
let x_raw = x.to_raw();
let y_raw = y.to_raw();

let mut res = x;
res &= y;

prop_assert_eq!(
res,
Felt::from_raw([
x_raw[0] & y_raw[0],
x_raw[1] & y_raw[1],
x_raw[2] & y_raw[2],
x_raw[3] & y_raw[3],
])
);
}

#[test]
fn bit_or(x in any::<Felt>(), y in any::<Felt>()) {
let x_raw = x.to_raw();
let y_raw = y.to_raw();

assert_eq!(
x | y,
Felt::from_raw([
x_raw[0] | y_raw[0],
x_raw[1] | y_raw[1],
x_raw[2] | y_raw[2],
x_raw[3] | y_raw[3],
])
);
}

#[test]
fn bit_or_assign(x in any::<Felt>(), y in any::<Felt>()) {
let x_raw = x.to_raw();
let y_raw = y.to_raw();

let mut res = x;
res |= y;

assert_eq!(
res,
Felt::from_raw([
x_raw[0] | y_raw[0],
x_raw[1] | y_raw[1],
x_raw[2] | y_raw[2],
x_raw[3] | y_raw[3],
])
);
}

#[test]
fn bit_xor(x in any::<Felt>(), y in any::<Felt>()) {
let x_raw = x.to_raw();
let y_raw = y.to_raw();

assert_eq!(
x ^ y,
Felt::from_raw([
x_raw[0] ^ y_raw[0],
x_raw[1] ^ y_raw[1],
x_raw[2] ^ y_raw[2],
x_raw[3] ^ y_raw[3],
])
);
}

#[test]
fn bit_xor_assign(x in any::<Felt>(), y in any::<Felt>()) {
let x_raw = x.to_raw();
let y_raw = y.to_raw();

let mut res = x;
res ^= y;

assert_eq!(
res,
Felt::from_raw([
x_raw[0] ^ y_raw[0],
x_raw[1] ^ y_raw[1],
x_raw[2] ^ y_raw[2],
x_raw[3] ^ y_raw[3],
])
);
}


#[test]
fn zero_additive_identity(x in any::<Felt>()) {
prop_assert_eq!(x, x + Felt::ZERO);
Expand Down Expand Up @@ -1550,7 +1402,6 @@ mod test {
prop_assert_eq!(felt_from_ref.to_bytes_be(), x);
prop_assert_eq!(felt.to_bytes_be(), x);
}

#[test]
fn iter_sum(a in any::<Felt>(), b in any::<Felt>(), c in any::<Felt>()) {
prop_assert_eq!([a, b, c].iter().sum::<Felt>(), a + b + c);
Expand Down

0 comments on commit ea23995

Please sign in to comment.