diff --git a/crates/utils/src/lib.cairo b/crates/utils/src/lib.cairo index 3018850b5..e6d7fb517 100644 --- a/crates/utils/src/lib.cairo +++ b/crates/utils/src/lib.cairo @@ -10,7 +10,6 @@ mod fmt; mod helpers; mod i256; mod math; -mod num; mod rlp; mod serialization; mod set; diff --git a/crates/utils/src/math.cairo b/crates/utils/src/math.cairo index 82113f888..55b9148ac 100644 --- a/crates/utils/src/math.cairo +++ b/crates/utils/src/math.cairo @@ -6,7 +6,6 @@ use integer::{ u128_overflowing_mul, u64_wide_mul, u64_to_felt252, u32_wide_mul, u32_to_felt252, u8_wide_mul, u16_to_felt252 }; -use utils::num::{SizeOf}; // === Exponentiation === @@ -226,12 +225,13 @@ impl BitshiftImpl< +Copy, +Drop, +PartialOrd, - +SizeOf + +BitSize, + +TryInto, > of Bitshift { fn shl(self: T, shift: T) -> T { // if we shift by more than nb_bits of T, the result is 0 // we early return to save gas and prevent unexpected behavior - if shift > shift.size_of() - One::one() { + if shift > BitSize::::bits().try_into().unwrap() - One::one() { panic_with_felt252('mul Overflow'); } let two = One::one() + One::one(); @@ -240,7 +240,7 @@ impl BitshiftImpl< fn shr(self: T, shift: T) -> T { // early return to save gas if shift > nb_bits of T - if shift > shift.size_of() - One::one() { + if shift > BitSize::::bits().try_into().unwrap() - One::one() { panic_with_felt252('mul Overflow'); } let two = One::one() + One::one(); @@ -272,7 +272,8 @@ impl WrappingBitshiftImpl< +Copy, +OverflowingMul, +WrappingExponentiation, - +SizeOf + +BitSize, + +TryInto, > of WrappingBitshift { fn wrapping_shl(self: T, shift: T) -> T { let two = One::::one() + One::::one(); @@ -283,7 +284,7 @@ impl WrappingBitshiftImpl< fn wrapping_shr(self: T, shift: T) -> T { let two = One::::one() + One::::one(); - if shift > shift.size_of() - One::one() { + if shift > BitSize::::bits().try_into().unwrap() - One::one() { return Zero::zero(); } self / two.pow(shift) diff --git a/crates/utils/src/num.cairo b/crates/utils/src/num.cairo deleted file mode 100644 index 02309be27..000000000 --- a/crates/utils/src/num.cairo +++ /dev/null @@ -1,76 +0,0 @@ -// === SizeOf === - -trait SizeOf { - /// Returns the size in bits of Self. - fn size() -> T; - fn size_of(self: @T) -> T; -} - -impl U8SizeOf of SizeOf { - fn size() -> u8 { - 8 - } - fn size_of(self: @u8) -> u8 { - U8SizeOf::size() - } -} - -impl U16SizeOf of SizeOf { - fn size() -> u16 { - 16 - } - fn size_of(self: @u16) -> u16 { - U16SizeOf::size() - } -} - -impl U32SizeOf of SizeOf { - fn size() -> u32 { - 32 - } - fn size_of(self: @u32) -> u32 { - U32SizeOf::size() - } -} - -impl U64SizeOf of SizeOf { - fn size() -> u64 { - 64 - } - fn size_of(self: @u64) -> u64 { - U64SizeOf::size() - } -} - -impl U128SizeOf of SizeOf { - #[inline(always)] - fn size() -> u128 { - 128 - } - #[inline(always)] - fn size_of(self: @u128) -> u128 { - U128SizeOf::size() - } -} - -impl Felt252SizeOf of SizeOf { - #[inline(always)] - fn size() -> felt252 { - 252 - } - #[inline(always)] - fn size_of(self: @felt252) -> felt252 { - Felt252SizeOf::size() - } -} - -impl U256SizeOf of SizeOf { - #[inline(always)] - fn size() -> u256 { - 256 - } - #[inline(always)] - fn size_of(self: @u256) -> u256 { - U256SizeOf::size() - } -} diff --git a/crates/utils/src/tests.cairo b/crates/utils/src/tests.cairo index 32610bd21..e980a6488 100644 --- a/crates/utils/src/tests.cairo +++ b/crates/utils/src/tests.cairo @@ -5,7 +5,6 @@ mod test_helpers; mod test_i256; mod test_math; mod test_modexp; -mod test_num; mod test_rlp; mod test_serialization; mod test_set; diff --git a/crates/utils/src/tests/test_num.cairo b/crates/utils/src/tests/test_num.cairo deleted file mode 100644 index 8b2de4caf..000000000 --- a/crates/utils/src/tests/test_num.cairo +++ /dev/null @@ -1,17 +0,0 @@ -use utils::num::{U8SizeOf, U64SizeOf, Felt252SizeOf, SizeOf}; - -#[test] -fn test_sizeof() { - assert(10_u8.size_of() == 8, 'should be 8'); - assert(100_u8.size_of() == 8, 'should be 8'); - assert(20_u256.size_of() == 256, 'should be 256'); - assert(32_felt252.size_of() == 252, 'should be 252'); - assert(1_usize.size_of() == 32, 'should be 32'); -} - -#[test] -fn test_size() { - assert(U8SizeOf::size() == 8, 'should be 8'); - assert(U64SizeOf::size() == 64, 'should be 64'); - assert(Felt252SizeOf::size() == 252, 'should be 252'); -}