Users relying on the getStakeAtRisk function may receive inaccurate information about the stake at risk for a fighter in the current round.
Proof of Concept
In the StakeAtRisk contract, the getStakeAtRisk function retrieves the stake amount for a fighter in the current round directly from the stakeAtRisk mapping without considering any reclaimed stakes. As a result, the function consistently returns the total stake amount without adjusting for stakes that have been reclaimed by the fighter. This oversight leads to an incorrect representation of the stake at risk, impacting the reliability and fairness of the system.
function getStakeAtRisk(uint256 fighterId) external view returns(uint256) {
return stakeAtRisk[roundId][fighterId];
}
Test Case and Test Result:
Test Case:
/// @notice Test getting the stake at risk for a players fighter that has stake at risk.
function testGetStakeAtRisk() public {
address player = vm.addr(3);
uint256 stakeAmount = 3_000 * 10 ** 18;
uint256 expectedStakeAtRiskAmount = (stakeAmount * 100) / 100000;
uint256 tokenId = 0;
// player gets fighter
_mintFromMergingPool(player);
assertEq(_fighterFarmContract.ownerOf(tokenId), player);
// player gets NRN
_fundUserWith4kNeuronByTreasury(player);
vm.prank(player);
// player stakes NRN
_rankedBattleContract.stakeNRN(stakeAmount, 0);
assertEq(_rankedBattleContract.amountStaked(0), stakeAmount);
// player battles
vm.prank(address(_GAME_SERVER_ADDRESS));
// loses battle
_rankedBattleContract.updateBattleRecord(0, 50, 2, 1500, true);
assertEq(_stakeAtRiskContract.stakeAtRisk(0, 0), expectedStakeAtRiskAmount);
assertEq(_stakeAtRiskContract.getStakeAtRisk(tokenId), expectedStakeAtRiskAmount);
}
The getStakeAtRisk function should be modified to deduct any reclaimed stakes from the total stake at risk for the fighter in the current round before returning the result.
Lines of code
https://github.com/code-423n4/2024-02-ai-arena/blob/cd1a0e6d1b40168657d1aaee8223dc050e15f8cc/src/StakeAtRisk.sol#L132-L134
Vulnerability details
Impact
Users relying on the
getStakeAtRisk
function may receive inaccurate information about the stake at risk for a fighter in the current round.Proof of Concept
In the
StakeAtRisk
contract, thegetStakeAtRisk
function retrieves the stake amount for a fighter in the current round directly from thestakeAtRisk
mapping without considering any reclaimed stakes. As a result, the function consistently returns the total stake amount without adjusting for stakes that have been reclaimed by the fighter. This oversight leads to an incorrect representation of the stake at risk, impacting the reliability and fairness of the system.Test Case and Test Result: Test Case:
Test Result:
Tools Used
Manual. Foundry
Recommended Mitigation Steps
The
getStakeAtRisk
function should be modified to deduct any reclaimed stakes from the total stake at risk for the fighter in the current round before returning the result.Assessed type
Other