Skip to content
This repository was archived by the owner on Aug 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# =============================================================================
# GLOBAL OWNERS
# =============================================================================
* @NethermindEth/nubia-admins
* @NethermindEth/nubia-general
* @NethermindEth/nubia-starknet-by-example
* @NethermindEth/nubia-starknet-by-example-admin
* @NethermindEth/role_angkor_admin
* @NethermindEth/role_legal_users
* @NethermindEth/role_nubia_admin
* @NethermindEth/security-admins

# =============================================================================
# INDIVIDUALS
# =============================================================================
* @julio4
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Starknet by Example

Dev preview at: https://starknet-by-example-dev.voyager.online/
> [!WARNING]
> Starknet By Example was moved to [Starkware's official Starknet documentation](https://github.com/starknet-io/starknet-docs/tree/main/modules/archive/pages/starknet-by-example). This repository is now archived and may not be up to date.

## Description

Expand Down
46 changes: 42 additions & 4 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ dependencies = [
[[package]]
name = "commit_reveal"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "components"
Expand Down Expand Up @@ -125,13 +128,24 @@ dependencies = [
name = "factory"
version = "0.1.0"

[[package]]
name = "garaga"
version = "0.15.5"
source = "git+https://github.com/keep-starknet-strange/garaga.git?tag=v0.15.5#8cc51a86a84401b063b39520e2d67254baeaebe5"

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

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

[[package]]
name = "l1_l2_token_bridge"
Expand All @@ -143,6 +157,9 @@ dependencies = [
[[package]]
name = "library_calls"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "mappings"
Expand All @@ -154,6 +171,9 @@ dependencies = [
[[package]]
name = "merkle_tree"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "nft_dutch_auction"
Expand Down Expand Up @@ -267,17 +287,26 @@ dependencies = [
"snforge_std",
]

[[package]]
name = "snarkjs"
version = "0.1.0"
dependencies = [
"garaga",
"openzeppelin_token",
"snforge_std",
]

[[package]]
name = "snforge_scarb_plugin"
version = "0.38.0"
version = "0.38.3"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:c4d128eedb5fca4362be38a84e5f5a85bd94ec1557bab7c045d48de0163e406c"
checksum = "sha256:0cd914b547acd96b4cad99a78e95c0eda001d0c280da4969b2161e286079cf46"

[[package]]
name = "snforge_std"
version = "0.38.0"
version = "0.38.3"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:8b3eaff778105c313b78708974c253cd927ecf5c896f4557a0ea4f10f427b554"
checksum = "sha256:d376526fbbe22535ad89ed630b11d6e209f22c50168de6c6430c0591c81c3174"
dependencies = [
"snforge_scarb_plugin",
]
Expand All @@ -299,6 +328,9 @@ dependencies = [
[[package]]
name = "store_using_packing"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "storing_custom_types"
Expand All @@ -310,6 +342,9 @@ dependencies = [
[[package]]
name = "struct_as_mapping_key"
version = "0.1.0"
dependencies = [
"snforge_std",
]

[[package]]
name = "testing_how_to"
Expand Down Expand Up @@ -353,3 +388,6 @@ dependencies = [
[[package]]
name = "write_to_any_slot"
version = "0.1.0"
dependencies = [
"snforge_std",
]
1 change: 1 addition & 0 deletions Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ openzeppelin_token = "1.0.0"
openzeppelin_utils = "1.0.0"
components = { path = "listings/applications/components" }
pragma_lib = { git = "https://github.com/astraly-labs/pragma-lib", tag = "2.9.1" }
garaga = { git = "https://github.com/keep-starknet-strange/garaga.git", tag = "v0.15.5" }

[workspace.package]
description = "Collection of examples of how to use the Cairo programming language to create smart contracts on Starknet."
Expand Down
2 changes: 1 addition & 1 deletion _typos.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[default]
extend-ignore-identifiers-re = ["requestor", "REQUESTOR", "Requestor"]
extend-ignore-identifiers-re = ["requestor", "REQUESTOR", "Requestor", "groth", "Groth"]

[type.po]
extend-glob = ["*.po", "*.css", "*.js"]
Expand Down
3 changes: 2 additions & 1 deletion listings/advanced-concepts/commit_reveal/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ edition.workspace = true
starknet.workspace = true

[dev-dependencies]
cairo_test.workspace = true
assert_macros.workspace = true
snforge_std.workspace = true

[scripts]
test.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub trait ICommitmentRevealTrait<T> {

// [!region contract]
#[starknet::contract]
pub mod CommitmentRevealTraits {
mod CommitmentRevealTraits {
use starknet::storage::{StoragePointerWriteAccess, StoragePointerReadAccess};
use core::hash::HashStateTrait;
use core::pedersen::PedersenTrait;
Expand All @@ -32,26 +32,20 @@ pub mod CommitmentRevealTraits {

#[cfg(test)]
mod tests {
use super::{
CommitmentRevealTraits, ICommitmentRevealTraitDispatcher,
ICommitmentRevealTraitDispatcherTrait,
};

use super::{ICommitmentRevealTraitDispatcher, ICommitmentRevealTraitDispatcherTrait};
use core::hash::HashStateTrait;
use core::pedersen::PedersenTrait;
use starknet::syscalls::deploy_syscall;
use snforge_std::{ContractClassTrait, DeclareResultTrait, declare};

fn deploy() -> ICommitmentRevealTraitDispatcher {
let (contract_address, _) = deploy_syscall(
CommitmentRevealTraits::TEST_CLASS_HASH.try_into().unwrap(), 0, array![].span(), false,
)
.unwrap();
let contract = declare("CommitmentRevealTraits").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![]).unwrap();
ICommitmentRevealTraitDispatcher { contract_address }
}

#[test]
fn commit_and_reveal() {
let mut contract = deploy();
let contract = deploy();

// [!region offchain]
// Off-chain, compute the commitment hash for secret
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ edition.workspace = true
starknet.workspace = true

[dev-dependencies]
cairo_test.workspace = true
assert_macros.workspace = true
snforge_std.workspace = true

[scripts]
test.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub trait ISolidityHashExample<TContractState> {
}

#[starknet::contract]
pub mod SolidityHashExample {
mod SolidityHashExample {
use core::keccak::keccak_u256s_be_inputs;
use core::integer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
mod tests {
use hash_solidity_compatible::contract::{SolidityHashExample, ISolidityHashExample};
use starknet::{contract_address_const, testing::set_contract_address};
use hash_solidity_compatible::contract::{
ISolidityHashExampleDispatcher, ISolidityHashExampleDispatcherTrait,
};
use snforge_std::{ContractClassTrait, DeclareResultTrait, declare};

fn setup() -> SolidityHashExample::ContractState {
let mut state = SolidityHashExample::contract_state_for_testing();
let contract_address = contract_address_const::<0x1>();
set_contract_address(contract_address);
state
}

#[test]
fn get_same_hash_solidity() {
let mut state = setup();
let mut array: Array<u256> = array![];
array.append(1);

let hash_expected: u256 =
0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6;
let hash_received: u256 = state.hash_data(array.span());
fn setup() -> ISolidityHashExampleDispatcher {
let contract = declare("SolidityHashExample").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![]).unwrap();
ISolidityHashExampleDispatcher { contract_address }
}

assert_eq!(hash_received, hash_expected);
}
#[test]
fn get_same_hash_solidity() {
let contract = setup();
let hash_expected: u256 = 0xb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6;
assert_eq!(contract.hash_data(array![1].span()), hash_expected);
}
3 changes: 2 additions & 1 deletion listings/advanced-concepts/hash_trait/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ edition.workspace = true
starknet.workspace = true

[dev-dependencies]
cairo_test.workspace = true
assert_macros.workspace = true
snforge_std.workspace = true

[scripts]
test.workspace = true
Expand Down
19 changes: 8 additions & 11 deletions listings/advanced-concepts/hash_trait/src/hash_trait.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait IHashTrait<T> {

// [!region hash]
#[starknet::contract]
pub mod HashTraits {
mod HashTraits {
use starknet::storage::StoragePointerWriteAccess;
use core::hash::{HashStateTrait, HashStateExTrait};
use core::{pedersen::PedersenTrait, poseidon::PoseidonTrait};
Expand Down Expand Up @@ -64,22 +64,19 @@ pub mod HashTraits {

#[cfg(test)]
mod tests {
use super::{HashTraits, IHashTraitDispatcher, IHashTraitDispatcherTrait};
use starknet::syscalls::deploy_syscall;
use super::{IHashTraitDispatcher, IHashTraitDispatcherTrait};
use snforge_std::{ContractClassTrait, DeclareResultTrait, declare};

fn deploy() -> IHashTraitDispatcher {
let mut calldata = array![];
let (address, _) = deploy_syscall(
HashTraits::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false,
)
.unwrap();
IHashTraitDispatcher { contract_address: address }
let contract = declare("HashTraits").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![]).unwrap();
IHashTraitDispatcher { contract_address }
}


#[test]
fn test_pedersen_hash() {
let mut contract = deploy();
let contract = deploy();

let id = 0x1;
let username = 'A.stark';
Expand All @@ -91,7 +88,7 @@ mod tests {

#[test]
fn test_poseidon_hash() {
let mut contract = deploy();
let contract = deploy();

let id = 0x1;
let username = 'A.stark';
Expand Down
3 changes: 2 additions & 1 deletion listings/advanced-concepts/library_calls/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ edition.workspace = true
starknet.workspace = true

[dev-dependencies]
cairo_test.workspace = true
assert_macros.workspace = true
snforge_std.workspace = true

[scripts]
test.workspace = true
Expand Down
33 changes: 13 additions & 20 deletions listings/advanced-concepts/library_calls/src/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
mod tests {
use starknet::syscalls::deploy_syscall;
use library_calls::library_call::{
MathUtils, MathUtilsLibraryCall, IMathUtilsDispatcher, IMathUtilsDispatcherTrait,
};
use library_calls::library_call::{IMathUtilsDispatcher, IMathUtilsDispatcherTrait};
use snforge_std::{ContractClassTrait, DeclareResultTrait, declare};

#[test]
fn test_library_dispatcher() {
let math_utils_class_hash: starknet::ClassHash = MathUtils::TEST_CLASS_HASH
.try_into()
.unwrap();
let mut calldata: Array<felt252> = array![];
let (address, _) = deploy_syscall(
MathUtilsLibraryCall::TEST_CLASS_HASH.try_into().unwrap(), 0, calldata.span(), false,
)
.unwrap();
let mut contract = IMathUtilsDispatcher { contract_address: address };
#[test]
fn test_library_dispatcher() {
let math_utils = declare("MathUtils").unwrap().contract_class();

contract.set_class_hash(math_utils_class_hash);
let mut result = contract.add(30, 5);
assert_eq!(result, 35, "Wrong result");
}
let contract = declare("MathUtilsLibraryCall").unwrap().contract_class();
let (contract_address, _) = contract.deploy(@array![]).unwrap();
let contract = IMathUtilsDispatcher { contract_address };

contract.set_class_hash(*math_utils.class_hash);

let mut result = contract.add(30, 5);
assert_eq!(result, 35, "Wrong result");
}
3 changes: 2 additions & 1 deletion listings/advanced-concepts/store_using_packing/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ edition.workspace = true
starknet.workspace = true

[dev-dependencies]
cairo_test.workspace = true
assert_macros.workspace = true
snforge_std.workspace = true

[scripts]
test.workspace = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait ITime<TContractState> {
}

#[starknet::contract]
pub mod TimeContract {
mod TimeContract {
use starknet::storage::{StoragePointerWriteAccess, StoragePointerReadAccess};
use super::Time;
use starknet::storage_access::StorePacking;
Expand Down
Loading
Loading