code-423n4 / 2024-03-abracadabra-money-findings

9 stars 7 forks source link

Incorrect rewards calculation with low balances (rounding down to zero) #185

Closed c4-bot-9 closed 8 months ago

c4-bot-9 commented 8 months ago

Lines of code

https://github.com/code-423n4/2024-03-abracadabra-money/blob/1f4693fdbf33e9ad28132643e2d6f7635834c6c6/src/staking/LockingMultiRewards.sol#L292-L295

Vulnerability details

[M-08] Incorrect rewards calculation with low balances (rounding down to zero)

Impact

Proof of Concept

LockingMultiRewards._earned function

    function _earned(address user, uint256 balance_, address rewardToken, uint256 rewardPerToken_) internal view returns (uint256) {
        uint256 pendingUserRewardsPerToken = rewardPerToken_ - userRewardPerTokenPaid[user][rewardToken];
        return ((balance_ * pendingUserRewardsPerToken) / 1e18) + rewards[user][rewardToken];
    }

Tools Used

Manual Review.

Recommended Mitigation Steps

Implement a mechanism that prevents updating the rewards[user_][token_] if (balance_ * pendingUserRewardsPerToken) is < 1e18 .

Assessed type

Math

0xm3rlin commented 8 months ago

no factor

c4-pre-sort commented 8 months ago

141345 marked the issue as insufficient quality report

141345 commented 8 months ago

similar to https://github.com/code-423n4/2024-03-abracadabra-money-findings/issues/166, but lack detailed POC why rounding could have problem

thereksfour commented 8 months ago

Invalid, 1e18 is the amplifier for rewardPerToken_ to prevent rounding losses, divided by 1e18 is the correct reward amount

c4-judge commented 8 months ago

thereksfour marked the issue as unsatisfactory: Invalid