AI Arena - tpiliposian's results

In AI Arena you train an AI character to battle in a platform fighting game. Imagine a cross between PokΓ©mon and Super Smash Bros, but the characters are AIs, and you can train them to learn almost any skill in preparation for battle.

General Information

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

AI Arena

Findings Distribution

Researcher Performance

Rank: 271/283

Findings: 2

Award: $0.04

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Lines of code

https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/GameItems.sol#L289-L303 https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/GameItems.sol#L204

Vulnerability details

Impact

In the GameItems.sol contract there is a potential security issue that could allow users to bypass transfer restrictions set by the contract. Specifically, users could exploit the ERC1155's safeBatchTransferFrom function to transfer tokens in batches, potentially bypassing individual transfer restrictions imposed by the contract.

Proof of Concept

The GameItems.sol contract implements transfer restrictions using a boolean flag to determine if a game item is transferable.

    /// @param transferable Boolean of whether or not the game item can be transferred

However, the ERC1155 standard's safeBatchTransferFrom function does not perform individual transferability checks for each token in the batch, allowing users to transfer tokens in batches regardless of their transferability status.

     * @dev See {IERC1155-safeBatchTransferFrom}.
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory values,
        bytes memory data
    ) public virtual {
        address sender = _msgSender();
        if (from != sender && !isApprovedForAll(from, sender)) {
            revert ERC1155MissingApprovalForAll(sender, from);
        }
        _safeBatchTransferFrom(from, to, ids, values, data);
    }

Tools Used

Manual review.

Consider overriding the safeBatchTransferFrom function to perform transferability checks for each token being transferred in the batch or disallow batch transferring.

Assessed type

Other

#0 - c4-pre-sort

2024-02-22T03:46:59Z

raymondfam marked the issue as sufficient quality report

#1 - c4-pre-sort

2024-02-22T03:47:06Z

raymondfam marked the issue as duplicate of #18

#2 - c4-pre-sort

2024-02-26T00:27:51Z

raymondfam marked the issue as duplicate of #575

#3 - c4-judge

2024-03-05T04:53:08Z

HickupHH3 marked the issue as satisfactory

Lines of code

https://github.com/code-423n4/2024-02-ai-arena/blob/f2952187a8afc44ee6adc28769657717b498b7d4/src/FighterFarm.sol#L484-L531 https://github.com/code-423n4/2024-02-ai-arena/blob/f2952187a8afc44ee6adc28769657717b498b7d4/src/FighterFarm.sol#L307-L331

Vulnerability details

Impact

The vulnerability in the FighterFarm smart contract stems from its reliance on on-chain randomness, which can be predictable, and the susceptibility to manipulation through the fighters.length property. This combination allows users to potentially manipulate the creation process of fighters, leading to unfair advantages in the associated game or ecosystem.

Proof of Concept

mintFromMergingPool function is calling _createNewFighter with these parameters:

    function mintFromMergingPool(
        address to, 
        string calldata modelHash, 
        string calldata modelType, 
        uint256[2] calldata customAttributes
    ) 
        public 
    {
        require(msg.sender == _mergingPoolAddress);
        _createNewFighter(
            to, 
@>          uint256(keccak256(abi.encode(msg.sender, fighters.length))), 
            modelHash, 
            modelType,
            0,
            0,
            customAttributes
        );
    }

So the dna of the fighter is being calculated throughout the on-chain randomness, moreover using the fighters.length, which any user can change (increase) with creating new fighter:

    function _createNewFighter(
        address to, 
        uint256 dna, 
        string memory modelHash,
        string memory modelType, 
        uint8 fighterType,
        uint8 iconsType,
        uint256[2] memory customAttributes
    ) 
        private 
    {  
        require(balanceOf(to) < MAX_FIGHTERS_ALLOWED);
        uint256 element; 
        uint256 weight;
        uint256 newDna;
        if (customAttributes[0] == 100) {
            (element, weight, newDna) = _createFighterBase(dna, fighterType);
        }
        else {
            element = customAttributes[0];
            weight = customAttributes[1];
            newDna = dna;
        }
        uint256 newId = fighters.length;

        bool dendroidBool = fighterType == 1;
        FighterOps.FighterPhysicalAttributes memory attrs = _aiArenaHelperInstance.createPhysicalAttributes(
            newDna,
            generation[fighterType],
            iconsType,
            dendroidBool
        );
@>      fighters.push(
            FighterOps.Fighter(
                weight,
                element,
                attrs,
                newId,
                modelHash,
                modelType,
                generation[fighterType],
                iconsType,
                dendroidBool
            )
        );
        _safeMint(to, newId);
        FighterOps.fighterCreatedEmitter(newId, weight, element, generation[fighterType]);
    }

By artificially increasing the length of the fighters array, an attacker can influence the randomization process used to generate attributes for newly created fighters. This manipulation allows the attacker to bias the creation of fighters in their favor, granting them unfair advantages within the game.

Tools Used

Manual review.

Use off-chain randomness, e.g. Chainlink VRF.

Assessed type

Other

#0 - c4-pre-sort

2024-02-24T01:25:20Z

raymondfam marked the issue as sufficient quality report

#1 - c4-pre-sort

2024-02-24T01:26:09Z

raymondfam marked the issue as duplicate of #53

#2 - c4-judge

2024-03-06T03:47:25Z

HickupHH3 marked the issue as satisfactory

#3 - c4-judge

2024-03-15T02:10:54Z

HickupHH3 changed the severity to 2 (Med Risk)

#4 - c4-judge

2024-03-20T01:04:04Z

HickupHH3 marked the issue as duplicate of #376

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax Β© 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter