Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to 2.7.0 #321

Merged
merged 35 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c17e14d
first draft
gaetbout Jul 24, 2024
081df79
save
gaetbout Jul 24, 2024
c5344fe
remove some extra warnings
gaetbout Jul 24, 2024
4a1a6a8
remove last wrapping warning + turn some impl X into +
gaetbout Jul 24, 2024
726d8ca
all last warning but IndexView related
gaetbout Jul 24, 2024
1a0a7bd
fix prev push
gaetbout Jul 24, 2024
62398bf
using dw
gaetbout Jul 24, 2024
fadb4c1
remove some var
gaetbout Jul 24, 2024
a0b724c
remove todo comment
gaetbout Jul 24, 2024
36e6017
intermediate fix
gaetbout Jul 26, 2024
d694a17
intermediate fix
gaetbout Jul 29, 2024
bcdaa3a
2.7.0 intermediate
gaetbout Aug 1, 2024
2daed18
cairo_test in workspace
gaetbout Aug 1, 2024
a9ab9bd
fix storage package tests
gaetbout Aug 1, 2024
d72314c
fix vec.cairo Index
gaetbout Aug 1, 2024
7d8751e
fix one IndexView, still 3 to go
gaetbout Aug 2, 2024
2df8094
fix one IndexView, still 2 to go
gaetbout Aug 2, 2024
7f506ec
removing one more IndexView
gaetbout Aug 5, 2024
e695ad5
update import
gaetbout Aug 5, 2024
9b110d4
deprecated list-trait
gaetbout Aug 5, 2024
a2c5085
adding some deprecated
gaetbout Aug 5, 2024
163c8e8
clean
gaetbout Aug 5, 2024
2dba500
generic SHR
gaetbout Aug 5, 2024
da5caab
adding note
gaetbout Aug 5, 2024
4ce919c
while let some => for loop
gaetbout Aug 5, 2024
caa630d
assert() => assert!()
gaetbout Aug 5, 2024
6eb901b
update some assert_ea! to remove error message
gaetbout Aug 5, 2024
9891394
update some assert! to remove error message
gaetbout Aug 5, 2024
faab8f0
IndexViewImpl => +IndexView
gaetbout Aug 6, 2024
307e3d6
uint_min(size, 16); > core::cmp::min
gaetbout Aug 6, 2024
2a4f6b8
remove kron mut
gaetbout Aug 6, 2024
e8546cf
overflowing to checked where possible
gaetbout Aug 7, 2024
846621a
byte using starknet's sha256
gaetbout Aug 7, 2024
bb609a0
remove pub for u256_overflow_add/sub
gaetbout Aug 9, 2024
68465dd
Milan's remark
gaetbout Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scarb 2.6.4
scarb 2.7.0
5 changes: 3 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ name = "alexandria"
version = "0.1.0"
description = "Community maintained Cairo and Starknet libraries"
homepage = "https://github.com/keep-starknet-strange/alexandria/"
cairo-version = "2.6.3"
cairo-version = "2.7.0"

[workspace.dependencies]
starknet = "2.6.3"
starknet = "2.7.0"
cairo_test = "2.7.0"

[workspace.tool.fmt]
sort-module-level-items = true
Expand Down
5 changes: 4 additions & 1 deletion packages/ascii/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ edition = "2023_11"
fmt.workspace = true

[dependencies]
alexandria_data_structures = { path = "../data_structures" }
alexandria_data_structures = { path = "../data_structures" }

[dev-dependencies]
cairo_test.workspace = true
48 changes: 22 additions & 26 deletions packages/ascii/src/integer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ impl ToAsciiArrayTraitImpl<
}

let mut num = self;
while num
.is_non_zero() {
let (quotient, remainder) = DivRem::div_rem(
num,
TryInto::<felt252, T>::try_into(10).unwrap().try_into().expect('Division by 0')
);
new_arr.append(remainder.into() + 48);
num = quotient;
};
while num.is_non_zero() {
let (quotient, remainder) = DivRem::div_rem(
num, TryInto::<felt252, T>::try_into(10).unwrap().try_into().expect('Division by 0')
);
new_arr.append(remainder.into() + 48);
num = quotient;
};
new_arr
}
}
Expand Down Expand Up @@ -110,8 +108,8 @@ impl BigIntegerToAsciiTraitImpl<
match inverse_ascii_arr.pop_back() {
Option::Some(val) => {
let new_ascii = ascii * 256 + *val;
// if index is at 30 it means we have reached the max size of felt252 at 31 characters
// so we append the current ascii and reset the ascii to 0
// if index is at 30 it means we have reached the max size of felt252 at 31
// characters so we append the current ascii and reset the ascii to 0
ascii = if index == 30 {
data.append(new_ascii);
0
Expand Down Expand Up @@ -175,22 +173,20 @@ impl U256ToAsciiTraitImpl of ToAsciiTrait<u256, Array<felt252>> {
let mut inverse_ascii_arr = self.to_inverse_ascii_array().span();
let mut index = 0;
let mut ascii: felt252 = 0;
while let Option::Some(val) = inverse_ascii_arr
.pop_back() {
let new_ascii = ascii * 256 + *val;
// if index is currently at 30 it means we have processed the number for index 31
// this means we have reached the max size of felt252 at 31 characters
// so we append the current ascii and reset the ascii to 0
// do the same at index 61 as well because max u256 is 78 characters
ascii =
if index == 30 || index == 61 {
data.append(new_ascii);
0
} else {
new_ascii
};
index += 1;
while let Option::Some(val) = inverse_ascii_arr.pop_back() {
let new_ascii = ascii * 256 + *val;
// if index is currently at 30 it means we have processed the number for index 31
// this means we have reached the max size of felt252 at 31 characters
// so we append the current ascii and reset the ascii to 0
// do the same at index 61 as well because max u256 is 78 characters
ascii = if index == 30 || index == 61 {
data.append(new_ascii);
0
} else {
new_ascii
};
index += 1;
};

if ascii.is_non_zero() {
data.append(ascii);
Expand Down
78 changes: 39 additions & 39 deletions packages/ascii/src/tests/test_ascii_integer.cairo
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
use alexandria_ascii::ToAsciiTrait;
use core::integer::BoundedInt;
use core::num::traits::Bounded;

#[test]
#[available_gas(2000000000)]
fn u256_to_ascii() {
// ------------------------------ max u256 test ----------------------------- //
// max u256 int in cairo is GitHub Copilot: The maximum u256 number in Cairo is `
// 115792089237316195423570985008687907853269984665640564039457584007913129639935`.
let num: u256 = BoundedInt::max();
let num: u256 = Bounded::MAX;
let ascii: Array<felt252> = num.to_ascii();
assert_eq!(ascii.len(), 3, "max u256 wrong len");
assert_eq!(*ascii.at(0), '1157920892373161954235709850086', "max u256 wrong first felt");
assert_eq!(*ascii.at(1), '8790785326998466564056403945758', "max u256 wrong second felt");
assert_eq!(*ascii.at(2), '4007913129639935', "max u256 wrong third felt");
assert_eq!(ascii.len(), 3);
assert_eq!(*ascii.at(0), '1157920892373161954235709850086');
assert_eq!(*ascii.at(1), '8790785326998466564056403945758');
assert_eq!(*ascii.at(2), '4007913129639935');
// ------------------------------ min u256 test ----------------------------- //
let num: u256 = BoundedInt::min();
let num: u256 = Bounded::MIN;
let ascii: Array<felt252> = num.to_ascii();

assert_eq!(ascii.len(), 1, "min u256 wrong len");
assert_eq!(*ascii.at(0), '0', "min u256 wrong felt");
assert_eq!(ascii.len(), 1);
assert_eq!(*ascii.at(0), '0');
// ---------------------------- 31 char u256 test --------------------------- //
let ascii: Array<felt252> = 1157920892373161954235709850086_u256.to_ascii();
assert_eq!(ascii.len(), 1, "u256 31 char wrong len");
assert_eq!(*ascii.at(0), '1157920892373161954235709850086', "31 char u256 wrong felt");
assert_eq!(ascii.len(), 1);
assert_eq!(*ascii.at(0), '1157920892373161954235709850086');
// ---------------------------- 62 char u256 test --------------------------- //
let ascii: Array<felt252> = 11579208923731619542357098500868790785326998466564056403945758_u256
.to_ascii();
assert_eq!(ascii.len(), 2, "u256 31 char wrong len");
assert_eq!(*ascii.at(0), '1157920892373161954235709850086', "31 char u256 wrong felt");
assert_eq!(*ascii.at(1), '8790785326998466564056403945758', "62 char u256 wrong felt");
assert_eq!(ascii.len(), 2);
assert_eq!(*ascii.at(0), '1157920892373161954235709850086');
assert_eq!(*ascii.at(1), '8790785326998466564056403945758');
}

#[test]
#[available_gas(2000000)]
fn u128_to_ascii() {
// ------------------------------ max u128 test ----------------------------- //
// max u128 int in cairo is 340282366920938463463374607431768211455
let num: u128 = BoundedInt::max();
let num: u128 = Bounded::MAX;
let ascii: Array<felt252> = num.to_ascii();

assert_eq!(ascii.len(), 2, "max u128 wrong len");
assert_eq!(*ascii.at(0), '3402823669209384634633746074317', "max u128 wrong first felt");
assert_eq!(*ascii.at(1), '68211455', "max u128 wrong second felt");
assert_eq!(ascii.len(), 2);
assert_eq!(*ascii.at(0), '3402823669209384634633746074317');
assert_eq!(*ascii.at(1), '68211455');
// ------------------------------ min u128 test ----------------------------- //
let num: u128 = BoundedInt::min();
let num: u128 = Bounded::MIN;
let ascii: Array<felt252> = num.to_ascii();

assert_eq!(ascii.len(), 1, "min u128 wrong len");
assert_eq!(*ascii.at(0), '0', "min u128 wrong felt");
assert_eq!(ascii.len(), 1);
assert_eq!(*ascii.at(0), '0');
// ---------------------------- 31 char u128 test --------------------------- //
let ascii: Array<felt252> = 3402823669209384634633746074317_u128.to_ascii();
assert_eq!(ascii.len(), 1, "u128 31 char wrong len");
assert_eq!(*ascii.at(0), '3402823669209384634633746074317', "31 char u128 wrong felt");
assert_eq!(ascii.len(), 1);
assert_eq!(*ascii.at(0), '3402823669209384634633746074317');
}

#[test]
#[available_gas(2000000)]
fn u64_to_ascii() {
// ------------------------------ max u64 test ------------------------------ //
let num: u64 = BoundedInt::max();
assert_eq!(num.to_ascii(), '18446744073709551615', "incorrect u64 max felt");
let num: u64 = Bounded::MAX;
assert_eq!(num.to_ascii(), '18446744073709551615');
// ------------------------------ min u64 test ------------------------------ //
let num: u64 = BoundedInt::min();
assert_eq!(num.to_ascii(), '0', "incorrect u64 min felt");
let num: u64 = Bounded::MIN;
assert_eq!(num.to_ascii(), '0');
}

#[test]
#[available_gas(2000000)]
fn u32_to_ascii() {
// ------------------------------ max u32 test ------------------------------ //
let num: u32 = BoundedInt::max();
assert_eq!(num.to_ascii(), '4294967295', "incorrect u32 max felt");
let num: u32 = Bounded::MAX;
assert_eq!(num.to_ascii(), '4294967295');
// ------------------------------ min u32 test ------------------------------ //
let num: u32 = BoundedInt::min();
assert_eq!(num.to_ascii(), '0', "incorrect u32 min felt");
let num: u32 = Bounded::MIN;
assert_eq!(num.to_ascii(), '0');
}

#[test]
#[available_gas(2000000)]
fn u16_to_ascii() {
// ------------------------------ max u16 test ------------------------------ //
let num: u16 = BoundedInt::max();
assert_eq!(num.to_ascii(), '65535', "incorrect u16 max felt");
let num: u16 = Bounded::MAX;
assert_eq!(num.to_ascii(), '65535');
// ------------------------------ min u16 test ------------------------------ //
let num: u16 = BoundedInt::min();
assert_eq!(num.to_ascii(), '0', "incorrect u16 min felt");
let num: u16 = Bounded::MIN;
assert_eq!(num.to_ascii(), '0');
}

#[test]
#[available_gas(2000000)]
fn u8_to_ascii() {
// ------------------------------- max u8 test ------------------------------ //
let num: u8 = BoundedInt::max();
assert_eq!(num.to_ascii(), '255', "incorrect u8 max felt");
let num: u8 = Bounded::MAX;
assert_eq!(num.to_ascii(), '255');
// ------------------------------- min u8 test ------------------------------ //
let num: u8 = BoundedInt::min();
assert_eq!(num.to_ascii(), '0', "incorrect u8 min felt");
let num: u8 = Bounded::MIN;
assert_eq!(num.to_ascii(), '0');
}
3 changes: 3 additions & 0 deletions packages/bytes/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ fmt.workspace = true
alexandria_math = { path = "../math" }
alexandria_data_structures = { path = "../data_structures" }
starknet.workspace = true

[dev-dependencies]
cairo_test.workspace = true
Loading
Loading