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: 39/283
Findings: 1
Award: $166.17
🌟 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
166.1676 USDC - $166.17
AI Arena is a PvP battle game on the web3 platform using L2, where the fighters are artificial intelligence (AI) trained by humans. Each fighter has physical attributes, generation, weight, element, fighter type, and model data.
Structuring the code is crucial for conducting a thorough analysis of the code base. This enables auditors to predict the level of contract difficulty, identify critical contracts, and determine security-critical features such as payment functions or assembly usage. Additionally, this approach accurately measures the time required to perform a detailed audit and helps determine the cost of a project audit. To achieve efficiency, clarity, and improvements, it is essential to have a comprehensive view of the entire architecture. This enables the identification of the basic structure, relationships between modules, and key design patterns. By understanding the big picture, we can analyze the complexity of the code and reveal its strengths and potential for improvement with confidence.
We began by thoroughly reviewing and read docs AI Arena procotol the provided documentations, as well as reviewing the video provided. Here, we made note of important information, noted down unclear parts and overall tried to fully understand how the protocol should function. We also took notes of integrated and inherited protocols and mapped out possible risk areas.
While we were studying the docs, we had ran static analyzers and linters through the contracts to detect basic vulnerabilities and other non critical errors. The result of our static analysis was then compared to the provided bot reports and those deemed known were removed.
After the documentation review and static analysis, we started the process of manual code inspection. We noted how the contracts were divided into different modules and we inspected the contracts in each module carefully. We stuidied each of the contracts, tested how each function behaves and compared that to how they're expected to behave. We then tried out various attack ideas, including the ones provided by the sponsors. We noted the dependencies, inheritancies, and possible vulnerabilities that can arise from them. We made comparisons to issues found in protocols of the same kind (including older commits) to see if the same mistakes were repeated and how effective the provided fixes were.
After this was done, we made notes on the issues we found and prepared the analysis report.
Issue | Description | Recommendation |
---|---|---|
Potential reentrancy attack | The reRoll function calls an external contract's function (_neuronInstance.transferFrom) which can potentially allow a reentrancy attack. | Consider using the Checks-Effects-Interactions pattern to prevent reentrancy attacks. Move the external call to the end of the function, after all state changes have been made. |
Function complexity | The claimFighters function has multiple responsibilities, including verifying the signature, updating the nftsClaimed mapping, and creating new fighters. | Split the function into smaller, more manageable functions to improve readability and maintainability. |
Unclear function behavior | The behavior of the _createFighterBase function is not clear, especially how the dna parameter is used to calculate the element and weight values. | Add comments or documentation to explain the function's behavior and how the input parameters are used. |
Function complexity | The _createFighterBase function contains multiple calculations that could be simplified. | Simplify the function by calculating the element and weight values in a single line, and removing the unnecessary newDna calculation. |
Memory allocation | Memory allocation concern in _updateRecord function. | The _updateRecord function may lead to memory fragmentation or excessive memory usage due to frequent updates to the fighterBattleRecord mapping. Suggest considering alternative data structures or memory management techniques to mitigate this concern. |
Resource leakage | possibility in _updateRecord function. | The _updateRecord function might not release or reset resources properly after execution, potentially leading to memory leaks. Recommend adding checks or cleanup routines to ensure proper resource management. |
tokenId
. This can be inefficient for large collections.allGameItemAttributes
with a mapping that uses the token ID as the key.price
is used without explanation.const uint256 PRICE_MULTIPLIER = 1e18;
and use it to calculate the price: uint256 totalCost = allGameItemAttributes[tokenId].itemPrice.mul(quantity).mul(PRICE_MULTIPLIER);
.allGameItemAttributes[tokenId].itemsRemaining - quantity
can result in underflow if quantity
is larger than the remaining items.const uint256 DAY = 1 days;
and use it to calculate the replenish time: dailyAllowanceReplenishTime[owner][tokenId] = block.timestamp + DAY;
.remaining - amount
can result in underflow if amount
is larger than the remaining allowance.Change it to something more descriptive
price
to totalCost
Function purpose is not clear from its name , Change it to something more descriptive
Exemplary unit test coverage: The codebase shines with its meticulous unit testing strategy. The comprehensive suite of unit tests ensures the reliability and resilience of the system's core functionality, providing confidence in its performance under various scenarios.
Artful integration of Natspec: A commendable strength is the thoughtful integration of Natspec. The use of this documentation format not only improves code readability, but also exemplifies a commitment to providing clear and human-friendly documentation that fosters a more collaborative and accessible development environment.
Opportunities to improve documentation: While the codebase stands out in many ways, there is an opportunity for refinement in the documentation. Addressing this area of improvement can increase the overall clarity of the codebase, make it more accessible, and facilitate seamless collaboration among developers. In essence, the codebase demonstrates proficiency in testing methodologies and documentation practices. Strengthening the documentation further would strengthen the codebase's comprehensibility and contribute to an even more polished and developer-friendly ecosystem.
NRN rewards are based on NFT performance, amount staked, and Elo rating.
There is a risk of losing points and bets for players who lose.
In general, the AI Arena project exhibits an interesting and well-developed architecture we believe the team has done a good job regarding the code, but the identified risks need to be addressed, and measures should be implemented to protect the protocol from potential malicious use cases. Additionally, it is recommended to improve the documentation and comments in the code to enhance understanding and collaboration among developers. It is also highly recommended that the team continues to invest in security measures such as mitigation reviews, audits, and bug bounty programs to maintain the security and reliability of the project.
53 hours
#0 - c4-pre-sort
2024-02-25T20:21:18Z
raymondfam marked the issue as high quality report
#1 - c4-sponsor
2024-03-04T01:56:49Z
brandinho (sponsor) acknowledged
#2 - c4-judge
2024-03-19T08:26:30Z
HickupHH3 marked the issue as grade-a