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

feat: bump to scarb 2.9.2 #342

Merged
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.8.2
scarb 2.9.2
1 change: 1 addition & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ name = "alexandria_encoding"
version = "0.1.0"
dependencies = [
"alexandria_bytes",
"alexandria_data_structures",
"alexandria_math",
"alexandria_numeric",
]
Expand Down
6 changes: 3 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,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.8.2"
cairo-version = "2.9.2"

[workspace.dependencies]
starknet = "2.8.2"
cairo_test = "2.8.2"
starknet = "2.9.2"
cairo_test = "2.9.2"

[workspace.tool.fmt]
sort-module-level-items = true
Expand Down
5 changes: 3 additions & 2 deletions packages/ascii/src/integer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ 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')
num,
TryInto::<felt252, T>::try_into(10).unwrap().try_into().expect('Division by 0'),
);
new_arr.append(remainder.into() + 48);
num = quotient;
Expand Down Expand Up @@ -153,7 +154,7 @@ impl U256ToAsciiArrayTraitImpl of ToAsciiArrayTrait<u256> {
let mut num = self;
while num != 0 {
let (quotient, remainder) = DivRem::div_rem(
num, 10_u256.try_into().expect('Division by 0')
num, 10_u256.try_into().expect('Division by 0'),
);
new_arr.append(remainder.try_into().expect('number overflow felt252') + 48);
num = quotient;
Expand Down
2 changes: 1 addition & 1 deletion packages/ascii/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pub mod integer;

#[cfg(test)]
mod tests;
use integer::{ToAsciiTrait, ToAsciiArrayTrait};
use integer::{ToAsciiArrayTrait, ToAsciiTrait};
26 changes: 13 additions & 13 deletions packages/bytes/src/bytes.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alexandria_bytes::utils::{
u128_join, read_sub_u128, u128_split, u128_array_slice, keccak_u128s_be, u32s_to_u256
keccak_u128s_be, read_sub_u128, u128_array_slice, u128_join, u128_split, u32s_to_u256,
};
use alexandria_math::{U128BitShift, U256BitShift};
use core::byte_array::ByteArrayTrait;
Expand Down Expand Up @@ -34,7 +34,7 @@ pub const BYTES_PER_ELEMENT: usize = 16;
#[derive(Drop, Clone, PartialEq, Serde)]
pub struct Bytes {
size: usize,
data: Array<u128>
data: Array<u128>,
}

pub impl BytesIndex of IndexView<Bytes, usize> {
Expand Down Expand Up @@ -64,7 +64,7 @@ pub trait BytesTrait {
fn read_u128_packed(self: @Bytes, offset: usize, size: usize) -> (usize, u128);
/// Read value with element_size bytes from Bytes, and packed into u128 array
fn read_u128_array_packed(
self: @Bytes, offset: usize, array_length: usize, element_size: usize
self: @Bytes, offset: usize, array_length: usize, element_size: usize,
) -> (usize, Array<u128>);
/// Read value with size bytes from Bytes, and packed into felt252
fn read_felt252_packed(self: @Bytes, offset: usize, size: usize) -> (usize, felt252);
Expand Down Expand Up @@ -120,14 +120,14 @@ pub trait BytesTrait {
#[deprecated(
feature: "deprecated-keccak",
note: "Use `core::keccak::compute_keccak_byte_array`.",
since: "2.7.0"
since: "2.7.0",
)]
fn keccak(self: @Bytes) -> u256;
/// sha256 hash
#[deprecated(
feature: "deprecated-sha256",
note: "Use `core::sha256::compute_sha256_byte_array`.",
since: "2.7.0"
since: "2.7.0",
)]
fn sha256(self: @Bytes) -> u256;
}
Expand All @@ -146,7 +146,7 @@ impl BytesImpl of BytesTrait {
fn zero(size: usize) -> Bytes {
let mut data = array![];
let (data_index, mut data_len) = DivRem::div_rem(
size, BYTES_PER_ELEMENT.try_into().expect('Division by 0')
size, BYTES_PER_ELEMENT.try_into().expect('Division by 0'),
);

if data_index != 0 {
Expand Down Expand Up @@ -228,18 +228,18 @@ impl BytesImpl of BytesTrait {
*self.data[element_index],
BYTES_PER_ELEMENT,
element_offset,
BYTES_PER_ELEMENT - element_offset
BYTES_PER_ELEMENT - element_offset,
);
let right = read_sub_u128(
*self.data[element_index + 1], BYTES_PER_ELEMENT, 0, end_element_offset
*self.data[element_index + 1], BYTES_PER_ELEMENT, 0, end_element_offset,
);
u128_join(left, right, end_element_offset)
};
(offset + size, value)
}

fn read_u128_array_packed(
self: @Bytes, offset: usize, array_length: usize, element_size: usize
self: @Bytes, offset: usize, array_length: usize, element_size: usize,
) -> (usize, Array<u128>) {
assert(offset + array_length * element_size <= self.size(), 'out of bound');
let mut array = array![];
Expand Down Expand Up @@ -431,17 +431,17 @@ impl BytesImpl of BytesTrait {
if size + last_element_size > BYTES_PER_ELEMENT {
let (left, right) = u128_split(value, size, BYTES_PER_ELEMENT - last_element_size);
let value_full = u128_join(
last_element_value, left, BYTES_PER_ELEMENT - last_element_size
last_element_value, left, BYTES_PER_ELEMENT - last_element_size,
);
let value_padded = u128_join(
right, 0, 2 * BYTES_PER_ELEMENT - size - last_element_size
right, 0, 2 * BYTES_PER_ELEMENT - size - last_element_size,
);
data.append(value_full);
data.append(value_padded);
} else {
let value = u128_join(last_element_value, value, size);
let value_padded = u128_join(
value, 0, BYTES_PER_ELEMENT - size - last_element_size
value, 0, BYTES_PER_ELEMENT - size - last_element_size,
);
data.append(value_padded);
}
Expand Down Expand Up @@ -543,7 +543,7 @@ impl BytesImpl of BytesTrait {
let mut hash_data = u128_array_slice(self.data, 0, last_data_index);
// To compute hash, we should remove 0 padded
let (last_element_value, _) = u128_split(
*self.data[last_data_index], BYTES_PER_ELEMENT, last_element_size
*self.data[last_data_index], BYTES_PER_ELEMENT, last_element_size,
);
hash_data.append(last_element_value);
return keccak_u128s_be(hash_data.span(), self.size());
Expand Down
2 changes: 1 addition & 1 deletion packages/bytes/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ pub mod storage;
mod tests;
pub mod utils;

pub use bytes::{Bytes, BytesTrait, BytesIndex};
pub use bytes::{Bytes, BytesIndex, BytesTrait};
pub use storage::BytesStore;
20 changes: 10 additions & 10 deletions packages/bytes/src/storage.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use alexandria_bytes::bytes::{Bytes, BytesTrait, BYTES_PER_ELEMENT};
use alexandria_bytes::bytes::{BYTES_PER_ELEMENT, Bytes, BytesTrait};
use core::num::traits::CheckedAdd;
use starknet::SyscallResult;
use starknet::storage_access::{
Store, StorageAddress, StorageBaseAddress, storage_address_from_base,
storage_base_address_from_felt252, storage_address_from_base_and_offset,
StorageAddress, StorageBaseAddress, Store, storage_address_from_base,
storage_address_from_base_and_offset, storage_base_address_from_felt252,
};

/// Store for a `Bytes` object.
Expand All @@ -27,13 +27,13 @@ pub impl BytesStore of Store<Bytes> {
}
#[inline(always)]
fn read_at_offset(
address_domain: u32, base: StorageBaseAddress, offset: u8
address_domain: u32, base: StorageBaseAddress, offset: u8,
) -> SyscallResult<Bytes> {
inner_read_bytes(address_domain, storage_address_from_base_and_offset(base, offset))
}
#[inline(always)]
fn write_at_offset(
address_domain: u32, base: StorageBaseAddress, offset: u8, value: Bytes
address_domain: u32, base: StorageBaseAddress, offset: u8, value: Bytes,
) -> SyscallResult<()> {
inner_write_bytes(address_domain, storage_address_from_base_and_offset(base, offset), value)
}
Expand Down Expand Up @@ -64,7 +64,7 @@ fn inner_read_bytes(address_domain: u32, address: StorageAddress) -> SyscallResu
Option::None => { return SyscallResult::Err(array!['Invalid Bytes size']); },
};
let (mut remaining_full_words, last_word_len) = DivRem::div_rem(
size, BYTES_PER_ELEMENT.try_into().unwrap()
size, BYTES_PER_ELEMENT.try_into().unwrap(),
);
let mut chunk = 0;
let mut chunk_base = inner_bytes_pointer(address, chunk);
Expand All @@ -76,7 +76,7 @@ fn inner_read_bytes(address_domain: u32, address: StorageAddress) -> SyscallResu
}
let value =
match starknet::syscalls::storage_read_syscall(
address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk)
address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk),
) {
Result::Ok(value) => value,
Result::Err(err) => { break Result::Err(err); },
Expand All @@ -99,7 +99,7 @@ fn inner_read_bytes(address_domain: u32, address: StorageAddress) -> SyscallResu
}?;
if last_word_len != 0 {
let last_word = starknet::syscalls::storage_read_syscall(
address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk)
address_domain, storage_address_from_base_and_offset(chunk_base, index_in_chunk),
)?;
data.append(last_word.try_into().expect('Invalid last word'));
}
Expand All @@ -110,7 +110,7 @@ fn inner_read_bytes(address_domain: u32, address: StorageAddress) -> SyscallResu
/// The length of the bytes is written to `address` at domain `address_domain`.
/// For more info read the documentation of `BytesStore`.
fn inner_write_bytes(
address_domain: u32, address: StorageAddress, value: Bytes
address_domain: u32, address: StorageAddress, value: Bytes,
) -> SyscallResult<()> {
let size = value.size();
starknet::syscalls::storage_write_syscall(address_domain, address, size.into())?;
Expand All @@ -126,7 +126,7 @@ fn inner_write_bytes(
match starknet::syscalls::storage_write_syscall(
address_domain,
storage_address_from_base_and_offset(chunk_base, index_in_chunk),
(*curr_value).into()
(*curr_value).into(),
) {
Result::Ok(_) => {},
Result::Err(err) => { break Result::Err(err); },
Expand Down
Loading
Loading