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

Update cairo to 2.6.0 #283

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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.5.4
scarb 2.6.0
4 changes: 2 additions & 2 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ name = "alexandria"
version = "0.1.0"
description = "Community maintained Cairo and Starknet libraries"
homepage = "https://github.com/keep-starknet-strange/alexandria/"
cairo-version = "2.5.4"
cairo-version = "2.6.0"

[workspace.dependencies]
starknet = "=2.5.4"
starknet = "=2.6.0"

[workspace.tool.fmt]
sort-module-level-items = true
Expand Down
16 changes: 9 additions & 7 deletions src/ascii/src/integer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ 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
13 changes: 7 additions & 6 deletions src/bytes/src/bytes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,13 @@ impl BytesImpl of BytesTrait {
let mut hash_data: Array<u8> = array![];
let mut i: usize = 0;
let mut offset: usize = 0;
while i != self.size() {
let (new_offset, hash_data_item) = self.read_u8(offset);
hash_data.append(hash_data_item);
offset = new_offset;
i += 1;
};
while i != self
.size() {
let (new_offset, hash_data_item) = self.read_u8(offset);
hash_data.append(hash_data_item);
offset = new_offset;
i += 1;
};

let output: Array<u8> = sha256(hash_data);
u8_array_to_u256(output.span())
Expand Down
17 changes: 9 additions & 8 deletions src/bytes/src/utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ fn update_u256_array_at(arr: @Array<u256>, index: usize, value: u256) -> Array<u
let mut new_arr = array![];
let mut i = 0;

while i != arr.len() {
if i == index {
new_arr.append(value);
} else {
new_arr.append(*arr[i]);
}
i += 1;
};
while i != arr
.len() {
if i == index {
new_arr.append(value);
} else {
new_arr.append(*arr[i]);
}
i += 1;
};
new_arr
}

Expand Down
11 changes: 6 additions & 5 deletions src/linalg/src/dot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ fn dot<T, +Mul<T>, +AddEq<T>, +Zeroable<T>, +Copy<T>, +Drop<T>,>(

// [Compute] Dot product in a loop
let mut sum = Zeroable::zero();
while !xs.is_empty() {
let x = *xs.pop_front().unwrap();
let y = *ys.pop_front().unwrap();
sum += x * y;
};
while !xs
.is_empty() {
let x = *xs.pop_front().unwrap();
let y = *ys.pop_front().unwrap();
sum += x * y;
};
sum
}
13 changes: 7 additions & 6 deletions src/math/src/keccak256.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ fn reverse_endianness(value: u256) -> u256 {
fn keccak256(mut self: Span<u8>) -> u256 {
// Converts byte array to little endian 8 byte words array.
let mut words64: Array<u64> = Default::default();
while self.len() >= 8 {
let current_word = self.slice(0, 8);
let (value, _) = U64Trait::from_le_bytes(current_word);
words64.append(value);
self = self.slice(8, self.len() - 8);
};
while self
.len() >= 8 {
let current_word = self.slice(0, 8);
let (value, _) = U64Trait::from_le_bytes(current_word);
words64.append(value);
self = self.slice(8, self.len() - 8);
};
// handle last word specifically
let (last_word, last_word_bytes) = U64Trait::from_le_bytes(self);
reverse_endianness(cairo_keccak(ref words64, last_word, last_word_bytes))
Expand Down
12 changes: 7 additions & 5 deletions src/numeric/src/trapezoidal_rule.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ fn trapezoidal_rule<
// [Compute] Trapezoidal rule
let mut index = 0;
let mut value = Zeroable::zero();
while index + 1 != xs.len() {
assert(*xs[index + 1] > *xs[index], 'Abscissa must be sorted');
value += (*xs[index + 1] - *xs[index]) * (*ys[index] + *ys[index + 1]);
index += 1;
};
while index
+ 1 != xs
.len() {
assert(*xs[index + 1] > *xs[index], 'Abscissa must be sorted');
value += (*xs[index + 1] - *xs[index]) * (*ys[index] + *ys[index + 1]);
index += 1;
};
value / Into::into(2_u8)
}
Loading