Skip to content

Commit

Permalink
refactor: SizeOf replacement (#759)
Browse files Browse the repository at this point in the history
* SizeOf replacement

* Merge branch 'main' into bitsize
  • Loading branch information
TAdev0 committed Apr 19, 2024
1 parent 46d7fff commit 5d1dca8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 101 deletions.
1 change: 0 additions & 1 deletion crates/utils/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod fmt;
mod helpers;
mod i256;
mod math;
mod num;
mod rlp;
mod serialization;
mod set;
Expand Down
13 changes: 7 additions & 6 deletions crates/utils/src/math.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===

Expand Down Expand Up @@ -226,12 +225,13 @@ impl BitshiftImpl<
+Copy<T>,
+Drop<T>,
+PartialOrd<T>,
+SizeOf<T>
+BitSize<T>,
+TryInto<usize, T>,
> of Bitshift<T> {
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::<T>::bits().try_into().unwrap() - One::one() {
panic_with_felt252('mul Overflow');
}
let two = One::one() + One::one();
Expand All @@ -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::<T>::bits().try_into().unwrap() - One::one() {
panic_with_felt252('mul Overflow');
}
let two = One::one() + One::one();
Expand Down Expand Up @@ -272,7 +272,8 @@ impl WrappingBitshiftImpl<
+Copy<T>,
+OverflowingMul<T>,
+WrappingExponentiation<T>,
+SizeOf<T>
+BitSize<T>,
+TryInto<usize, T>,
> of WrappingBitshift<T> {
fn wrapping_shl(self: T, shift: T) -> T {
let two = One::<T>::one() + One::<T>::one();
Expand All @@ -283,7 +284,7 @@ impl WrappingBitshiftImpl<
fn wrapping_shr(self: T, shift: T) -> T {
let two = One::<T>::one() + One::<T>::one();

if shift > shift.size_of() - One::one() {
if shift > BitSize::<T>::bits().try_into().unwrap() - One::one() {
return Zero::zero();
}
self / two.pow(shift)
Expand Down
76 changes: 0 additions & 76 deletions crates/utils/src/num.cairo

This file was deleted.

1 change: 0 additions & 1 deletion crates/utils/src/tests.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 0 additions & 17 deletions crates/utils/src/tests/test_num.cairo

This file was deleted.

0 comments on commit 5d1dca8

Please sign in to comment.