Platform: Code4rena
Start Date: 09/02/2024
Pot Size: $60,500 USDC
Total HM: 17
Participants: 283
Period: 12 days
Judge:
Id: 328
League: ETH
Rank: 127/283
Findings: 1
Award: $20.07
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: 0xSmartContract
Also found by: 0xAsen, 0xDetermination, 0xStriker, 0xblack_bird, 0xbrett8571, 0xepley, 0xweb3boy, 14si2o_Flint, Bauchibred, DarkTower, JayShreeRAM, JcFichtner, K42, McToady, Myd, PoeAudits, Rolezn, SAQ, ZanyBonzy, aariiif, albahaca, ansa-zanjbeel, cheatc0d3, clara, cudo, dimulski, fouzantanveer, foxb868, hassanshakeel13, hunter_w3b, kaveyjoe, klau5, peanuts, pipidu83, popeye, rspadi, scokaf, shaflow2, tala7985, wahedtalash77, yongskiws
20.0744 USDC - $20.07
Overview
AI Arena is a PvP platform fighting game where the fighters are AIs that were trained by humans. In the web3 version of our game, these fighters are tokenized via the FighterFarm.sol smart contract. Players are able to enter their NFT fighters into ranked battle to earn rewards in our native token $NRN. Our token is an ERC20 token, as defined in the Neuron.sol smart contract. During deployment, we grant our RankedBattle.sol smart contract the MINTER and STAKER roles in order to facilitate our reward system. Additionally, the FighterFarm.sol and GameItems.sol smart contracts are granted the SPENDER role to allow for in-game purchases with our native token. Players are only able to earn $NRN in our game by staking their tokens and winning. However, it is important to note that it is possible for players to lose part of their stake if they perform poorly. Additionally, to level the playing field, we take the square root of the amount staked to calculate the stakingFactor , which is used in the points calculation after each ranked match.
Scope
The engagement involved analyzing nine (9) different Solidity Smart Contracts:
AiArenaHelper.sol: This contract creates mint passes for those who have qualified, which are claimable for AI Arena fighters at a later date
FighterFarm.sol: This contract manages the creation, ownership, and redemption of AI Arena Fighter NFTs, including the ability to mint new NFTs from a merging pool or through the redemption of mint passes.
FighterOps.sol: This library defines the Fighter struct and contains methods for fetching information about a fighter.
GameItems.sol: This contract represents a collection of game items used in AI Arena.
MergingPool.sol: This contract allows users to stake their fighters to earn rewards.
Neuron.sol: The Neuron token is used for various functions within the platform, including staking, governance, and rewards.
RankedBattle.sol: This contract provides functionality for staking NRN tokens on fighters, tracking battle records, calculating and distributing rewards based on battle outcomes and staked amounts, and allowing claiming of accumulated rewards.
StakeAtRisk.sol: This contract allows the RankedBattle contract to manage the staking of NRN tokens at risk during battles.
VoltageManager.sol: This contract allows the management of voltage for game items and provides functions for using and replenishing voltage.
*Unique:
*Existing Patterns:
solidity AccessControl
.*Strengths:
*Weaknesses:
Contracts have owners with privileged rights to perform admin tasks and need to be trusted to not perform malicious updates or drain funds.
File: src/Neuron.sol
11: contract Neuron is ERC20, AccessControl {
External Contract Dependencies: AI Arena relies on external contracts from Openzepplin. If any of these contracts have vulnerabilities, it would affect the protocol.
Test Coverage: The test coverage provided by AI Arena is: 90% however, 100% tests coverage is recommended.
Like any smart contract-based system, AI Arena is exposed to potential coding bugs or vulnerabilities. Exploiting these issues could result in the loss of funds or manipulation of the protocol.
The AI Arena documentation is quite comprehensive and detailed, providing a solid overview of how the protocol is structured and how its various aspects function. However, there is room for additional details, such as more diagrams, to gain a deeper understanding of how different contracts interact and their functions. I would also recommend creating quality Medium articles, it’s a great way to provide an in-depth look at many of the topics in the project and it is used by many blockchain projects.
See automated findings here
The 4naly3er report can be found here.
AI Arena’s architecture seems solid in general, none the less here are some areas that could be improved:
Testing and Simulations: I recommend creating a live testnet app. Here is an example from The Open Dollar protocol. Conduct thorough testing of all contracts and functions and simulations to understand how they will behave under various market conditions.
Monitoring Recommendations: While audits help in identifying code-level issues in the current implementation and potentially the code deployed in production, the AI Arena team is encouraged to consider incorporating monitoring activities in the production environment. Ongoing monitoring of deployed contracts helps identify potential threats and issues affecting production environments. With the goal of providing a complete security assessment, the monitoring recommendations section raises several actions addressing trust assumptions and out-of-scope components that can benefit from on-chain monitoring.
I recommend rewriting some of the tests in the codebase for this audit to use the actual contracts instead of mock addresses like in some cases. This will offer greater confidence during system deployment.
Financial Activity: Consider monitoring the token transfers over the bridge to identify: Transfers during normal operations to establish a baseline of healthy properties. Any large deviation, such as an unexpectedly large withdrawal, may indicate unusual behavior of the contracts or an ongoing attack. Transactions that revert. These may indicate a user interface bug, an ongoing attack or other unexpected edge cases.
Gas Optimizations
Other recommendations
My analysis of the AI Arena protocol Included understanding the architecture, mechanism, overall codebase, and possible risks associated with the protocol.
Day 1: I spent time reading the available documentation in order to have a deep understanding of the protocol.
Day 2: I analyzed the codebase for better understanding, Performed a Mechanism review, and investigated possible systemic risks, and centralization risks.
Day 3: I dedicated this day to coming up with possible Architecture recommendations after identifying possible risks and prepared the final analysis report.
Conclusion
The AI Arena ecosystem is a well-designed and innovative NFT platform fighting game offering a wide range of features and capabilities. However, there are areas where improvements could be made, particularly in terms of permission management, gas efficiency, and potential exploitation of certain modules. By addressing these issues, AI Arena could become even more secure, efficient, and reliable.
24 hours
#0 - c4-pre-sort
2024-02-25T20:34:00Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2024-03-19T08:12:48Z
HickupHH3 marked the issue as grade-b