From e279061ee893386b6f235e7ef3466dbea4302152 Mon Sep 17 00:00:00 2001 From: Leonard Paturel Date: Tue, 5 Mar 2024 11:29:46 +0000 Subject: [PATCH] update and format --- .tool-versions | 2 +- Scarb.toml | 4 ++-- src/ascii/src/integer.cairo | 16 +++++++++------- src/bytes/src/bytes.cairo | 13 +++++++------ src/bytes/src/utils.cairo | 17 +++++++++-------- src/linalg/src/dot.cairo | 11 ++++++----- src/math/src/keccak256.cairo | 13 +++++++------ src/numeric/src/trapezoidal_rule.cairo | 12 +++++++----- 8 files changed, 48 insertions(+), 40 deletions(-) diff --git a/.tool-versions b/.tool-versions index 49edbb53..f2e92b79 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.5.4 +scarb 2.6.0 diff --git a/Scarb.toml b/Scarb.toml index bdd45ec6..adaad591 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -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 diff --git a/src/ascii/src/integer.cairo b/src/ascii/src/integer.cairo index ff911d09..da0ff88d 100644 --- a/src/ascii/src/integer.cairo +++ b/src/ascii/src/integer.cairo @@ -36,13 +36,15 @@ impl ToAsciiArrayTraitImpl< } let mut num = self; - while num.is_non_zero() { - let (quotient, remainder) = DivRem::div_rem( - num, TryInto::::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::::try_into(10).unwrap().try_into().expect('Division by 0') + ); + new_arr.append(remainder.into() + 48); + num = quotient; + }; new_arr } } diff --git a/src/bytes/src/bytes.cairo b/src/bytes/src/bytes.cairo index 44c102f3..f285f73f 100644 --- a/src/bytes/src/bytes.cairo +++ b/src/bytes/src/bytes.cairo @@ -499,12 +499,13 @@ impl BytesImpl of BytesTrait { let mut hash_data: Array = 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 = sha256(hash_data); u8_array_to_u256(output.span()) diff --git a/src/bytes/src/utils.cairo b/src/bytes/src/utils.cairo index 125ada82..0cd23259 100644 --- a/src/bytes/src/utils.cairo +++ b/src/bytes/src/utils.cairo @@ -71,14 +71,15 @@ fn update_u256_array_at(arr: @Array, index: usize, value: u256) -> Array, +AddEq, +Zeroable, +Copy, +Drop,>( // [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 } diff --git a/src/math/src/keccak256.cairo b/src/math/src/keccak256.cairo index 7788ce96..a1c9d15b 100644 --- a/src/math/src/keccak256.cairo +++ b/src/math/src/keccak256.cairo @@ -46,12 +46,13 @@ fn reverse_endianness(value: u256) -> u256 { fn keccak256(mut self: Span) -> u256 { // Converts byte array to little endian 8 byte words array. let mut words64: Array = 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)) diff --git a/src/numeric/src/trapezoidal_rule.cairo b/src/numeric/src/trapezoidal_rule.cairo index d6c72161..0cdd0073 100644 --- a/src/numeric/src/trapezoidal_rule.cairo +++ b/src/numeric/src/trapezoidal_rule.cairo @@ -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) }