-
Notifications
You must be signed in to change notification settings - Fork 28
feat: Tournament System Implementation #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
anonfedora
wants to merge
9
commits into
SunsetLabs-Game:main
from
anonfedora:feat/tournament_system_implementation
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
843f0e5
feat: Tournament System Implementation
anonfedora 756b5c5
Merge branch 'main' into feat/tournament_system_implementation
anonfedora c1a8825
fix: issues
anonfedora f8c5101
fix: recommended fixes
anonfedora fbbd36f
fix: recommended fixes/ player removal
anonfedora f7cf42e
fix: address code review suggestions for tournament and guild systems
anonfedora 23e6184
feat: add complete tournament lifecycle and fix prize distribution
anonfedora 3f757de
security: fix critical vulnerabilities in tournament reward distribution
anonfedora 184e995
feat: add input validation and registration window enforcement
anonfedora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| use starknet::ContractAddress; | ||
| use core::num::traits::zero::Zero; | ||
| use crate::helpers::base::ContractAddressDefault; | ||
|
|
||
| // --- ENUMS --- | ||
|
|
||
| #[derive(Drop, Copy, Serde, Debug, Default, PartialEq, Introspect)] | ||
| pub enum GuildRole { | ||
| #[default] | ||
| Member, | ||
| Officer, | ||
| Leader, | ||
| } | ||
|
|
||
| // --- MODELS --- | ||
|
|
||
| #[dojo::model] | ||
| #[derive(Drop, Copy, Serde, Debug, Default, PartialEq)] | ||
| pub struct Guild { | ||
| #[key] | ||
| pub id: u256, | ||
| pub name: felt252, | ||
| pub leader: ContractAddress, | ||
| pub level: u32, | ||
| pub experience: u256, | ||
| pub member_count: u32, | ||
| pub max_members: u32, | ||
| pub created_at: u64, | ||
| pub description: felt252, | ||
| } | ||
|
|
||
| #[dojo::model] | ||
| #[derive(Drop, Copy, Serde, Debug, PartialEq, Default)] | ||
| pub struct GuildMember { | ||
| #[key] | ||
| pub guild_id: u256, | ||
| #[key] | ||
| pub player_id: ContractAddress, | ||
| pub role: GuildRole, | ||
| pub joined_at: u64, | ||
| pub contribution: u256, | ||
| } | ||
|
|
||
| #[dojo::model] | ||
| #[derive(Drop, Copy, Serde, Debug, PartialEq, Default)] | ||
| pub struct PlayerGuildMembership { | ||
| #[key] | ||
| pub player_id: ContractAddress, | ||
| pub guild_id: u256, | ||
| } | ||
|
|
||
| #[dojo::model] | ||
| #[derive(Drop, Copy, Serde, Debug, PartialEq, Default)] | ||
| pub struct GuildInvite { | ||
| #[key] | ||
| pub guild_id: u256, | ||
| #[key] | ||
| pub player_id: ContractAddress, | ||
| pub invited_by: ContractAddress, | ||
| pub created_at: u64, | ||
| pub expires_at: u64, | ||
| pub is_accepted: bool, | ||
| } | ||
|
|
||
| // --- EVENTS --- | ||
|
|
||
| #[derive(Copy, Drop, Serde)] | ||
| #[dojo::event] | ||
| pub struct GuildCreated { | ||
| #[key] | ||
| pub guild_id: u256, | ||
| pub leader: ContractAddress, | ||
| pub name: felt252, | ||
| } | ||
|
|
||
| #[derive(Copy, Drop, Serde)] | ||
| #[dojo::event] | ||
| pub struct GuildJoined { | ||
| #[key] | ||
| pub guild_id: u256, | ||
| pub player_id: ContractAddress, | ||
| pub role: GuildRole, | ||
| } | ||
|
|
||
| #[derive(Copy, Drop, Serde)] | ||
| #[dojo::event] | ||
| pub struct GuildLeft { | ||
| #[key] | ||
| pub guild_id: u256, | ||
| pub player_id: ContractAddress, | ||
| } | ||
|
|
||
| #[derive(Copy, Drop, Serde)] | ||
| #[dojo::event] | ||
| pub struct GuildInviteSent { | ||
| #[key] | ||
| pub guild_id: u256, | ||
| pub player_id: ContractAddress, | ||
| pub invited_by: ContractAddress, | ||
| } | ||
|
|
||
| #[derive(Copy, Drop, Serde)] | ||
| #[dojo::event] | ||
| pub struct GuildInviteAccepted { | ||
| #[key] | ||
| pub guild_id: u256, | ||
| pub player_id: ContractAddress, | ||
| } | ||
|
|
||
| #[derive(Copy, Drop, Serde)] | ||
| #[dojo::event] | ||
| pub struct GuildLevelUp { | ||
| #[key] | ||
| pub guild_id: u256, | ||
| pub new_level: u32, | ||
| } | ||
|
|
||
| // --- HELPERS & ERRORS --- | ||
|
|
||
| pub mod Errors { | ||
| pub const GUILD_NOT_FOUND: felt252 = 'Guild not found'; | ||
| pub const PLAYER_ALREADY_IN_GUILD: felt252 = 'Player already in guild'; | ||
| pub const PLAYER_NOT_IN_GUILD: felt252 = 'Player not in guild'; | ||
| pub const NOT_GUILD_LEADER: felt252 = 'Not the guild leader'; | ||
| pub const NOT_GUILD_OFFICER: felt252 = 'Not a guild officer'; | ||
| pub const GUILD_FULL: felt252 = 'Guild is full'; | ||
| pub const INVALID_GUILD_NAME: felt252 = 'Invalid guild name'; | ||
| pub const INSUFFICIENT_PERMISSIONS: felt252 = 'Insufficient permissions'; | ||
| pub const INVITE_NOT_FOUND: felt252 = 'Invite not found'; | ||
| pub const INVITE_EXPIRED: felt252 = 'Invite expired'; | ||
| pub const ALREADY_INVITED: felt252 = 'Player already invited'; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Potential reentrancy vulnerability in
deduct_creditsThe function checks the balance before burning, creating a potential race condition. Between the balance check and the burn operation, the player's credits could be modified by another transaction, leading to an incorrect burn amount.
Apply this diff to make the operation atomic:
fn deduct_credits(ref self: Player, amount: u256, erc1155_address: ContractAddress) { self.check(); assert(amount > 0, 'INVALID AMOUNT'); - assert(self.get_credits(erc1155_address) >= amount, 'Insufficient credits'); + // Let the burn function handle insufficient balance checks self.burn(CREDITS, erc1155_address, amount); }The ERC1155 contract should handle the balance validation atomically during the burn operation.
π Committable suggestion
π€ Prompt for AI Agents