Skip to content
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
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
scarb 2.7.0
dojo 1.0.0-alpha.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,365 @@
[
{
"type": "impl",
"name": "ContractImpl",
"interface_name": "dojo::contract::contract::IContract"
},
{
"type": "struct",
"name": "core::byte_array::ByteArray",
"members": [
{
"name": "data",
"type": "core::array::Array::<core::bytes_31::bytes31>"
},
{
"name": "pending_word",
"type": "core::felt252"
},
{
"name": "pending_word_len",
"type": "core::integer::u32"
}
]
},
{
"type": "interface",
"name": "dojo::contract::contract::IContract",
"items": [
{
"type": "function",
"name": "contract_name",
"inputs": [],
"outputs": [
{
"type": "core::byte_array::ByteArray"
}
],
"state_mutability": "view"
},
{
"type": "function",
"name": "namespace",
"inputs": [],
"outputs": [
{
"type": "core::byte_array::ByteArray"
}
],
"state_mutability": "view"
},
{
"type": "function",
"name": "tag",
"inputs": [],
"outputs": [
{
"type": "core::byte_array::ByteArray"
}
],
"state_mutability": "view"
},
{
"type": "function",
"name": "name_hash",
"inputs": [],
"outputs": [
{
"type": "core::felt252"
}
],
"state_mutability": "view"
},
{
"type": "function",
"name": "namespace_hash",
"inputs": [],
"outputs": [
{
"type": "core::felt252"
}
],
"state_mutability": "view"
},
{
"type": "function",
"name": "selector",
"inputs": [],
"outputs": [
{
"type": "core::felt252"
}
],
"state_mutability": "view"
}
]
},
{
"type": "impl",
"name": "WorldProviderImpl",
"interface_name": "dojo::world::world_contract::IWorldProvider"
},
{
"type": "struct",
"name": "dojo::world::world_contract::IWorldDispatcher",
"members": [
{
"name": "contract_address",
"type": "core::starknet::contract_address::ContractAddress"
}
]
},
{
"type": "interface",
"name": "dojo::world::world_contract::IWorldProvider",
"items": [
{
"type": "function",
"name": "world",
"inputs": [],
"outputs": [
{
"type": "dojo::world::world_contract::IWorldDispatcher"
}
],
"state_mutability": "view"
}
]
},
{
"type": "impl",
"name": "TournamentActionImpl",
"interface_name": "bytebeasts::systems::tournament::ITournamentAction"
},
{
"type": "enum",
"name": "bytebeasts::models::tournament::TournamentStatus",
"variants": [
{
"name": "Pending",
"type": "()"
},
{
"name": "Ongoing",
"type": "()"
},
{
"name": "Completed",
"type": "()"
}
]
},
{
"type": "struct",
"name": "bytebeasts::models::tournament::Tournament",
"members": [
{
"name": "tournament_id",
"type": "core::integer::u32"
},
{
"name": "name",
"type": "core::felt252"
},
{
"name": "status",
"type": "bytebeasts::models::tournament::TournamentStatus"
},
{
"name": "entry_fee",
"type": "core::integer::u32"
},
{
"name": "max_participants",
"type": "core::integer::u32"
},
{
"name": "current_participants",
"type": "core::array::Array::<core::integer::u32>"
},
{
"name": "prize_pool",
"type": "core::integer::u32"
}
]
},
{
"type": "interface",
"name": "bytebeasts::systems::tournament::ITournamentAction",
"items": [
{
"type": "function",
"name": "create_tournament",
"inputs": [
{
"name": "tournament_id",
"type": "core::integer::u32"
},
{
"name": "name",
"type": "core::felt252"
},
{
"name": "status",
"type": "bytebeasts::models::tournament::TournamentStatus"
},
{
"name": "entry_fee",
"type": "core::integer::u32"
},
{
"name": "max_participants",
"type": "core::integer::u32"
},
{
"name": "current_participants",
"type": "core::array::Array::<core::integer::u32>"
},
{
"name": "prize_pool",
"type": "core::integer::u32"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "register_player",
"inputs": [
{
"name": "tournament_id",
"type": "core::integer::u32"
},
{
"name": "new_player_id",
"type": "core::integer::u32"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "start_tournament",
"inputs": [
{
"name": "tournament_id",
"type": "core::integer::u32"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "complete_tournament",
"inputs": [
{
"name": "tournament_id",
"type": "core::integer::u32"
},
{
"name": "player_id",
"type": "core::integer::u32"
}
],
"outputs": [],
"state_mutability": "external"
},
Comment on lines +255 to +269
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Potential issue

Based on the implementation found, I can now provide a final response:

Access control and validation concerns confirmed for complete_tournament

The implementation has the following issues:

  • No access control checks for who can call complete_tournament
  • Anyone can declare a winner as long as they're a participant
  • Missing validation that tournament hasn't already been completed

Recommended changes:

  • Add access control to restrict who can complete tournaments (e.g., tournament creator or admin)
  • Add a check to prevent double-completion
  • Consider adding a verification mechanism for the winner beyond just participant status
🔗 Analysis chain

Verify access control and state validation for complete_tournament

The new complete_tournament function needs additional safeguards:

  1. Verify that player_id is a current participant
  2. Ensure tournament is in Ongoing status
  3. Implement access control for who can complete a tournament

Consider adding these checks to prevent unauthorized tournament completions.


Let me search for the tournament system implementation to verify the access controls and state validation.


Let me try searching with ripgrep instead to find the implementation.


Let me check for any access control mechanisms in the tournament system.


Let me try one more search to find the contract definition and any access control patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for access control implementations in the contract
rg -A 5 "complete_tournament|access|permission|owner" src/

Length of output: 69729


Script:

#!/bin/bash
# Search for tournament system implementation
ast-grep --pattern $'fn complete_tournament(ref world: IWorldDispatcher, tournament_id: u32, player_id: u32) {
  $$$
}'

Length of output: 120


Script:

#!/bin/bash
# Search for tournament system implementation with context
rg -U "fn complete_tournament.*\{[\s\S]*?\}" -A 10 src/

Length of output: 1579


Script:

#!/bin/bash
# Search for tournament system contract definition and any access control
rg -B 5 -A 5 "#\[dojo::contract\].*tournament" src/

Length of output: 53


Script:

#!/bin/bash
# Search for tournament system contract and implementation
rg -B 5 -A 10 "contract\]|impl TournamentSystem|fn complete_tournament" src/systems/tournament.cairo

Length of output: 1521

{
"type": "function",
"name": "get_tournament",
"inputs": [
{
"name": "tournament_id",
"type": "core::integer::u32"
}
],
"outputs": [
{
"type": "bytebeasts::models::tournament::Tournament"
}
],
"state_mutability": "view"
}
]
},
{
"type": "impl",
"name": "IDojoInitImpl",
"interface_name": "bytebeasts::systems::tournament::tournament_system::IDojoInit"
},
{
"type": "interface",
"name": "bytebeasts::systems::tournament::tournament_system::IDojoInit",
"items": [
{
"type": "function",
"name": "dojo_init",
"inputs": [],
"outputs": [],
"state_mutability": "view"
}
]
},
{
"type": "impl",
"name": "UpgradableImpl",
"interface_name": "dojo::contract::upgradeable::IUpgradeable"
},
{
"type": "interface",
"name": "dojo::contract::upgradeable::IUpgradeable",
"items": [
{
"type": "function",
"name": "upgrade",
"inputs": [
{
"name": "new_class_hash",
"type": "core::starknet::class_hash::ClassHash"
}
],
"outputs": [],
"state_mutability": "external"
}
]
},
{
"type": "event",
"name": "dojo::contract::upgradeable::upgradeable::Upgraded",
"kind": "struct",
"members": [
{
"name": "class_hash",
"type": "core::starknet::class_hash::ClassHash",
"kind": "data"
}
]
},
{
"type": "event",
"name": "dojo::contract::upgradeable::upgradeable::Event",
"kind": "enum",
"variants": [
{
"name": "Upgraded",
"type": "dojo::contract::upgradeable::upgradeable::Upgraded",
"kind": "nested"
}
]
},
{
"type": "event",
"name": "bytebeasts::systems::tournament::tournament_system::Event",
"kind": "enum",
"variants": [
{
"name": "UpgradeableEvent",
"type": "dojo::contract::upgradeable::upgradeable::Event",
"kind": "nested"
}
]
}
Comment on lines +353 to +364
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add events for tournament state changes

The contract only defines upgrade events but lacks events for important tournament operations:

  • Tournament creation/completion
  • Player registration
  • Tournament status changes

Add these events to provide better transparency and enable off-chain tracking. Example structure:

 {
   "type": "event",
   "name": "bytebeasts::systems::tournament::tournament_system::Event",
   "kind": "enum",
   "variants": [
     {
       "name": "UpgradeableEvent",
       "type": "dojo::contract::upgradeable::upgradeable::Event",
       "kind": "nested"
     },
+    {
+      "name": "TournamentCreated",
+      "type": "bytebeasts::systems::tournament::tournament_system::TournamentCreated",
+      "kind": "nested"
+    },
+    {
+      "name": "TournamentCompleted",
+      "type": "bytebeasts::systems::tournament::tournament_system::TournamentCompleted",
+      "kind": "nested"
+    },
+    {
+      "name": "PlayerRegistered",
+      "type": "bytebeasts::systems::tournament::tournament_system::PlayerRegistered",
+      "kind": "nested"
+    }
   ]
 }

Committable suggestion skipped: line range outside the PR's diff.

]
Loading
Loading