Skip to content

Commit

Permalink
first draft
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Oct 15, 2024
1 parent 0adfaab commit c8057ab
Show file tree
Hide file tree
Showing 25 changed files with 22 additions and 53 deletions.
3 changes: 1 addition & 2 deletions packages/bytes/src/bytes.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alexandria_bytes::utils::{
u128_join, read_sub_u128, u128_split, u128_array_slice, keccak_u128s_be, u8_array_to_u256,
u32s_to_u256
u128_join, read_sub_u128, u128_split, u128_array_slice, keccak_u128s_be, u32s_to_u256
};
use alexandria_math::{U128BitShift, U256BitShift};
use core::byte_array::ByteArrayTrait;
Expand Down
1 change: 0 additions & 1 deletion packages/bytes/src/tests/test_bytes.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alexandria_bytes::utils::{BytesDebug, BytesDisplay};
use alexandria_bytes::{Bytes, BytesTrait, BytesIndex};
use starknet::ContractAddress;

#[test]
#[available_gas(20000000)]
Expand Down
4 changes: 2 additions & 2 deletions packages/bytes/src/tests/test_bytes_store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ mod ABytesStore {
#[cfg(test)]
mod tests {
use alexandria_bytes::utils::{BytesDebug, BytesDisplay};
use alexandria_bytes::{Bytes, BytesTrait, BytesStore};
use alexandria_bytes::{BytesTrait, BytesStore};
use starknet::syscalls::deploy_syscall;
use starknet::{ClassHash, ContractAddress, SyscallResultTrait,};
use starknet::{ClassHash, SyscallResultTrait,};
use super::{ABytesStore, IABytesStoreDispatcher, IABytesStoreDispatcherTrait};

fn deploy() -> IABytesStoreDispatcher {
Expand Down
3 changes: 1 addition & 2 deletions packages/bytes/src/utils.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use alexandria_bytes::{Bytes, BytesTrait};
use alexandria_math::const_pow::pow2;
use alexandria_data_structures::array_ext::ArrayTraitExt;
use core::fmt::{Debug, Display, Formatter, Error};
use core::integer::u128_byte_reverse;
use core::keccak::cairo_keccak;
use core::to_byte_array::{AppendFormattedToByteArray, FormatAsByteArray};
use core::to_byte_array::FormatAsByteArray;

fn format_byte_hex(byte: u8, ref f: Formatter) -> Result<(), Error> {
let base: NonZero<u8> = 16_u8.try_into().unwrap();
Expand Down
6 changes: 3 additions & 3 deletions packages/data_structures/src/tests/array_ext.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ mod position {
}

mod occurrences {
use super::{ArrayTraitExt, get_u128_array, get_felt252_array};
use super::ArrayTraitExt;

#[test]
#[available_gas(2000000)]
Expand Down Expand Up @@ -633,7 +633,7 @@ mod max_position {
}

mod dedup {
use super::{ArrayTraitExt, get_u128_array, get_felt252_array};
use super::ArrayTraitExt;

#[test]
#[available_gas(2000000)]
Expand Down Expand Up @@ -716,7 +716,7 @@ mod dedup {
}

mod unique {
use super::{ArrayTraitExt, get_u128_array, get_felt252_array};
use super::ArrayTraitExt;

#[test]
#[available_gas(2000000)]
Expand Down
2 changes: 1 addition & 1 deletion packages/data_structures/src/tests/queue.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alexandria_data_structures::queue::{Queue, QueueTrait};
use alexandria_data_structures::queue::QueueTrait;

#[test]
#[available_gas(2000000)]
Expand Down
1 change: 0 additions & 1 deletion packages/encoding/src/sol_abi/encode.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use alexandria_bytes::{Bytes, BytesTrait};
use core::traits::TryInto;
use starknet::{ContractAddress, EthAddress};

/// Encode selector trait meant to provide an interface similar to Solidity's
Expand Down
1 change: 0 additions & 1 deletion packages/encoding/src/tests/base64_felt_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use alexandria_data_structures::array_ext::ArrayTraitExt;
use alexandria_encoding::base64::{
Base64Encoder, Base64UrlEncoder, Base64FeltEncoder, Base64UrlFeltEncoder
};
use core::traits::TryInto;

fn bytes_be(val: felt252) -> Array<u8> {
let mut result = array![];
Expand Down
9 changes: 2 additions & 7 deletions packages/math/src/bip340.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
//! bip340 implementation
use core::byte_array::ByteArrayTrait;
use core::math::u256_mul_mod_n;
use core::option::OptionTrait;
use core::result::ResultTrait;
use core::sha256::compute_sha256_byte_array; //Available in Cairo ^2.7.0.
use core::starknet::SyscallResultTrait;
use core::to_byte_array::{AppendFormattedToByteArray, FormatAsByteArray};
use core::traits::Into;

use starknet::{secp256k1::{Secp256k1Point}, secp256_trait::{Secp256Trait, Secp256PointTrait}};

Expand Down Expand Up @@ -76,7 +70,8 @@ fn hash_challenge(rx: u256, px: u256, m: ByteArray) -> u256 {
/// * `m`: `ByteArray` - The message for which the signature is being verified.
///
/// # Returns
/// * `bool` - `true` if the signature is verified for the message and public key, `false` otherwise.
/// * `bool` - `true` if the signature is verified for the message and public key, `false`
/// otherwise.
pub fn verify(px: u256, rx: u256, s: u256, m: ByteArray) -> bool {
let n = Secp256Trait::<Secp256k1Point>::get_curve_size();

Expand Down
8 changes: 3 additions & 5 deletions packages/math/src/ed25519.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use alexandria_math::mod_arithmetics::{mult_mod, sqr_mod, div_mod, pow_mod, equality_mod};
use alexandria_math::mod_arithmetics::{mult_mod, sqr_mod, div_mod, pow_mod};
use alexandria_math::sha512::{sha512, SHA512_LEN};
use alexandria_math::u512_arithmetics::{u512_add, u512_sub};
use alexandria_math::u512_arithmetics::{u512_sub};
use core::integer::{u512, u512_safe_div_rem_by_u256};
use core::math::u256_inv_mod;
use core::num::traits::{OverflowingMul, WideMul};
use core::option::OptionTrait;
use core::traits::{Div, TryInto};
use core::num::traits::WideMul;

// Subtraction without modulo operation
// assumes a, b < modulo
Expand Down
2 changes: 0 additions & 2 deletions packages/math/src/mod_arithmetics.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use core::integer::{u512, u512_safe_div_rem_by_u256};
use core::num::traits::{WrappingAdd, OverflowingAdd, OverflowingSub, WideMul};
use core::option::OptionTrait;
use core::traits::TryInto;

/// Function that performs modular addition. Will panick if result is > u256 max
/// # Arguments
Expand Down
1 change: 0 additions & 1 deletion packages/math/src/sha512.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use core::num::traits::Bounded;
use core::num::traits::WrappingAdd;
use core::traits::{BitAnd, BitXor, BitOr};
use super::BitShift;

// Variable naming is compliant to RFC-6234 (https://datatracker.ietf.org/doc/html/rfc6234)

Expand Down
3 changes: 0 additions & 3 deletions packages/math/src/tests/bip340_test.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use alexandria_math::bip340::{verify};
use core::byte_array::ByteArrayTrait;
use core::clone::Clone;
use core::option::OptionTrait;
use core::traits::Into;

impl U256IntoByteArray of Into<u256, ByteArray> {
fn into(self: u256) -> ByteArray {
Expand Down
2 changes: 1 addition & 1 deletion packages/math/src/tests/i257_test.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alexandria_math::i257::{i257, I257Impl, i257_div_rem, i257_assert_no_negative_zero};
use alexandria_math::i257::{i257, I257Impl, i257_div_rem};
use core::num::traits::Zero;

#[test]
Expand Down
1 change: 0 additions & 1 deletion packages/math/src/tests/mod_arithmetics_test.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use alexandria_math::mod_arithmetics::{add_mod, sub_mod, mult_mod, sqr_mod, div_mod, pow_mod};
use core::traits::TryInto;

const p: u256 =
57896044618658097711785492504343953926634992332820282019728792003956564819949; // 2^255 - 19
Expand Down
2 changes: 1 addition & 1 deletion packages/math/src/tests/sha512_test.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alexandria_math::sha512::{WordOperations, sha512, Word64, Word64WordOperations};
use alexandria_math::sha512::{sha512, Word64WordOperations};

fn get_lorem_ipsum() -> Array<u8> {
let mut input: Array<u8> = array![
Expand Down
1 change: 0 additions & 1 deletion packages/math/src/trigonometry.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::traits::TryInto;
const BASE_I64: i64 = 100000000;
const FAST_I90: i64 = 90 * BASE_I64;

Expand Down
2 changes: 1 addition & 1 deletion packages/merkle_tree/src/storage_proof.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alexandria_math::const_pow::pow2_felt252;
use core::hash::HashStateTrait;
use core::pedersen::PedersenTrait;
use core::poseidon::PoseidonTrait;
use alexandria_math::const_pow::pow2_felt252;

#[derive(Drop, Serde)]
pub struct BinaryNode {
Expand Down
4 changes: 1 addition & 3 deletions packages/merkle_tree/src/tests/merkle_tree_test.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Internal imports
use alexandria_merkle_tree::merkle_tree::{
Hasher, MerkleTree, pedersen::PedersenHasherImpl, poseidon::PoseidonHasherImpl, MerkleTreeTrait,
MerkleTreeImpl
Hasher, MerkleTree, pedersen::PedersenHasherImpl, poseidon::PoseidonHasherImpl, MerkleTreeImpl
};


mod regular_call_merkle_tree_pedersen {
// Internal imports
use alexandria_merkle_tree::merkle_tree::{
Expand Down
4 changes: 1 addition & 3 deletions packages/merkle_tree/src/tests/storage_proof_test.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use alexandria_merkle_tree::storage_proof::{
ContractStateProof, ContractData, TrieNode, BinaryNode, EdgeNode, verify
};
use alexandria_merkle_tree::storage_proof::verify;

use alexandria_merkle_tree::tests::storage_proof_test_data::{balance_proof, total_balance_proof};

Expand Down
4 changes: 2 additions & 2 deletions packages/merkle_tree/src/tests/storage_proof_test_data.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alexandria_merkle_tree::storage_proof::{
ContractStateProof, ContractData, TrieNode, BinaryNode, EdgeNode, BinaryNodeImpl, EdgeNodeImpl,
ContractStateProofImpl, ContractDataImpl
ContractStateProof, TrieNode, BinaryNodeImpl, EdgeNodeImpl, ContractStateProofImpl,
ContractDataImpl
};

pub(crate) fn balance_proof() -> ContractStateProof {
Expand Down
2 changes: 0 additions & 2 deletions packages/numeric/src/integers.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use alexandria_math::BitShift;

pub trait UIntBytes<T> {
fn from_bytes(input: Span<u8>) -> Option<T>;
fn to_bytes(self: T) -> Span<u8>;
Expand Down
2 changes: 1 addition & 1 deletion packages/searching/src/tests/dijkstra_test.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alexandria_searching::dijkstra::{Graph, Node, GraphTrait, NodeGetters};
use alexandria_searching::dijkstra::{GraphTrait, NodeGetters};
use core::nullable::{FromNullableResult, match_nullable};


Expand Down
5 changes: 1 addition & 4 deletions packages/storage/src/tests/list_test.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use alexandria_storage::{List, ListTrait};
use core::option::OptionTrait;
use alexandria_storage::ListTrait;
use core::starknet::storage::StorageAsPointer;
use core::traits::TryInto;
use starknet::{
ClassHash, ContractAddress, syscalls::deploy_syscall, SyscallResultTrait,
testing::set_contract_address,
storage_access::{
storage_base_address_from_felt252, storage_address_from_base, StorageBaseAddress
}
Expand Down
2 changes: 0 additions & 2 deletions packages/utils/src/fmt.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use starknet::{ContractAddress, EthAddress, ClassHash, StorageAddress};
/// Display
mod display_felt252_based {
use core::fmt::{Display, Formatter, Error};
use core::to_byte_array::AppendFormattedToByteArray;
pub impl TDisplay<T, +Into<T, felt252>, +Copy<T>> of Display<T> {
fn fmt(self: @T, ref f: Formatter) -> Result<(), Error> {
let value: felt252 = (*self).into();
Expand All @@ -22,7 +21,6 @@ pub impl StorageAddressDisplay = display_felt252_based::TDisplay<StorageAddress>
/// Debug
mod debug_display_based {
use core::fmt::{Display, Debug, Formatter, Error};
use core::to_byte_array::AppendFormattedToByteArray;
pub impl TDebug<T, +Display<T>> of Debug<T> {
fn fmt(self: @T, ref f: Formatter) -> Result<(), Error> {
Display::fmt(self, ref f)
Expand Down

0 comments on commit c8057ab

Please sign in to comment.