From 162bed1c636d31ccaaa90ed3eb32c9eb1d5e3bd3 Mon Sep 17 00:00:00 2001 From: ishay-starkware <165644203+ishay-starkware@users.noreply.github.com> Date: Wed, 18 Dec 2024 16:47:57 +0200 Subject: [PATCH] feat: bump to scarb 2.9.2 (#342) bump `scarb` to 2.9.2 add missing `data_structures` package dependency to encoding package update `bigdecimal` to 0.4.7 in macros package update `cairo-lang-macro` to 0.1.1 in `macros` package cargo.toml update `cairo-lang-parser` 2.9.2 in `macros` package cargo.toml update `cairo-lang-syntax` 2.9.2 in `macros` package cargo.toml ## Pull Request type Please check the type of change your PR introduces: - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no API changes) - [ ] Build-related changes - [ ] Documentation content changes - [x] Other (please describe): update version ## What is the current behavior? Issue Number: N/A ## What is the new behavior? - - - ## Does this introduce a breaking change? - [ ] Yes - [x] No ## Other information --------- Co-authored-by: LucasLvy --- .tool-versions | 2 +- Scarb.lock | 1 + Scarb.toml | 6 +- packages/ascii/src/integer.cairo | 5 +- packages/ascii/src/lib.cairo | 2 +- packages/bytes/src/bytes.cairo | 26 +- packages/bytes/src/lib.cairo | 2 +- packages/bytes/src/storage.cairo | 20 +- packages/bytes/src/tests/test_bytes.cairo | 50 +- .../bytes/src/tests/test_bytes_store.cairo | 8 +- packages/bytes/src/utils.cairo | 6 +- packages/data_structures/src/bit_array.cairo | 39 +- .../data_structures/src/byte_reader.cairo | 23 +- packages/data_structures/src/stack.cairo | 2 +- .../data_structures/src/tests/array_ext.cairo | 6 +- .../data_structures/src/tests/bit_array.cairo | 4 +- .../src/tests/byte_appender.cairo | 5 +- .../src/tests/byte_array_ext.cairo | 4 +- .../src/tests/byte_reader.cairo | 10 +- .../data_structures/src/tests/span_ext.cairo | 8 +- .../data_structures/src/tests/stack.cairo | 12 +- packages/data_structures/src/tests/vec.cairo | 24 +- packages/encoding/Scarb.toml | 1 + packages/encoding/src/base64.cairo | 2 +- packages/encoding/src/reversible.cairo | 22 +- packages/encoding/src/rlp.cairo | 12 +- .../encoding/src/tests/base64_felt_test.cairo | 2 +- packages/encoding/src/tests/base64_test.cairo | 4 +- .../encoding/src/tests/reversible_test.cairo | 2 +- packages/encoding/src/tests/rlp_test.cairo | 154 +++--- packages/encoding/src/tests/sol_abi.cairo | 34 +- packages/linalg/src/dot.cairo | 4 +- packages/linalg/src/kron.cairo | 4 +- packages/linalg/src/norm.cairo | 2 +- packages/linalg/src/tests/kron_test.cairo | 2 +- packages/macros/Cargo.lock | 378 ++++++++----- packages/macros/Cargo.toml | 10 +- packages/macros/src/pow.rs | 92 +++- packages/macros_tests/Scarb.toml | 2 +- .../macros_tests/src/test_num_traits.cairo | 6 +- packages/macros_tests/src/test_pow.cairo | 2 +- .../macros_tests/src/test_zero_trait.cairo | 6 +- packages/math/src/bip340.cairo | 4 +- packages/math/src/bitmap.cairo | 4 +- packages/math/src/const_pow.cairo | 496 ++++-------------- packages/math/src/ed25519.cairo | 14 +- packages/math/src/fast_power.cairo | 8 +- packages/math/src/i257.cairo | 4 +- packages/math/src/karatsuba.cairo | 2 +- packages/math/src/keccak256.cairo | 2 +- packages/math/src/lcm_of_n_numbers.cairo | 2 +- packages/math/src/lib.cairo | 8 +- packages/math/src/mod_arithmetics.cairo | 4 +- packages/math/src/sha256.cairo | 84 +-- packages/math/src/sha512.cairo | 20 +- packages/math/src/tests/const_pow_test.cairo | 14 +- packages/math/src/tests/ed25519_test.cairo | 8 +- packages/math/src/tests/fast_power_test.cairo | 6 +- packages/math/src/tests/i257_test.cairo | 2 +- .../src/tests/lcm_of_n_numbers_test.cairo | 2 +- packages/math/src/tests/math_test.cairo | 6 +- .../math/src/tests/mod_arithmetics_test.cairo | 8 +- packages/math/src/tests/sha256_test.cairo | 4 +- packages/math/src/tests/sha512_test.cairo | 4 +- packages/math/src/tests/test_keccak256.cairo | 2 +- .../src/tests/u512_arithmetics_test.cairo | 10 +- .../math/src/tests/wad_ray_math_test.cairo | 2 +- packages/math/src/trigonometry.cairo | 10 +- packages/math/src/u512_arithmetics.cairo | 20 +- packages/merkle_tree/src/merkle_tree.cairo | 14 +- packages/merkle_tree/src/storage_proof.cairo | 28 +- .../src/tests/merkle_tree_test.cairo | 32 +- .../src/tests/storage_proof_test_data.cairo | 358 ++++++------- packages/numeric/src/cumprod.cairo | 2 +- packages/numeric/src/cumsum.cairo | 2 +- packages/numeric/src/diff.cairo | 4 +- packages/numeric/src/integers.cairo | 4 +- packages/numeric/src/interpolate.cairo | 4 +- .../src/tests/interpolate_fast_test.cairo | 28 +- .../numeric/src/tests/interpolate_test.cairo | 28 +- packages/numeric/src/trapezoidal_rule.cairo | 2 +- packages/searching/src/binary_search.cairo | 10 +- packages/searching/src/dijkstra.cairo | 2 +- packages/sorting/src/interface.cairo | 2 +- packages/sorting/src/merge_sort.cairo | 2 +- packages/sorting/src/quick_sort.cairo | 4 +- packages/storage/src/list.cairo | 28 +- packages/storage/src/tests/list_test.cairo | 29 +- packages/utils/src/fmt.cairo | 10 +- 89 files changed, 1091 insertions(+), 1258 deletions(-) diff --git a/.tool-versions b/.tool-versions index cc60fd62..f6645f9f 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.8.2 +scarb 2.9.2 diff --git a/Scarb.lock b/Scarb.lock index 0cd56aae..908bf62e 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -28,6 +28,7 @@ name = "alexandria_encoding" version = "0.1.0" dependencies = [ "alexandria_bytes", + "alexandria_data_structures", "alexandria_math", "alexandria_numeric", ] diff --git a/Scarb.toml b/Scarb.toml index 3f9da5e1..2e4db5a9 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -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 diff --git a/packages/ascii/src/integer.cairo b/packages/ascii/src/integer.cairo index 1d7a0d40..20deea1d 100644 --- a/packages/ascii/src/integer.cairo +++ b/packages/ascii/src/integer.cairo @@ -39,7 +39,8 @@ 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') + num, + TryInto::::try_into(10).unwrap().try_into().expect('Division by 0'), ); new_arr.append(remainder.into() + 48); num = quotient; @@ -153,7 +154,7 @@ impl U256ToAsciiArrayTraitImpl of ToAsciiArrayTrait { 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; diff --git a/packages/ascii/src/lib.cairo b/packages/ascii/src/lib.cairo index c1272d53..0c6a50d2 100644 --- a/packages/ascii/src/lib.cairo +++ b/packages/ascii/src/lib.cairo @@ -2,4 +2,4 @@ pub mod integer; #[cfg(test)] mod tests; -use integer::{ToAsciiTrait, ToAsciiArrayTrait}; +use integer::{ToAsciiArrayTrait, ToAsciiTrait}; diff --git a/packages/bytes/src/bytes.cairo b/packages/bytes/src/bytes.cairo index b0e14920..735511c8 100644 --- a/packages/bytes/src/bytes.cairo +++ b/packages/bytes/src/bytes.cairo @@ -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; @@ -34,7 +34,7 @@ pub const BYTES_PER_ELEMENT: usize = 16; #[derive(Drop, Clone, PartialEq, Serde)] pub struct Bytes { size: usize, - data: Array + data: Array, } pub impl BytesIndex of IndexView { @@ -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); /// Read value with size bytes from Bytes, and packed into felt252 fn read_felt252_packed(self: @Bytes, offset: usize, size: usize) -> (usize, felt252); @@ -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; } @@ -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 { @@ -228,10 +228,10 @@ 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) }; @@ -239,7 +239,7 @@ impl BytesImpl of BytesTrait { } 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) { assert(offset + array_length * element_size <= self.size(), 'out of bound'); let mut array = array![]; @@ -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); } @@ -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()); diff --git a/packages/bytes/src/lib.cairo b/packages/bytes/src/lib.cairo index 7bac6d07..4e613ed5 100644 --- a/packages/bytes/src/lib.cairo +++ b/packages/bytes/src/lib.cairo @@ -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; diff --git a/packages/bytes/src/storage.cairo b/packages/bytes/src/storage.cairo index 25fb3801..27b813b6 100644 --- a/packages/bytes/src/storage.cairo +++ b/packages/bytes/src/storage.cairo @@ -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. @@ -27,13 +27,13 @@ pub impl BytesStore of Store { } #[inline(always)] fn read_at_offset( - address_domain: u32, base: StorageBaseAddress, offset: u8 + address_domain: u32, base: StorageBaseAddress, offset: u8, ) -> SyscallResult { 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) } @@ -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); @@ -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); }, @@ -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')); } @@ -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())?; @@ -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); }, diff --git a/packages/bytes/src/tests/test_bytes.cairo b/packages/bytes/src/tests/test_bytes.cairo index 20372ec6..184a937f 100644 --- a/packages/bytes/src/tests/test_bytes.cairo +++ b/packages/bytes/src/tests/test_bytes.cairo @@ -1,5 +1,5 @@ use alexandria_bytes::utils::{BytesDebug, BytesDisplay}; -use alexandria_bytes::{Bytes, BytesTrait, BytesIndex}; +use alexandria_bytes::{Bytes, BytesIndex, BytesTrait}; #[test] #[available_gas(20000000)] @@ -58,8 +58,8 @@ fn test_bytes_update() { array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 - ] + 0x01020304050607080910000000000000, + ], ); bytes.update_at(16, 0x16); @@ -81,7 +81,7 @@ fn test_bytes_read_u128_packed() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -114,7 +114,7 @@ fn test_bytes_read_u128_packed_out_of_bound() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -129,7 +129,7 @@ fn test_bytes_read_u128_packed_too_large() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -143,7 +143,7 @@ fn test_bytes_read_u128_array_packed() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -169,7 +169,7 @@ fn test_bytes_read_u128_array_packed_out_of_bound() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -184,7 +184,7 @@ fn test_bytes_read_u128_array_packed_too_large() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -198,7 +198,7 @@ fn test_bytes_read_felt252_packed() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -215,7 +215,7 @@ fn test_bytes_read_felt252_packed_out_of_bound() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -230,7 +230,7 @@ fn test_bytes_read_felt252_packed_too_large() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -244,7 +244,7 @@ fn test_bytes_read_u8() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -260,7 +260,7 @@ fn test_bytes_read_u16() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -276,7 +276,7 @@ fn test_bytes_read_u32() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -292,7 +292,7 @@ fn test_bytes_read_usize() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -308,7 +308,7 @@ fn test_bytes_read_u64() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -324,7 +324,7 @@ fn test_bytes_read_u128() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -340,7 +340,7 @@ fn test_bytes_read_u256() { let array = array![ 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x01020304050607080910000000000000 + 0x01020304050607080910000000000000, ]; let bytes = BytesTrait::new(42, array); @@ -355,7 +355,7 @@ fn test_bytes_read_u256() { #[available_gas(20000000)] fn test_bytes_read_bytes31() { let bytes: Bytes = BytesTrait::new( - 42, array![0x0102030405060708090a0b0c0d0e0f10, 0x1112131415161718191a1b1c1d1e1f17, 0x0] + 42, array![0x0102030405060708090a0b0c0d0e0f10, 0x1112131415161718191a1b1c1d1e1f17, 0x0], ); let (offset, val) = bytes.read_bytes31(2); assert_eq!(offset, 33); @@ -374,7 +374,7 @@ fn test_bytes_read_u256_array() { 0x16151413121110090807060504030201, 0x01020304050607080910111213141516, 0x01020304050607080910111213141516, - 0x16151413121110090000000000000000 + 0x16151413121110090000000000000000, ]; let bytes = BytesTrait::new(88, array); @@ -546,14 +546,14 @@ fn test_bytes_concat() { 0x05060708090000000000000000000102, 0x0304050607015401855d7796176b05d1, 0x60196ff92381eb7910f5446c2e0e04e1, - 0x3db2194a4f0000000000000000000000 + 0x3db2194a4f0000000000000000000000, ]; let mut bytes = BytesTrait::new(117, array); let array: Array = array![ 0x01020304050607080910111213140154, 0x01855d7796176b05d160196ff92381eb, - 0x7910f5446c2e0e04e13db2194a4f0000 + 0x7910f5446c2e0e04e13db2194a4f0000, ]; let other = BytesTrait::new(46, array); @@ -693,8 +693,8 @@ fn test_byte_array_conversions() { 0x01020304050607080910111213141516, 0x16151413121110090807060504030201, 0x60196ff92381eb7910f5446c2e0e04e1, - 0x3db2194a000000000000000000000000 - ] + 0x3db2194a000000000000000000000000, + ], ); let byte_array: ByteArray = bytes.clone().into(); let new_bytes: Bytes = byte_array.into(); diff --git a/packages/bytes/src/tests/test_bytes_store.cairo b/packages/bytes/src/tests/test_bytes_store.cairo index 3172ead2..59960fa1 100644 --- a/packages/bytes/src/tests/test_bytes_store.cairo +++ b/packages/bytes/src/tests/test_bytes_store.cairo @@ -30,9 +30,9 @@ mod ABytesStore { #[cfg(test)] mod tests { use alexandria_bytes::utils::{BytesDebug, BytesDisplay}; - use alexandria_bytes::{BytesTrait, BytesStore}; + use alexandria_bytes::{BytesStore, BytesTrait}; use starknet::syscalls::deploy_syscall; - use starknet::{ClassHash, SyscallResultTrait,}; + use starknet::{ClassHash, SyscallResultTrait}; use super::{ABytesStore, IABytesStoreDispatcher, IABytesStoreDispatcherTrait}; fn deploy() -> IABytesStoreDispatcher { @@ -62,8 +62,8 @@ mod tests { let bytes = BytesTrait::new( 40, array![ - 0x01020304050607080910, 0x11121314151617181920, 0x21222324252627280000000000000000 - ] + 0x01020304050607080910, 0x11121314151617181920, 0x21222324252627280000000000000000, + ], ); contract.set_bytes(bytes.clone()); assert_eq!(contract.get_bytes(), bytes); diff --git a/packages/bytes/src/utils.cairo b/packages/bytes/src/utils.cairo index 764c9886..89541745 100644 --- a/packages/bytes/src/utils.cairo +++ b/packages/bytes/src/utils.cairo @@ -1,6 +1,6 @@ use alexandria_bytes::{Bytes, BytesTrait}; use alexandria_math::const_pow::pow2; -use core::fmt::{Debug, Display, Formatter, Error}; +use core::fmt::{Debug, Display, Error, Formatter}; use core::integer::u128_byte_reverse; use core::keccak::cairo_keccak; use core::to_byte_array::FormatAsByteArray; @@ -83,7 +83,7 @@ fn u256_reverse_endian(input: u256) -> u256 { fn keccak_add_uint128_be(ref keccak_input: Array::, value: u128, value_size: usize) { if value_size == 16 { let (high, low) = core::integer::u128_safe_divmod( - u128_byte_reverse(value), 0x10000000000000000_u128.try_into().unwrap() + u128_byte_reverse(value), 0x10000000000000000_u128.try_into().unwrap(), ); keccak_input.append(low.try_into().unwrap()); keccak_input.append(high.try_into().unwrap()); @@ -94,7 +94,7 @@ fn keccak_add_uint128_be(ref keccak_input: Array::, value: u128, value_size keccak_input.append(reversed_value.try_into().unwrap()); } else { let (high, low) = DivRem::div_rem( - reversed_value, pow2(64).try_into().expect('Division by 0') + reversed_value, pow2(64).try_into().expect('Division by 0'), ); keccak_input.append(low.try_into().unwrap()); keccak_input.append(high.try_into().unwrap()); diff --git a/packages/data_structures/src/bit_array.cairo b/packages/data_structures/src/bit_array.cairo index 6e5e0fdd..8d01b315 100644 --- a/packages/data_structures/src/bit_array.cairo +++ b/packages/data_structures/src/bit_array.cairo @@ -20,12 +20,12 @@ pub struct BitArray { impl BitArrayDefaultImpl of Default { fn default() -> BitArray { - BitArray { data: array![], current: 0, read_pos: 0, write_pos: 0, } + BitArray { data: array![], current: 0, read_pos: 0, write_pos: 0 } } } pub trait BitArrayTrait { - fn new(data: Array, current: felt252, read_pos: usize, write_pos: usize,) -> BitArray; + fn new(data: Array, current: felt252, read_pos: usize, write_pos: usize) -> BitArray; fn current(self: @BitArray) -> felt252; fn data(self: BitArray) -> Array; /// Appends a single bit to the BitArray @@ -125,8 +125,8 @@ pub trait BitArrayTrait { } impl BitArrayImpl of BitArrayTrait { - fn new(data: Array, current: felt252, read_pos: usize, write_pos: usize,) -> BitArray { - BitArray { data, current, read_pos, write_pos, } + fn new(data: Array, current: felt252, read_pos: usize, write_pos: usize) -> BitArray { + BitArray { data, current, read_pos, write_pos } } fn current(self: @BitArray) -> felt252 { @@ -139,7 +139,7 @@ impl BitArrayImpl of BitArrayTrait { fn append_bit(ref self: BitArray, bit: bool) { let (byte_number, bit_offset) = DivRem::div_rem( - self.write_pos, 8_usize.try_into().unwrap() + self.write_pos, 8_usize.try_into().unwrap(), ); let byte_offset = BYTES_IN_BYTES31_MINUS_ONE - (byte_number % BYTES_IN_BYTES31); let bit_offset = 7 - bit_offset; @@ -190,7 +190,7 @@ impl BitArrayImpl of BitArrayTrait { let high = 0; let low = self._read_word_be_recursive(0, length)?.try_into().unwrap(); u256 { low, high } - } + }, ) } @@ -221,7 +221,7 @@ impl BitArrayImpl of BitArrayTrait { let limb1 = 0; let limb0 = self._read_word_be_recursive(0, length)?.try_into().unwrap(); u512 { limb0, limb1, limb2, limb3 } - } + }, ) } @@ -231,7 +231,7 @@ impl BitArrayImpl of BitArrayTrait { return; } let (mut byte_offset, mut bit_offset) = DivRem::div_rem( - length - 1, 8_usize.try_into().unwrap() + length - 1, 8_usize.try_into().unwrap(), ); loop { self.append_bit(select(word, byte_offset, bit_offset)); @@ -300,7 +300,7 @@ impl BitArrayImpl of BitArrayTrait { Option::None => { result = Option::None; break; - } + }, } if bit_offset == 7 { byte_offset += 1; @@ -323,7 +323,7 @@ impl BitArrayImpl of BitArrayTrait { let low = self.read_word_le(length)?.try_into().unwrap(); let high = 0; u256 { low, high } - } + }, ) } @@ -339,7 +339,7 @@ impl BitArrayImpl of BitArrayTrait { limb0: limb0.try_into().unwrap(), limb1: limb1.try_into().unwrap(), limb2: limb2.try_into().unwrap(), - limb3: limb3.try_into().unwrap() + limb3: limb3.try_into().unwrap(), } } else if length > 256 { let limb0 = self.read_word_le(128)?; @@ -350,7 +350,7 @@ impl BitArrayImpl of BitArrayTrait { limb0: limb0.try_into().unwrap(), limb1: limb1.try_into().unwrap(), limb2: limb2.try_into().unwrap(), - limb3 + limb3, } } else if length > 128 { let limb0 = self.read_word_le(128)?; @@ -358,7 +358,10 @@ impl BitArrayImpl of BitArrayTrait { let limb2 = 0; let limb3 = 0; u512 { - limb0: limb0.try_into().unwrap(), limb1: limb1.try_into().unwrap(), limb2, limb3 + limb0: limb0.try_into().unwrap(), + limb1: limb1.try_into().unwrap(), + limb2, + limb3, } } else { let limb0 = self.read_word_le(length)?; @@ -366,7 +369,7 @@ impl BitArrayImpl of BitArrayTrait { let limb2 = 0; let limb3 = 0; u512 { limb0: limb0.try_into().unwrap(), limb1, limb2, limb3 } - } + }, ) } @@ -419,7 +422,7 @@ impl BitArrayInternalImpl of BitArrayInternalTrait { fn word_and_offset(self: @BitArray, index: usize) -> (felt252, usize, usize) { let (byte_number, bit_offset) = DivRem::div_rem(index, 8_usize.try_into().unwrap()); let (word_index, byte_offset) = DivRem::div_rem( - byte_number, BYTES_IN_BYTES31.try_into().unwrap() + byte_number, BYTES_IN_BYTES31.try_into().unwrap(), ); let bit_offset = 7_usize - bit_offset; let byte_offset = BYTES_IN_BYTES31_MINUS_ONE - byte_offset; @@ -443,7 +446,7 @@ impl BitArrayInternalImpl of BitArrayInternalTrait { } fn _read_word_be_recursive( - ref self: BitArray, current: felt252, length: usize + ref self: BitArray, current: felt252, length: usize, ) -> Option { if length == 0 { return Option::Some(current); @@ -544,7 +547,7 @@ pub fn one_shift_left_bytes_u128(n_bytes: usize) -> u128 { 14 => 0x10000000000000000000000000000, 15 => 0x1000000000000000000000000000000, _ => core::panic_with_felt252( - 'n_bytes too big' - ), // For some reason we can't use panic!("") macro here... (running out of gas) + 'n_bytes too big', + ) // For some reason we can't use panic!("") macro here... (running out of gas) } } diff --git a/packages/data_structures/src/byte_reader.cairo b/packages/data_structures/src/byte_reader.cairo index 51a79702..f6412616 100644 --- a/packages/data_structures/src/byte_reader.cairo +++ b/packages/data_structures/src/byte_reader.cairo @@ -172,7 +172,7 @@ pub trait ByteReader { } impl ByteReaderImpl< - T, +Drop, +Len, +IndexView, +Into::Target, @u8> + T, +Drop, +Len, +IndexView, +Into::Target, @u8>, > of ByteReader { #[inline] fn reader(self: @T) -> ByteReaderState { @@ -217,7 +217,7 @@ impl ByteReaderImpl< b1.into() * one_shift_left_bytes_u128(3).try_into().unwrap() + b2.into() * one_shift_left_bytes_u128(2).try_into().unwrap() + b3.into() * one_shift_left_bytes_u128(1).try_into().unwrap() - + b4.into() + + b4.into(), ) } else { Option::None @@ -235,7 +235,7 @@ impl ByteReaderImpl< b1.into() + b2.into() * one_shift_left_bytes_u128(1).try_into().unwrap() + b3.into() * one_shift_left_bytes_u128(2).try_into().unwrap() - + b4.into() * one_shift_left_bytes_u128(3).try_into().unwrap() + + b4.into() * one_shift_left_bytes_u128(3).try_into().unwrap(), ) } else { Option::None @@ -261,7 +261,7 @@ impl ByteReaderImpl< + b5.into() * one_shift_left_bytes_u128(3).try_into().unwrap() + b6.into() * one_shift_left_bytes_u128(2).try_into().unwrap() + b7.into() * one_shift_left_bytes_u128(1).try_into().unwrap() - + b8.into() + + b8.into(), ) } else { Option::None @@ -287,7 +287,7 @@ impl ByteReaderImpl< + b5.into() * one_shift_left_bytes_u128(4).try_into().unwrap() + b6.into() * one_shift_left_bytes_u128(5).try_into().unwrap() + b7.into() * one_shift_left_bytes_u128(6).try_into().unwrap() - + b8.into() * one_shift_left_bytes_u128(7).try_into().unwrap() + + b8.into() * one_shift_left_bytes_u128(7).try_into().unwrap(), ) } else { Option::None @@ -329,7 +329,7 @@ impl ByteReaderImpl< + b13.into() * one_shift_left_bytes_u128(03).try_into().unwrap() + b14.into() * one_shift_left_bytes_u128(02).try_into().unwrap() + b15.into() * one_shift_left_bytes_u128(01).try_into().unwrap() - + b16.into() + + b16.into(), ) } else { Option::None @@ -371,7 +371,7 @@ impl ByteReaderImpl< + b13.into() * one_shift_left_bytes_u128(12).try_into().unwrap() + b14.into() * one_shift_left_bytes_u128(13).try_into().unwrap() + b15.into() * one_shift_left_bytes_u128(14).try_into().unwrap() - + b16.into() * one_shift_left_bytes_u128(15).try_into().unwrap() + + b16.into() * one_shift_left_bytes_u128(15).try_into().unwrap(), ) } else { Option::None @@ -438,7 +438,7 @@ impl ByteReaderImpl< fn read_u256(ref self: ByteReaderState) -> Option { let result = u256 { - high: self.data.word_u128(self.index)?, low: self.data.word_u128(self.index + 16)? + high: self.data.word_u128(self.index)?, low: self.data.word_u128(self.index + 16)?, }; self.index += 32; Option::Some(result) @@ -446,7 +446,8 @@ impl ByteReaderImpl< fn read_u256_le(ref self: ByteReaderState) -> Option { let result = u256 { - low: self.data.word_u128_le(self.index)?, high: self.data.word_u128_le(self.index + 16)? + low: self.data.word_u128_le(self.index)?, + high: self.data.word_u128_le(self.index + 16)?, }; self.index += 32; Option::Some(result) @@ -457,7 +458,7 @@ impl ByteReaderImpl< limb3: self.data.word_u128(self.index)?, limb2: self.data.word_u128(self.index + 16)?, limb1: self.data.word_u128(self.index + 32)?, - limb0: self.data.word_u128(self.index + 48)? + limb0: self.data.word_u128(self.index + 48)?, }; self.index += 64; Option::Some(result) @@ -468,7 +469,7 @@ impl ByteReaderImpl< limb0: self.data.word_u128_le(self.index)?, limb1: self.data.word_u128_le(self.index + 16)?, limb2: self.data.word_u128_le(self.index + 32)?, - limb3: self.data.word_u128_le(self.index + 48)? + limb3: self.data.word_u128_le(self.index + 48)?, }; self.index += 64; Option::Some(result) diff --git a/packages/data_structures/src/stack.cairo b/packages/data_structures/src/stack.cairo index b7e0190e..16f70b0d 100644 --- a/packages/data_structures/src/stack.cairo +++ b/packages/data_structures/src/stack.cairo @@ -115,7 +115,7 @@ impl DestructNullableStack> of Destruct> { } } -impl NullableStackImpl, +Drop,> of StackTrait, T> { +impl NullableStackImpl, +Drop> of StackTrait, T> { #[inline(always)] fn new() -> NullableStack { let elements: Felt252Dict> = Default::default(); diff --git a/packages/data_structures/src/tests/array_ext.cairo b/packages/data_structures/src/tests/array_ext.cairo index 21432cea..c8bea6a5 100644 --- a/packages/data_structures/src/tests/array_ext.cairo +++ b/packages/data_structures/src/tests/array_ext.cairo @@ -201,7 +201,7 @@ mod concat { } mod pop_front_n { - use super::{ArrayTraitExt, get_u128_array, get_felt252_array}; + use super::{ArrayTraitExt, get_felt252_array, get_u128_array}; #[test] #[available_gas(2000000)] @@ -277,7 +277,7 @@ mod pop_front_n { } mod remove_front_n { - use super::{ArrayTraitExt, get_u128_array, get_felt252_array}; + use super::{ArrayTraitExt, get_felt252_array, get_u128_array}; #[test] #[available_gas(2000000)] @@ -435,7 +435,7 @@ mod contains { } mod position { - use super::{ArrayTraitExt, get_u128_array, get_felt252_array}; + use super::{ArrayTraitExt, get_felt252_array, get_u128_array}; #[test] #[available_gas(2000000)] diff --git a/packages/data_structures/src/tests/bit_array.cairo b/packages/data_structures/src/tests/bit_array.cairo index c2feb95c..e6c457fe 100644 --- a/packages/data_structures/src/tests/bit_array.cairo +++ b/packages/data_structures/src/tests/bit_array.cairo @@ -1,5 +1,5 @@ use alexandria_data_structures::bit_array::{ - BitArray, BitArrayTrait, one_shift_left_bytes_felt252, shift_bit + BitArray, BitArrayTrait, one_shift_left_bytes_felt252, shift_bit, }; use core::integer::u512; use core::num::traits::Bounded; @@ -17,7 +17,7 @@ fn test_append_bit() { let val: bytes31 = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .try_into() .unwrap(); - let expected: Array = array![val, val,]; + let expected: Array = array![val, val]; assert_eq!(ba.current(), 0xa * one_shift_left_bytes_felt252(30) * shift_bit(4).into()); assert!(ba.data() == expected, "illegal array"); } diff --git a/packages/data_structures/src/tests/byte_appender.cairo b/packages/data_structures/src/tests/byte_appender.cairo index fb70058b..688af2ad 100644 --- a/packages/data_structures/src/tests/byte_appender.cairo +++ b/packages/data_structures/src/tests/byte_appender.cairo @@ -1,7 +1,8 @@ use alexandria_data_structures::byte_appender::ByteAppender; use alexandria_data_structures::tests::byte_reader::{ - test_array_8, test_array_16, test_array_16_neg, test_array_32, test_array_64, test_byte_array_8, - test_byte_array_16, test_byte_array_16_neg, test_byte_array_32, test_byte_array_64 + test_array_16, test_array_16_neg, test_array_32, test_array_64, test_array_8, + test_byte_array_16, test_byte_array_16_neg, test_byte_array_32, test_byte_array_64, + test_byte_array_8, }; use core::integer::u512; diff --git a/packages/data_structures/src/tests/byte_array_ext.cairo b/packages/data_structures/src/tests/byte_array_ext.cairo index ce74a13a..3cc1888e 100644 --- a/packages/data_structures/src/tests/byte_array_ext.cairo +++ b/packages/data_structures/src/tests/byte_array_ext.cairo @@ -3,7 +3,7 @@ use alexandria_data_structures::byte_array_ext::{ByteArrayIntoArrayU8, SpanU8Int #[test] #[available_gas(1000000)] fn test_span_u8_into_byte_array() { - let array: Array = array![1, 2, 3, 4, 5, 6, 7, 8,]; + let array: Array = array![1, 2, 3, 4, 5, 6, 7, 8]; let ba: ByteArray = array.span().into(); let mut index = 0_usize; while let Option::Some(byte) = ba.at(index) { @@ -36,6 +36,6 @@ fn serialized_byte_array_64() -> Array { 0x40, 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f, 0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e, - 0x3f40 + 0x3f40, ] } diff --git a/packages/data_structures/src/tests/byte_reader.cairo b/packages/data_structures/src/tests/byte_reader.cairo index 965ad745..cd1f6bae 100644 --- a/packages/data_structures/src/tests/byte_reader.cairo +++ b/packages/data_structures/src/tests/byte_reader.cairo @@ -557,7 +557,7 @@ pub fn test_array_32() -> Array { 29, 30, 31, - 32 + 32, ] } @@ -594,7 +594,7 @@ pub fn test_array_32_neg() -> Array { 0xe3, 0xe2, 0xe1, - 0xe0 + 0xe0, ] } @@ -615,7 +615,7 @@ pub fn test_array_16_neg() -> Array { 0xff, 0xff, 0xff, - 0xfe + 0xfe, ] } @@ -684,7 +684,7 @@ pub fn test_array_64() -> Array { 61, 62, 63, - 64 + 64, ] } @@ -694,6 +694,6 @@ fn serialized_byte_array_64() -> Array { 0x40, 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f, 0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e, - 0x3f40 + 0x3f40, ] } diff --git a/packages/data_structures/src/tests/span_ext.cairo b/packages/data_structures/src/tests/span_ext.cairo index 0d404a90..3c87a26e 100644 --- a/packages/data_structures/src/tests/span_ext.cairo +++ b/packages/data_structures/src/tests/span_ext.cairo @@ -2,7 +2,7 @@ use alexandria_data_structures::span_ext::{SpanTraitExt}; use super::{get_felt252_array, get_u128_array}; mod pop_front_n { - use super::{SpanTraitExt, get_u128_array, get_felt252_array}; + use super::{SpanTraitExt, get_felt252_array, get_u128_array}; #[test] #[available_gas(2000000)] @@ -77,7 +77,7 @@ mod pop_front_n { } mod pop_back_n { - use super::{SpanTraitExt, get_u128_array, get_felt252_array}; + use super::{SpanTraitExt, get_felt252_array, get_u128_array}; #[test] #[available_gas(2000000)] @@ -152,7 +152,7 @@ mod pop_back_n { } mod remove_front_n { - use super::{SpanTraitExt, get_u128_array, get_felt252_array}; + use super::{SpanTraitExt, get_felt252_array, get_u128_array}; #[test] #[available_gas(2000000)] @@ -221,7 +221,7 @@ mod remove_front_n { } mod remove_back_n { - use super::{SpanTraitExt, get_u128_array, get_felt252_array}; + use super::{SpanTraitExt, get_felt252_array, get_u128_array}; #[test] #[available_gas(2000000)] diff --git a/packages/data_structures/src/tests/stack.cairo b/packages/data_structures/src/tests/stack.cairo index fefcf71c..71355d28 100644 --- a/packages/data_structures/src/tests/stack.cairo +++ b/packages/data_structures/src/tests/stack.cairo @@ -1,5 +1,5 @@ // Internal imports -use alexandria_data_structures::stack::{StackTrait, Felt252Stack, NullableStack}; +use alexandria_data_structures::stack::{Felt252Stack, NullableStack, StackTrait}; fn stack_new_test>(stack: @S) { @@ -11,7 +11,7 @@ fn stack_is_empty_test>(stack: @S) { } fn stack_push_test, +Drop, +Destruct>( - ref stack: S, val_1: T, val_2: T + ref stack: S, val_1: T, val_2: T, ) { stack.push(val_1); stack.push(val_2); @@ -21,7 +21,7 @@ fn stack_push_test, +Drop, +Destruct>( } fn stack_peek_test, +Drop, +Copy, +PartialEq, +Destruct>( - ref stack: S, val_1: T, val_2: T + ref stack: S, val_1: T, val_2: T, ) { stack.push(val_1); stack.push(val_2); @@ -34,7 +34,7 @@ fn stack_peek_test, +Drop, +Copy, +PartialEq, + } fn stack_pop_test, +Drop, +Copy, +PartialEq, +Destruct>( - ref stack: S, val_1: T, val_2: T + ref stack: S, val_1: T, val_2: T, ) { stack.push(val_1); stack.push(val_2); @@ -49,9 +49,9 @@ fn stack_pop_test, +Drop, +Copy, +PartialEq, +D } fn stack_push_pop_push_test< - S, T, +StackTrait, +Drop, +Copy, +PartialEq, +Destruct + S, T, +StackTrait, +Drop, +Copy, +PartialEq, +Destruct, >( - ref stack: S, val_1: T, val_2: T, val_3: T + ref stack: S, val_1: T, val_2: T, val_3: T, ) { stack.push(val_1); stack.push(val_2); diff --git a/packages/data_structures/src/tests/vec.cairo b/packages/data_structures/src/tests/vec.cairo index a57b1258..4f5fd38c 100644 --- a/packages/data_structures/src/tests/vec.cairo +++ b/packages/data_structures/src/tests/vec.cairo @@ -7,14 +7,14 @@ fn vec_new_test>(vec: @V) { } fn vec_len_test, +Drop, +Copy, +PartialEq, +Destruct>( - ref vec: V, val_1: T + ref vec: V, val_1: T, ) { vec.push(val_1); assert!(vec.len() == 1, "vec length should be 1"); } fn vec_get_test, +Drop, +Copy, +PartialEq, +Destruct>( - ref vec: V, val_1: T + ref vec: V, val_1: T, ) { vec.push(val_1); assert!(vec.get(0).unwrap() == val_1, "vec get should return val_1"); @@ -22,22 +22,22 @@ fn vec_get_test, +Drop, +Copy, +PartialEq, +Destr } fn vec_at_test, +Drop, +Copy, +PartialEq, +Destruct>( - ref vec: V, val_1: T + ref vec: V, val_1: T, ) { vec.push(val_1); assert!(vec.at(0) == val_1, "vec at should return val_1"); } fn vec_at_out_of_bounds_test< - V, T, +VecTrait, +Drop, +Copy, +PartialEq, +Destruct + V, T, +VecTrait, +Drop, +Copy, +PartialEq, +Destruct, >( - ref vec: V + ref vec: V, ) { vec.at(0); } fn vec_push_test, +Drop, +Copy, +PartialEq, +Destruct>( - ref vec: V, val_1: T + ref vec: V, val_1: T, ) { vec.push(val_1); assert!(vec.len() == 1, "vec length should be 1"); @@ -45,7 +45,7 @@ fn vec_push_test, +Drop, +Copy, +PartialEq, +Dest } fn vec_set_test, +Drop, +Copy, +PartialEq, +Destruct>( - ref vec: V, val_1: T, val_2: T + ref vec: V, val_1: T, val_2: T, ) { vec.push(val_1); vec.set(0, val_2); @@ -54,9 +54,9 @@ fn vec_set_test, +Drop, +Copy, +PartialEq, +Destr } fn vec_set_test_expect_error< - V, T, +VecTrait, +Drop, +Copy, +PartialEq, +Destruct + V, T, +VecTrait, +Drop, +Copy, +PartialEq, +Destruct, >( - ref vec: V, val_1: T, val_2: T + ref vec: V, val_1: T, val_2: T, ) { vec.push(val_1); vec.set(1, val_2); @@ -71,9 +71,9 @@ fn vec_index_trait_test< +Copy, +PartialEq, +Destruct, - +Into + +Into, >( - ref vec: V, val_1: T, val_2: T + ref vec: V, val_1: T, val_2: T, ) { vec.push(val_1); vec.push(val_2); @@ -93,7 +93,7 @@ fn vec_index_trait_out_of_bounds_test< +PartialEq, +Destruct, >( - ref vec: V, val_1: T + ref vec: V, val_1: T, ) { vec[0]; } diff --git a/packages/encoding/Scarb.toml b/packages/encoding/Scarb.toml index 82c57476..c9c1a49e 100644 --- a/packages/encoding/Scarb.toml +++ b/packages/encoding/Scarb.toml @@ -12,6 +12,7 @@ fmt.workspace = true alexandria_math = { path = "../math" } alexandria_numeric = { path = "../numeric" } alexandria_bytes = { path = "../bytes" } +alexandria_data_structures = { path = "../data_structures" } [dev-dependencies] cairo_test.workspace = true \ No newline at end of file diff --git a/packages/encoding/src/base64.cairo b/packages/encoding/src/base64.cairo index f6d6b2d1..efe2437b 100644 --- a/packages/encoding/src/base64.cairo +++ b/packages/encoding/src/base64.cairo @@ -273,7 +273,7 @@ fn get_base64_char_set() -> Array { '6', '7', '8', - '9' + '9', ]; result } diff --git a/packages/encoding/src/reversible.cairo b/packages/encoding/src/reversible.cairo index 1116fc64..8b11fa0c 100644 --- a/packages/encoding/src/reversible.cairo +++ b/packages/encoding/src/reversible.cairo @@ -1,6 +1,6 @@ use core::integer::u512; use core::num::traits::Zero; -use core::ops::{MulAssign, AddAssign}; +use core::ops::{AddAssign, MulAssign}; const SELECT_BYTE: u16 = 0x100; const SELECT_BIT: u8 = 0b10; @@ -33,9 +33,9 @@ pub fn reversing< +Drop, +MulAssign, +Rem, - +AddAssign + +AddAssign, >( - word: T, size: usize, step: T + word: T, size: usize, step: T, ) -> (T, T) { let result = Zero::zero(); reversing_partial_result(word, result, size, step) @@ -50,9 +50,9 @@ pub fn reversing_partial_result< +Drop, +MulAssign, +Rem, - +AddAssign + +AddAssign, >( - mut word: T, mut onto: T, size: usize, step: T + mut word: T, mut onto: T, size: usize, step: T, ) -> (T, T) { let mut i: usize = 0; while i != size { @@ -163,7 +163,7 @@ impl U512Reversible of ReversibleBytes { limb0: limb3_reversed, limb1: limb2_reversed, limb2: limb1_reversed, - limb3: limb0_reversed + limb3: limb0_reversed, } } } @@ -179,7 +179,7 @@ impl U512ReversibleBits of ReversibleBits { limb0: limb3_reversed, limb1: limb2_reversed, limb2: limb1_reversed, - limb3: limb0_reversed + limb3: limb0_reversed, } } } @@ -193,7 +193,7 @@ impl Bytes31Reversible of ReversibleBytes { let u256 { low, high } = (*self).into(); let (c_rev, _) = reversing(word: high, size: 15, step: SELECT_BYTE.into()); let (low_rev, a) = reversing_partial_result( // pushes b_rev yielding low_rev - word: low, onto: c_rev, size: 1, step: SELECT_BYTE.into() + word: low, onto: c_rev, size: 1, step: SELECT_BYTE.into(), ); let (high_rev, _) = reversing(word: a, size: 15, step: SELECT_BYTE.into()); let felt: felt252 = u256 { low: low_rev, high: high_rev }.try_into().unwrap(); @@ -206,7 +206,7 @@ impl Bytes31ReversibleBits of ReversibleBits { let u256 { low, high } = (*self).into(); let (c_rev, _) = reversing(word: high, size: 120, step: SELECT_BIT.into()); let (low_rev, a) = reversing_partial_result( // pushes b_rev yielding low_rev - word: low, onto: c_rev, size: 8, step: SELECT_BIT.into() + word: low, onto: c_rev, size: 8, step: SELECT_BIT.into(), ); let (high_rev, _) = reversing(word: a, size: 120, step: SELECT_BIT.into()); let felt: felt252 = u256 { low: low_rev, high: high_rev }.try_into().unwrap(); @@ -221,7 +221,7 @@ impl ArrayReversibleBytes, +Drop, +ReversibleBytes> of Reversi loop { match span.pop_back() { Option::Some(value) => { result.append(value.reverse_bytes()); }, - Option::None => { break; } + Option::None => { break; }, } }; result @@ -235,7 +235,7 @@ impl ArrayReversibleBits, +Copy, +Drop> of Reversibl loop { match span.pop_back() { Option::Some(value) => { result.append(value.reverse_bits()); }, - Option::None => { break; } + Option::None => { break; }, } }; result diff --git a/packages/encoding/src/rlp.cairo b/packages/encoding/src/rlp.cairo index 88a3adc1..0913e0ca 100644 --- a/packages/encoding/src/rlp.cairo +++ b/packages/encoding/src/rlp.cairo @@ -6,20 +6,20 @@ use alexandria_numeric::integers::UIntBytes; pub enum RLPError { EmptyInput, InputTooShort, - PayloadTooLong + PayloadTooLong, } // Possible RLP types #[derive(Drop, PartialEq)] pub enum RLPType { String, - List + List, } #[derive(Drop, Copy, PartialEq)] pub enum RLPItem { String: Span, - List: Span + List: Span, } #[generate_trait] @@ -107,7 +107,7 @@ pub impl RLPImpl of RLPTrait { } output.extend_from_span(payload); } - } + }, } if input.len() > 0 { @@ -182,14 +182,14 @@ pub impl RLPImpl of RLPTrait { } else { output.append(RLPItem::List(array![].span())); } - } + }, }; let total_item_len = len + offset; if total_item_len < input_len { output .extend_from_span( - Self::decode(input.slice(total_item_len, input_len - total_item_len))? + Self::decode(input.slice(total_item_len, input_len - total_item_len))?, ); } diff --git a/packages/encoding/src/tests/base64_felt_test.cairo b/packages/encoding/src/tests/base64_felt_test.cairo index 72923373..29ea1b73 100644 --- a/packages/encoding/src/tests/base64_felt_test.cairo +++ b/packages/encoding/src/tests/base64_felt_test.cairo @@ -1,6 +1,6 @@ use alexandria_data_structures::array_ext::ArrayTraitExt; use alexandria_encoding::base64::{ - Base64Encoder, Base64UrlEncoder, Base64FeltEncoder, Base64UrlFeltEncoder + Base64Encoder, Base64FeltEncoder, Base64UrlEncoder, Base64UrlFeltEncoder, }; fn bytes_be(val: felt252) -> Array { diff --git a/packages/encoding/src/tests/base64_test.cairo b/packages/encoding/src/tests/base64_test.cairo index 34e16f75..ee1b2ae1 100644 --- a/packages/encoding/src/tests/base64_test.cairo +++ b/packages/encoding/src/tests/base64_test.cairo @@ -1,4 +1,4 @@ -use alexandria_encoding::base64::{Base64Encoder, Base64Decoder, Base64UrlEncoder, Base64UrlDecoder}; +use alexandria_encoding::base64::{Base64Decoder, Base64Encoder, Base64UrlDecoder, Base64UrlEncoder}; #[test] #[available_gas(2000000000)] @@ -69,7 +69,7 @@ fn base64decode_simple_test() { #[available_gas(2000000000)] fn base64decode_hello_world_test() { let input = array![ - 'a', 'G', 'V', 's', 'b', 'G', '8', 'g', 'd', '2', '9', 'y', 'b', 'G', 'Q', '=' + 'a', 'G', 'V', 's', 'b', 'G', '8', 'g', 'd', '2', '9', 'y', 'b', 'G', 'Q', '=', ]; let result = Base64Decoder::decode(input); diff --git a/packages/encoding/src/tests/reversible_test.cairo b/packages/encoding/src/tests/reversible_test.cairo index 0618b4c7..c285cde1 100644 --- a/packages/encoding/src/tests/reversible_test.cairo +++ b/packages/encoding/src/tests/reversible_test.cairo @@ -69,7 +69,7 @@ fn test_reverse_bytes_u512() { limb0: t3.reverse_bytes(), limb1: t2.reverse_bytes(), limb2: t1.reverse_bytes(), - limb3: t0.reverse_bytes() + limb3: t0.reverse_bytes(), }; let rev = t.reverse_bytes(); assert!(rev == t_rev, "not equal"); diff --git a/packages/encoding/src/tests/rlp_test.cairo b/packages/encoding/src/tests/rlp_test.cairo index ab15cb66..a64425a9 100644 --- a/packages/encoding/src/tests/rlp_test.cairo +++ b/packages/encoding/src/tests/rlp_test.cairo @@ -1,4 +1,4 @@ -use alexandria_encoding::rlp::{RLPError, RLPType, RLPTrait, RLPItem}; +use alexandria_encoding::rlp::{RLPError, RLPItem, RLPTrait, RLPType}; #[test] #[available_gas(99999999)] @@ -161,7 +161,7 @@ fn test_rlp_decode_short_string() { 0xa8, 0xda, 0x3b, - 0xf7 + 0xf7, ]; let res = RLPTrait::decode(arr.span()).unwrap(); @@ -204,7 +204,7 @@ fn test_rlp_decode_short_string_input_too_short() { 0xbb, 0xa8, 0xda, - 0x3b + 0x3b, ]; let res = RLPTrait::decode(arr.span()); @@ -278,7 +278,7 @@ fn test_rlp_decode_long_string_with_payload_len_on_1_byte() { 0x86, 0x19, 0x7d, - 0xd9 + 0xd9, ]; let res = RLPTrait::decode(arr.span()).unwrap(); @@ -628,7 +628,7 @@ fn test_rlp_decode_long_string_with_payload_len_on_2_bytes() { 0x76, 0x99, 0x87, - 0x60 + 0x60, ]; let res = RLPTrait::decode(arr.span()).unwrap(); @@ -645,7 +645,7 @@ fn test_rlp_decode_long_string_with_payload_len_on_2_bytes() { #[test] #[available_gas(99999999)] fn test_rlp_decode_long_string_with_payload_len_too_short() { - let arr = array![0xb9, 0x01,]; + let arr = array![0xb9, 0x01]; let res = RLPTrait::decode(arr.span()); @@ -686,7 +686,7 @@ fn test_rlp_decode_short_nested_list() { #[test] #[available_gas(99999999999)] fn test_rlp_decode_multi_list() { - let mut arr = array![0xc6, 0x82, 0x7a, 0x77, 0xc1, 0x04, 0x01,]; + let mut arr = array![0xc6, 0x82, 0x7a, 0x77, 0xc1, 0x04, 0x01]; let res = RLPTrait::decode(arr.span()).unwrap(); @@ -1245,7 +1245,7 @@ fn test_rlp_decode_long_list() { 0xe2, 0xb3, 0x5f, - 0x80 + 0x80, ]; let res = RLPTrait::decode(arr.span()).unwrap(); @@ -1282,9 +1282,9 @@ fn test_rlp_decode_long_list() { 0x73, 0xc1, 0x4a, - 0xf4 + 0xf4, ] - .span() + .span(), ); let expected_1 = RLPItem::String( array![ @@ -1319,9 +1319,9 @@ fn test_rlp_decode_long_list() { 0x02, 0x50, 0x71, - 0xb4 + 0xb4, ] - .span() + .span(), ); let expected_2 = RLPItem::String( array![ @@ -1356,9 +1356,9 @@ fn test_rlp_decode_long_list() { 0xfa, 0x3f, 0xcd, - 0xee + 0xee, ] - .span() + .span(), ); let expected_3 = RLPItem::String( array![ @@ -1393,9 +1393,9 @@ fn test_rlp_decode_long_list() { 0x37, 0xa6, 0x38, - 0x51 + 0x51, ] - .span() + .span(), ); let expected_4 = RLPItem::String( array![ @@ -1430,9 +1430,9 @@ fn test_rlp_decode_long_list() { 0xdb, 0x97, 0x18, - 0xd7 + 0xd7, ] - .span() + .span(), ); let expected_5 = RLPItem::String( array![ @@ -1467,9 +1467,9 @@ fn test_rlp_decode_long_list() { 0xb3, 0xe2, 0x03, - 0x4c + 0x4c, ] - .span() + .span(), ); let expected_6 = RLPItem::String( array![ @@ -1504,9 +1504,9 @@ fn test_rlp_decode_long_list() { 0xbb, 0x13, 0x01, - 0x30 + 0x30, ] - .span() + .span(), ); let expected_7 = RLPItem::String( array![ @@ -1541,9 +1541,9 @@ fn test_rlp_decode_long_list() { 0x5f, 0xf8, 0x52, - 0xae + 0xae, ] - .span() + .span(), ); let expected_8 = RLPItem::String( array![ @@ -1578,9 +1578,9 @@ fn test_rlp_decode_long_list() { 0x53, 0x4a, 0x96, - 0x58 + 0x58, ] - .span() + .span(), ); let expected_9 = RLPItem::String( array![ @@ -1615,9 +1615,9 @@ fn test_rlp_decode_long_list() { 0xad, 0xc4, 0xc1, - 0xa3 + 0xa3, ] - .span() + .span(), ); let expected_10 = RLPItem::String( array![ @@ -1652,9 +1652,9 @@ fn test_rlp_decode_long_list() { 0x66, 0x03, 0x42, - 0xe7 + 0xe7, ] - .span() + .span(), ); let expected_11 = RLPItem::String( array![ @@ -1689,9 +1689,9 @@ fn test_rlp_decode_long_list() { 0xd9, 0x9b, 0x26, - 0x14 + 0x14, ] - .span() + .span(), ); let expected_12 = RLPItem::String( array![ @@ -1726,9 +1726,9 @@ fn test_rlp_decode_long_list() { 0x2f, 0xe6, 0x09, - 0xf3 + 0xf3, ] - .span() + .span(), ); let expected_13 = RLPItem::String( array![ @@ -1763,9 +1763,9 @@ fn test_rlp_decode_long_list() { 0xc9, 0x2a, 0xb1, - 0xfd + 0xfd, ] - .span() + .span(), ); let expected_14 = RLPItem::String( array![ @@ -1800,9 +1800,9 @@ fn test_rlp_decode_long_list() { 0x29, 0xe2, 0x50, - 0x2f + 0x2f, ] - .span() + .span(), ); let expected_15 = RLPItem::String( array![ @@ -1837,9 +1837,9 @@ fn test_rlp_decode_long_list() { 0x8f, 0xe2, 0xb3, - 0x5f + 0x5f, ] - .span() + .span(), ); let expected_16 = RLPItem::String(array![].span()); @@ -1861,7 +1861,7 @@ fn test_rlp_decode_long_list() { expected_13, expected_14, expected_15, - expected_16 + expected_16, ]; let expected_item = RLPItem::List(expected.span()); @@ -1901,7 +1901,7 @@ fn test_rlp_decode_long_list_with_input_too_short() { 0x1f, 0x68, 0xcd, - 0xb4 + 0xb4, ]; let res = RLPTrait::decode(arr.span()); @@ -1913,7 +1913,7 @@ fn test_rlp_decode_long_list_with_input_too_short() { #[test] #[available_gas(99999999999)] fn test_rlp_decode_long_list_with_len_too_short() { - let arr = array![0xf9, 0x02,]; + let arr = array![0xf9, 0x02]; let res = RLPTrait::decode(arr.span()); @@ -2138,9 +2138,9 @@ fn test_rlp_encode_long_list() { 0x73, 0xc1, 0x4a, - 0xf4 + 0xf4, ] - .span() + .span(), ); let string_1 = RLPItem::String( array![ @@ -2175,9 +2175,9 @@ fn test_rlp_encode_long_list() { 0x02, 0x50, 0x71, - 0xb4 + 0xb4, ] - .span() + .span(), ); let string_2 = RLPItem::String( array![ @@ -2212,9 +2212,9 @@ fn test_rlp_encode_long_list() { 0xfa, 0x3f, 0xcd, - 0xee + 0xee, ] - .span() + .span(), ); let string_3 = RLPItem::String( array![ @@ -2249,9 +2249,9 @@ fn test_rlp_encode_long_list() { 0x37, 0xa6, 0x38, - 0x51 + 0x51, ] - .span() + .span(), ); let string_4 = RLPItem::String( array![ @@ -2286,9 +2286,9 @@ fn test_rlp_encode_long_list() { 0xdb, 0x97, 0x18, - 0xd7 + 0xd7, ] - .span() + .span(), ); let string_5 = RLPItem::String( array![ @@ -2323,9 +2323,9 @@ fn test_rlp_encode_long_list() { 0xb3, 0xe2, 0x03, - 0x4c + 0x4c, ] - .span() + .span(), ); let string_6 = RLPItem::String( array![ @@ -2360,9 +2360,9 @@ fn test_rlp_encode_long_list() { 0xbb, 0x13, 0x01, - 0x30 + 0x30, ] - .span() + .span(), ); let string_7 = RLPItem::String( array![ @@ -2397,9 +2397,9 @@ fn test_rlp_encode_long_list() { 0x5f, 0xf8, 0x52, - 0xae + 0xae, ] - .span() + .span(), ); let string_8 = RLPItem::String( array![ @@ -2434,9 +2434,9 @@ fn test_rlp_encode_long_list() { 0x53, 0x4a, 0x96, - 0x58 + 0x58, ] - .span() + .span(), ); let string_9 = RLPItem::String( array![ @@ -2471,9 +2471,9 @@ fn test_rlp_encode_long_list() { 0xad, 0xc4, 0xc1, - 0xa3 + 0xa3, ] - .span() + .span(), ); let string_10 = RLPItem::String( array![ @@ -2508,9 +2508,9 @@ fn test_rlp_encode_long_list() { 0x66, 0x03, 0x42, - 0xe7 + 0xe7, ] - .span() + .span(), ); let string_11 = RLPItem::String( array![ @@ -2545,9 +2545,9 @@ fn test_rlp_encode_long_list() { 0xd9, 0x9b, 0x26, - 0x14 + 0x14, ] - .span() + .span(), ); let string_12 = RLPItem::String( array![ @@ -2582,9 +2582,9 @@ fn test_rlp_encode_long_list() { 0x2f, 0xe6, 0x09, - 0xf3 + 0xf3, ] - .span() + .span(), ); let string_13 = RLPItem::String( array![ @@ -2619,9 +2619,9 @@ fn test_rlp_encode_long_list() { 0xc9, 0x2a, 0xb1, - 0xfd + 0xfd, ] - .span() + .span(), ); let string_14 = RLPItem::String( array![ @@ -2656,9 +2656,9 @@ fn test_rlp_encode_long_list() { 0x29, 0xe2, 0x50, - 0x2f + 0x2f, ] - .span() + .span(), ); let string_15 = RLPItem::String( array![ @@ -2693,9 +2693,9 @@ fn test_rlp_encode_long_list() { 0x8f, 0xe2, 0xb3, - 0x5f + 0x5f, ] - .span() + .span(), ); let string_16 = RLPItem::String(array![].span()); @@ -2717,7 +2717,7 @@ fn test_rlp_encode_long_list() { string_13, string_14, string_15, - string_16 + string_16, ]; let list = RLPItem::List(strings_list.span()); @@ -3256,7 +3256,7 @@ fn test_rlp_encode_long_list() { 0xe2, 0xb3, 0x5f, - 0x80 + 0x80, ]; assert!(res == expected.span(), "Wrong value"); diff --git a/packages/encoding/src/tests/sol_abi.cairo b/packages/encoding/src/tests/sol_abi.cairo index e3f2d278..6b0cbe02 100644 --- a/packages/encoding/src/tests/sol_abi.cairo +++ b/packages/encoding/src/tests/sol_abi.cairo @@ -1,8 +1,8 @@ use alexandria_bytes::utils::{BytesDebug, BytesDisplay}; use alexandria_bytes::{Bytes, BytesTrait}; use alexandria_encoding::sol_abi::{ - encode::SolAbiEncodeTrait, encode_as::SolAbiEncodeAsTrait, encode::SolAbiEncodeSelectorTrait, - decode::SolAbiDecodeTrait, sol_bytes::SolBytesTrait + decode::SolAbiDecodeTrait, encode::SolAbiEncodeSelectorTrait, encode::SolAbiEncodeTrait, + encode_as::SolAbiEncodeAsTrait, sol_bytes::SolBytesTrait, }; use core::bytes_31; use core::to_byte_array::FormatAsByteArray; @@ -62,8 +62,8 @@ fn encode_test() { 0x049d36570d4e46f48e99674bd3fcc846, 0x44ddd6b96f7c741b1562b82f9e004dc7, 0x000000000000000000000000DeaDbeef, - 0xdEAdbeefdEadbEEFdeadbeEFdEaDbeeF - ] + 0xdEAdbeefdEadbEEFdeadbeEFdEaDbeeF, + ], ); let mut encoded: Bytes = BytesTrait::new_empty(); let address: ContractAddress = @@ -108,8 +108,8 @@ fn encode_packed_test() { 0x46f48e99674bd3fcc84644ddd6b96f7c, 0x741b1562b82f9e004dc7DeaDbeefdEAd, 0xbeefdEadbEEFdeadbeEFdEaDbeeFa0aa, - 0xabacad00000000000000000000000000 - ] + 0xabacad00000000000000000000000000, + ], ); let mut encoded: Bytes = BytesTrait::new_empty(); let address: ContractAddress = @@ -140,7 +140,7 @@ fn encode_packed_test() { #[test] fn encoded_as_test() { let expected: Bytes = BytesTrait::new( - 29, array![0x10111200000000000000000000000000, 0x0000000000aabbcc0000a0b1c2000000] + 29, array![0x10111200000000000000000000000000, 0x0000000000aabbcc0000a0b1c2000000], ); let mut encoded: Bytes = BytesTrait::new_empty(); encoded = encoded @@ -175,8 +175,8 @@ fn selector_test() { 0xDeaDbeefdEAdbeefdEadbEEFdeadbeEF, 0xdEaDbeeF000000000000000000000000, 0x00000000000000000000000000000000, - 0x00002710000000000000000000000000 - ] + 0x00002710000000000000000000000000, + ], ); let mut encoded: Bytes = BytesTrait::new_empty(); let eth_address: EthAddress = 0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF_u256.into(); @@ -212,8 +212,8 @@ fn decode_test() { 0x00a0a1a2a30000000000000000000000, 0x00000000000000000000000000001234, 0x000000000000000000000000Deadbeef, - 0xDeaDbeefdEAdbeefdEadbEEFdeadbeEF - ] + 0xDeaDbeefdEAdbeefdEadbEEFdeadbeEF, + ], ); let mut offset = 0; @@ -237,7 +237,7 @@ fn decode_test() { assert_eq!( decoded, 0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcd_u256, - "Decode uint256 failed" + "Decode uint256 failed", ); assert_eq!(offset, 160); @@ -251,7 +251,7 @@ fn decode_test() { let decoded: ByteArray = encoded.decode(ref offset); let expected: ByteArray = SolBytesTrait::bytes32( - 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3000000000000000000000000_u256 + 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3000000000000000000000000_u256, ) .into(); assert_eq!(decoded, expected); @@ -293,7 +293,7 @@ fn sol_bytes_test() { // Test bytesX with integer types needing `into` calls let expectedVal21: Bytes = SolBytesTrait::bytes21( - 0x0000a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2_u256 + 0x0000a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2_u256, ); let bytesVal18: Bytes = SolBytesTrait::bytes18(0xa0a1a2a3a4a5a6a7a8a9aaabacadaeaf_u128); let bytesVal3: Bytes = SolBytesTrait::bytes3(0xb0b1b2); @@ -304,13 +304,13 @@ fn sol_bytes_test() { // Test bytesX with Bytes types let expectedVal25: Bytes = SolBytesTrait::bytes25( - 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8_u256 + 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8_u256, ); let bytesVal6: Bytes = SolBytesTrait::bytes6( - BytesTrait::new(16, array![0xa0a1a2a3a4a500000000000000000000]) + BytesTrait::new(16, array![0xa0a1a2a3a4a500000000000000000000]), ); let bytesArray: ByteArray = SolBytesTrait::bytes32( - 0xa6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b800000000000000000000000000_u256 + 0xa6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b800000000000000000000000000_u256, ) .into(); let bytesVal19: Bytes = SolBytesTrait::bytes19(bytesArray); diff --git a/packages/linalg/src/dot.cairo b/packages/linalg/src/dot.cairo index 7257f689..e3fd14f3 100644 --- a/packages/linalg/src/dot.cairo +++ b/packages/linalg/src/dot.cairo @@ -8,8 +8,8 @@ use core::ops::AddAssign; /// * `ys` - The second sequence of len L. /// # Returns /// * `sum` - The dot product. -pub fn dot, +AddAssign, +Zero, +Copy, +Drop,>( - mut xs: Span, mut ys: Span +pub fn dot, +AddAssign, +Zero, +Copy, +Drop>( + mut xs: Span, mut ys: Span, ) -> T { // [Check] Inputs assert(xs.len() == ys.len(), 'Arrays must have the same len'); diff --git a/packages/linalg/src/kron.cairo b/packages/linalg/src/kron.cairo index 89aae78e..0943319d 100644 --- a/packages/linalg/src/kron.cairo +++ b/packages/linalg/src/kron.cairo @@ -11,8 +11,8 @@ pub enum KronError { /// * `ys` - The second sequence of len L. /// # Returns /// * `Result, KronError>` - The Kronecker product. -pub fn kron, +Copy, +Drop,>( - mut xs: Span, mut ys: Span +pub fn kron, +Copy, +Drop>( + mut xs: Span, mut ys: Span, ) -> Result, KronError> { // [Check] Inputs if xs.len() != ys.len() { diff --git a/packages/linalg/src/norm.cairo b/packages/linalg/src/norm.cairo index dee80fff..db2799cd 100644 --- a/packages/linalg/src/norm.cairo +++ b/packages/linalg/src/norm.cairo @@ -11,7 +11,7 @@ use core::num::traits::Zero; /// # Returns /// * `u128` - The norm for the array. pub fn norm, +Zero, +Copy, +Drop>( - mut xs: Span, ord: u128, iter: usize + mut xs: Span, ord: u128, iter: usize, ) -> u128 { let mut norm: u128 = 0; for x_value in xs { diff --git a/packages/linalg/src/tests/kron_test.cairo b/packages/linalg/src/tests/kron_test.cairo index 26be4b66..629c7675 100644 --- a/packages/linalg/src/tests/kron_test.cairo +++ b/packages/linalg/src/tests/kron_test.cairo @@ -1,4 +1,4 @@ -use alexandria_linalg::kron::{kron, KronError}; +use alexandria_linalg::kron::{KronError, kron}; #[test] #[available_gas(2000000)] diff --git a/packages/macros/Cargo.lock b/packages/macros/Cargo.lock index caae0b80..dec7619d 100644 --- a/packages/macros/Cargo.lock +++ b/packages/macros/Cargo.lock @@ -19,9 +19,11 @@ name = "alexandria_macros" version = "0.1.0" dependencies = [ "bigdecimal", + "cairo-lang-filesystem", "cairo-lang-macro", "cairo-lang-parser", "cairo-lang-syntax", + "cairo-lang-utils", ] [[package]] @@ -38,9 +40,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bigdecimal" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d712318a27c7150326677b321a5fa91b55f6d9034ffd67f20319e147d40cee" +checksum = "7f31f3af01c5c65a07985c804d3366560e6fa7883d640a122819b14ec327482c" dependencies = [ "autocfg", "libm", @@ -51,24 +53,24 @@ dependencies = [ [[package]] name = "bitflags" -version = "1.3.2" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "cairo-lang-debug" -version = "2.7.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac7332f2b041ca28b24b0311a0b4a35f426bb52836a2d268a8374ea262e9e6b" +checksum = "d7763505dcfe15f36899074c27185bf7e3494875f63fd06350c6e3ed8d1f91d5" dependencies = [ "cairo-lang-utils", ] [[package]] name = "cairo-lang-diagnostics" -version = "2.7.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c29625349297ad791942377763f5b04c779ea694f436488dc6ad194720b89487" +checksum = "761d20ca9c3a3eb7025b2488aa6e0e5dc23c5d551dd95e83a989b5e87687f523" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", @@ -78,24 +80,25 @@ dependencies = [ [[package]] name = "cairo-lang-filesystem" -version = "2.7.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "651012f2956bea884c7a3ab9df21dc76112d7edd3f403b37ca5be62fc3f41b09" +checksum = "d9dc486c554e2df3be8e84c47e30fe55b59d2349b680fbe992bfba801ef93ff5" dependencies = [ "cairo-lang-debug", "cairo-lang-utils", "path-clean", - "salsa", + "rust-analyzer-salsa", "semver", "serde", "smol_str", + "toml", ] [[package]] name = "cairo-lang-macro" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26c60c78d20f833d8229fa6442de629d73d01e6a238714afdf9c7269d56b4bb7" +checksum = "dda77fe9404e438edaa80c9acaf0d72260aa883ba433812d0a745f5a72f31881" dependencies = [ "cairo-lang-macro-attributes", "cairo-lang-macro-stable", @@ -110,7 +113,7 @@ checksum = "e32e958decd95ae122ee64daa26721da2f76e83231047f947fd9cdc5d3c90cc6" dependencies = [ "quote", "scarb-stable-hash", - "syn 2.0.74", + "syn", ] [[package]] @@ -121,9 +124,9 @@ checksum = "c49906d6b1c215e5814be7c5c65ecf2328898b335bee8c2409ec07cfb5530daf" [[package]] name = "cairo-lang-parser" -version = "2.7.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f262ad5f1110ff70c93deb81cce024cf160f4a4518762e7deb2047fe73846789" +checksum = "37e2b488f659432c8b866bf540e54ab3696a24ac0f366faac33b860c5313e78c" dependencies = [ "cairo-lang-diagnostics", "cairo-lang-filesystem", @@ -134,32 +137,39 @@ dependencies = [ "itertools", "num-bigint", "num-traits", - "salsa", + "rust-analyzer-salsa", "smol_str", "unescaper", ] +[[package]] +name = "cairo-lang-primitive-token" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "123ac0ecadf31bacae77436d72b88fa9caef2b8e92c89ce63a125ae911a12fae" + [[package]] name = "cairo-lang-syntax" -version = "2.7.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2a376f88d815b63505be54a6afa93d75b67cfd65835922ec648cfcbb0a5e4b4" +checksum = "0a38f1431f22a9487b9b0dd7aef098c9605fe6b8677e0f620547aa69195f7fb5" dependencies = [ "cairo-lang-debug", "cairo-lang-filesystem", + "cairo-lang-primitive-token", "cairo-lang-utils", "num-bigint", "num-traits", - "salsa", + "rust-analyzer-salsa", "smol_str", "unescaper", ] [[package]] name = "cairo-lang-syntax-codegen" -version = "2.7.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01f276bc28f6302fc63032046a12b60d18498906e65f646acb963244eed97f7c" +checksum = "fd7990586c9bb37eaa875ffeb218bdecf96f87881d03263ebf84fcd46514ca9f" dependencies = [ "genco", "xshell", @@ -167,12 +177,12 @@ dependencies = [ [[package]] name = "cairo-lang-utils" -version = "2.7.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55a394e545f1500bea093d01be40895d3234faaa24d9585d08a509c514cabd88" +checksum = "ff5d7609abc99c15de7d7f90b8441b27e2bd52e930a3014c95a9b620e5d3211a" dependencies = [ - "hashbrown 0.14.5", - "indexmap 2.4.0", + "hashbrown", + "indexmap", "itertools", "num-bigint", "num-traits", @@ -195,12 +205,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "crossbeam-utils" -version = "0.8.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" - [[package]] name = "data-encoding" version = "2.6.0" @@ -238,15 +242,9 @@ checksum = "553630feadf7b76442b0849fd25fdf89b860d933623aec9693fed19af0400c78" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn", ] -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - [[package]] name = "hashbrown" version = "0.14.5" @@ -260,22 +258,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - -[[package]] -name = "indexmap" -version = "1.9.3" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" -dependencies = [ - "autocfg", - "hashbrown 0.12.3", -] +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "indexmap" @@ -284,19 +269,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown", "serde", ] -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - [[package]] name = "itertools" version = "0.12.1" @@ -341,7 +317,7 @@ checksum = "cb26336e6dc7cc76e7927d2c9e7e3bb376d7af65a6f56a0b16c47d18a9b1abc5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn", ] [[package]] @@ -355,10 +331,10 @@ dependencies = [ ] [[package]] -name = "log" -version = "0.4.22" +name = "memchr" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "num-bigint" @@ -403,27 +379,25 @@ checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" [[package]] name = "parking_lot" -version = "0.11.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ - "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.8.6" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", - "instant", "libc", "redox_syscall", "smallvec", - "winapi", + "windows-targets 0.52.6", ] [[package]] @@ -432,6 +406,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17359afc20d7ab31fdb42bb844c8b3bb1dabd7dcf7e68428492da7f16966fcef" +[[package]] +name = "pin-project-lite" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -452,9 +432,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "03a862b389f93e68874fbf580b9de08dd02facb9a788ebadaf4a3fd33cf58834" dependencies = [ "bitflags", ] @@ -466,40 +446,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2" [[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "salsa" -version = "0.16.1" +name = "rust-analyzer-salsa" +version = "0.17.0-pre.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b84d9f96071f3f3be0dc818eae3327625d8ebc95b58da37d6850724f31d3403" +checksum = "719825638c59fd26a55412a24561c7c5bcf54364c88b9a7a04ba08a6eafaba8d" dependencies = [ - "crossbeam-utils", - "indexmap 1.9.3", + "indexmap", "lock_api", - "log", "oorandom", "parking_lot", + "rust-analyzer-salsa-macros", "rustc-hash", - "salsa-macros", "smallvec", + "tracing", + "triomphe", ] [[package]] -name = "salsa-macros" -version = "0.16.0" +name = "rust-analyzer-salsa-macros" +version = "0.17.0-pre.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3904a4ba0a9d0211816177fd34b04c7095443f8cdacd11175064fe541c8fe2" +checksum = "4d96498e9684848c6676c399032ebc37c52da95ecbefa83d71ccc53b9f8a4a8e" dependencies = [ "heck", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "scarb-stable-hash" version = "1.0.0" @@ -542,7 +522,16 @@ checksum = "6aea2634c86b0e8ef2cfdc0c340baede54ec27b1e46febd7f80dffb2aa44a00e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn", +] + +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", ] [[package]] @@ -561,15 +550,10 @@ dependencies = [ ] [[package]] -name = "syn" -version = "1.0.109" +name = "stable_deref_trait" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "syn" @@ -599,57 +583,104 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn", ] [[package]] -name = "unescaper" -version = "0.1.5" +name = "toml" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c878a167baa8afd137494101a688ef8c67125089ff2249284bd2b5f9bfedb815" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" dependencies = [ - "thiserror", + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", ] [[package]] -name = "unicode-ident" -version = "1.0.12" +name = "toml_datetime" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] [[package]] -name = "unicode-segmentation" -version = "1.11.0" +name = "toml_edit" +version = "0.22.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] [[package]] -name = "version_check" -version = "0.9.5" +name = "tracing" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "triomphe" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef8f7726da4807b58ea5c96fdc122f80702030edc33b35aff9190a51148ccc85" +dependencies = [ + "serde", + "stable_deref_trait", +] [[package]] -name = "winapi" -version = "0.3.9" +name = "unescaper" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "c878a167baa8afd137494101a688ef8c67125089ff2249284bd2b5f9bfedb815" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "thiserror", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "version_check" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "windows-sys" @@ -657,7 +688,7 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets", + "windows-targets 0.48.5", ] [[package]] @@ -666,13 +697,29 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -681,42 +728,99 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + [[package]] name = "xshell" version = "0.2.6" @@ -755,5 +859,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.74", + "syn", ] diff --git a/packages/macros/Cargo.toml b/packages/macros/Cargo.toml index b0752034..b2c206e6 100644 --- a/packages/macros/Cargo.toml +++ b/packages/macros/Cargo.toml @@ -7,7 +7,9 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -bigdecimal = "0.4.5" -cairo-lang-macro = "0.1" -cairo-lang-parser = "2.7.0" -cairo-lang-syntax = "2.7.0" +bigdecimal = "0.4.7" +cairo-lang-macro = "0.1.1" +cairo-lang-parser = "2.9.2" +cairo-lang-syntax = "2.9.2" +cairo-lang-filesystem = "2.9.2" +cairo-lang-utils = "2.9.2" diff --git a/packages/macros/src/pow.rs b/packages/macros/src/pow.rs index 5ad557c5..76058573 100644 --- a/packages/macros/src/pow.rs +++ b/packages/macros/src/pow.rs @@ -1,7 +1,12 @@ +use bigdecimal::num_bigint::BigInt; use bigdecimal::{num_traits::pow, BigDecimal}; + +use cairo_lang_filesystem::ids::{FileKind, FileLongId, VirtualFile}; use cairo_lang_macro::{inline_macro, Diagnostic, ProcMacroResult, TokenStream}; +use cairo_lang_parser::db::ParserGroup; use cairo_lang_parser::utils::SimpleParserDatabase; -use cairo_lang_syntax::node::kind::SyntaxKind::Arg; +use cairo_lang_syntax::node::ast::{ArgClause, Expr, ExprInlineMacro, WrappedArgList}; +use cairo_lang_utils::{Intern, Upcast}; /// Compile-time power function. /// @@ -14,41 +19,82 @@ use cairo_lang_syntax::node::kind::SyntaxKind::Arg; #[inline_macro] pub fn pow(token_stream: TokenStream) -> ProcMacroResult { let db = SimpleParserDatabase::default(); - let (parsed, _diag) = db.parse_virtual_with_diagnostics(token_stream); - - let macro_args: Vec = parsed - .descendants(&db) - .filter_map(|node| { - if let Arg = node.kind(&db) { - Some(node.get_text(&db)) - } else { - None - } - }) - .collect(); + // Get the ExprInlineMacro object so we can use the helper functions. + let mac = parse_inline_macro(token_stream, &db); + // Get the arguments of the macro. This macro expects a tuple as argument so we get the WrappedArgList::ParenthesizedArgList + let macro_args = if let WrappedArgList::ParenthesizedArgList(args) = mac.arguments(db.upcast()) + { + args.arguments(db.upcast()).elements(db.upcast()) + } else { + vec![] + }; if macro_args.len() != 2 { return ProcMacroResult::new(TokenStream::empty()) .with_diagnostics(Diagnostic::error("Invalid number of arguments").into()); } - - let base: BigDecimal = match macro_args[0].parse() { - Ok(val) => val, - Err(_) => { + let base = match get_arg_value(db.upcast(), ¯o_args[0].arg_clause(db.upcast())) { + Some(val) => val, + None => { return ProcMacroResult::new(TokenStream::empty()) - .with_diagnostics(Diagnostic::error("Invalid base value").into()); + .with_diagnostics(Diagnostic::error("Invalid base value").into()) } - }; + } + .into(); - let exp: usize = match macro_args[1].parse() { - Ok(val) => val, - Err(_) => { + let exp = match get_arg_value(db.upcast(), ¯o_args[1].arg_clause(db.upcast())) { + Some(val) => val, + None => { return ProcMacroResult::new(TokenStream::empty()) - .with_diagnostics(Diagnostic::error("Invalid exponent value").into()); + .with_diagnostics(Diagnostic::error("Invalid exponent value").into()) } + } + .try_into(); + let exp = if let Ok(exponent) = exp { + exponent + } else { + return ProcMacroResult::new(TokenStream::empty()) + .with_diagnostics(Diagnostic::error("Invalid exponent value").into()); }; let result: BigDecimal = pow(base, exp); ProcMacroResult::new(TokenStream::new(result.to_string())) } + +/// Return an [`ExprInlineMacro`] from the text received. The expected text is the macro arguments. +/// For example the initial macro text was `pow!(10, 3)`, the text in the token stream is only `(10, 3)` +fn parse_inline_macro(token_stream: impl ToString, db: &SimpleParserDatabase) -> ExprInlineMacro { + // Create a virtual file that will be parsed. + let file = FileLongId::Virtual(VirtualFile { + parent: None, + name: "parser_input".into(), + content: format!("pow!{}", token_stream.to_string()).into(), // easiest workaround after change + code_mappings: [].into(), + kind: FileKind::Expr, // this part is different than db.parse_virtual + }) + .intern(db); + + // Could fail if there was a parsing error but it shouldn't happen as the file has already + // been parsed once to reach this macro. + let node = db.file_expr_syntax(file).unwrap(); + + let Expr::InlineMacro(inline_macro) = node else { + panic!() // should not happen + }; + + inline_macro +} + +/// Returns the value of a literal argument. +fn get_arg_value(db: &SimpleParserDatabase, arg_clause: &ArgClause) -> Option { + let base_expr = match arg_clause { + ArgClause::Unnamed(arg_clause) => arg_clause.value(db.upcast()), + _ => return None, + }; + if let Expr::Literal(base_lit) = base_expr { + base_lit.numeric_value(db.upcast()) + } else { + None + } +} diff --git a/packages/macros_tests/Scarb.toml b/packages/macros_tests/Scarb.toml index eb4d4880..aa54aaeb 100644 --- a/packages/macros_tests/Scarb.toml +++ b/packages/macros_tests/Scarb.toml @@ -8,4 +8,4 @@ edition = "2024_07" alexandria_macros = { path = "../macros" } [dev-dependencies] -cairo_test = "2.7.0" +cairo_test = "2.9.2" diff --git a/packages/macros_tests/src/test_num_traits.cairo b/packages/macros_tests/src/test_num_traits.cairo index 6e9492dd..1f57ba4c 100644 --- a/packages/macros_tests/src/test_num_traits.cairo +++ b/packages/macros_tests/src/test_num_traits.cairo @@ -2,7 +2,7 @@ #[derive(Add, AddAssign, Sub, SubAssign, Mul, MulAssign, Div, DivAssign, Debug, Drop, PartialEq)] struct B { pub a: u8, - b: u16 + b: u16, } // a generic struct @@ -10,7 +10,7 @@ struct B { struct G { x: T1, pub y: T2, - z: T2 + z: T2, } @@ -19,7 +19,7 @@ struct G { struct C { pub g: G, i: u64, - j: u32 + j: u32, } #[test] diff --git a/packages/macros_tests/src/test_pow.cairo b/packages/macros_tests/src/test_pow.cairo index 1ea1b6fe..01593d25 100644 --- a/packages/macros_tests/src/test_pow.cairo +++ b/packages/macros_tests/src/test_pow.cairo @@ -7,6 +7,6 @@ fn test_pow_macro() { assert_eq!(pow!(20, 30), 1073741824000000000000000000000000000000_felt252); assert_eq!( pow!(2, 255), - 57896044618658097711785492504343953926634992332820282019728792003956564819968_u256 + 57896044618658097711785492504343953926634992332820282019728792003956564819968_u256, ); } diff --git a/packages/macros_tests/src/test_zero_trait.cairo b/packages/macros_tests/src/test_zero_trait.cairo index a2b7b087..72351b27 100644 --- a/packages/macros_tests/src/test_zero_trait.cairo +++ b/packages/macros_tests/src/test_zero_trait.cairo @@ -4,7 +4,7 @@ use core::num::traits::Zero; #[derive(Zero, Debug, Drop, PartialEq)] struct B { pub a: u8, - b: u16 + b: u16, } // a generic struct @@ -12,7 +12,7 @@ struct B { struct G { x: T1, pub y: T2, - z: T2 + z: T2, } // a complex struct @@ -20,7 +20,7 @@ struct G { struct C { pub g: G, i: u64, - j: u32 + j: u32, } diff --git a/packages/math/src/bip340.cairo b/packages/math/src/bip340.cairo index a145edc5..39b669f1 100644 --- a/packages/math/src/bip340.cairo +++ b/packages/math/src/bip340.cairo @@ -2,7 +2,7 @@ use core::sha256::compute_sha256_byte_array; //Available in Cairo ^2.7.0. use core::starknet::SyscallResultTrait; -use starknet::{secp256k1::{Secp256k1Point}, secp256_trait::{Secp256Trait, Secp256PointTrait}}; +use starknet::{secp256_trait::{Secp256PointTrait, Secp256Trait}, secp256k1::{Secp256k1Point}}; const TWO_POW_32: u128 = 0x100000000; const TWO_POW_64: u128 = 0x10000000000000000; @@ -85,7 +85,7 @@ pub fn verify(px: u256, rx: u256, s: u256, m: ByteArray) -> bool { match Secp256Trait::::secp256_ec_get_point_from_x_syscall(px, false) .unwrap_syscall() { Option::Some(P) => P, - Option::None => { return false; } + Option::None => { return false; }, }; // e = int(hashBIP0340/challenge(bytes(rx) || bytes(px) || m)) mod n. diff --git a/packages/math/src/bitmap.cairo b/packages/math/src/bitmap.cairo index 505b664b..7260231b 100644 --- a/packages/math/src/bitmap.cairo +++ b/packages/math/src/bitmap.cairo @@ -21,7 +21,7 @@ pub impl Bitmap< +Into, +TryInto, +Drop, - +Copy + +Copy, > of BitmapTrait { /// The bit value at the provided index of a number. /// # Arguments @@ -196,7 +196,7 @@ pub impl Bitmap< let nrsb = Self::nearest_right_significant_bit(x, i); match (nlsb, nrsb) { ( - Option::Some(lhs), Option::Some(rhs) + Option::Some(lhs), Option::Some(rhs), ) => { if i - rhs < lhs - i || (priority && (i - rhs == lhs - i)) { Option::Some(rhs) diff --git a/packages/math/src/const_pow.cairo b/packages/math/src/const_pow.cairo index 9f76b3db..b96c5107 100644 --- a/packages/math/src/const_pow.cairo +++ b/packages/math/src/const_pow.cairo @@ -10,7 +10,7 @@ pub fn pow2_u256(exponent: u32) -> u256 { if exponent < 128 { pow2(exponent).into() } else { - u256 { low: 0, high: pow2(exponent - 128), } + u256 { low: 0, high: pow2(exponent - 128) } } } @@ -24,134 +24,39 @@ pub fn pow2_u256(exponent: u32) -> u256 { /// * If `exponent` is greater than 127 (out of the supported range) pub fn pow2(exponent: u32) -> u128 { let hardcoded_results: [u128; 128] = [ - 0x1, - 0x2, - 0x4, - 0x8, - 0x10, - 0x20, - 0x40, - 0x80, - 0x100, - 0x200, - 0x400, - 0x800, - 0x1000, - 0x2000, - 0x4000, - 0x8000, - 0x10000, - 0x20000, - 0x40000, - 0x80000, - 0x100000, - 0x200000, - 0x400000, - 0x800000, - 0x1000000, - 0x2000000, - 0x4000000, - 0x8000000, - 0x10000000, - 0x20000000, - 0x40000000, - 0x80000000, - 0x100000000, - 0x200000000, - 0x400000000, - 0x800000000, - 0x1000000000, - 0x2000000000, - 0x4000000000, - 0x8000000000, - 0x10000000000, - 0x20000000000, - 0x40000000000, - 0x80000000000, - 0x100000000000, - 0x200000000000, - 0x400000000000, - 0x800000000000, - 0x1000000000000, - 0x2000000000000, - 0x4000000000000, - 0x8000000000000, - 0x10000000000000, - 0x20000000000000, - 0x40000000000000, - 0x80000000000000, - 0x100000000000000, - 0x200000000000000, - 0x400000000000000, - 0x800000000000000, - 0x1000000000000000, - 0x2000000000000000, - 0x4000000000000000, - 0x8000000000000000, - 0x10000000000000000, - 0x20000000000000000, - 0x40000000000000000, - 0x80000000000000000, - 0x100000000000000000, - 0x200000000000000000, - 0x400000000000000000, - 0x800000000000000000, - 0x1000000000000000000, - 0x2000000000000000000, - 0x4000000000000000000, - 0x8000000000000000000, - 0x10000000000000000000, - 0x20000000000000000000, - 0x40000000000000000000, - 0x80000000000000000000, - 0x100000000000000000000, - 0x200000000000000000000, - 0x400000000000000000000, - 0x800000000000000000000, - 0x1000000000000000000000, - 0x2000000000000000000000, - 0x4000000000000000000000, - 0x8000000000000000000000, - 0x10000000000000000000000, - 0x20000000000000000000000, - 0x40000000000000000000000, - 0x80000000000000000000000, - 0x100000000000000000000000, - 0x200000000000000000000000, - 0x400000000000000000000000, - 0x800000000000000000000000, - 0x1000000000000000000000000, - 0x2000000000000000000000000, - 0x4000000000000000000000000, - 0x8000000000000000000000000, - 0x10000000000000000000000000, - 0x20000000000000000000000000, - 0x40000000000000000000000000, - 0x80000000000000000000000000, - 0x100000000000000000000000000, - 0x200000000000000000000000000, - 0x400000000000000000000000000, - 0x800000000000000000000000000, - 0x1000000000000000000000000000, - 0x2000000000000000000000000000, - 0x4000000000000000000000000000, - 0x8000000000000000000000000000, - 0x10000000000000000000000000000, - 0x20000000000000000000000000000, - 0x40000000000000000000000000000, - 0x80000000000000000000000000000, - 0x100000000000000000000000000000, - 0x200000000000000000000000000000, - 0x400000000000000000000000000000, - 0x800000000000000000000000000000, - 0x1000000000000000000000000000000, - 0x2000000000000000000000000000000, - 0x4000000000000000000000000000000, - 0x8000000000000000000000000000000, - 0x10000000000000000000000000000000, - 0x20000000000000000000000000000000, - 0x40000000000000000000000000000000, - 0x80000000000000000000000000000000 + 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, + 0x4000, 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, 0x800000, + 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x100000000, 0x200000000, 0x400000000, 0x800000000, 0x1000000000, 0x2000000000, + 0x4000000000, 0x8000000000, 0x10000000000, 0x20000000000, 0x40000000000, 0x80000000000, + 0x100000000000, 0x200000000000, 0x400000000000, 0x800000000000, 0x1000000000000, + 0x2000000000000, 0x4000000000000, 0x8000000000000, 0x10000000000000, 0x20000000000000, + 0x40000000000000, 0x80000000000000, 0x100000000000000, 0x200000000000000, 0x400000000000000, + 0x800000000000000, 0x1000000000000000, 0x2000000000000000, 0x4000000000000000, + 0x8000000000000000, 0x10000000000000000, 0x20000000000000000, 0x40000000000000000, + 0x80000000000000000, 0x100000000000000000, 0x200000000000000000, 0x400000000000000000, + 0x800000000000000000, 0x1000000000000000000, 0x2000000000000000000, 0x4000000000000000000, + 0x8000000000000000000, 0x10000000000000000000, 0x20000000000000000000, + 0x40000000000000000000, 0x80000000000000000000, 0x100000000000000000000, + 0x200000000000000000000, 0x400000000000000000000, 0x800000000000000000000, + 0x1000000000000000000000, 0x2000000000000000000000, 0x4000000000000000000000, + 0x8000000000000000000000, 0x10000000000000000000000, 0x20000000000000000000000, + 0x40000000000000000000000, 0x80000000000000000000000, 0x100000000000000000000000, + 0x200000000000000000000000, 0x400000000000000000000000, 0x800000000000000000000000, + 0x1000000000000000000000000, 0x2000000000000000000000000, 0x4000000000000000000000000, + 0x8000000000000000000000000, 0x10000000000000000000000000, 0x20000000000000000000000000, + 0x40000000000000000000000000, 0x80000000000000000000000000, 0x100000000000000000000000000, + 0x200000000000000000000000000, 0x400000000000000000000000000, 0x800000000000000000000000000, + 0x1000000000000000000000000000, 0x2000000000000000000000000000, + 0x4000000000000000000000000000, 0x8000000000000000000000000000, + 0x10000000000000000000000000000, 0x20000000000000000000000000000, + 0x40000000000000000000000000000, 0x80000000000000000000000000000, + 0x100000000000000000000000000000, 0x200000000000000000000000000000, + 0x400000000000000000000000000000, 0x800000000000000000000000000000, + 0x1000000000000000000000000000000, 0x2000000000000000000000000000000, + 0x4000000000000000000000000000000, 0x8000000000000000000000000000000, + 0x10000000000000000000000000000000, 0x20000000000000000000000000000000, + 0x40000000000000000000000000000000, 0x80000000000000000000000000000000, ]; *hardcoded_results.span()[exponent] } @@ -166,174 +71,59 @@ pub fn pow2(exponent: u32) -> u128 { /// * If `exponent` is greater than 251 (out of the supported range) pub fn pow2_felt252(exponent: u32) -> felt252 { let hardcoded_results: [felt252; 251] = [ - 0x1, - 0x2, - 0x4, - 0x8, - 0x10, - 0x20, - 0x40, - 0x80, - 0x100, - 0x200, - 0x400, - 0x800, - 0x1000, - 0x2000, - 0x4000, - 0x8000, - 0x10000, - 0x20000, - 0x40000, - 0x80000, - 0x100000, - 0x200000, - 0x400000, - 0x800000, - 0x1000000, - 0x2000000, - 0x4000000, - 0x8000000, - 0x10000000, - 0x20000000, - 0x40000000, - 0x80000000, - 0x100000000, - 0x200000000, - 0x400000000, - 0x800000000, - 0x1000000000, - 0x2000000000, - 0x4000000000, - 0x8000000000, - 0x10000000000, - 0x20000000000, - 0x40000000000, - 0x80000000000, - 0x100000000000, - 0x200000000000, - 0x400000000000, - 0x800000000000, - 0x1000000000000, - 0x2000000000000, - 0x4000000000000, - 0x8000000000000, - 0x10000000000000, - 0x20000000000000, - 0x40000000000000, - 0x80000000000000, - 0x100000000000000, - 0x200000000000000, - 0x400000000000000, - 0x800000000000000, - 0x1000000000000000, - 0x2000000000000000, - 0x4000000000000000, - 0x8000000000000000, - 0x10000000000000000, - 0x20000000000000000, - 0x40000000000000000, - 0x80000000000000000, - 0x100000000000000000, - 0x200000000000000000, - 0x400000000000000000, - 0x800000000000000000, - 0x1000000000000000000, - 0x2000000000000000000, - 0x4000000000000000000, - 0x8000000000000000000, - 0x10000000000000000000, - 0x20000000000000000000, - 0x40000000000000000000, - 0x80000000000000000000, - 0x100000000000000000000, - 0x200000000000000000000, - 0x400000000000000000000, - 0x800000000000000000000, - 0x1000000000000000000000, - 0x2000000000000000000000, - 0x4000000000000000000000, - 0x8000000000000000000000, - 0x10000000000000000000000, - 0x20000000000000000000000, - 0x40000000000000000000000, - 0x80000000000000000000000, - 0x100000000000000000000000, - 0x200000000000000000000000, - 0x400000000000000000000000, - 0x800000000000000000000000, - 0x1000000000000000000000000, - 0x2000000000000000000000000, - 0x4000000000000000000000000, - 0x8000000000000000000000000, - 0x10000000000000000000000000, - 0x20000000000000000000000000, - 0x40000000000000000000000000, - 0x80000000000000000000000000, - 0x100000000000000000000000000, - 0x200000000000000000000000000, - 0x400000000000000000000000000, - 0x800000000000000000000000000, - 0x1000000000000000000000000000, - 0x2000000000000000000000000000, - 0x4000000000000000000000000000, - 0x8000000000000000000000000000, - 0x10000000000000000000000000000, - 0x20000000000000000000000000000, - 0x40000000000000000000000000000, - 0x80000000000000000000000000000, - 0x100000000000000000000000000000, - 0x200000000000000000000000000000, - 0x400000000000000000000000000000, - 0x800000000000000000000000000000, - 0x1000000000000000000000000000000, - 0x2000000000000000000000000000000, - 0x4000000000000000000000000000000, - 0x8000000000000000000000000000000, - 0x10000000000000000000000000000000, - 0x20000000000000000000000000000000, - 0x40000000000000000000000000000000, - 0x80000000000000000000000000000000, - 0x100000000000000000000000000000000, - 0x200000000000000000000000000000000, - 0x400000000000000000000000000000000, - 0x800000000000000000000000000000000, - 0x1000000000000000000000000000000000, - 0x2000000000000000000000000000000000, - 0x4000000000000000000000000000000000, - 0x8000000000000000000000000000000000, - 0x10000000000000000000000000000000000, - 0x20000000000000000000000000000000000, - 0x40000000000000000000000000000000000, - 0x80000000000000000000000000000000000, - 0x100000000000000000000000000000000000, - 0x200000000000000000000000000000000000, - 0x400000000000000000000000000000000000, - 0x800000000000000000000000000000000000, - 0x1000000000000000000000000000000000000, - 0x2000000000000000000000000000000000000, - 0x4000000000000000000000000000000000000, - 0x8000000000000000000000000000000000000, - 0x10000000000000000000000000000000000000, - 0x20000000000000000000000000000000000000, - 0x40000000000000000000000000000000000000, - 0x80000000000000000000000000000000000000, - 0x100000000000000000000000000000000000000, - 0x200000000000000000000000000000000000000, - 0x400000000000000000000000000000000000000, - 0x800000000000000000000000000000000000000, - 0x1000000000000000000000000000000000000000, - 0x2000000000000000000000000000000000000000, - 0x4000000000000000000000000000000000000000, - 0x8000000000000000000000000000000000000000, - 0x10000000000000000000000000000000000000000, - 0x20000000000000000000000000000000000000000, - 0x40000000000000000000000000000000000000000, - 0x80000000000000000000000000000000000000000, - 0x100000000000000000000000000000000000000000, - 0x200000000000000000000000000000000000000000, - 0x400000000000000000000000000000000000000000, - 0x800000000000000000000000000000000000000000, + 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, + 0x4000, 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, 0x800000, + 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, + 0x100000000, 0x200000000, 0x400000000, 0x800000000, 0x1000000000, 0x2000000000, + 0x4000000000, 0x8000000000, 0x10000000000, 0x20000000000, 0x40000000000, 0x80000000000, + 0x100000000000, 0x200000000000, 0x400000000000, 0x800000000000, 0x1000000000000, + 0x2000000000000, 0x4000000000000, 0x8000000000000, 0x10000000000000, 0x20000000000000, + 0x40000000000000, 0x80000000000000, 0x100000000000000, 0x200000000000000, 0x400000000000000, + 0x800000000000000, 0x1000000000000000, 0x2000000000000000, 0x4000000000000000, + 0x8000000000000000, 0x10000000000000000, 0x20000000000000000, 0x40000000000000000, + 0x80000000000000000, 0x100000000000000000, 0x200000000000000000, 0x400000000000000000, + 0x800000000000000000, 0x1000000000000000000, 0x2000000000000000000, 0x4000000000000000000, + 0x8000000000000000000, 0x10000000000000000000, 0x20000000000000000000, + 0x40000000000000000000, 0x80000000000000000000, 0x100000000000000000000, + 0x200000000000000000000, 0x400000000000000000000, 0x800000000000000000000, + 0x1000000000000000000000, 0x2000000000000000000000, 0x4000000000000000000000, + 0x8000000000000000000000, 0x10000000000000000000000, 0x20000000000000000000000, + 0x40000000000000000000000, 0x80000000000000000000000, 0x100000000000000000000000, + 0x200000000000000000000000, 0x400000000000000000000000, 0x800000000000000000000000, + 0x1000000000000000000000000, 0x2000000000000000000000000, 0x4000000000000000000000000, + 0x8000000000000000000000000, 0x10000000000000000000000000, 0x20000000000000000000000000, + 0x40000000000000000000000000, 0x80000000000000000000000000, 0x100000000000000000000000000, + 0x200000000000000000000000000, 0x400000000000000000000000000, 0x800000000000000000000000000, + 0x1000000000000000000000000000, 0x2000000000000000000000000000, + 0x4000000000000000000000000000, 0x8000000000000000000000000000, + 0x10000000000000000000000000000, 0x20000000000000000000000000000, + 0x40000000000000000000000000000, 0x80000000000000000000000000000, + 0x100000000000000000000000000000, 0x200000000000000000000000000000, + 0x400000000000000000000000000000, 0x800000000000000000000000000000, + 0x1000000000000000000000000000000, 0x2000000000000000000000000000000, + 0x4000000000000000000000000000000, 0x8000000000000000000000000000000, + 0x10000000000000000000000000000000, 0x20000000000000000000000000000000, + 0x40000000000000000000000000000000, 0x80000000000000000000000000000000, + 0x100000000000000000000000000000000, 0x200000000000000000000000000000000, + 0x400000000000000000000000000000000, 0x800000000000000000000000000000000, + 0x1000000000000000000000000000000000, 0x2000000000000000000000000000000000, + 0x4000000000000000000000000000000000, 0x8000000000000000000000000000000000, + 0x10000000000000000000000000000000000, 0x20000000000000000000000000000000000, + 0x40000000000000000000000000000000000, 0x80000000000000000000000000000000000, + 0x100000000000000000000000000000000000, 0x200000000000000000000000000000000000, + 0x400000000000000000000000000000000000, 0x800000000000000000000000000000000000, + 0x1000000000000000000000000000000000000, 0x2000000000000000000000000000000000000, + 0x4000000000000000000000000000000000000, 0x8000000000000000000000000000000000000, + 0x10000000000000000000000000000000000000, 0x20000000000000000000000000000000000000, + 0x40000000000000000000000000000000000000, 0x80000000000000000000000000000000000000, + 0x100000000000000000000000000000000000000, 0x200000000000000000000000000000000000000, + 0x400000000000000000000000000000000000000, 0x800000000000000000000000000000000000000, + 0x1000000000000000000000000000000000000000, 0x2000000000000000000000000000000000000000, + 0x4000000000000000000000000000000000000000, 0x8000000000000000000000000000000000000000, + 0x10000000000000000000000000000000000000000, 0x20000000000000000000000000000000000000000, + 0x40000000000000000000000000000000000000000, 0x80000000000000000000000000000000000000000, + 0x100000000000000000000000000000000000000000, 0x200000000000000000000000000000000000000000, + 0x400000000000000000000000000000000000000000, 0x800000000000000000000000000000000000000000, 0x1000000000000000000000000000000000000000000, 0x2000000000000000000000000000000000000000000, 0x4000000000000000000000000000000000000000000, @@ -416,7 +206,7 @@ pub fn pow2_felt252(exponent: u32) -> felt252 { 0x80000000000000000000000000000000000000000000000000000000000000, 0x100000000000000000000000000000000000000000000000000000000000000, 0x200000000000000000000000000000000000000000000000000000000000000, - 0x400000000000000000000000000000000000000000000000000000000000000 + 0x400000000000000000000000000000000000000000000000000000000000000, ]; *hardcoded_results.span()[exponent] } @@ -431,44 +221,17 @@ pub fn pow2_felt252(exponent: u32) -> felt252 { /// * If `exponent` is greater than 38 (out of the supported range) pub fn pow10(exponent: u32) -> u128 { let hardcoded_results: [u128; 38] = [ - 1, - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 10000000, - 100000000, - 1000000000, - 10000000000, - 100000000000, - 1000000000000, - 10000000000000, - 100000000000000, - 1000000000000000, - 10000000000000000, - 100000000000000000, - 1000000000000000000, - 10000000000000000000, - 100000000000000000000, - 1000000000000000000000, - 10000000000000000000000, - 100000000000000000000000, - 1000000000000000000000000, - 10000000000000000000000000, - 100000000000000000000000000, - 1000000000000000000000000000, - 10000000000000000000000000000, - 100000000000000000000000000000, - 1000000000000000000000000000000, - 10000000000000000000000000000000, - 100000000000000000000000000000000, - 1000000000000000000000000000000000, - 10000000000000000000000000000000000, - 100000000000000000000000000000000000, - 1000000000000000000000000000000000000, - 10000000000000000000000000000000000000 + 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, + 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, + 10000000000000000, 100000000000000000, 1000000000000000000, 10000000000000000000, + 100000000000000000000, 1000000000000000000000, 10000000000000000000000, + 100000000000000000000000, 1000000000000000000000000, 10000000000000000000000000, + 100000000000000000000000000, 1000000000000000000000000000, 10000000000000000000000000000, + 100000000000000000000000000000, 1000000000000000000000000000000, + 10000000000000000000000000000000, 100000000000000000000000000000000, + 1000000000000000000000000000000000, 10000000000000000000000000000000000, + 100000000000000000000000000000000000, 1000000000000000000000000000000000000, + 10000000000000000000000000000000000000, ]; *hardcoded_results.span()[exponent] } @@ -483,51 +246,20 @@ pub fn pow10(exponent: u32) -> u128 { /// * If `exponent` is greater than 77 (out of the supported range) pub fn pow10_u256(exponent: u32) -> u256 { let hardcoded_results: [u256; 77] = [ - 1, - 10, - 100, - 1000, - 10000, - 100000, - 1000000, - 10000000, - 100000000, - 1000000000, - 10000000000, - 100000000000, - 1000000000000, - 10000000000000, - 100000000000000, - 1000000000000000, - 10000000000000000, - 100000000000000000, - 1000000000000000000, - 10000000000000000000, - 100000000000000000000, - 1000000000000000000000, - 10000000000000000000000, - 100000000000000000000000, - 1000000000000000000000000, - 10000000000000000000000000, - 100000000000000000000000000, - 1000000000000000000000000000, - 10000000000000000000000000000, - 100000000000000000000000000000, - 1000000000000000000000000000000, - 10000000000000000000000000000000, - 100000000000000000000000000000000, - 1000000000000000000000000000000000, - 10000000000000000000000000000000000, - 100000000000000000000000000000000000, - 1000000000000000000000000000000000000, - 10000000000000000000000000000000000000, - 100000000000000000000000000000000000000, - 1000000000000000000000000000000000000000, - 10000000000000000000000000000000000000000, - 100000000000000000000000000000000000000000, - 1000000000000000000000000000000000000000000, - 10000000000000000000000000000000000000000000, - 100000000000000000000000000000000000000000000, + 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, + 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, + 10000000000000000, 100000000000000000, 1000000000000000000, 10000000000000000000, + 100000000000000000000, 1000000000000000000000, 10000000000000000000000, + 100000000000000000000000, 1000000000000000000000000, 10000000000000000000000000, + 100000000000000000000000000, 1000000000000000000000000000, 10000000000000000000000000000, + 100000000000000000000000000000, 1000000000000000000000000000000, + 10000000000000000000000000000000, 100000000000000000000000000000000, + 1000000000000000000000000000000000, 10000000000000000000000000000000000, + 100000000000000000000000000000000000, 1000000000000000000000000000000000000, + 10000000000000000000000000000000000000, 100000000000000000000000000000000000000, + 1000000000000000000000000000000000000000, 10000000000000000000000000000000000000000, + 100000000000000000000000000000000000000000, 1000000000000000000000000000000000000000000, + 10000000000000000000000000000000000000000000, 100000000000000000000000000000000000000000000, 1000000000000000000000000000000000000000000000, 10000000000000000000000000000000000000000000000, 100000000000000000000000000000000000000000000000, @@ -559,7 +291,7 @@ pub fn pow10_u256(exponent: u32) -> u256 { 10000000000000000000000000000000000000000000000000000000000000000000000000, 100000000000000000000000000000000000000000000000000000000000000000000000000, 1000000000000000000000000000000000000000000000000000000000000000000000000000, - 10000000000000000000000000000000000000000000000000000000000000000000000000000 + 10000000000000000000000000000000000000000000000000000000000000000000000000000, ]; *hardcoded_results.span()[exponent] } diff --git a/packages/math/src/ed25519.cairo b/packages/math/src/ed25519.cairo index 3813a7b3..458d8243 100644 --- a/packages/math/src/ed25519.cairo +++ b/packages/math/src/ed25519.cairo @@ -1,5 +1,5 @@ -use alexandria_math::mod_arithmetics::{mult_mod, sqr_mod, div_mod, pow_mod}; -use alexandria_math::sha512::{sha512, SHA512_LEN}; +use alexandria_math::mod_arithmetics::{div_mod, mult_mod, pow_mod, sqr_mod}; +use alexandria_math::sha512::{SHA512_LEN, sha512}; use alexandria_math::u512_arithmetics::{u512_sub}; use core::integer::{u512, u512_safe_div_rem_by_u256}; use core::math::u256_inv_mod; @@ -26,7 +26,7 @@ fn sub_wo_mod_u512(a: u512, b: u512, modulo: u256) -> u512 { let u256 { low: limb2, high: limb3 } = u256 { low, high } + modulo; u512 { limb0, limb1, limb2, limb3 } }, - b + b, ) } @@ -107,7 +107,7 @@ impl PointDoublingPoint of PointOperations { // y1y2 + ax1x2 = y1y2 - x1x2, a = -1 let (_, y1y2_ax1x2) = u512_safe_div_rem_by_u256( - sub_wo_mod_u512(y1y2_512, x1x2_512, p), prime_nz + sub_wo_mod_u512(y1y2_512, x1x2_512, p), prime_nz, ); // 1 / (y1y2 + ax1x2) @@ -116,7 +116,7 @@ impl PointDoublingPoint of PointOperations { // x1y2 − y1x2 let (_, x1y2_sub_y1x2) = u512_safe_div_rem_by_u256( - sub_wo_mod_u512(x1y2_512, y1x2_512, p), prime_nz + sub_wo_mod_u512(x1y2_512, y1x2_512, p), prime_nz, ); // 1 / (x1y2 − y1x2) @@ -268,7 +268,7 @@ impl U256TryIntoPoint of TryInto { let x_candidate_root: u256 = mult_mod( u_times_v_power_3, pow_mod(mult_mod(u, v_pow_7, prime_nz), p_minus_5_div_8, prime_nz), - prime_nz + prime_nz, ); let v_times_x_squared: u256 = mult_mod(v, sqr_mod(x_candidate_root, prime_nz), prime_nz); @@ -291,7 +291,7 @@ impl U256TryIntoPoint of TryInto { x = p - x; } - Option::Some(Point { x: x, y: y, }) + Option::Some(Point { x: x, y: y }) } } diff --git a/packages/math/src/fast_power.cairo b/packages/math/src/fast_power.cairo index 11329b97..f171f13f 100644 --- a/packages/math/src/fast_power.cairo +++ b/packages/math/src/fast_power.cairo @@ -20,9 +20,9 @@ pub fn fast_power< +TryInto, +PartialEq, +Copy, - +Drop + +Drop, >( - base: T, mut power: T + base: T, mut power: T, ) -> T { assert!(base != 0_u8.into(), "fast_power: invalid input"); @@ -63,9 +63,9 @@ pub fn fast_power_mod< +TryInto, +PartialEq, +Copy, - +Drop + +Drop, >( - base: T, mut power: T, modulus: T + base: T, mut power: T, modulus: T, ) -> T { assert!(base != 0_u8.into(), "fast_power: invalid input"); diff --git a/packages/math/src/i257.cairo b/packages/math/src/i257.cairo index 325c5796..94b2a4b2 100644 --- a/packages/math/src/i257.cairo +++ b/packages/math/src/i257.cairo @@ -1,6 +1,6 @@ -use core::fmt::{Display, Formatter, Error}; +use core::fmt::{Display, Error, Formatter}; use core::num::traits::Zero; -use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign}; +use core::ops::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign}; // ====================== INT 257 ====================== diff --git a/packages/math/src/karatsuba.cairo b/packages/math/src/karatsuba.cairo index 8c4a9c6e..df3aeb2a 100644 --- a/packages/math/src/karatsuba.cairo +++ b/packages/math/src/karatsuba.cairo @@ -1,6 +1,6 @@ //! # Karatsuba Multiplication. use core::cmp::max; -use super::{count_digits_of_base, const_pow::pow10}; +use super::{const_pow::pow10, count_digits_of_base}; /// Algorithm to multiply two numbers in O(n^1.6) running time /// # Arguments diff --git a/packages/math/src/keccak256.cairo b/packages/math/src/keccak256.cairo index e73bd604..9b4d9353 100644 --- a/packages/math/src/keccak256.cairo +++ b/packages/math/src/keccak256.cairo @@ -47,7 +47,7 @@ fn reverse_endianness(value: u256) -> u256 { #[deprecated( feature: "deprecated-keccak", note: "Use `core::keccak::compute_keccak_byte_array`.", - since: "2.7.0" + since: "2.7.0", )] pub fn keccak256(mut self: Span) -> u256 { // Converts byte array to little endian 8 byte words array. diff --git a/packages/math/src/lcm_of_n_numbers.cairo b/packages/math/src/lcm_of_n_numbers.cairo index 56316b72..c750fe75 100644 --- a/packages/math/src/lcm_of_n_numbers.cairo +++ b/packages/math/src/lcm_of_n_numbers.cairo @@ -12,7 +12,7 @@ pub enum LCMError { /// # Returns /// * `Result` - The lcm of input numbers pub fn lcm, +Into, +Mul, +Div, +Copy, +Drop>( - mut n: Span + mut n: Span, ) -> Result { // Return empty input error if n.is_empty() { diff --git a/packages/math/src/lib.cairo b/packages/math/src/lib.cairo index 3f309bfb..aa011505 100644 --- a/packages/math/src/lib.cairo +++ b/packages/math/src/lib.cairo @@ -28,7 +28,7 @@ pub mod u512_arithmetics; pub mod wad_ray_math; pub mod zellers_congruence; use core::num::traits::Bounded; -use core::num::traits::{WrappingAdd, WrappingSub, WrappingMul, WideMul, OverflowingMul}; +use core::num::traits::{OverflowingMul, WideMul, WrappingAdd, WrappingMul, WrappingSub}; /// Raise a number to a power. /// O(log n) time complexity. @@ -37,7 +37,7 @@ use core::num::traits::{WrappingAdd, WrappingSub, WrappingMul, WideMul, Overflow /// # Returns /// * `T` - The result of base raised to the power of exp. pub fn pow, +Mul, +Div, +Rem, +PartialEq, +Into, +Drop, +Copy>( - base: T, exp: T + base: T, exp: T, ) -> T { if exp == 0_u8.into() { 1_u8.into() @@ -176,7 +176,7 @@ pub impl U64BitRotate of BitRotate { fn rotate_left(x: u64, n: u64) -> u64 { let word = WideMul::wide_mul(x, pow(2, n)); let (quotient, remainder) = DivRem::div_rem( - word, 0x10000000000000000_u128.try_into().unwrap() + word, 0x10000000000000000_u128.try_into().unwrap(), ); (quotient + remainder).try_into().unwrap() } @@ -192,7 +192,7 @@ pub impl U128BitRotate of BitRotate { fn rotate_left(x: u128, n: u128) -> u128 { let word = WideMul::wide_mul(x, pow(2, n)); let (quotient, remainder) = DivRem::div_rem( - word, u256 { low: 0, high: 1 }.try_into().unwrap() + word, u256 { low: 0, high: 1 }.try_into().unwrap(), ); (quotient + remainder).try_into().unwrap() } diff --git a/packages/math/src/mod_arithmetics.cairo b/packages/math/src/mod_arithmetics.cairo index ffe811c8..067b4d82 100644 --- a/packages/math/src/mod_arithmetics.cairo +++ b/packages/math/src/mod_arithmetics.cairo @@ -1,5 +1,5 @@ use core::integer::{u512, u512_safe_div_rem_by_u256}; -use core::num::traits::{WrappingAdd, OverflowingAdd, OverflowingSub, WideMul}; +use core::num::traits::{OverflowingAdd, OverflowingSub, WideMul, WrappingAdd}; /// Function that performs modular addition. Will panick if result is > u256 max /// # Arguments @@ -84,7 +84,7 @@ fn u128_add_with_carry(a: u128, b: u128) -> (u128, u128) { } pub fn u256_wide_sqr(a: u256) -> u512 { - let u256 { high: limb1, low: limb0, } = WideMul::wide_mul(a.low, a.low); + let u256 { high: limb1, low: limb0 } = WideMul::wide_mul(a.low, a.low); let u256 { high: limb2, low: limb1_part } = WideMul::wide_mul(a.low, a.high); let (limb1, limb1_overflow0) = u128_add_with_carry(limb1, limb1_part); let (limb1, limb1_overflow1) = u128_add_with_carry(limb1, limb1_part); diff --git a/packages/math/src/sha256.cairo b/packages/math/src/sha256.cairo index 6e7264e1..f7d557ec 100644 --- a/packages/math/src/sha256.cairo +++ b/packages/math/src/sha256.cairo @@ -48,7 +48,7 @@ fn ssig1(x: u32) -> u32 { #[deprecated( feature: "deprecated-sha256", note: "Use `core::sha256::compute_sha256_byte_array`.", - since: "2.7.0" + since: "2.7.0", )] pub fn sha256(mut data: Array) -> Array { let data_len: u64 = (data.len() * 8).into(); @@ -191,77 +191,17 @@ fn from_u8Array_to_u32Array(mut data: Span) -> Array { result } -const h: [ - u32 - ; 8] = [ - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19 +const h: [u32; 8] = [ + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, ]; -const k: [ - u32 - ; 64] = [ - 0x428a2f98, - 0x71374491, - 0xb5c0fbcf, - 0xe9b5dba5, - 0x3956c25b, - 0x59f111f1, - 0x923f82a4, - 0xab1c5ed5, - 0xd807aa98, - 0x12835b01, - 0x243185be, - 0x550c7dc3, - 0x72be5d74, - 0x80deb1fe, - 0x9bdc06a7, - 0xc19bf174, - 0xe49b69c1, - 0xefbe4786, - 0x0fc19dc6, - 0x240ca1cc, - 0x2de92c6f, - 0x4a7484aa, - 0x5cb0a9dc, - 0x76f988da, - 0x983e5152, - 0xa831c66d, - 0xb00327c8, - 0xbf597fc7, - 0xc6e00bf3, - 0xd5a79147, - 0x06ca6351, - 0x14292967, - 0x27b70a85, - 0x2e1b2138, - 0x4d2c6dfc, - 0x53380d13, - 0x650a7354, - 0x766a0abb, - 0x81c2c92e, - 0x92722c85, - 0xa2bfe8a1, - 0xa81a664b, - 0xc24b8b70, - 0xc76c51a3, - 0xd192e819, - 0xd6990624, - 0xf40e3585, - 0x106aa070, - 0x19a4c116, - 0x1e376c08, - 0x2748774c, - 0x34b0bcb5, - 0x391c0cb3, - 0x4ed8aa4a, - 0x5b9cca4f, - 0x682e6ff3, - 0x748f82ee, - 0x78a5636f, - 0x84c87814, - 0x8cc70208, - 0x90befffa, - 0xa4506ceb, - 0xbef9a3f7, - 0xc67178f2 +const k: [u32; 64] = [ + 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, + 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, + 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, + 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, + 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, + 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, + 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, ]; diff --git a/packages/math/src/sha512.cairo b/packages/math/src/sha512.cairo index f9c4165b..bc621b1d 100644 --- a/packages/math/src/sha512.cairo +++ b/packages/math/src/sha512.cairo @@ -1,6 +1,6 @@ use core::num::traits::Bounded; use core::num::traits::WrappingAdd; -use core::traits::{BitAnd, BitXor, BitOr}; +use core::traits::{BitAnd, BitOr, BitXor}; // Variable naming is compliant to RFC-6234 (https://datatracker.ietf.org/doc/html/rfc6234) @@ -114,7 +114,7 @@ pub impl Word64WordOperations of WordOperations { } fn rotr(self: Word64, n: u64) -> Word64 { let data = BitOr::bitor( - math_shr_u64(self.data, n), math_shl_u64(self.data, (U64_BIT_NUM - n)) + math_shr_u64(self.data, n), math_shl_u64(self.data, (U64_BIT_NUM - n)), ); Word64 { data } } @@ -123,19 +123,19 @@ pub impl Word64WordOperations of WordOperations { let data = self.data.into(); let data: u128 = BitOr::bitor( math_shr_precomputed::(data, two_pow_n.into()), - math_shl_precomputed::(data, two_pow_64_n.into()) + math_shl_precomputed::(data, two_pow_64_n.into()), ); let data: u64 = match data.try_into() { Option::Some(data) => data, - Option::None => (data & MAX_U64).try_into().unwrap() + Option::None => (data & MAX_U64).try_into().unwrap(), }; Word64 { data } } fn rotl(self: Word64, n: u64) -> Word64 { let data = BitOr::bitor( - math_shl_u64(self.data, n), math_shr_u64(self.data, (U64_BIT_NUM - n)) + math_shl_u64(self.data, n), math_shr_u64(self.data, (U64_BIT_NUM - n)), ); Word64 { data } } @@ -204,10 +204,8 @@ pub fn fpow(mut base: u128, mut power: u128) -> u128 { result } -const two_squarings: [ - u64 - ; 6] = [ - TWO_POW_1, TWO_POW_2, TWO_POW_4, TWO_POW_8, TWO_POW_16, TWO_POW_32 +const two_squarings: [u64; 6] = [ + TWO_POW_1, TWO_POW_2, TWO_POW_4, TWO_POW_8, TWO_POW_16, TWO_POW_32, ]; // Uses cache for faster powers of 2 in a u128 // Uses TWO_POW_* constants @@ -240,14 +238,14 @@ fn math_shr(x: u128, n: u64) -> u128 { // Shift left with precomputed powers of 2 fn math_shl_precomputed, +Rem, +Drop, +Copy, +Into>( - x: T, two_power_n: T + x: T, two_power_n: T, ) -> T { x * two_power_n } // Shift right with precomputed powers of 2 fn math_shr_precomputed, +Rem, +Drop, +Copy, +Into>( - x: T, two_power_n: T + x: T, two_power_n: T, ) -> T { x / two_power_n } diff --git a/packages/math/src/tests/const_pow_test.cairo b/packages/math/src/tests/const_pow_test.cairo index 35284ba3..5433e7e0 100644 --- a/packages/math/src/tests/const_pow_test.cairo +++ b/packages/math/src/tests/const_pow_test.cairo @@ -1,4 +1,4 @@ -use alexandria_math::const_pow::{pow2, pow2_u256, pow10, pow10_u256}; +use alexandria_math::const_pow::{pow10, pow10_u256, pow2, pow2_u256}; #[test] #[available_gas(1000000000)] @@ -12,7 +12,7 @@ fn pow2_test() { assert_eq!( pow2(127), 0x80000000000000000000000000000000, - "2^127 should be 0x80000000000000000000000000000000" + "2^127 should be 0x80000000000000000000000000000000", ); } @@ -24,12 +24,12 @@ fn pow2_u256_test() { assert_eq!( pow2_u256(128), 340282366920938463463374607431768211456, - "2^128 should be 340282366920938463463374607431768211456" + "2^128 should be 340282366920938463463374607431768211456", ); assert_eq!( pow2_u256(255), 57896044618658097711785492504343953926634992332820282019728792003956564819968, - "2^255 should be 57896044618658097711785492504343953926634992332820282019728792003956564819968" + "2^255 should be 57896044618658097711785492504343953926634992332820282019728792003956564819968", ); } @@ -44,7 +44,7 @@ fn pow10_test() { assert_eq!( pow10(37), 10000000000000000000000000000000000000, - "10^37 should be 10000000000000000000000000000000000000" + "10^37 should be 10000000000000000000000000000000000000", ); } @@ -57,12 +57,12 @@ fn pow10_u256_test() { assert_eq!( pow10_u256(38), 100000000000000000000000000000000000000, - "10^38 should be 100000000000000000000000000000000000000" + "10^38 should be 100000000000000000000000000000000000000", ); assert_eq!( pow10_u256(76), 10000000000000000000000000000000000000000000000000000000000000000000000000000, - "10^76 should be 10000000000000000000000000000000000000000000000000000000000000000000000000000" + "10^76 should be 10000000000000000000000000000000000000000000000000000000000000000000000000000", ); } diff --git a/packages/math/src/tests/ed25519_test.cairo b/packages/math/src/tests/ed25519_test.cairo index 3cb0ff31..435ecc98 100644 --- a/packages/math/src/tests/ed25519_test.cairo +++ b/packages/math/src/tests/ed25519_test.cairo @@ -1,4 +1,4 @@ -use alexandria_math::ed25519::{verify_signature, Point, PointOperations, p_non_zero}; +use alexandria_math::ed25519::{Point, PointOperations, p_non_zero, verify_signature}; // Public keys and signatures were generated with JS library Noble // (https://github.com/paulmillr/noble-ed25519) @@ -92,15 +92,15 @@ fn verify_signature_invalid_length() { fn affine_point_op() { let p1 = Point { x: 46706390780465557264338673484185971070529246228527338942042475661633188627656, - y: 15299170165656271974649334809062094114079726227711063015095704409550798436788 + y: 15299170165656271974649334809062094114079726227711063015095704409550798436788, }; let p2 = Point { x: 26148317933504540005443173402042326458672162458767831815669826413036406984486, - y: 30850316547316149219369061290562558254923949145644564178378051444253659681385 + y: 30850316547316149219369061290562558254923949145644564178378051444253659681385, }; let res = Point { x: 34426924428514608760437100447421064591311588584549077394333265447466212246087, - y: 29872771498517479181395568267318965384440757492476580330810382845026939417492 + y: 29872771498517479181395568267318965384440757492476580330810382845026939417492, }; assert!(res == p1.add(p2, p_non_zero)); } diff --git a/packages/math/src/tests/fast_power_test.cairo b/packages/math/src/tests/fast_power_test.cairo index d6af0bfc..7964fef9 100644 --- a/packages/math/src/tests/fast_power_test.cairo +++ b/packages/math/src/tests/fast_power_test.cairo @@ -15,7 +15,7 @@ fn fast_power_test() { assert_eq!( fast_power(2_u256, 255_u256), 0x8000000000000000000000000000000000000000000000000000000000000000, - "invalid result" + "invalid result", ); } @@ -29,7 +29,7 @@ fn fast_power_mod_test() { assert_eq!(fast_power_mod(2_u128, 100_u128, 1000000007_u128), 976371285); assert_eq!( fast_power_mod(2_u128, 127_u128, 340282366920938463463374607431768211454_u128), - 170141183460469231731687303715884105728 + 170141183460469231731687303715884105728, ); assert_eq!(fast_power_mod(2_u128, 127_u128, 34028236692093846346337460743176821144_u128), 8); @@ -37,6 +37,6 @@ fn fast_power_mod_test() { assert_eq!( fast_power_mod(2_u128, 88329_u128, 34028236692093846346337460743176821144_u128), - 2199023255552 + 2199023255552, ); } diff --git a/packages/math/src/tests/i257_test.cairo b/packages/math/src/tests/i257_test.cairo index 615617e2..ded43401 100644 --- a/packages/math/src/tests/i257_test.cairo +++ b/packages/math/src/tests/i257_test.cairo @@ -1,4 +1,4 @@ -use alexandria_math::i257::{i257, I257Impl, i257_div_rem}; +use alexandria_math::i257::{I257Impl, i257, i257_div_rem}; use core::num::traits::Zero; #[test] diff --git a/packages/math/src/tests/lcm_of_n_numbers_test.cairo b/packages/math/src/tests/lcm_of_n_numbers_test.cairo index 265fdd77..833a3a9f 100644 --- a/packages/math/src/tests/lcm_of_n_numbers_test.cairo +++ b/packages/math/src/tests/lcm_of_n_numbers_test.cairo @@ -1,4 +1,4 @@ -use alexandria_math::lcm_of_n_numbers::{lcm, LCMError}; +use alexandria_math::lcm_of_n_numbers::{LCMError, lcm}; // the following trait is not safe, it is only used for testing. impl u128_into_u32 of Into { diff --git a/packages/math/src/tests/math_test.cairo b/packages/math/src/tests/math_test.cairo index f7a767f3..eebbae2f 100644 --- a/packages/math/src/tests/math_test.cairo +++ b/packages/math/src/tests/math_test.cairo @@ -1,4 +1,4 @@ -use alexandria_math::{count_digits_of_base, pow, BitShift, BitRotate, WrappingMath}; +use alexandria_math::{BitRotate, BitShift, WrappingMath, count_digits_of_base, pow}; use core::num::traits::Bounded; // Test power function @@ -345,7 +345,7 @@ fn test_wrapping_math_wrapping() { assert_eq!(Bounded::::MAX.wrapping_add(2_u128), 1_u128); assert_eq!(2_u128.wrapping_add(Bounded::::MAX), 1_u128); assert_eq!( - Bounded::::MAX.wrapping_add(Bounded::::MAX), Bounded::::MAX - 1_u128 + Bounded::::MAX.wrapping_add(Bounded::::MAX), Bounded::::MAX - 1_u128, ); assert_eq!(Bounded::::MIN.wrapping_sub(1_u128), Bounded::::MAX); assert_eq!(Bounded::::MIN.wrapping_sub(2_u128), Bounded::::MAX - 1_u128); @@ -359,7 +359,7 @@ fn test_wrapping_math_wrapping() { assert_eq!(Bounded::::MAX.wrapping_add(2_u256), 1_u256); assert_eq!(2_u256.wrapping_add(Bounded::::MAX), 1_u256); assert_eq!( - Bounded::::MAX.wrapping_add(Bounded::::MAX), Bounded::::MAX - 1_u256 + Bounded::::MAX.wrapping_add(Bounded::::MAX), Bounded::::MAX - 1_u256, ); assert_eq!(Bounded::::MIN.wrapping_sub(1_u256), Bounded::::MAX); assert_eq!(Bounded::::MIN.wrapping_sub(2_u256), Bounded::::MAX - 1_u256); diff --git a/packages/math/src/tests/mod_arithmetics_test.cairo b/packages/math/src/tests/mod_arithmetics_test.cairo index 11619fe7..01326a86 100644 --- a/packages/math/src/tests/mod_arithmetics_test.cairo +++ b/packages/math/src/tests/mod_arithmetics_test.cairo @@ -1,4 +1,4 @@ -use alexandria_math::mod_arithmetics::{add_mod, sub_mod, mult_mod, sqr_mod, div_mod, pow_mod}; +use alexandria_math::mod_arithmetics::{add_mod, div_mod, mult_mod, pow_mod, sqr_mod, sub_mod}; const p: u256 = 57896044618658097711785492504343953926634992332820282019728792003956564819949; // 2^255 - 19 @@ -121,12 +121,12 @@ fn sqr_mod_test() { assert_eq!( sqr_mod(p, pow_256_minus_1.try_into().unwrap()), mult_mod(p, p, pow_256_minus_1.try_into().unwrap()), - "Incorrect result" + "Incorrect result", ); assert_eq!( sqr_mod(pow_256_minus_1, p.try_into().unwrap()), mult_mod(pow_256_minus_1, pow_256_minus_1, p.try_into().unwrap()), - "Incorrect result" + "Incorrect result", ); } @@ -150,7 +150,7 @@ fn pow_mod_test() { assert_eq!(pow_mod(2, 260, prime_non_zero), 608); assert_eq!( pow_mod(10, 260, prime_non_zero), - 17820046977743035104984469918379927979184337110507416960697246160624073120874 + 17820046977743035104984469918379927979184337110507416960697246160624073120874, ); assert_eq!(pow_mod(4, 174, prime_non_zero), 188166885971377801784666882048); assert_eq!(pow_mod(100, p, prime_non_zero), 100); diff --git a/packages/math/src/tests/sha256_test.cairo b/packages/math/src/tests/sha256_test.cairo index b3a1f04c..1387d131 100644 --- a/packages/math/src/tests/sha256_test.cairo +++ b/packages/math/src/tests/sha256_test.cairo @@ -46,7 +46,7 @@ fn sha256_empty_test() { #[available_gas(200000000000)] fn sha256_random_data_test() { let mut input: Array = array![ - 0x57, 0x77, 0x71, 0x71, 0x66, 0x50, 0x45, 0x51, 0x51, 0x43, 0x39, 0x48, 0x38 + 0x57, 0x77, 0x71, 0x71, 0x66, 0x50, 0x45, 0x51, 0x51, 0x43, 0x39, 0x48, 0x38, ]; let result = sha256::sha256(input); assert_eq!(*result[0], 61); @@ -662,7 +662,7 @@ fn sha256_url() { 'e', 'x', '"', - '}' + '}', ]; let result = sha256::sha256(data); diff --git a/packages/math/src/tests/sha512_test.cairo b/packages/math/src/tests/sha512_test.cairo index 40a59841..18919b86 100644 --- a/packages/math/src/tests/sha512_test.cairo +++ b/packages/math/src/tests/sha512_test.cairo @@ -1,4 +1,4 @@ -use alexandria_math::sha512::{sha512, Word64WordOperations}; +use alexandria_math::sha512::{Word64WordOperations, sha512}; fn get_lorem_ipsum() -> Array { let mut input: Array = array![ @@ -322,7 +322,7 @@ fn get_lorem_ipsum() -> Array { 0x77, 0x69, 0x74, - 0x68 + 0x68, ]; input } diff --git a/packages/math/src/tests/test_keccak256.cairo b/packages/math/src/tests/test_keccak256.cairo index 4807da6f..3d7691dc 100644 --- a/packages/math/src/tests/test_keccak256.cairo +++ b/packages/math/src/tests/test_keccak256.cairo @@ -58,7 +58,7 @@ fn test_keccak256_full_u256() { 0x29, 0x30, 0x31, - 0x32 + 0x32, ]; let hash = keccak256(input.span()); diff --git a/packages/math/src/tests/u512_arithmetics_test.cairo b/packages/math/src/tests/u512_arithmetics_test.cairo index 0bc755a0..993b686b 100644 --- a/packages/math/src/tests/u512_arithmetics_test.cairo +++ b/packages/math/src/tests/u512_arithmetics_test.cairo @@ -21,14 +21,14 @@ fn test_u512_sub() { let sub0 = u512_sub(mu512(5, 6, 7, 8), mu512(1, 2, 3, 4)); assert!(sub0 == mu512(4, 4, 4, 4)); - let sub1 = u512_sub(mu512(3, 2, 1, MAX_128,), mu512(7, 6, 5, 4)); + let sub1 = u512_sub(mu512(3, 2, 1, MAX_128), mu512(7, 6, 5, 4)); assert!( sub1 == mu512( 0xfffffffffffffffffffffffffffffffc, 0xfffffffffffffffffffffffffffffffb, 0xfffffffffffffffffffffffffffffffb, - 0xfffffffffffffffffffffffffffffffa - ) + 0xfffffffffffffffffffffffffffffffa, + ), ); let sub2 = u512_sub(mu512(3, 2, 1, 1), mu512(7, 6, 5, 0)); @@ -37,7 +37,7 @@ fn test_u512_sub() { 0xfffffffffffffffffffffffffffffffc, 0xfffffffffffffffffffffffffffffffb, 0xfffffffffffffffffffffffffffffffb, - 0 - ) + 0, + ), ); } diff --git a/packages/math/src/tests/wad_ray_math_test.cairo b/packages/math/src/tests/wad_ray_math_test.cairo index d105b400..f0ab416c 100644 --- a/packages/math/src/tests/wad_ray_math_test.cairo +++ b/packages/math/src/tests/wad_ray_math_test.cairo @@ -1,5 +1,5 @@ use alexandria_math::wad_ray_math::{ - ray_div, ray_mul, wad_div, wad_mul, ray_to_wad, wad_to_ray, ray, wad, half_ray, half_wad + half_ray, half_wad, ray, ray_div, ray_mul, ray_to_wad, wad, wad_div, wad_mul, wad_to_ray, }; use alexandria_math::{pow}; diff --git a/packages/math/src/trigonometry.cairo b/packages/math/src/trigonometry.cairo index 746df3bb..2e569258 100644 --- a/packages/math/src/trigonometry.cairo +++ b/packages/math/src/trigonometry.cairo @@ -7,9 +7,7 @@ const FAST_180: u64 = 180 * BASE; const FAST_90: u64 = 90 * BASE; const FAST_10: u64 = 10 * BASE; -const sin_table: [ - u64 - ; 10] = [ +const sin_table: [u64; 10] = [ 0_u64, // sin(0) 17364818_u64, // sin(10) 34202014_u64, // sin(20) @@ -22,9 +20,7 @@ const sin_table: [ 100000000_u64 // sin(90) ]; -const cos_table: [ - u64 - ; 10] = [ +const cos_table: [u64; 10] = [ 100000000_u64, // cos(0) 99984769_u64, // cos(1) 99939082_u64, // cos(2) @@ -34,7 +30,7 @@ const cos_table: [ 99452190_u64, // cos(6) 99254615_u64, // cos(7) 99026807_u64, // cos(8) - 98768834_u64, // cos(9) + 98768834_u64 // cos(9) ]; // Calculate fast sin(x) diff --git a/packages/math/src/u512_arithmetics.cairo b/packages/math/src/u512_arithmetics.cairo index 1544c52f..3c4eaf7a 100644 --- a/packages/math/src/u512_arithmetics.cairo +++ b/packages/math/src/u512_arithmetics.cairo @@ -40,13 +40,15 @@ pub fn u512_add(lhs: u512, rhs: u512) -> u512 { let rhs: u256X2 = rhs.into(); // No overflow allowed - let u256 { low: limb2, high: limb3 } = u256_overflow_add(lhs.high, rhs.high) - .expect('u512 add overflow'); + let u256 { + low: limb2, high: limb3, + } = u256_overflow_add(lhs.high, rhs.high).expect('u512 add overflow'); match u256_overflow_add(lhs.low, rhs.low) { Result::Ok(u256 { low: limb0, high: limb1 }) => { u512 { limb0, limb1, limb2, limb3 } }, - Result::Err(u256 { low: limb0, - high: limb1 }) => { + Result::Err(u256 { + low: limb0, high: limb1, + }) => { // Try to move overflow to limb2 let (limb2, did_overflow) = limb2.overflowing_add(1_u128); if did_overflow { @@ -69,13 +71,15 @@ pub fn u512_sub(lhs: u512, rhs: u512) -> u512 { let rhs: u256X2 = rhs.into(); // No overflow allowed - let u256 { low: limb2, high: limb3 } = u256_overflow_sub(lhs.high, rhs.high) - .expect('u512 sub overflow'); + let u256 { + low: limb2, high: limb3, + } = u256_overflow_sub(lhs.high, rhs.high).expect('u512 sub overflow'); match u256_overflow_sub(lhs.low, rhs.low) { Result::Ok(u256 { low: limb0, high: limb1 }) => { u512 { limb0, limb1, limb2, limb3 } }, - Result::Err(u256 { low: limb0, - high: limb1 }) => { + Result::Err(u256 { + low: limb0, high: limb1, + }) => { // Try to move overflow to limb2 let (limb2, did_overflow) = limb2.overflowing_sub(1_u128); if did_overflow { diff --git a/packages/merkle_tree/src/merkle_tree.cairo b/packages/merkle_tree/src/merkle_tree.cairo index 7b348e30..50074742 100644 --- a/packages/merkle_tree/src/merkle_tree.cairo +++ b/packages/merkle_tree/src/merkle_tree.cairo @@ -73,7 +73,7 @@ pub mod poseidon { #[derive(Drop)] pub struct MerkleTree { - hasher: T + hasher: T, } /// MerkleTree trait. @@ -82,7 +82,7 @@ pub trait MerkleTreeTrait { fn new() -> MerkleTree; /// Compute the merkle root of a given proof. fn compute_root( - ref self: MerkleTree, current_node: felt252, proof: Span + ref self: MerkleTree, current_node: felt252, proof: Span, ) -> felt252; /// Verify a merkle proof. fn verify(ref self: MerkleTree, root: felt252, leaf: felt252, proof: Span) -> bool; @@ -104,7 +104,7 @@ pub impl MerkleTreeImpl, +Copy, +Drop> of MerkleTreeTra /// # Returns /// The merkle root. fn compute_root( - ref self: MerkleTree, mut current_node: felt252, mut proof: Span + ref self: MerkleTree, mut current_node: felt252, mut proof: Span, ) -> felt252 { for proof_element in proof { // Compute the hash of the current node and the current element of the proof. @@ -129,7 +129,7 @@ pub impl MerkleTreeImpl, +Copy, +Drop> of MerkleTreeTra /// # Returns /// True if the proof is valid, false otherwise. fn verify( - ref self: MerkleTree, root: felt252, mut leaf: felt252, mut proof: Span + ref self: MerkleTree, root: felt252, mut leaf: felt252, mut proof: Span, ) -> bool { for proof_element in proof { // Compute the hash of the current node and the current element of the proof. @@ -153,7 +153,7 @@ pub impl MerkleTreeImpl, +Copy, +Drop> of MerkleTreeTra /// # Returns /// The merkle proof. fn compute_proof( - ref self: MerkleTree, mut leaves: Array, index: u32 + ref self: MerkleTree, mut leaves: Array, index: u32, ) -> Span { let mut proof: Array = array![]; @@ -176,7 +176,7 @@ pub impl MerkleTreeImpl, +Copy, +Drop> of MerkleTreeTra /// * `hasher` - The hasher to use. /// * `proof` - The proof array to fill. fn compute_proof, +Drop>( - mut nodes: Array, mut hasher: T, index: u32, ref proof: Array + mut nodes: Array, mut hasher: T, index: u32, ref proof: Array, ) { if index % 2 == 0 { proof.append(*nodes.at(index + 1)); @@ -201,7 +201,7 @@ fn compute_proof, +Drop>( /// # Returns /// The next layer of nodes. fn get_next_level, +Drop>( - mut nodes: Span, ref hasher: T + mut nodes: Span, ref hasher: T, ) -> Array { let mut next_level: Array = array![]; while let Option::Some(left) = nodes.pop_front() { diff --git a/packages/merkle_tree/src/storage_proof.cairo b/packages/merkle_tree/src/storage_proof.cairo index 96f085fd..240caee1 100644 --- a/packages/merkle_tree/src/storage_proof.cairo +++ b/packages/merkle_tree/src/storage_proof.cairo @@ -41,7 +41,7 @@ pub struct ContractData { class_hash: felt252, nonce: felt252, contract_state_hash_version: felt252, - storage_proof: Array + storage_proof: Array, } #[generate_trait] @@ -50,7 +50,7 @@ pub impl ContractDataImpl of ContractDataTrait { class_hash: felt252, nonce: felt252, contract_state_hash_version: felt252, - storage_proof: Array + storage_proof: Array, ) -> ContractData { ContractData { class_hash, nonce, contract_state_hash_version, storage_proof } } @@ -60,15 +60,15 @@ pub impl ContractDataImpl of ContractDataTrait { pub struct ContractStateProof { class_commitment: felt252, contract_proof: Array, - contract_data: ContractData + contract_data: ContractData, } #[generate_trait] pub impl ContractStateProofImpl of ContractStateProofTrait { fn new( - class_commitment: felt252, contract_proof: Array, contract_data: ContractData + class_commitment: felt252, contract_proof: Array, contract_data: ContractData, ) -> ContractStateProof { - ContractStateProof { class_commitment, contract_proof, contract_data, } + ContractStateProof { class_commitment, contract_proof, contract_data } } } @@ -90,29 +90,29 @@ pub fn verify( expected_state_commitment: felt252, contract_address: felt252, storage_address: felt252, - proof: ContractStateProof + proof: ContractStateProof, ) -> felt252 { let contract_data = proof.contract_data; let (contract_root_hash, storage_value) = traverse( - storage_address, contract_data.storage_proof + storage_address, contract_data.storage_proof, ); let contract_state_hash = pedersen_hash_4( contract_data.class_hash, contract_root_hash, contract_data.nonce, - contract_data.contract_state_hash_version + contract_data.contract_state_hash_version, ); let (contracts_tree_root, expected_contract_state_hash) = traverse( - contract_address, proof.contract_proof + contract_address, proof.contract_proof, ); assert(expected_contract_state_hash == contract_state_hash, 'wrong contract_state_hash'); let state_commitment = poseidon_hash( - 'STARKNET_STATE_V0', contracts_tree_root, proof.class_commitment + 'STARKNET_STATE_V0', contracts_tree_root, proof.class_commitment, ); assert(expected_state_commitment == state_commitment, 'wrong state_commitment'); @@ -126,7 +126,7 @@ fn traverse(expected_path: felt252, proof: Array) -> (felt252, felt252 let leaf = *match nodes.pop_back().unwrap() { TrieNode::Binary(_) => panic!("expected Edge got Leaf"), - TrieNode::Edge(edge) => edge + TrieNode::Edge(edge) => edge, }; let mut expected_hash = node_hash(@TrieNode::Edge(leaf)); @@ -151,11 +151,11 @@ fn traverse(expected_path: felt252, proof: Array) -> (felt252, felt252 assert(expected_hash == *edge_node.child, 'invalid node hash'); path += *edge_node.path * path_length_pow2; path_length_pow2 *= pow2_felt252((*edge_node.length).into()); - } + }, } expected_hash = node_hash(node); }, - Option::None => { break; } + Option::None => { break; }, }; }; assert(expected_path == path, 'invalid proof path'); @@ -166,7 +166,7 @@ fn traverse(expected_path: felt252, proof: Array) -> (felt252, felt252 fn node_hash(node: @TrieNode) -> felt252 { match node { TrieNode::Binary(binary) => pedersen_hash(*binary.left, *binary.right), - TrieNode::Edge(edge) => pedersen_hash(*edge.child, *edge.path) + (*edge.length).into() + TrieNode::Edge(edge) => pedersen_hash(*edge.child, *edge.path) + (*edge.length).into(), } } diff --git a/packages/merkle_tree/src/tests/merkle_tree_test.cairo b/packages/merkle_tree/src/tests/merkle_tree_test.cairo index 1c50bbfd..1086dbca 100644 --- a/packages/merkle_tree/src/tests/merkle_tree_test.cairo +++ b/packages/merkle_tree/src/tests/merkle_tree_test.cairo @@ -1,12 +1,12 @@ // Internal imports use alexandria_merkle_tree::merkle_tree::{ - Hasher, MerkleTree, pedersen::PedersenHasherImpl, poseidon::PoseidonHasherImpl, MerkleTreeImpl + Hasher, MerkleTree, MerkleTreeImpl, pedersen::PedersenHasherImpl, poseidon::PoseidonHasherImpl, }; mod regular_call_merkle_tree_pedersen { // Internal imports use alexandria_merkle_tree::merkle_tree::{ - Hasher, MerkleTree, pedersen::PedersenHasherImpl, MerkleTreeTrait, + Hasher, MerkleTree, MerkleTreeTrait, pedersen::PedersenHasherImpl, }; #[test] #[available_gas(2000000)] @@ -16,7 +16,7 @@ mod regular_call_merkle_tree_pedersen { let root = 0x15ac9e457789ef0c56e5d559809e7336a909c14ee2511503fa7af69be1ba639; let leaf = 0x1; let valid_proof = array![ - 0x2, 0x68ba2a188dd231112c1cb5aaa5d18be6d84f6c8683e5c3a6638dee83e727acc + 0x2, 0x68ba2a188dd231112c1cb5aaa5d18be6d84f6c8683e5c3a6638dee83e727acc, ] .span(); let leaves = array![0x1, 0x2, 0x3]; @@ -37,7 +37,7 @@ mod regular_call_merkle_tree_pedersen { // [Assert] Verify an invalid proof. let invalid_proof = array![ - 0x2 + 1, 0x68ba2a188dd231112c1cb5aaa5d18be6d84f6c8683e5c3a6638dee83e727acc + 0x2 + 1, 0x68ba2a188dd231112c1cb5aaa5d18be6d84f6c8683e5c3a6638dee83e727acc, ] .span(); let result = merkle_tree.verify(root, leaf, invalid_proof); @@ -63,7 +63,7 @@ fn merkle_tree_pedersen_test() { // [Assert] Compute merkle root. let computed_root = MerkleTreeImpl::< - _, PedersenHasherImpl + _, PedersenHasherImpl, >::compute_root(ref merkle_tree, leaf, valid_proof); assert_eq!(computed_root, root); @@ -71,30 +71,30 @@ fn merkle_tree_pedersen_test() { let mut input_leaves = leaves; let index = 0; let computed_proof = MerkleTreeImpl::< - _, PedersenHasherImpl + _, PedersenHasherImpl, >::compute_proof(ref merkle_tree, input_leaves, index); assert_eq!(computed_proof, valid_proof); // [Assert] Verify a valid proof. let result = MerkleTreeImpl::< - _, PedersenHasherImpl + _, PedersenHasherImpl, >::verify(ref merkle_tree, root, leaf, valid_proof); assert!(result, "verify valid proof failed"); // [Assert] Verify an invalid proof. let invalid_proof = array![ - 0x2 + 1, 0x68ba2a188dd231112c1cb5aaa5d18be6d84f6c8683e5c3a6638dee83e727acc + 0x2 + 1, 0x68ba2a188dd231112c1cb5aaa5d18be6d84f6c8683e5c3a6638dee83e727acc, ] .span(); let result = MerkleTreeImpl::< - _, PedersenHasherImpl + _, PedersenHasherImpl, >::verify(ref merkle_tree, root, leaf, invalid_proof); assert!(!result, "verify invalid proof failed"); // [Assert] Verify a valid proof with an invalid leaf. let invalid_leaf = 0x1 + 1; let result = MerkleTreeImpl::< - _, PedersenHasherImpl + _, PedersenHasherImpl, >::verify(ref merkle_tree, root, invalid_leaf, valid_proof); assert!(!result, "wrong result"); } @@ -112,7 +112,7 @@ fn merkle_tree_poseidon_test() { // [Assert] Compute merkle root. let computed_root = MerkleTreeImpl::< - _, PoseidonHasherImpl + _, PoseidonHasherImpl, >::compute_root(ref merkle_tree, leaf, valid_proof); assert_eq!(computed_root, root); @@ -120,30 +120,30 @@ fn merkle_tree_poseidon_test() { let mut input_leaves = leaves; let index = 0; let computed_proof = MerkleTreeImpl::< - _, PoseidonHasherImpl + _, PoseidonHasherImpl, >::compute_proof(ref merkle_tree, input_leaves, index); assert_eq!(computed_proof, valid_proof); // [Assert] Verify a valid proof. let result = MerkleTreeImpl::< - _, PoseidonHasherImpl + _, PoseidonHasherImpl, >::verify(ref merkle_tree, root, leaf, valid_proof); assert!(result, "verify valid proof failed"); // [Assert] Verify an invalid proof. let invalid_proof = array![ - 0x2 + 1, 0x68ba2a188dd231112c1cb5aaa5d18be6d84f6c8683e5c3a6638dee83e727acc + 0x2 + 1, 0x68ba2a188dd231112c1cb5aaa5d18be6d84f6c8683e5c3a6638dee83e727acc, ] .span(); let result = MerkleTreeImpl::< - _, PoseidonHasherImpl + _, PoseidonHasherImpl, >::verify(ref merkle_tree, root, leaf, invalid_proof); assert!(!result, "verify invalid proof failed"); // [Assert] Verify a valid proof with an invalid leaf. let invalid_leaf = 0x1 + 1; let result = MerkleTreeImpl::< - _, PoseidonHasherImpl + _, PoseidonHasherImpl, >::verify(ref merkle_tree, root, invalid_leaf, valid_proof); assert!(!result, "wrong result"); } diff --git a/packages/merkle_tree/src/tests/storage_proof_test_data.cairo b/packages/merkle_tree/src/tests/storage_proof_test_data.cairo index f7978204..9a04adf0 100644 --- a/packages/merkle_tree/src/tests/storage_proof_test_data.cairo +++ b/packages/merkle_tree/src/tests/storage_proof_test_data.cairo @@ -1,6 +1,6 @@ use alexandria_merkle_tree::storage_proof::{ - ContractStateProof, TrieNode, BinaryNodeImpl, EdgeNodeImpl, ContractStateProofImpl, - ContractDataImpl + BinaryNodeImpl, ContractDataImpl, ContractStateProof, ContractStateProofImpl, EdgeNodeImpl, + TrieNode, }; pub(crate) fn balance_proof() -> ContractStateProof { @@ -18,142 +18,142 @@ pub(crate) fn balance_proof() -> ContractStateProof { TrieNode::Binary( BinaryNodeImpl::new( 0x74b59299e8315ce3c9d679b0a439f8bd6d55f1f7544b98852c85c953ec57e8, - 0x2390819e385bb1876e077b5ed4a4bae52c0e16ae7efee4c889c3d5247f6fb60 - ) + 0x2390819e385bb1876e077b5ed4a4bae52c0e16ae7efee4c889c3d5247f6fb60, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x5ef3be75d230f16f9f62058cd51f33fe511f132400e24ede72fe931d9afcd59, - 0x404d825da685c12746a2b2b7089c13561135ac529a6624b848951993331de4f - ) + 0x404d825da685c12746a2b2b7089c13561135ac529a6624b848951993331de4f, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x5cbf312528ca49ab9012f368994adcb85f778360c68d61ddfa94e5db04e39bf, - 0x4df940db2395b5a8929cf658e36b45e88431aa9b0a1513e5318d81e83af66ca - ) + 0x4df940db2395b5a8929cf658e36b45e88431aa9b0a1513e5318d81e83af66ca, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x5e002697a7591f4cb36f024142c249493ea69f2820aae9842b085d9cd20a825, - 0x78e4c02f55114f6b4989788d52e2d03bd3416f720d090215a7f95d1178166c6 - ) + 0x78e4c02f55114f6b4989788d52e2d03bd3416f720d090215a7f95d1178166c6, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x4ad60a445f0a47f285861868f332f310b405acc3366a44483b534daefc4061b, - 0x4a3bff604eb492f216f053a8756d7c3cb2f80649c4a3fea7d5ed939b24c784c - ) + 0x4a3bff604eb492f216f053a8756d7c3cb2f80649c4a3fea7d5ed939b24c784c, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x316045f83427fc1a617bb370fa2b1a7a03d462b264729424f52c6ae00e1f71a, - 0x7ca38911fbfba4481ea60591a97b01861825c1f908dd7fc3141192b79b55d43 - ) + 0x7ca38911fbfba4481ea60591a97b01861825c1f908dd7fc3141192b79b55d43, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x17bf798cac821552f0e3d804dd9876e286c63d64d64aca19aea00ea9110ff58, - 0x33b2593a0e40d4ed0ddb6d8b7b824a2bde13062dc405c2394a8a797c35b4b32 - ) + 0x33b2593a0e40d4ed0ddb6d8b7b824a2bde13062dc405c2394a8a797c35b4b32, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x1a78b3285e1f816ec7fdeeecbd7de855c3fe50e49cb9d294c0fbe698a8f0964, - 0x737aebdf31cbf55171144bd658e0e82862541b0af78d3241e13de77015f1ce3 - ) + 0x737aebdf31cbf55171144bd658e0e82862541b0af78d3241e13de77015f1ce3, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x7267f91ecdc6e579864613a406750bc80363a2be5ff863f020e5531eb8d947a, - 0x65bcc933abbb3c71cf3edd535204f34eb58a7329a53688039733420571f45fc - ) + 0x65bcc933abbb3c71cf3edd535204f34eb58a7329a53688039733420571f45fc, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0xac490c5cda65c26fe042c08d9bec48f399db1b0c551eb3fcbcf5fc51643beb, - 0x574edd4ea6655ada56844d7b7797af4fb66fa8e86361ee201d817de885ab751 - ) + 0x574edd4ea6655ada56844d7b7797af4fb66fa8e86361ee201d817de885ab751, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x54407ae16b65fd67d64fc8528f7240cd4c6914041dd9e3bf7c56cbab58eb42e, - 0x5e7d51e63c8c33f864418dd61e720cfcda9363d9b6b1c5de11f68b2d0a9a448 - ) + 0x5e7d51e63c8c33f864418dd61e720cfcda9363d9b6b1c5de11f68b2d0a9a448, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x4550dba3e8b473bc2b4cc6c99c43ec90864930f4ec06affb267f24ad16df0b5, - 0x545515cd797a277cdb88ab7efaa63ea979220696e51c6173de23984ff1746c4 - ) + 0x545515cd797a277cdb88ab7efaa63ea979220696e51c6173de23984ff1746c4, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x14fa907e7e9633b6f3dcabfe07e8dac02e0aea480949bfd0f8dea13ecb5c50c, - 0x5448b1aac9acedab60b5401d6330bfabd397f1086ab42948ed1fa81e38a2157 - ) + 0x5448b1aac9acedab60b5401d6330bfabd397f1086ab42948ed1fa81e38a2157, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x1139a46c5e89fbcc483b8726d3e7707122b57ccdf955df4216cb1a93ffffd7a, - 0x6729ff6fec2dfcc6535bc4eea26fc4eb65e0285d4f8ae0fe6be4c343d9bb720 - ) + 0x6729ff6fec2dfcc6535bc4eea26fc4eb65e0285d4f8ae0fe6be4c343d9bb720, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x3d7dcabc79ce522ffb88b167edfd51896a6430a456250290f2ac1cdbe6572b3, - 0x990164dd962c5d48dd9a98cd8845bfdd483cbc07bbbfcd2c19daee84992e28 - ) + 0x990164dd962c5d48dd9a98cd8845bfdd483cbc07bbbfcd2c19daee84992e28, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x59cc416528b7228ed0064a393ed60462f5e556d5a236f7b94ea8d510641cd64, - 0x325c342f00e73f97c8a1ff2462c754dbb27b967223954f690e1d069e5088599 - ) + 0x325c342f00e73f97c8a1ff2462c754dbb27b967223954f690e1d069e5088599, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x3c976052cb6c461679e159c1b711e8d0261d240745931ea399edf389848f99d, - 0x4f65e0c2b833c972c02ad133e6aa152a6e9d15bca277c2b163bc09c8b2e2b1c - ) + 0x4f65e0c2b833c972c02ad133e6aa152a6e9d15bca277c2b163bc09c8b2e2b1c, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x338b6575ed50d84769024e54decfde68968be33bb266f1faa0a0fd9157e47e9, - 0x130c2fd7a701ec84b9ef42c9a45cb115581c268de360db13e748c1c2c62cc03 - ) + 0x130c2fd7a701ec84b9ef42c9a45cb115581c268de360db13e748c1c2c62cc03, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x57a2288b799d131ce7d6c934ce288e5dcc72214871e92f25420d6cb70de6f57, - 0x3be816d1fe67968529d322c2d550b3968dc846a938d4878c97f3e974c17f9b - ) + 0x3be816d1fe67968529d322c2d550b3968dc846a938d4878c97f3e974c17f9b, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x14f24c1f2b88d01188f4d72cfe1857668cb5507a92516cf356a618363aa369c, - 0x19a3203d5b1ec5a02c56f8672694f766a2a1f073430cca00362b71b19dc71f2 - ) + 0x19a3203d5b1ec5a02c56f8672694f766a2a1f073430cca00362b71b19dc71f2, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x2b54c34d1145942663561aba685c1afd12e991739a30d109fdbe17ff1416f60, - 0x547e87abcc29a44e0f57f5bd4c9ca5bddb73a8a24ef1faf188aab963158df04 - ) + 0x547e87abcc29a44e0f57f5bd4c9ca5bddb73a8a24ef1faf188aab963158df04, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x412b79bf0b5c3ac8eeca6ffc739aa9c48a0fb9834f9f683ef75400023547ea4, - 0x412022f2d1d47198766e74d76a6933348a922727170ed03c6a73b1c854bc11f - ) + 0x412022f2d1d47198766e74d76a6933348a922727170ed03c6a73b1c854bc11f, + ), ), TrieNode::Edge( EdgeNodeImpl::new( 0x221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3, 0x1fe7bef4bd2a37b56eab84508f217fd2a85694bbeb95e98049faa0de0a2011c, - 229 - ) - ) + 229, + ), + ), ], contract_data: ContractDataImpl::new( class_hash: 0x1cb96b938da26c060d5fd807eef8b580c49490926393a5eeb408a89f84b9b46, @@ -163,131 +163,131 @@ pub(crate) fn balance_proof() -> ContractStateProof { TrieNode::Binary( BinaryNodeImpl::new( 0x5b1f6f4ba862f9d83fb1c6cbfc8ab6ccf8864ff40f9cd1e86b653978b7da18e, - 0x6a14610de840e87de4c10fca04caa9fe93f854b6e3dd528dde1eedddf0ce84 - ) + 0x6a14610de840e87de4c10fca04caa9fe93f854b6e3dd528dde1eedddf0ce84, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x1e43960a3be85b1ad5a3b198617b0740b684e87a44e9e688f39cfa491cda57a, - 0x51ae9c0371c2f844155d26505bb26cf312e37aeae8e5610135579225c63b78e - ) + 0x51ae9c0371c2f844155d26505bb26cf312e37aeae8e5610135579225c63b78e, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x418949d2696cf64b33ea5f45d97bd2b21a0a664bebf96321902a01cd3b48d2a, - 0x6fd4f5c829467a9ceeb891549993fb83b8003588d8c8cff156bd1c099dbc5ef - ) + 0x6fd4f5c829467a9ceeb891549993fb83b8003588d8c8cff156bd1c099dbc5ef, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x7d07c08fa0f20455453f16b278ca6f710553339a2dbb8f58e15925a6217643, - 0x47129129d16cb646a2c34f7c9c067c9acaad81b6839b6fc09e8b80c34bebde7 - ) + 0x47129129d16cb646a2c34f7c9c067c9acaad81b6839b6fc09e8b80c34bebde7, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x175c91990d2333c3de3f370030f901f1872a24aa5f6da397a213e2a5b0d16b9, - 0x65a68f50434c58e521c95a1397ed91a10eed6e0aa2c417ca08d54caf39a0708 - ) + 0x65a68f50434c58e521c95a1397ed91a10eed6e0aa2c417ca08d54caf39a0708, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x4849c87d07ba2a2b8349c3bf55638b549888e9c04f42220f1df86aa41483a8b, - 0x19f7fc3721a344be4598e7973ee3b1b5fb1451b4d7d7bab65d6f9528ad171cc - ) + 0x19f7fc3721a344be4598e7973ee3b1b5fb1451b4d7d7bab65d6f9528ad171cc, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x68eac761b78dc264977294b7d2971160597048591ddd82a566c69f084d35843, - 0x384b4f58bf7f2cad7d361fc4f39061e9441f61053cb92aa4ca7591c1d2ce332 - ) + 0x384b4f58bf7f2cad7d361fc4f39061e9441f61053cb92aa4ca7591c1d2ce332, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x8530109039a3265f9bed7d53935d934d8b3c243559c824f936212d82568d7, - 0x609f90d6f706eb20ed763dda2409b873303257a4bd21efec3f0cef4f1e1bb15 - ) + 0x609f90d6f706eb20ed763dda2409b873303257a4bd21efec3f0cef4f1e1bb15, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x214a3f760450952ded394c66f9e771c743c8fc1b94408c3d75d7218e3c4ea0d, - 0x4acaaa512264bfad4c4fae98f7ffc61af4ab6ef12f691a93eb77498e28bd981 - ) + 0x4acaaa512264bfad4c4fae98f7ffc61af4ab6ef12f691a93eb77498e28bd981, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x132a39f6d01334cea3f78df8fc6562de3b12ecbb59c039c04d5114dcc786e4f, - 0x589c451d11284e28647bd8f69cc52316340bdbb06cc8dfd3e58693521867b8f - ) + 0x589c451d11284e28647bd8f69cc52316340bdbb06cc8dfd3e58693521867b8f, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x283b8a927ca6f39030687e134a0fbb62581152c8c356c39398c10d6439137b4, - 0x26c8829289038b3fd39cbb84a77d5b581d207b02da385fd6bdb784831b7042c - ) + 0x26c8829289038b3fd39cbb84a77d5b581d207b02da385fd6bdb784831b7042c, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x5a6263b13773bb2b02b60016825a626f4811d6f4a2015de7c6b1a34475ae518, - 0x74de5b7ad01a7652cb6f8bdd7eec2087063cd4c1c9774d8c571f42de2de790e - ) + 0x74de5b7ad01a7652cb6f8bdd7eec2087063cd4c1c9774d8c571f42de2de790e, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x19dc54d0aadb395e9592f85ed9ba3766e8427c20ed1511ad626ebfbf61c3f03, - 0x260370da71cc1846829b69960e450b73a2f0155e2e4a9c2bee14246696c5e20 - ) + 0x260370da71cc1846829b69960e450b73a2f0155e2e4a9c2bee14246696c5e20, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x14e0a63dd9f386828c7af13462d186926013c4c21c0665540a7cdbaf8129998, - 0x22fb7449e5d36d92fedc78b6748bbd197ea244a7154b2535efa1cd83d8922ee - ) + 0x22fb7449e5d36d92fedc78b6748bbd197ea244a7154b2535efa1cd83d8922ee, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x4ad9584d03093e399559c74959224dbc546d4fd5645a04663717e7f26e1ae73, - 0x1c6e23d891ecf1b564372671373a1fb6c532be0125891e8aaafe8426e9795d8 - ) + 0x1c6e23d891ecf1b564372671373a1fb6c532be0125891e8aaafe8426e9795d8, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x9ac60824ab502ac8be539b6dfeb05a3f71b74e948388bf5eb739fa53481afd, - 0x696b378cb1848e77e9ceaab566a5f42dde26de2fd5cfcbaa2fd97d03aeea47 - ) + 0x696b378cb1848e77e9ceaab566a5f42dde26de2fd5cfcbaa2fd97d03aeea47, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x46a09c16ff0771585b796f48e96ddc36e7916b397c7cbd60de12618c427552d, - 0x12842effc2e3ad5ef995ec99f002b6540049f1368187625c08086a83523fe73 - ) + 0x12842effc2e3ad5ef995ec99f002b6540049f1368187625c08086a83523fe73, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x70854f31bd97611b9896baad3d44f7de4fc20d4ab1fd4a62fb4fa7eebb2affc, - 0x518745f6fb6490d53796a377b1c04923a58041d8c8063fcd6d2d3c7e7b06d19 - ) + 0x518745f6fb6490d53796a377b1c04923a58041d8c8063fcd6d2d3c7e7b06d19, + ), ), TrieNode::Edge( EdgeNodeImpl::new( 0x3, 0x1c5f3e73c9e969b9c5a621955d4813de68ca42a777fd4915ac5e71a73219893, 2, - ) + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x59e2516845b39a0f0771e257685ac06e3c3f1f479825521be982162dd249b24, 0x1e4a53612070bf13d7677c61cb5448713d8479d57fba3d50059227d57ba0522, - ) + ), ), TrieNode::Edge( EdgeNodeImpl::new( 0x108cd202d1472587dfe63dbf2d5ec767cbf4218b59b7ab71956780c6ee, 0x78bc9be7c9e60005, 230, - ) - ) + ), + ), ], - ) + ), ) } @@ -305,142 +305,142 @@ pub(crate) fn total_balance_proof() -> ContractStateProof { TrieNode::Binary( BinaryNodeImpl::new( 0x74b59299e8315ce3c9d679b0a439f8bd6d55f1f7544b98852c85c953ec57e8, - 0x2390819e385bb1876e077b5ed4a4bae52c0e16ae7efee4c889c3d5247f6fb60 - ) + 0x2390819e385bb1876e077b5ed4a4bae52c0e16ae7efee4c889c3d5247f6fb60, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x5ef3be75d230f16f9f62058cd51f33fe511f132400e24ede72fe931d9afcd59, - 0x404d825da685c12746a2b2b7089c13561135ac529a6624b848951993331de4f - ) + 0x404d825da685c12746a2b2b7089c13561135ac529a6624b848951993331de4f, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x5cbf312528ca49ab9012f368994adcb85f778360c68d61ddfa94e5db04e39bf, - 0x4df940db2395b5a8929cf658e36b45e88431aa9b0a1513e5318d81e83af66ca - ) + 0x4df940db2395b5a8929cf658e36b45e88431aa9b0a1513e5318d81e83af66ca, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x5e002697a7591f4cb36f024142c249493ea69f2820aae9842b085d9cd20a825, - 0x78e4c02f55114f6b4989788d52e2d03bd3416f720d090215a7f95d1178166c6 - ) + 0x78e4c02f55114f6b4989788d52e2d03bd3416f720d090215a7f95d1178166c6, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x4ad60a445f0a47f285861868f332f310b405acc3366a44483b534daefc4061b, - 0x4a3bff604eb492f216f053a8756d7c3cb2f80649c4a3fea7d5ed939b24c784c - ) + 0x4a3bff604eb492f216f053a8756d7c3cb2f80649c4a3fea7d5ed939b24c784c, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x316045f83427fc1a617bb370fa2b1a7a03d462b264729424f52c6ae00e1f71a, - 0x7ca38911fbfba4481ea60591a97b01861825c1f908dd7fc3141192b79b55d43 - ) + 0x7ca38911fbfba4481ea60591a97b01861825c1f908dd7fc3141192b79b55d43, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x17bf798cac821552f0e3d804dd9876e286c63d64d64aca19aea00ea9110ff58, - 0x33b2593a0e40d4ed0ddb6d8b7b824a2bde13062dc405c2394a8a797c35b4b32 - ) + 0x33b2593a0e40d4ed0ddb6d8b7b824a2bde13062dc405c2394a8a797c35b4b32, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x1a78b3285e1f816ec7fdeeecbd7de855c3fe50e49cb9d294c0fbe698a8f0964, - 0x737aebdf31cbf55171144bd658e0e82862541b0af78d3241e13de77015f1ce3 - ) + 0x737aebdf31cbf55171144bd658e0e82862541b0af78d3241e13de77015f1ce3, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x7267f91ecdc6e579864613a406750bc80363a2be5ff863f020e5531eb8d947a, - 0x65bcc933abbb3c71cf3edd535204f34eb58a7329a53688039733420571f45fc - ) + 0x65bcc933abbb3c71cf3edd535204f34eb58a7329a53688039733420571f45fc, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0xac490c5cda65c26fe042c08d9bec48f399db1b0c551eb3fcbcf5fc51643beb, - 0x574edd4ea6655ada56844d7b7797af4fb66fa8e86361ee201d817de885ab751 - ) + 0x574edd4ea6655ada56844d7b7797af4fb66fa8e86361ee201d817de885ab751, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x54407ae16b65fd67d64fc8528f7240cd4c6914041dd9e3bf7c56cbab58eb42e, - 0x5e7d51e63c8c33f864418dd61e720cfcda9363d9b6b1c5de11f68b2d0a9a448 - ) + 0x5e7d51e63c8c33f864418dd61e720cfcda9363d9b6b1c5de11f68b2d0a9a448, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x4550dba3e8b473bc2b4cc6c99c43ec90864930f4ec06affb267f24ad16df0b5, - 0x545515cd797a277cdb88ab7efaa63ea979220696e51c6173de23984ff1746c4 - ) + 0x545515cd797a277cdb88ab7efaa63ea979220696e51c6173de23984ff1746c4, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x14fa907e7e9633b6f3dcabfe07e8dac02e0aea480949bfd0f8dea13ecb5c50c, - 0x5448b1aac9acedab60b5401d6330bfabd397f1086ab42948ed1fa81e38a2157 - ) + 0x5448b1aac9acedab60b5401d6330bfabd397f1086ab42948ed1fa81e38a2157, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x1139a46c5e89fbcc483b8726d3e7707122b57ccdf955df4216cb1a93ffffd7a, - 0x6729ff6fec2dfcc6535bc4eea26fc4eb65e0285d4f8ae0fe6be4c343d9bb720 - ) + 0x6729ff6fec2dfcc6535bc4eea26fc4eb65e0285d4f8ae0fe6be4c343d9bb720, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x3d7dcabc79ce522ffb88b167edfd51896a6430a456250290f2ac1cdbe6572b3, - 0x990164dd962c5d48dd9a98cd8845bfdd483cbc07bbbfcd2c19daee84992e28 - ) + 0x990164dd962c5d48dd9a98cd8845bfdd483cbc07bbbfcd2c19daee84992e28, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x59cc416528b7228ed0064a393ed60462f5e556d5a236f7b94ea8d510641cd64, - 0x325c342f00e73f97c8a1ff2462c754dbb27b967223954f690e1d069e5088599 - ) + 0x325c342f00e73f97c8a1ff2462c754dbb27b967223954f690e1d069e5088599, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x3c976052cb6c461679e159c1b711e8d0261d240745931ea399edf389848f99d, - 0x4f65e0c2b833c972c02ad133e6aa152a6e9d15bca277c2b163bc09c8b2e2b1c - ) + 0x4f65e0c2b833c972c02ad133e6aa152a6e9d15bca277c2b163bc09c8b2e2b1c, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x338b6575ed50d84769024e54decfde68968be33bb266f1faa0a0fd9157e47e9, - 0x130c2fd7a701ec84b9ef42c9a45cb115581c268de360db13e748c1c2c62cc03 - ) + 0x130c2fd7a701ec84b9ef42c9a45cb115581c268de360db13e748c1c2c62cc03, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x57a2288b799d131ce7d6c934ce288e5dcc72214871e92f25420d6cb70de6f57, - 0x3be816d1fe67968529d322c2d550b3968dc846a938d4878c97f3e974c17f9b - ) + 0x3be816d1fe67968529d322c2d550b3968dc846a938d4878c97f3e974c17f9b, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x14f24c1f2b88d01188f4d72cfe1857668cb5507a92516cf356a618363aa369c, - 0x19a3203d5b1ec5a02c56f8672694f766a2a1f073430cca00362b71b19dc71f2 - ) + 0x19a3203d5b1ec5a02c56f8672694f766a2a1f073430cca00362b71b19dc71f2, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x2b54c34d1145942663561aba685c1afd12e991739a30d109fdbe17ff1416f60, - 0x547e87abcc29a44e0f57f5bd4c9ca5bddb73a8a24ef1faf188aab963158df04 - ) + 0x547e87abcc29a44e0f57f5bd4c9ca5bddb73a8a24ef1faf188aab963158df04, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x412b79bf0b5c3ac8eeca6ffc739aa9c48a0fb9834f9f683ef75400023547ea4, - 0x412022f2d1d47198766e74d76a6933348a922727170ed03c6a73b1c854bc11f - ) + 0x412022f2d1d47198766e74d76a6933348a922727170ed03c6a73b1c854bc11f, + ), ), TrieNode::Edge( EdgeNodeImpl::new( 0x221cb83fa859dbdb4c44beeaa0bb37c7537ad5ae66fe5e0efd20e6eb3, 0x1fe7bef4bd2a37b56eab84508f217fd2a85694bbeb95e98049faa0de0a2011c, - 229 - ) - ) + 229, + ), + ), ], contract_data: ContractDataImpl::new( class_hash: 0x1cb96b938da26c060d5fd807eef8b580c49490926393a5eeb408a89f84b9b46, @@ -450,125 +450,125 @@ pub(crate) fn total_balance_proof() -> ContractStateProof { TrieNode::Binary( BinaryNodeImpl::new( 0x5b1f6f4ba862f9d83fb1c6cbfc8ab6ccf8864ff40f9cd1e86b653978b7da18e, - 0x6a14610de840e87de4c10fca04caa9fe93f854b6e3dd528dde1eedddf0ce84 - ) + 0x6a14610de840e87de4c10fca04caa9fe93f854b6e3dd528dde1eedddf0ce84, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x520667ac8a496785d0cd5cb089b0cb29945b562e83710fc86af2efc8036c70b, - 0x37ac663feac78c6874c9b590da7a95c81300999b98a3e81e67e68da3ea4c0da - ) + 0x37ac663feac78c6874c9b590da7a95c81300999b98a3e81e67e68da3ea4c0da, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x349bdf44a6242b9a59f1a2f7e80fa1ac46537ba79a87dfdc1242dd5e56c0e3d, - 0x4aa5bab04c0c8736256a8af971e3586fd7cf2b4c9bfcba5b0e41d6deb2c0210 - ) + 0x4aa5bab04c0c8736256a8af971e3586fd7cf2b4c9bfcba5b0e41d6deb2c0210, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x6f80e375bf182b03a572efa3d173f5e24d24c46767b539b09d5da71a6660f30, - 0x3a1195997ac1a9c0916fedc1e517f898107f3b7c77a296f9a35ff81151439aa - ) + 0x3a1195997ac1a9c0916fedc1e517f898107f3b7c77a296f9a35ff81151439aa, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x2647b8aa91f2bb4e1d69f4980edd96682f598cc48cbb20dbbf936ffc377b4e, - 0x39e7026a6f18dd6f708a8952c7b0aacbbf1db905218054297477d8c25318568 - ) + 0x39e7026a6f18dd6f708a8952c7b0aacbbf1db905218054297477d8c25318568, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x4e2a00cf57be57bbd118c9ab71895c7047183735ece0939e77788ec10e71012, - 0x41312dcf660136c32c91f58e3ee95369d19d412d64fa1ec4a23c294764bc882 - ) + 0x41312dcf660136c32c91f58e3ee95369d19d412d64fa1ec4a23c294764bc882, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x39e3c2bf03259269187def48eb867ad895db833facb97a2f470b582d36f437b, - 0x39bee0562de69bee56148afe63102e5b02f90a03633490a052bce4e34c2875f - ) + 0x39bee0562de69bee56148afe63102e5b02f90a03633490a052bce4e34c2875f, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x45db82dc29b036f35b7c66fc8dd13697daf088bbc927d25ca4cc9f1817a0089, - 0x52deda355e21ebb91d0c9b184691a18b1839ce7955120aa7fd80a6938d56f5d - ) + 0x52deda355e21ebb91d0c9b184691a18b1839ce7955120aa7fd80a6938d56f5d, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x3e4394e2845c925b8472c7ee03cefe64c395a560bd75900088b10add7f51625, - 0xfb1ea9c19ce64ee5d00bb19cf5faac2872da0745a58ebf9079b2f6ff92ebda - ) + 0xfb1ea9c19ce64ee5d00bb19cf5faac2872da0745a58ebf9079b2f6ff92ebda, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x7043bd6bb907453c60db302e508991260904d039f410ff97d38bd2d60ca5d75, - 0x76886a77ca42c2dacb8780c85afc14182b1d8e41b60f93d2599218ebd557aa7 - ) + 0x76886a77ca42c2dacb8780c85afc14182b1d8e41b60f93d2599218ebd557aa7, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x6e005e3c288932475c89a0027ab76f54305e52fdf76e1276822eafdd5467a8, - 0x6135e891729cd592e022cf5d41eff16aa7961d989e4d825f68c580578c4570 - ) + 0x6135e891729cd592e022cf5d41eff16aa7961d989e4d825f68c580578c4570, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x7fff05dc95866ab7824f986bf1397186f762e29492dd7a8acbe40f50f1d27ee, - 0x1bdf43fbab99379bdda54fbf68f8559e53e1d8a06856335bbe90c007de0e41b - ) + 0x1bdf43fbab99379bdda54fbf68f8559e53e1d8a06856335bbe90c007de0e41b, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x6ab794547fdc0c0df16d2b50d0888e9879e7d65f09b472d760035a9a2e20902, - 0x53fcb3fd666b04e0a47c1217ad463562592c6b9667e6ce6170b29f4caeb04f4 - ) + 0x53fcb3fd666b04e0a47c1217ad463562592c6b9667e6ce6170b29f4caeb04f4, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x6635812b09537421c48fe6a76a0879044797b1f29dd64575cd43b033fcd5f1c, - 0x4e330b33f2a61e74481081c85f43cc04d16aa379f2b5a78c9b18759a49fcff1 - ) + 0x4e330b33f2a61e74481081c85f43cc04d16aa379f2b5a78c9b18759a49fcff1, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x2958f83f705b6e469df752f5b3164daa32cf7b5ecb5f70d45ca1414ff506a07, - 0xfb5f65d6e84d9fcff953b7104fdd986deb87abf0d6718b6e428ba97a21238d - ) + 0xfb5f65d6e84d9fcff953b7104fdd986deb87abf0d6718b6e428ba97a21238d, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x792f8b2826c608d0505c83ce3f3856aed9e0e5fe4ee000f5bfefc2d1ffbc61c, - 0x8677c2610258f9e59456fcae3d2308fb62f1d402c2dabf849dbd756ccef424 - ) + 0x8677c2610258f9e59456fcae3d2308fb62f1d402c2dabf849dbd756ccef424, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x1701d58385b31302c77262266e4111e079c00344b991941fedd06dbd01d9396, - 0x7f986636ccc6810f859e062b93905d7ff21ac6bd902de9ee8c0701d623793fd - ) + 0x7f986636ccc6810f859e062b93905d7ff21ac6bd902de9ee8c0701d623793fd, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x4c9bfbf1f1530a1af3243e828cc0d7985b54c8c1f0c8b8b5189e49d5040068b, - 0x1b10ed0481c3d5d12f0a2eaa7a67078550c2654cbafc33763802a90cf3203b3 - ) + 0x1b10ed0481c3d5d12f0a2eaa7a67078550c2654cbafc33763802a90cf3203b3, + ), ), TrieNode::Binary( BinaryNodeImpl::new( 0x2d0cea7e0eec26969fff766b2e37d001249103fc62a621a3ff6692325fc1096, - 0xea434f6ac5a646ee23bfe12099993ea0626f4d7aa7598fe0933cfc3ce140f7 - ) + 0xea434f6ac5a646ee23bfe12099993ea0626f4d7aa7598fe0933cfc3ce140f7, + ), ), TrieNode::Edge( EdgeNodeImpl::new( 0x74624a0e3e0d8e6b72bd35514f62b3e8e70fbaff4ed27181de4ffd4604, 0x275077fb6c1316d13a907, - 232 - ) - ) + 232, + ), + ), ], - ) + ), ) } diff --git a/packages/numeric/src/cumprod.cairo b/packages/numeric/src/cumprod.cairo index 4b12c373..2d462101 100644 --- a/packages/numeric/src/cumprod.cairo +++ b/packages/numeric/src/cumprod.cairo @@ -5,7 +5,7 @@ /// * `sequence` - The sequence to operate. /// # Returns /// * `Array` - The cumulative product of sequence. -pub fn cumprod, +Copy, +Drop,>(mut sequence: Span) -> Array { +pub fn cumprod, +Copy, +Drop>(mut sequence: Span) -> Array { // [Check] Inputs assert(sequence.len() >= 1, 'Array must have at least 1 elt'); diff --git a/packages/numeric/src/cumsum.cairo b/packages/numeric/src/cumsum.cairo index 31732f4d..0e231c7e 100644 --- a/packages/numeric/src/cumsum.cairo +++ b/packages/numeric/src/cumsum.cairo @@ -5,7 +5,7 @@ /// * `sequence` - The sequence to operate. /// # Returns /// * `Array` - The cumulative sum of sequence. -pub fn cumsum, +Copy, +Drop,>(mut sequence: Span) -> Array { +pub fn cumsum, +Copy, +Drop>(mut sequence: Span) -> Array { // [Check] Inputs assert(sequence.len() >= 1, 'Array must have at least 1 elt'); diff --git a/packages/numeric/src/diff.cairo b/packages/numeric/src/diff.cairo index c59a0c97..dd7ee36d 100644 --- a/packages/numeric/src/diff.cairo +++ b/packages/numeric/src/diff.cairo @@ -6,8 +6,8 @@ use core::num::traits::Zero; /// * `sequence` - The sorted sequence to operate. /// # Returns /// * `Array` - The discrete difference of sorted sequence. -pub fn diff, +Sub, +Copy, +Drop, +Zero,>( - mut sequence: Span +pub fn diff, +Sub, +Copy, +Drop, +Zero>( + mut sequence: Span, ) -> Array { // [Check] Inputs assert(sequence.len() >= 1, 'Array must have at least 1 elt'); diff --git a/packages/numeric/src/integers.cairo b/packages/numeric/src/integers.cairo index 019dfe57..1b454cc8 100644 --- a/packages/numeric/src/integers.cairo +++ b/packages/numeric/src/integers.cairo @@ -41,14 +41,14 @@ impl U32BytesImpl of UIntBytes { (val3 / 0x1000000).try_into().unwrap(), (val2 / 0x10000).try_into().unwrap(), (val1 / 0x100).try_into().unwrap(), - val0 + val0, ] .span(); } if val2 != 0 { return array![ - (val2 / 0x10000).try_into().unwrap(), (val1 / 0x100).try_into().unwrap(), val0 + (val2 / 0x10000).try_into().unwrap(), (val1 / 0x100).try_into().unwrap(), val0, ] .span(); } diff --git a/packages/numeric/src/interpolate.cairo b/packages/numeric/src/interpolate.cairo index 6303da1e..7269075d 100644 --- a/packages/numeric/src/interpolate.cairo +++ b/packages/numeric/src/interpolate.cairo @@ -28,7 +28,7 @@ pub enum Extrapolation { pub fn interpolate< T, +PartialOrd, +Add, +Sub, +Mul, +Div, +Zero, +Copy, +Drop, >( - x: T, xs: Span, ys: Span, interpolation: Interpolation, extrapolation: Extrapolation + x: T, xs: Span, ys: Span, interpolation: Interpolation, extrapolation: Extrapolation, ) -> T { // [Check] Inputs assert!(xs.len() == ys.len(), "Arrays must have the same len"); @@ -92,7 +92,7 @@ pub fn interpolate< pub fn interpolate_fast< T, +PartialOrd, +Add, +Sub, +Mul, +Div, +Zero, +Copy, +Drop, >( - x: T, xs: Span, ys: Span, interpolation: Interpolation, extrapolation: Extrapolation + x: T, xs: Span, ys: Span, interpolation: Interpolation, extrapolation: Extrapolation, ) -> T { // [Check] Inputs assert!(xs.len() == ys.len(), "Arrays must have the same len"); diff --git a/packages/numeric/src/tests/interpolate_fast_test.cairo b/packages/numeric/src/tests/interpolate_fast_test.cairo index 35be611f..744e5b0c 100644 --- a/packages/numeric/src/tests/interpolate_fast_test.cairo +++ b/packages/numeric/src/tests/interpolate_fast_test.cairo @@ -1,5 +1,5 @@ use alexandria_numeric::interpolate::{ - interpolate_fast as interpolate, Interpolation, Extrapolation + Extrapolation, Interpolation, interpolate_fast as interpolate, }; #[test] @@ -8,10 +8,10 @@ fn interp_extrapolation_test() { let xs: Array:: = array![3, 5, 7]; let ys = array![11, 13, 17]; assert_eq!( - interpolate(0, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 11 + interpolate(0, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 11, ); assert_eq!( - interpolate(9, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 17 + interpolate(9, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 17, ); assert_eq!(interpolate(0, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Null), 0); assert_eq!(interpolate(9, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Null), 0); @@ -23,10 +23,10 @@ fn interp_linear_test() { let xs: Array:: = array![3, 5, 7]; let ys = array![11, 13, 17]; assert_eq!( - interpolate(4, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 12 + interpolate(4, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 12, ); assert_eq!( - interpolate(4, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 12 + interpolate(4, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 12, ); } @@ -36,13 +36,13 @@ fn interp_nearest_test() { let xs: Array:: = array![3, 5, 7]; let ys = array![11, 13, 17]; assert_eq!( - interpolate(4, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 11 + interpolate(4, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 11, ); assert_eq!( - interpolate(6, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 13 + interpolate(6, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 13, ); assert_eq!( - interpolate(7, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 17 + interpolate(7, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 17, ); } @@ -53,15 +53,15 @@ fn interp_constant_left_test() { let ys = array![11, 13, 17]; assert_eq!( interpolate(4, xs.span(), ys.span(), Interpolation::ConstantLeft, Extrapolation::Constant), - 13 + 13, ); assert_eq!( interpolate(6, xs.span(), ys.span(), Interpolation::ConstantLeft, Extrapolation::Constant), - 17 + 17, ); assert_eq!( interpolate(7, xs.span(), ys.span(), Interpolation::ConstantLeft, Extrapolation::Constant), - 17 + 17, ); } @@ -91,15 +91,15 @@ fn interp_constant_right_test() { let ys = array![11, 13, 17]; assert_eq!( interpolate(4, xs.span(), ys.span(), Interpolation::ConstantRight, Extrapolation::Constant), - 11 + 11, ); assert_eq!( interpolate(6, xs.span(), ys.span(), Interpolation::ConstantRight, Extrapolation::Constant), - 13 + 13, ); assert_eq!( interpolate(7, xs.span(), ys.span(), Interpolation::ConstantRight, Extrapolation::Constant), - 13 + 13, ); } diff --git a/packages/numeric/src/tests/interpolate_test.cairo b/packages/numeric/src/tests/interpolate_test.cairo index 45f4f78b..55ff4319 100644 --- a/packages/numeric/src/tests/interpolate_test.cairo +++ b/packages/numeric/src/tests/interpolate_test.cairo @@ -1,4 +1,4 @@ -use alexandria_numeric::interpolate::{interpolate, Interpolation, Extrapolation}; +use alexandria_numeric::interpolate::{Extrapolation, Interpolation, interpolate}; #[test] #[available_gas(2000000)] @@ -6,10 +6,10 @@ fn interp_extrapolation_test() { let xs: Array:: = array![3, 5, 7]; let ys = array![11, 13, 17]; assert_eq!( - interpolate(0, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 11 + interpolate(0, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 11, ); assert_eq!( - interpolate(9, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 17 + interpolate(9, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 17, ); assert_eq!(interpolate(0, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Null), 0); assert_eq!(interpolate(9, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Null), 0); @@ -21,10 +21,10 @@ fn interp_linear_test() { let xs: Array:: = array![3, 5, 7]; let ys = array![11, 13, 17]; assert_eq!( - interpolate(4, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 12 + interpolate(4, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 12, ); assert_eq!( - interpolate(4, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 12 + interpolate(4, xs.span(), ys.span(), Interpolation::Linear, Extrapolation::Constant), 12, ); } @@ -34,13 +34,13 @@ fn interp_nearest_test() { let xs: Array:: = array![3, 5, 7]; let ys = array![11, 13, 17]; assert_eq!( - interpolate(4, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 11 + interpolate(4, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 11, ); assert_eq!( - interpolate(6, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 13 + interpolate(6, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 13, ); assert_eq!( - interpolate(7, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 17 + interpolate(7, xs.span(), ys.span(), Interpolation::Nearest, Extrapolation::Constant), 17, ); } @@ -51,15 +51,15 @@ fn interp_constant_left_test() { let ys = array![11, 13, 17]; assert_eq!( interpolate(4, xs.span(), ys.span(), Interpolation::ConstantLeft, Extrapolation::Constant), - 13 + 13, ); assert_eq!( interpolate(6, xs.span(), ys.span(), Interpolation::ConstantLeft, Extrapolation::Constant), - 17 + 17, ); assert_eq!( interpolate(7, xs.span(), ys.span(), Interpolation::ConstantLeft, Extrapolation::Constant), - 17 + 17, ); } @@ -70,15 +70,15 @@ fn interp_constant_right_test() { let ys = array![11, 13, 17]; assert_eq!( interpolate(4, xs.span(), ys.span(), Interpolation::ConstantRight, Extrapolation::Constant), - 11 + 11, ); assert_eq!( interpolate(6, xs.span(), ys.span(), Interpolation::ConstantRight, Extrapolation::Constant), - 13 + 13, ); assert_eq!( interpolate(7, xs.span(), ys.span(), Interpolation::ConstantRight, Extrapolation::Constant), - 13 + 13, ); } diff --git a/packages/numeric/src/trapezoidal_rule.cairo b/packages/numeric/src/trapezoidal_rule.cairo index d703c9c7..4f97397c 100644 --- a/packages/numeric/src/trapezoidal_rule.cairo +++ b/packages/numeric/src/trapezoidal_rule.cairo @@ -22,7 +22,7 @@ pub fn trapezoidal_rule< +Zero, +Into, >( - mut xs: Span, mut ys: Span + mut xs: Span, mut ys: Span, ) -> T { // [Check] Inputs assert(xs.len() == ys.len(), 'Arrays must have the same len'); diff --git a/packages/searching/src/binary_search.cairo b/packages/searching/src/binary_search.cairo index 10790bff..5a963bec 100644 --- a/packages/searching/src/binary_search.cairo +++ b/packages/searching/src/binary_search.cairo @@ -1,5 +1,5 @@ pub fn binary_search, +Drop, +PartialEq, +PartialOrd>( - span: Span, val: T + span: Span, val: T, ) -> Option { // Initial check if span.len() == 0 { @@ -23,12 +23,12 @@ pub fn binary_search, +Drop, +PartialEq, +PartialOrd>( let val = binary_search(span.slice(middle, len), val); match val { Option::Some(v) => Option::Some(v + middle), - Option::None => Option::None + Option::None => Option::None, } } pub fn binary_search_closest, +Drop, +PartialOrd>( - span: Span, val: T + span: Span, val: T, ) -> Option { // Initial check if (span.len() == 0) { @@ -57,13 +57,13 @@ pub fn binary_search_closest, +Drop, +PartialOrd>( let index = binary_search_closest(span.slice(0, middle + 1), val); match index { Option::Some(v) => Option::Some(v), - Option::None => Option::None + Option::None => Option::None, } } else { let index = binary_search_closest(span.slice(middle, len), val); match index { Option::Some(v) => Option::Some(v + middle), - Option::None => Option::None + Option::None => Option::None, } } } diff --git a/packages/searching/src/dijkstra.cairo b/packages/searching/src/dijkstra.cairo index 74147dff..222d4a05 100644 --- a/packages/searching/src/dijkstra.cairo +++ b/packages/searching/src/dijkstra.cairo @@ -5,7 +5,7 @@ use core::nullable::{FromNullableResult, match_nullable}; pub struct Node { source: u32, dest: u32, - weight: u128 + weight: u128, } #[generate_trait] diff --git a/packages/sorting/src/interface.cairo b/packages/sorting/src/interface.cairo index 827f4697..964627e8 100644 --- a/packages/sorting/src/interface.cairo +++ b/packages/sorting/src/interface.cairo @@ -6,6 +6,6 @@ pub trait Sortable { pub trait SortableVec { fn sort, +Drop, +PartialOrd, +Felt252DictValue>( - array: Felt252Vec + array: Felt252Vec, ) -> Felt252Vec; } diff --git a/packages/sorting/src/merge_sort.cairo b/packages/sorting/src/merge_sort.cairo index b0f20678..587074dc 100644 --- a/packages/sorting/src/merge_sort.cairo +++ b/packages/sorting/src/merge_sort.cairo @@ -47,7 +47,7 @@ fn merge_recursive, +Drop, +PartialOrd>( mut right_arr: Array, ref result_arr: Array, left_arr_ix: usize, - right_arr_ix: usize + right_arr_ix: usize, ) { if result_arr.len() == left_arr.len() + right_arr.len() { return; diff --git a/packages/sorting/src/quick_sort.cairo b/packages/sorting/src/quick_sort.cairo index 652cfe5b..6880aa49 100644 --- a/packages/sorting/src/quick_sort.cairo +++ b/packages/sorting/src/quick_sort.cairo @@ -11,7 +11,7 @@ use super::SortableVec; pub impl QuickSort of SortableVec { fn sort, +Drop, +PartialOrd, +Felt252DictValue>( - mut array: Felt252Vec + mut array: Felt252Vec, ) -> Felt252Vec { let array_size = array.len(); if array_size <= 1 { @@ -24,7 +24,7 @@ pub impl QuickSort of SortableVec { } fn quick_sort_range, +Drop, +PartialOrd, +Felt252DictValue>( - ref array: Felt252Vec, left: usize, right: usize + ref array: Felt252Vec, left: usize, right: usize, ) { if left >= right { return; diff --git a/packages/storage/src/list.cairo b/packages/storage/src/list.cairo index d4d29985..0cf6afd4 100644 --- a/packages/storage/src/list.cairo +++ b/packages/storage/src/list.cairo @@ -2,7 +2,7 @@ use core::ops::index::IndexView; use core::poseidon::poseidon_hash_span; use core::traits::DivRem; use starknet::storage_access::{ - Store, StorageBaseAddress, storage_address_from_base, storage_base_address_from_felt252 + StorageBaseAddress, Store, storage_address_from_base, storage_base_address_from_felt252, }; use starknet::{SyscallResult, SyscallResultTrait}; @@ -12,11 +12,11 @@ const POW2_8: u32 = 256; // 2^8 pub struct List { pub(crate) address_domain: u32, pub(crate) base: StorageBaseAddress, - len: u32, // number of elements in array + len: u32 // number of elements in array } #[deprecated( - feature: "deprecated-list-trait", note: "Use `starknet::storage::Vec`.", since: "2.7.0" + feature: "deprecated-list-trait", note: "Use `starknet::storage::Vec`.", since: "2.7.0", )] pub trait ListTrait { /// Instantiates a new List with the given base address. @@ -173,15 +173,15 @@ impl ListImpl, +Drop, +Store> of ListTrait { match span.pop_front() { Option::Some(v) => { let (base, offset) = calculate_base_and_offset_for_index( - self.base, index, storage_size + self.base, index, storage_size, ); match Store::write_at_offset(self.address_domain, base, offset, *v) { Result::Ok(_) => {}, - Result::Err(e) => { break Result::Err(e); } + Result::Err(e) => { break Result::Err(e); }, } index += 1; }, - Option::None => { break Store::write(self.address_domain, self.base, self.len); } + Option::None => { break Store::write(self.address_domain, self.base, self.len); }, }; } } @@ -198,7 +198,7 @@ impl ListImpl, +Drop, +Store> of ListTrait { fn append(ref self: List, value: T) -> SyscallResult { let (base, offset) = calculate_base_and_offset_for_index( - self.base, self.len, self.storage_size() + self.base, self.len, self.storage_size(), ); Store::write_at_offset(self.address_domain, base, offset, value)?; @@ -215,7 +215,7 @@ impl ListImpl, +Drop, +Store> of ListTrait { } let (base, offset) = calculate_base_and_offset_for_index( - *self.base, index, self.storage_size() + *self.base, index, self.storage_size(), ); let t = Store::read_at_offset(*self.address_domain, base, offset)?; Result::Ok(Option::Some(t)) @@ -224,7 +224,7 @@ impl ListImpl, +Drop, +Store> of ListTrait { fn set(ref self: List, index: u32, value: T) -> SyscallResult<()> { assert(index < self.len, 'List index out of bounds'); let (base, offset) = calculate_base_and_offset_for_index( - self.base, index, self.storage_size() + self.base, index, self.storage_size(), ); Store::write_at_offset(self.address_domain, base, offset, value) } @@ -259,7 +259,7 @@ impl ListImpl, +Drop, +Store> of ListTrait { } let value = match self.get(index) { Result::Ok(v) => v, - Result::Err(e) => { break Result::Err(e); } + Result::Err(e) => { break Result::Err(e); }, }.expect('List index out of bounds'); array.append(value); index += 1; @@ -267,7 +267,7 @@ impl ListImpl, +Drop, +Store> of ListTrait { match result { Result::Ok(_) => Result::Ok(array), - Result::Err(e) => Result::Err(e) + Result::Err(e) => Result::Err(e), } } @@ -321,7 +321,7 @@ impl AListIndexViewImpl, +Drop, +Store> of IndexView, // so for getting a Foo at index 90 this function would return address of segment2 and offset of 26 fn calculate_base_and_offset_for_index( - list_base: StorageBaseAddress, index: u32, storage_size: u8 + list_base: StorageBaseAddress, index: u32, storage_size: u8, ) -> (StorageBaseAddress, u8) { let max_elements = POW2_8 / storage_size.into(); let (key, offset) = DivRem::div_rem(index, max_elements.try_into().unwrap()); @@ -345,7 +345,7 @@ impl ListStore> of Store> { } fn read_at_offset( - address_domain: u32, base: StorageBaseAddress, offset: u8 + address_domain: u32, base: StorageBaseAddress, offset: u8, ) -> SyscallResult> { let len: u32 = Store::read_at_offset(address_domain, base, offset).unwrap_syscall(); Result::Ok(List { address_domain, base, len }) @@ -353,7 +353,7 @@ impl ListStore> of Store> { #[inline(always)] fn write_at_offset( - address_domain: u32, base: StorageBaseAddress, offset: u8, value: List + address_domain: u32, base: StorageBaseAddress, offset: u8, value: List, ) -> SyscallResult<()> { Store::write_at_offset(address_domain, base, offset, value.len) } diff --git a/packages/storage/src/tests/list_test.cairo b/packages/storage/src/tests/list_test.cairo index 6550c05d..a281095b 100644 --- a/packages/storage/src/tests/list_test.cairo +++ b/packages/storage/src/tests/list_test.cairo @@ -1,10 +1,11 @@ use alexandria_storage::ListTrait; use core::starknet::storage::StorageAsPointer; use starknet::{ - ClassHash, ContractAddress, syscalls::deploy_syscall, SyscallResultTrait, + ClassHash, ContractAddress, SyscallResultTrait, storage_access::{ - storage_base_address_from_felt252, storage_address_from_base, StorageBaseAddress - } + StorageBaseAddress, storage_address_from_base, storage_base_address_from_felt252, + }, + syscalls::deploy_syscall, }; #[starknet::interface] @@ -12,18 +13,18 @@ trait IAListHolder { fn do_get_len(self: @TContractState) -> (u32, u32); fn do_is_empty(self: @TContractState) -> (bool, bool); fn do_append( - ref self: TContractState, addrs_value: ContractAddress, numbers_value: u256 + ref self: TContractState, addrs_value: ContractAddress, numbers_value: u256, ) -> (u32, u32); fn do_get(self: @TContractState, index: u32) -> (Option, Option); fn do_get_index(self: @TContractState, index: u32) -> (ContractAddress, u256); fn do_set( - ref self: TContractState, index: u32, addrs_value: ContractAddress, numbers_value: u256 + ref self: TContractState, index: u32, addrs_value: ContractAddress, numbers_value: u256, ); fn do_clean(ref self: TContractState); fn do_pop_front(ref self: TContractState) -> (Option, Option); fn do_array(self: @TContractState) -> (Array, Array); fn do_append_span( - ref self: TContractState, addrs_array: Array, numbers_array: Array + ref self: TContractState, addrs_array: Array, numbers_array: Array, ); } @@ -38,7 +39,7 @@ mod AListHolder { // Into addresses: List, // to test a corelib compound struct - numbers: List + numbers: List, } #[abi(embed_v0)] @@ -52,20 +53,20 @@ mod AListHolder { } fn do_append( - ref self: ContractState, addrs_value: ContractAddress, numbers_value: u256 + ref self: ContractState, addrs_value: ContractAddress, numbers_value: u256, ) -> (u32, u32) { let mut a = self.addresses.read(); let mut n = self.numbers.read(); ( a.append(addrs_value).expect('syscallresult error'), - n.append(numbers_value).expect('syscallresult error') + n.append(numbers_value).expect('syscallresult error'), ) } fn do_get(self: @ContractState, index: u32) -> (Option, Option) { ( self.addresses.read().get(index).expect('syscallresult error'), - self.numbers.read().get(index).expect('syscallresult error') + self.numbers.read().get(index).expect('syscallresult error'), ) } @@ -74,7 +75,7 @@ mod AListHolder { } fn do_set( - ref self: ContractState, index: u32, addrs_value: ContractAddress, numbers_value: u256 + ref self: ContractState, index: u32, addrs_value: ContractAddress, numbers_value: u256, ) { let mut a = self.addresses.read(); let mut n = self.numbers.read(); @@ -94,7 +95,7 @@ mod AListHolder { let mut n = self.numbers.read(); ( a.pop_front().expect('syscallresult error'), - n.pop_front().expect('syscallresult error') + n.pop_front().expect('syscallresult error'), ) } @@ -105,7 +106,9 @@ mod AListHolder { } fn do_append_span( - ref self: ContractState, addrs_array: Array, numbers_array: Array + ref self: ContractState, + addrs_array: Array, + numbers_array: Array, ) { let mut a = self.addresses.read(); let mut n = self.numbers.read(); diff --git a/packages/utils/src/fmt.cairo b/packages/utils/src/fmt.cairo index c5ba3ada..16dc29ff 100644 --- a/packages/utils/src/fmt.cairo +++ b/packages/utils/src/fmt.cairo @@ -1,10 +1,10 @@ -use core::fmt::{Display, Debug, Formatter, Error}; -use starknet::{ContractAddress, EthAddress, ClassHash, StorageAddress}; +use core::fmt::{Debug, Display, Error, Formatter}; +use starknet::{ClassHash, ContractAddress, EthAddress, StorageAddress}; /// Display mod display_felt252_based { - use core::fmt::{Display, Formatter, Error}; + use core::fmt::{Display, Error, Formatter}; pub impl TDisplay, +Copy> of Display { fn fmt(self: @T, ref f: Formatter) -> Result<(), Error> { let value: felt252 = (*self).into(); @@ -20,7 +20,7 @@ pub impl StorageAddressDisplay = display_felt252_based::TDisplay /// Debug mod debug_display_based { - use core::fmt::{Display, Debug, Formatter, Error}; + use core::fmt::{Debug, Display, Error, Formatter}; pub impl TDebug> of Debug { fn fmt(self: @T, ref f: Formatter) -> Result<(), Error> { Display::fmt(self, ref f) @@ -57,7 +57,7 @@ pub impl SpanTDebug, +Copy> of Debug> { break Result::Err(Error {}); }; }, - Option::None => { break Result::Ok(()); } + Option::None => { break Result::Ok(()); }, }; }?; write!(f, "]")