Unsafe casting in RewardsDistributorV2 leads to underflow of ve_for_at
Vulnerability Detail
Solidity does not revert when casting a negative number to uint. Instead, it underflows to a large
number. In the RewardDistributor contract, the balance of a token at a specific time is calculated as follows:
sonny2k
Medium
Unsafe casting in RewardsDistributorV2 leads to underflow of ve_for_at
Vulnerability Detail
Solidity does not revert when casting a negative number to uint. Instead, it underflows to a large number. In the RewardDistributor contract, the balance of a token at a specific time is calculated as follows:
This is supposed to return zero when the calculated balance is a negative number. However, it underflows to a large number.
Impact
This would lead to incorrect reward distribution if third-party protocols depend on this function, or when further updates make use of this codebase.
Code Snippet
https://github.com/sherlock-audit/2024-06-velocimeter/blob/main/v4-contracts/contracts/RewardsDistributorV2.sol#L134-L140
Tool used
Manual Review
Recommendation
Recommend following other parts of the codebase and returning zero for a negative number.
Also, recommend applying the fix to other parts of RewardsDistributorV2 as well