DeFiHardhat
12,000 USDC
View results
Submission Details
Severity: low
Invalid

Missing muldiv usage can lead to overflow

Summary

Calculations throughout the contract use the mulDiv function. This prevents overflows unless the result itself is larger than uint256. However in the _capLpTokenSupply function the code does a raw multiplication followed by a raw division. This can lead to overflows if the result of the multiplication is larger than uint256.

Vulnerability Details

When calculating the LPtokenSupply capped values, if the LP has increased, the new capped LP supply is calculated as

lastLpTokenSupply.mulDiv(tempExp.to128x128().toUint256(), CAP_PRECISION2)

This uses the mulDiv since the intermediate result of lastLpTokenSupply * tempExp can be larger than uint256, especially since one is an exponentiated term and the other is scaled up by the CAP_PRECISION2 factor.

In fact, the chances of overflowing increase over time, since the tempExp term grows with time.

However, when calculating the capped LPtokenSupply on a decrease in LP, the code does a raw multiplication followed by a raw division.

lastLpTokenSupply
* (ABDKMathQuad.ONE.sub(crp.maxLpSupplyDecrease)).powu(capExponent).to128x128().toUint256() / CAP_PRECISION2;

This function should also use the mulDiv function so that the function does not revert due to overflow if the intermediate result is larger than uint256.

Impact

The calculation can revert due to underflow due to not using the mulDiv function. Can lead to a bricked well.

Tools Used

Manual Review

Recommendations

Use the mulDiv function in the _capLpTokenSupply function to prevent overflows.

Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

Informational/Invalid

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.