Closed sherlock-admin closed 1 year ago
While technically correct the precision loss would be limited to 3/4 decimals, and will not have a material impact when applied to the "minAmountOut" parameter.
We might adjust the order anyway, but will review first internally.
Not sure about "medium" severity, since this does not seem to have a material impact on the user experience / protocol safety.
The proposed fix to flip the order of operations here looks reasonable to me đź‘Ť
I believe sherlock does mark this issue as a med in most cases because there is a small impact in the calculation of funds
There are several instances on the code where this happens, all of them market as duplicates. I believe that a small truncation where precission would be needed due to calculating any type of repayment is a medium
While technically correct the precision loss would be limited to 3/4 decimals, and will not have a material impact when applied to the "minAmountOut" parameter.
Considering this issue as a low
Fix looks good. Instances of div before mul have been swapped
ShadowForce
high
division before multiplication may result in truncation of result
Summary
division before multiplication may result in truncation of result
Vulnerability Detail
in the snippet above we can see there is division before multiplication. As we all know doing this can result in truncation. funds may be lost (0) due to division before multiplication precision issues
for example: if _actionInfo.borrowPrice is less than 1, it will be truncated to 0. any further multiplication with this number will also result in 0. we observe multiplication after this point in this specific place.
all multiplacation must first be done before we decide to divide.
Impact
funds may be lost (0) due to division before multiplication precision issues
Code Snippet
https://github.com/IndexCoop/index-coop-smart-contracts/blob/317dfb677e9738fc990cf69d198358065e8cb595/contracts/adapters/AaveLeverageStrategyExtension.sol#L1147-L1152
Tool used
Manual Review
Recommendation
multiply first then divide to avoid precision loss