Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions yahia008/assignment_1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
6 changes: 6 additions & 0 deletions yahia008/assignment_1/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "assignment_1"
version = "0.1.0"
14 changes: 14 additions & 0 deletions yahia008/assignment_1/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "assignment_1"
version = "0.1.0"
edition = "2025_12"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[executable]

[cairo]
enable-gas = false

[dependencies]
cairo_execute = "2.17.0"
74 changes: 74 additions & 0 deletions yahia008/assignment_1/src/assignment1.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
use core::num::traits::CheckedMul;
use core::num::traits::CheckedAdd;
use core::num::traits::CheckedSub;

#[derive(Drop)]
enum MathError {
Overflow,
DivisionByZero,
Underflow,
}


#[executable]
fn main() {
let add_result = add_number(0, 0);
match add_result {
Result::Ok(v) => {
assert!(v==0, "assertion failed")
println!("add value {}", v)
},
Result::Err(_) => println!("add error ", ),
};

let mul_result = multiply_number(10, 5);
match mul_result {
Result::Ok(v) => {
assert!(v==50, "assertion failed")
println!("mul value {}", v)
},
Result::Err(_) => println!("mul error"),
};


let div_result = divide(10, 2);
match div_result {
Result::Ok(v) => {
assert!(v==5, "assertion failed")
println!("div value {}", v)
},
Result::Err(_) => println!("div error", ),
};

let sub_result = sub_num(10, 7);
match sub_result {
Result::Ok(v) => {
assert!(v==3, "assertion failed")
println!("sub value {}", v)
},
Result::Err(_) => println!("sub error"),
};
}



fn add_number(x: u128, y: u128) -> Result<u128, MathError> {
x.checked_add(y).ok_or(MathError::Overflow)
}

fn multiply_number(x:u128, y:u128) -> Result<u128, MathError> {
x.checked_mul(y).ok_or(MathError::Overflow)
}

fn divide(x: u128, y: u128) -> Result<u128, MathError>{
if y == 0 {
return Result::Err(MathError::DivisionByZero);
}

Result::Ok(x / y)
}

fn sub_num(x:u128, y:u128) -> Result<u128, MathError>{
x.checked_sub(y).ok_or(MathError::Underflow)
}

1 change: 1 addition & 0 deletions yahia008/assignment_1/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod assignment1;
5 changes: 5 additions & 0 deletions yahia008/assignment_2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.snfoundry_cache/
snfoundry_trace/
coverage/
profile/
24 changes: 24 additions & 0 deletions yahia008/assignment_2/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "assignment_2"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_scarb_plugin"
version = "0.59.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:871fba677c03b66a1bf40815dac0ab1b385eb1b9be6e6c3cf2ad9788eeb2b6bb"

[[package]]
name = "snforge_std"
version = "0.59.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:3620924fa08bd2d740b2b5b01ef86c8dab3d4b9c2206387c8dbdc8d2ec15133e"
dependencies = [
"snforge_scarb_plugin",
]
52 changes: 52 additions & 0 deletions yahia008/assignment_2/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "assignment_2"
version = "0.1.0"
edition = "2024_07"

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[dependencies]
starknet = "2.17.0"

[dev-dependencies]
snforge_std = "0.59.0"
assert_macros = "2.17.0"

[[target.starknet-contract]]
sierra = true

[scripts]
test = "snforge test"

[tool.scarb]
allow-prebuilt-plugins = ["snforge_std"]

# Visit https://foundry-rs.github.io/starknet-foundry/appendix/scarb-toml.html for more information

# [tool.snforge] # Define `snforge` tool section
# exit_first = true # Stop tests execution immediately upon the first failure
# fuzzer_runs = 1234 # Number of runs of the random fuzzer
# fuzzer_seed = 1111 # Seed for the random fuzzer

# [[tool.snforge.fork]] # Used for fork testing
# name = "SOME_NAME" # Fork name
# url = "http://your.rpc.url" # Url of the RPC provider
# block_id.tag = "latest" # Block to fork from (block tag)

# [[tool.snforge.fork]]
# name = "SOME_SECOND_NAME"
# url = "http://your.second.rpc.url"
# block_id.number = "123" # Block to fork from (block number)

# [[tool.snforge.fork]]
# name = "SOME_THIRD_NAME"
# url = "http://your.third.rpc.url"
# block_id.hash = "0x123" # Block to fork from (block hash)

# [profile.dev.cairo] # Configure Cairo compiler
# unstable-add-statements-code-locations-debug-info = true # Should be used if you want to use coverage
# unstable-add-statements-functions-debug-info = true # Should be used if you want to use coverage/profiler
# inlining-strategy = "avoid" # Should be used if you want to use coverage

# [features] # Used for conditional compilation
# enable_for_tests = [] # Feature name and list of other features that should be enabled with it
11 changes: 11 additions & 0 deletions yahia008/assignment_2/snfoundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Visit https://foundry-rs.github.io/starknet-foundry/appendix/snfoundry-toml.html
# and https://foundry-rs.github.io/starknet-foundry/projects/configuration.html for more information

# [sncast.default] # Define a profile name
# url = "https://api.zan.top/public/starknet-sepolia/rpc/v0_10" # Url of the RPC provider
# accounts-file = "../account-file" # Path to the file with the account data
# account = "mainuser" # Account from `accounts_file` or default account file that will be used for the transactions
# keystore = "~/keystore" # Path to the keystore file
# wait-params = { timeout = 300, retry-interval = 10 } # Wait for submitted transaction parameters
# block-explorer = "Voyager" # Block explorer service used to display links to transaction details
# show-explorer-links = true # Print links pointing to pages with transaction details in the chosen block explorer
77 changes: 77 additions & 0 deletions yahia008/assignment_2/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
mod mylogic;
use starknet::{ContractAddress};
#[starknet::interface]
pub trait ICounter<T> {
fn get_count(self: @T) -> u128;
fn get_owner(self: @T) -> ContractAddress;
fn transfer_ownership(ref self: T, new_owner: ContractAddress);
fn increase_count(ref self: T, amount: u128);
fn decrease_count (ref self:T, amount:u128);
fn reset_count(ref self:T);



}

#[starknet::contract]
mod CounterV2{
use crate::mylogic;
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};

use super::ICounter;
use starknet::ContractAddress;
use starknet::get_caller_address;


#[storage]
struct Storage{
count:u128,
owner:ContractAddress
}

#[constructor]
fn constructor(ref self:ContractState, initial_owner:ContractAddress){
self.owner.write(initial_owner);
self.count.write(0);
}

#[abi(embed_v0)]
impl ICounterimpl of ICounter<ContractState> {

fn get_count(self: @ContractState) -> u128 {
self.count.read()
}
fn get_owner(self: @ContractState) -> ContractAddress{
self.owner.read()
}
fn transfer_ownership(ref self: ContractState, new_owner: ContractAddress){
let caller = get_caller_address();
assert!(caller == self.owner.read(), "Only owner can transfer");
self.owner.write(new_owner);
}
fn increase_count(ref self: ContractState, amount: u128){
let caller:ContractAddress = get_caller_address();
assert!(caller == self.owner.read(), "Only owner can change state");

let current = self.count.read();
let new:u128 = mylogic::increase_count(current, amount);
self.count.write(new);
}
fn decrease_count (ref self:ContractState, amount:u128){
let caller:ContractAddress = get_caller_address();
assert!(caller == self.owner.read(), "Only owner can change state");

let current = self.count.read();
let new:u128 = mylogic::decrease_count(current, amount);
self.count.write(new);
}
fn reset_count(ref self:ContractState){
let caller = get_caller_address();
assert!(caller == self.owner.read(), "Only owner can change state");
let new:u128 = mylogic::reset_count();
self.count.write(new);


}
}
}
24 changes: 24 additions & 0 deletions yahia008/assignment_2/src/mylogic.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use core::num::traits::CheckedAdd;
use core::num::traits::CheckedSub;



pub fn increase_count(current: u128, amount: u128) -> u128{
if amount == 0
{
return current;
}
current.checked_add(amount).expect('overflow')
}

pub fn decrease_count(current: u128, amount: u128) -> u128 {
if amount == 0
{
return current;
}
current.checked_sub(amount).expect('underflow')
}

pub fn reset_count() -> u128 {
0
}
1 change: 1 addition & 0 deletions yahia008/av2_pro/arithmetic_logic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target
6 changes: 6 additions & 0 deletions yahia008/av2_pro/arithmetic_logic/Scarb.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code generated by scarb DO NOT EDIT.
version = 1

[[package]]
name = "arithmetic_logic"
version = "0.1.0"
19 changes: 19 additions & 0 deletions yahia008/av2_pro/arithmetic_logic/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "arithmetic_logic"
version = "0.1.0"
edition = "2025_12"


[lib]
sierra = true

# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html

[executable]

[cairo]
enable-gas = false

[dependencies]
cairo_execute = "2.17.0"

1 change: 1 addition & 0 deletions yahia008/av2_pro/arithmetic_logic/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod mylogic;
46 changes: 46 additions & 0 deletions yahia008/av2_pro/arithmetic_logic/src/mylogic.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use core::num::traits::CheckedAdd;
use core::num::traits::CheckedSub;
use core::num::traits::CheckedMul;

#[derive(Drop)]
enum MathError {
Overflow,
DivisionByZero,
Underflow,
}


pub fn add_num(x: u128, y: u128) -> u128{
if y == 0
{
return x;
}
x.checked_add(y).expect('overflow')
}

pub fn sub_num(x: u128, y: u128) -> u128 {
if y == 0
{
return x;
}
x.checked_sub(y).expect('underflow')
}

pub fn multiply_number(x:u128, y:u128) -> Result<u128, MathError> {
if x == 0 || y == 0 {
return Result::Ok(0);
}
x.checked_mul(y).ok_or(MathError::Overflow)
}

pub fn divide(x: u128, y: u128) -> Result<u128, MathError>{
if y == 0 {
return Result::Err(MathError::DivisionByZero);
}

Result::Ok(x / y)
}

pub fn reset_count() -> u128 {
0
}
5 changes: 5 additions & 0 deletions yahia008/av2_pro/counterv2_pro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
target
.snfoundry_cache/
snfoundry_trace/
coverage/
profile/
Loading