AI Arena - okolicodes'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: 237/283

Findings: 1

Award: $1.03

🌟 Selected for report: 0

🚀 Solo Findings: 0

Lines of code

https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/RankedBattle.sol#L519-L535

Vulnerability details

Impact

The users Staking factor fails to increase and as such remains same no matter their stake amount.

Proof of Concept

In the projects documentation, the staking factor helps to determine the amount of rewards a user could receive for a given round based on their staked amount. According to the docs, "The more NRN a player stakes, the more Points their Challenger NFT can accumulates" tho as the user stake increases the impact of the marginal NRN staked decreases as more NRN is staked. The issue here is that Based on the code implementation the staking factor is calculated wrongly and would always return 1 no matter the amount an average user stakes.

  function _getStakingFactor( uint256 tokenId, uint256 stakeAtRisk) private view 
        returns (uint256) 
    {
      uint256 stakingFactor_ = FixedPointMathLib.sqrt(
          (amountStaked[tokenId] + stakeAtRisk) / 10**18
      );
      if (stakingFactor_ == 0) {
        stakingFactor_ = 1;
      }
      return stakingFactor_;
    }    
}  

You can see that the calculation is given as the squareroot of (amountStaked[tokenId] + stakeAtRisk) / 10**18 Lets assume that a Fighter newly stakes 1000 NRN and has no stake at risk. The calculation will result to a zero number which will return 1. Even if a fighter stakes 1,000,000 NRN or 1,000,000,000 NRN tokens, with the above formular, the square root will always return a zero number still and therefore return 1. This is a flawed implementation as: users staking factor won't grow and cannot yield them rewards as supposed.

Tools Used

Manual Review + Godspeed

The divisor is a very large number and should be reduced

Assessed type

Other

#0 - c4-pre-sort

2024-02-22T16:28:34Z

raymondfam marked the issue as insufficient quality report

#1 - raymondfam

2024-02-22T16:30:12Z

1 NRN is 1e18 wei. 100 * 1e18 NRN would yield a factor 10.

#2 - c4-pre-sort

2024-02-22T16:30:23Z

raymondfam marked the issue as duplicate of #38

#3 - c4-judge

2024-03-07T02:58:22Z

HickupHH3 changed the severity to 3 (High Risk)

#4 - c4-judge

2024-03-07T03:18:49Z

HickupHH3 marked the issue as partial-50

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