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: 159/283
Findings: 1
Award: $13.63
๐ Selected for report: 0
๐ Solo Findings: 0
๐ Selected for report: 0xDetermination
Also found by: 0x11singh99, 0xAnah, 0xRiO, JcFichtner, K42, MatricksDeCoder, McToady, PetarTolev, Raihan, SAQ, SM3_SS, SY_S, Timenov, ahmedaghadi, al88nsk, dharma09, donkicha, emrekocak, favelanky, hunter_w3b, judeabara, kiqo, lrivo, lsaudit, merlinboii, mikesans, offside0011, oualidpro, peter, rekxor, shamsulhaq123, unique, yashgoel72, yovchev_yoan, ziyou-
13.6293 USDC - $13.63
uint8[] public attributes = [0, 1, 2, 3, 4, 5]; // Instead of string[] public attributes = ["head", "eyes", "mouth", "body", "hands", "feet"];
mapping(uint256 => mapping(uint8 => uint8[])) public attributeProbabilities; mapping(uint8 => uint8) public attributeToDnaDivisor;
// Use uint8[] memory defaultAttributeDivisor = [2, 3, 5, 7, 11, 13]; // instead of uint8[] public defaultAttributeDivisor = [2, 3, 5, 7, 11, 13];
constructor(uint8[][] memory probabilities) { _ownerAddress = msg.sender; uint256 attributesLength = attributes.length; uint8[6] memory defaultAttributeDivisor = [2, 3, 5, 7, 11, 13]; for (uint8 i = 0; i < attributesLength; i++) { attributeProbabilities[0][attributes[i]] = probabilities[i]; attributeToDnaDivisor[attributes[i]] = defaultAttributeDivisor[i]; } }
// Remove this addAttributeProbabilities(0, probabilities);
Is redundant because attributeProbabilities is initialized in line 53 also.
Gas Saving: 94140 gas (minimum)
https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/AiArenaHelper.sol#L47 https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/AiArenaHelper.sol#L70 https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/AiArenaHelper.sol#L72 https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/AiArenaHelper.sol#L96 https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/AiArenaHelper.sol#L98 https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/AiArenaHelper.sol#L135 https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/AiArenaHelper.sol#L147
require( allGameItemAttributes[tokenId].finiteSupply == false || ( allGameItemAttributes[tokenId].finiteSupply == true && quantity <= allGameItemAttributes[tokenId].itemsRemaining ) );
require( allGameItemAttributes[tokenId].finiteSupply == false || quantity <= allGameItemAttributes[tokenId].itemsRemaining );
function updateBattleRecord( uint256 tokenId, uint256 mergingPortion, //@note Could be uint8 uint8 battleResult, uint256 eloFactor, bool initiatorBool ) external { require(msg.sender == _gameServerAddress); require(mergingPortion <= 100);
function _addResultPoints( uint8 battleResult, uint256 tokenId, uint256 eloFactor, uint256 mergingPortion, address fighterOwner )
function viewFighterInfo( Fighter storage self, address owner ) public view returns ( address, uint256[6] memory, uint256, uint256, string memory, string memory, uint16 // Use uint8 instead of uint16 ) { return ( owner, getFighterAttributes(self), self.weight, self.element, self.modelHash, self.modelType, self.generation ); }
function uniqueTokensOutstanding() public view returns (uint256) { return allGameItemAttributes.length; // @note why not return _itemCount ? }
#0 - raymondfam
2024-02-25T21:41:10Z
8 generic G typically not found in the bot.
#1 - c4-pre-sort
2024-02-25T21:41:14Z
raymondfam marked the issue as sufficient quality report
#2 - c4-judge
2024-03-19T07:51:34Z
HickupHH3 marked the issue as grade-b